Kagome
Polkadot Runtime Engine in C++17
block_storage_impl.hpp
Go to the documentation of this file.
1 
6 #ifndef KAGOME_BLOCKCHAIN_BLOCKSTORAGEIMPL
7 #define KAGOME_BLOCKCHAIN_BLOCKSTORAGEIMPL
8 
10 
12 #include "crypto/hasher.hpp"
13 #include "log/logger.hpp"
15 
16 namespace kagome::blockchain {
17 
18  class BlockStorageImpl : public BlockStorage {
19  public:
20  ~BlockStorageImpl() override = default;
21 
29  static outcome::result<std::shared_ptr<BlockStorageImpl>> create(
30  storage::trie::RootHash state_root,
31  const std::shared_ptr<storage::BufferStorage> &storage,
32  const std::shared_ptr<crypto::Hasher> &hasher);
33 
34  outcome::result<std::vector<primitives::BlockHash>> getBlockTreeLeaves()
35  const override;
36  outcome::result<void> setBlockTreeLeaves(
37  std::vector<primitives::BlockHash> leaves) override;
38 
39  outcome::result<bool> hasBlockHeader(
40  const primitives::BlockId &id) const override;
41 
42  outcome::result<std::optional<primitives::BlockHeader>> getBlockHeader(
43  const primitives::BlockId &id) const override;
44  outcome::result<std::optional<primitives::BlockBody>> getBlockBody(
45  const primitives::BlockId &id) const override;
46  outcome::result<std::optional<primitives::BlockData>> getBlockData(
47  const primitives::BlockId &id) const override;
48  outcome::result<std::optional<primitives::Justification>> getJustification(
49  const primitives::BlockId &block) const override;
50 
51  outcome::result<void> putNumberToIndexKey(
52  const primitives::BlockInfo &block) override;
53 
54  outcome::result<primitives::BlockHash> putBlockHeader(
55  const primitives::BlockHeader &header) override;
56  outcome::result<void> putBlockData(
57  primitives::BlockNumber block_number,
58  const primitives::BlockData &block_data) override;
59  outcome::result<void> removeBlockData(
60  primitives::BlockNumber block_number,
61  const primitives::BlockDataFlags &remove_flags) override;
62  outcome::result<primitives::BlockHash> putBlock(
63  const primitives::Block &block) override;
64 
65  outcome::result<void> putJustification(
67  const primitives::BlockHash &hash,
68  primitives::BlockNumber number) override;
69  outcome::result<void> removeJustification(
70  const primitives::BlockHash &hash,
71  primitives::BlockNumber number) override;
72 
73  outcome::result<void> removeBlock(
74  const primitives::BlockInfo &block) override;
75 
76  outcome::result<primitives::BlockInfo> getLastFinalized() const override;
77 
78  private:
79  BlockStorageImpl(std::shared_ptr<storage::BufferStorage> storage,
80  std::shared_ptr<crypto::Hasher> hasher);
81 
82  std::shared_ptr<storage::BufferStorage> storage_;
83  std::shared_ptr<crypto::Hasher> hasher_;
85 
86  mutable std::optional<std::vector<primitives::BlockHash>>
88  };
89 } // namespace kagome::blockchain
90 
91 #endif // KAGOME_BLOCKCHAIN_BLOCKSTORAGEIMPL
outcome::result< void > putJustification(const primitives::Justification &j, const primitives::BlockHash &hash, primitives::BlockNumber number) override
Block class represents polkadot block primitive.
Definition: block.hpp:19
outcome::result< void > removeBlockData(primitives::BlockNumber block_number, const primitives::BlockDataFlags &remove_flags) override
outcome::result< void > setBlockTreeLeaves(std::vector< primitives::BlockHash > leaves) override
outcome::result< void > removeJustification(const primitives::BlockHash &hash, primitives::BlockNumber number) override
outcome::result< void > putBlockData(primitives::BlockNumber block_number, const primitives::BlockData &block_data) override
BlockStorageImpl(std::shared_ptr< storage::BufferStorage > storage, std::shared_ptr< crypto::Hasher > hasher)
outcome::result< std::optional< primitives::Justification > > getJustification(const primitives::BlockId &block) const override
uint32_t BlockNumber
Definition: common.hpp:18
outcome::result< void > putNumberToIndexKey(const primitives::BlockInfo &block) override
std::shared_ptr< storage::BufferStorage > storage_
std::shared_ptr< soralog::Logger > Logger
Definition: logger.hpp:23
outcome::result< std::optional< primitives::BlockData > > getBlockData(const primitives::BlockId &id) const override
static outcome::result< std::shared_ptr< BlockStorageImpl > > create(storage::trie::RootHash state_root, const std::shared_ptr< storage::BufferStorage > &storage, const std::shared_ptr< crypto::Hasher > &hasher)
std::optional< std::vector< primitives::BlockHash > > block_tree_leaves_
outcome::result< primitives::BlockInfo > getLastFinalized() const override
outcome::result< bool > hasBlockHeader(const primitives::BlockId &id) const override
Check if header existing by provided block {.
outcome::result< std::vector< primitives::BlockHash > > getBlockTreeLeaves() const override
outcome::result< std::optional< primitives::BlockHeader > > getBlockHeader(const primitives::BlockId &id) const override
boost::variant< BlockHash, BlockNumber > BlockId
Block id is the variant over BlockHash and BlockNumber.
Definition: block_id.hpp:18
outcome::result< void > removeBlock(const primitives::BlockInfo &block) override
outcome::result< std::optional< primitives::BlockBody > > getBlockBody(const primitives::BlockId &id) const override
outcome::result< primitives::BlockHash > putBlockHeader(const primitives::BlockHeader &header) override
outcome::result< primitives::BlockHash > putBlock(const primitives::Block &block) override
std::shared_ptr< crypto::Hasher > hasher_