Kagome
Polkadot Runtime Engine in C++17
justification_storage_policy.cpp
Go to the documentation of this file.
1 
7 
8 #include <memory>
9 
12 #include "primitives/digest.hpp"
13 
14 namespace kagome::blockchain {
15 
17  primitives::BlockHeader const &block_header) const {
18  if (block_header.number == 0) return true;
19 
20  BOOST_ASSERT_MSG(block_tree_ != nullptr,
21  "Block tree must have been initialized with "
22  "JustificationStoragePolicyImpl::initBlockchainInfo()");
23 
24  auto last_finalized = block_tree_->getLastFinalized();
25  BOOST_ASSERT_MSG(last_finalized.number >= block_header.number,
26  "Target block must be finalized");
27 
28  for (auto &digest : block_header.digest) {
29  if (auto *consensus_digest_enc =
30  boost::get<primitives::Consensus>(&digest);
31  consensus_digest_enc != nullptr) {
32  OUTCOME_TRY(consensus_digest, consensus_digest_enc->decode());
33  bool authority_change =
34  consensus_digest.isGrandpaDigestOf<primitives::ScheduledChange>()
35  || consensus_digest.isGrandpaDigestOf<primitives::ForcedChange>();
36  if (authority_change) return true;
37  }
38  }
39  if (block_header.number % 512 == 0) {
40  return true;
41  }
42  return false;
43  }
44 
46  std::shared_ptr<const blockchain::BlockTree> block_tree) {
47  BOOST_ASSERT_MSG(block_tree_ == nullptr,
48  "Block tree should be initialized once");
49  BOOST_ASSERT(block_tree != nullptr);
50  block_tree_ = block_tree;
51  }
52 
53 } // namespace kagome::blockchain
virtual outcome::result< bool > shouldStoreFor(const primitives::BlockHeader &block) const override
virtual void initBlockchainInfo(std::shared_ptr< const blockchain::BlockTree > block_tree)
Digest digest
chain-specific auxiliary data
BlockNumber number
index of the block in the chain
std::shared_ptr< const blockchain::BlockTree > block_tree_