Skip to content

Commit

Permalink
Merge pull request #2306 from AntelopeIO/gh_2285
Browse files Browse the repository at this point in the history
IF: Support Leap 5 Fork Database disk format and new Savanna disk format.
  • Loading branch information
greg7mdp authored Mar 15, 2024
2 parents 8a548e3 + 846703a commit 36ebf7a
Show file tree
Hide file tree
Showing 6 changed files with 234 additions and 180 deletions.
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) {
// 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());
}
}

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

0 comments on commit 36ebf7a

Please sign in to comment.