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

IF: Support Leap 5 Fork Database disk format and new Savanna disk format. #2306

Merged
merged 14 commits into from
Mar 15, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
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
19 changes: 7 additions & 12 deletions libraries/chain/controller.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1059,12 +1059,7 @@ struct controller_impl {
}

void fork_db_reset_root_to_chain_head() {
fork_db.apply<void>([&](auto& forkdb) {
apply<void>(chain_head, [&](const auto& head) {
if constexpr (std::is_same_v<std::decay_t<decltype(head)>, std::decay_t<decltype(forkdb.head())>>)
forkdb.reset_root(head);
});
});
fork_db.reset_root(chain_head.internal());
}

signed_block_ptr fork_db_fetch_block_by_id( const block_id_type& id ) const {
Expand Down Expand Up @@ -1438,10 +1433,10 @@ struct controller_impl {
}

if (startup == startup_t::genesis) {
if (!fork_db.fork_db_if_present()) {
if (fork_db.version_in_use() == fork_database::in_use_t::legacy) {
// switch to savanna if needed
apply_s<void>(chain_head, [&](const auto& head) {
fork_db.switch_from_legacy(chain_head);
fork_db.switch_from_legacy(chain_head.internal());
});
}
auto do_startup = [&](auto& forkdb) {
Expand Down Expand Up @@ -1694,12 +1689,12 @@ struct controller_impl {
// If we start at a block during or after the IF transition, we need to provide this information
// at startup.
// ---------------------------------------------------------------------------------------------
if (fork_db.fork_db_if_present()) {
if (auto in_use = fork_db.version_in_use(); in_use == fork_database::in_use_t::both || in_use == fork_database::in_use_t::savanna) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe you can have a method version_is_savanna() and version_is_legacy() to avoid this long expression. But no need to change now.

// we are already past the IF transition point where we create the updated fork_db.
// so we can't rely on the finalizer safety information update happening during the transition.
// see https://github.com/AntelopeIO/leap/issues/2070#issuecomment-1941901836
// -------------------------------------------------------------------------------------------
if (fork_db.fork_db_legacy_present()) {
if (in_use == fork_database::in_use_t::both) {
// fork_db_legacy is present as well, which means that we have not completed the transition
auto set_finalizer_defaults = [&](auto& forkdb) -> void {
auto lib = forkdb.root();
Expand Down Expand Up @@ -3025,7 +3020,7 @@ struct controller_impl {

chain_head = block_handle{std::move(new_head)};
if (s != controller::block_status::irreversible) {
fork_db.switch_from_legacy(chain_head);
fork_db.switch_from_legacy(chain_head.internal());
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not your PR. This internal() implies details exposed.

}
}

Expand Down Expand Up @@ -3756,7 +3751,7 @@ struct controller_impl {
} else if( new_head->id() != chain_head.id() ) {
ilog("switching forks from ${current_head_id} (block number ${current_head_num}) ${c} to ${new_head_id} (block number ${new_head_num}) ${n}",
("current_head_id", chain_head.id())("current_head_num", chain_head.block_num())("new_head_id", new_head->id())("new_head_num", new_head->block_num())
("c", log_fork_comparison(chain_head))("n", log_fork_comparison(*new_head)));
("c", log_fork_comparison(chain_head.internal()))("n", log_fork_comparison(*new_head)));

// not possible to log transaction specific infor when switching forks
if (auto dm_logger = get_deep_mind_logger(false)) {
Expand Down
Loading
Loading