Skip to content

Commit

Permalink
Fix issue in validated_block_exists_impl when id is not present (…
Browse files Browse the repository at this point in the history
…assert not always true)
  • Loading branch information
greg7mdp committed Sep 17, 2024
1 parent 54f626f commit 3a133d2
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 4 deletions.
1 change: 0 additions & 1 deletion libraries/chain/controller.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1139,7 +1139,6 @@ struct controller_impl {

// returns true if block `id`, or one of its ancestors not older than claimed_id, is found in fork_db
// and `is_valid()`
// precondition: `id` is already in fork_db, so is a descendent of `root`
// ------------------------------------------------------------------------------------------------------
bool fork_db_validated_block_exists( const block_id_type& id, const block_id_type& claimed_id ) const {
return fork_db.apply<bool>([&](const auto& forkdb) {
Expand Down
6 changes: 3 additions & 3 deletions libraries/chain/fork_database.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -610,19 +610,19 @@ namespace eosio::chain {

// returns true if block `id`, or one of its ancestors not older than claimed_id, is found in fork_db
// and `is_valid()`
// precondition: `id` is already in fork_db, so is a descendent of `root`
// ------------------------------------------------------------------------------------------------------
template<class BSP>
bool fork_database_impl<BSP>::validated_block_exists_impl(const block_id_type& id, const block_id_type& claimed_id) const {
assert(root && (root->id() == id || index.find(id) != index.end()));

This comment has been minimized.

Copy link
@heifner

heifner Sep 17, 2024

Member

This implementation assumes claimed_id is on the same branch as id.

This comment has been minimized.

Copy link
@greg7mdp

greg7mdp Sep 17, 2024

Author Contributor

Yes, since it is that last_qc_claim of id's child.

bool id_present = false;

for (auto i = index.find(id); i != index.end(); i = index.find((*i)->previous())) {
id_present = true;
if ((*i)->is_valid())
return true;
if ((*i)->id() == claimed_id)
return false;
}
return true;
return id_present;
}

// ------------------ fork_database -------------------------
Expand Down

0 comments on commit 3a133d2

Please sign in to comment.