Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[1.0.4] Advance fork db root when pending lib greater than head #1009

Merged
merged 3 commits into from
Nov 5, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 6 additions & 3 deletions libraries/chain/controller.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1497,9 +1497,12 @@ struct controller_impl {
assert(!irreversible_mode() || forkdb.head());
const auto& head_id = irreversible_mode() ? forkdb.head()->id() : chain_head.id();
// verifies lib is on head branch, otherwise returns an empty branch
// The new lib needs to be on the head branch because the forkdb.advance_root() below could purge blocks that
// would be needed to be re-applied on a fork switch from the exiting chain_head.
auto branch = forkdb.fetch_branch(head_id, new_lib_id);
// The new lib needs to be on the head branch because the forkdb.advance_root() below could purge blocks that
// would be needed to be re-applied on a fork switch from the exiting chain_head.
// Pending LIB can be greater than chain head, for example when syncing, in that case fetch branch from the
// pending LIB. If the pending LIB not found on the head branch then fetch_branch returns an empty branch.
// Otherwise fetch_branch will return from chain_head to root iff chain_head on pending LIB branch.
auto branch = new_lib_num <= chain_head.block_num() ? forkdb.fetch_branch(head_id, new_lib_id) : forkdb.fetch_branch(new_lib_id, head_id);
greg7mdp marked this conversation as resolved.
Show resolved Hide resolved
try {
auto should_process = [&](auto& bsp) {
// Only make irreversible blocks that have been validated. Blocks in the fork database may not be on our current best head
Expand Down
8 changes: 8 additions & 0 deletions unittests/fork_db_tests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,14 @@ BOOST_FIXTURE_TEST_CASE(add_remove_test, generate_forkdb_state) try {
BOOST_REQUIRE(branch.size() == 2);
BOOST_TEST(branch[0] == bsp12a);
BOOST_TEST(branch[1] == bsp11a);

// test fetch branch when lib is greater than head
branch = forkdb.fetch_branch(bsp13b->id(), bsp12a->id());
BOOST_TEST(branch.empty());
branch = forkdb.fetch_branch(bsp13b->id(), bsp12b->id());
BOOST_REQUIRE(branch.size() == 2);
BOOST_TEST(branch[0] == bsp12b);
BOOST_TEST(branch[1] == bsp11b);
} FC_LOG_AND_RETHROW();


Expand Down
Loading