6 #ifndef KAGOME_BLOCKCHAIN_TREE_NODE_HPP 7 #define KAGOME_BLOCKCHAIN_TREE_NODE_HPP 10 #include <unordered_set> 24 class TreeNode :
public std::enable_shared_from_this<TreeNode> {
34 const std::shared_ptr<TreeNode> &
parent,
42 std::vector<std::shared_ptr<TreeNode>>
children{};
52 return std::const_pointer_cast<
TreeNode>(
53 std::as_const(*this).findByHash(hash));
74 std::function<outcome::result<ExitToken>(
TreeNode const &node)>
const 78 return {
depth, block_hash};
91 const std::shared_ptr<TreeNode> &subtree_root_node,
92 std::optional<primitives::Justification> last_finalized_justification);
94 TreeMeta(std::unordered_set<primitives::BlockHash> leaves,
95 const std::shared_ptr<TreeNode> &deepest_leaf,
96 const std::shared_ptr<TreeNode> &last_finalized,
99 std::unordered_set<primitives::BlockHash>
leaves;
112 std::shared_ptr<TreeMeta> metadata)
113 : root_{std::move(root)}, metadata_{std::move(metadata)} {
114 BOOST_ASSERT(root_ !=
nullptr);
115 BOOST_ASSERT(metadata_ !=
nullptr);
123 void updateTreeRoot(std::shared_ptr<TreeNode> new_trie_root,
126 void updateMeta(
const std::shared_ptr<TreeNode> &new_node);
134 void removeFromMeta(
const std::shared_ptr<TreeNode> &node);
139 TreeMeta const &getMetadata()
const;
149 #endif // KAGOME_BLOCKCHAIN_TREE_NODE_HPP
bool operator==(const TreeNode &other) const
std::shared_ptr< TreeNode > root_
CachedTree(std::shared_ptr< TreeNode > root, std::shared_ptr< TreeMeta > metadata)
primitives::BlockInfo getBlockInfo() const
outcome::result< void > applyToChain(const primitives::BlockInfo &chain_end, std::function< outcome::result< ExitToken >(TreeNode const &node)> const &op) const
primitives::BlockNumber depth
std::shared_ptr< TreeMeta > metadata_
std::vector< std::shared_ptr< TreeNode > > children
std::shared_ptr< TreeNode > findByHash(const primitives::BlockHash &hash)
bool operator!=(const TreeNode &other) const
primitives::BlockHash block_hash
OUTCOME_HPP_DECLARE_ERROR(kagome::blockchain, TreeNode::Error)
std::shared_ptr< const TreeNode > findByHash(const primitives::BlockHash &hash) const
TreeNode(const primitives::BlockHash &hash, primitives::BlockNumber depth, bool finalized=false)
std::weak_ptr< TreeNode > parent