Skip to content

Commit

Permalink
fix removeLeaf (#1842)
Browse files Browse the repository at this point in the history
Signed-off-by: turuslan <turuslan.devbox@gmail.com>
  • Loading branch information
turuslan authored Oct 11, 2023
1 parent 0b5266b commit cad050d
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 2 deletions.
1 change: 1 addition & 0 deletions core/blockchain/block_tree_error.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ namespace kagome::blockchain {
SOME_BLOCK_IN_CHAIN_NOT_FOUND,
// block is not a leaf
BLOCK_IS_NOT_LEAF,
BLOCK_IS_FINALIZED,
BLOCK_NOT_EXISTS
};
} // namespace kagome::blockchain
Expand Down
2 changes: 2 additions & 0 deletions core/blockchain/impl/block_tree_error.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,8 @@ OUTCOME_CPP_DEFINE_CATEGORY(kagome::blockchain, BlockTreeError, e) {
return "the requested block body is not found in block storage";
case E::BLOCK_IS_NOT_LEAF:
return "the target block is not a leaf";
case E::BLOCK_IS_FINALIZED:
return "the target block is finalized";
case E::BLOCK_NOT_EXISTS:
return "target block doesn't exist";
}
Expand Down
6 changes: 4 additions & 2 deletions core/blockchain/impl/block_tree_impl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -596,8 +596,10 @@ namespace kagome::blockchain {
return block_tree_data_.exclusiveAccess(
[&](BlockTreeData &p) -> outcome::result<void> {
// Check if block is leaf
if (block_hash == getLastFinalizedNoLock(p).hash
or p.tree_->isLeaf(block_hash)) {
if (block_hash == getLastFinalizedNoLock(p).hash) {
return BlockTreeError::BLOCK_IS_FINALIZED;
}
if (not p.tree_->isLeaf(block_hash)) {
return BlockTreeError::BLOCK_IS_NOT_LEAF;
}

Expand Down

0 comments on commit cad050d

Please sign in to comment.