Skip to content

Commit

Permalink
GH-2057 Switch away from legacy forkdb in log_irreversible to simplif…
Browse files Browse the repository at this point in the history
…y snapshot and fork db close logic
  • Loading branch information
heifner committed Mar 20, 2024
1 parent 3efd4bf commit 26d82da
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 10 deletions.
5 changes: 2 additions & 3 deletions libraries/chain/controller.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1371,6 +1371,8 @@ struct controller_impl {
savanna_transistion_required = true;
// Do not advance irreversible past IF Genesis Block
break;
} else if ((*bitr)->block->is_proper_svnn_block()) {
fork_db.switch_to_savanna();
}
}
} catch( std::exception& ) {
Expand Down Expand Up @@ -1927,9 +1929,6 @@ struct controller_impl {
[&](const block_state_legacy_ptr& head) -> block_state_pair {
if (fork_db.version_in_use() == fork_database::in_use_t::both) {
return fork_db.apply_s<block_state_pair>([&](const auto& forkdb) -> block_state_pair {
if (forkdb.root()->header.is_proper_svnn_block()) {
return { {}, forkdb.head() }; // legacy not needed past transition
}
return { head, forkdb.head() };
});
}
Expand Down
14 changes: 7 additions & 7 deletions libraries/chain/fork_database.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -686,13 +686,8 @@ namespace eosio::chain {
wlog( "fork_database is in a bad state when closing; not writing out '${filename}', legacy_valid=${l}, savanna_valid=${s}",
("filename", fork_db_file)("l", legacy_valid)("s", savanna_valid) );
return;
} else if (legacy_valid && savanna_valid) {
// don't write legacy if not needed
assert(fork_db_s.root() && fork_db_s.root()->block);
if (fork_db_s.root()->block->is_proper_svnn_block()) {
legacy_valid = false;
in_use_value = in_use_t::savanna;
}
} else if (legacy_valid && savanna_valid && in_use_value == in_use_t::savanna) {
legacy_valid = false; // don't write legacy if not needed, we delay 'clear' of legacy until close
}
assert( (legacy_valid && (in_use_value == in_use_t::legacy)) ||
(savanna_valid && (in_use_value == in_use_t::savanna)) ||
Expand Down Expand Up @@ -804,6 +799,11 @@ namespace eosio::chain {
}
}

// only called from the main thread
void fork_database::switch_to_savanna() {
in_use = in_use_t::savanna;
}

block_branch_t fork_database::fetch_branch_from_head() const {
return apply<block_branch_t>([&](auto& forkdb) {
return forkdb.fetch_block_branch(forkdb.head()->id());
Expand Down
1 change: 1 addition & 0 deletions libraries/chain/include/eosio/chain/fork_database.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -156,6 +156,7 @@ namespace eosio::chain {

// switches to using both legacy and savanna during transition
void switch_from_legacy(const block_state_ptr& root);
void switch_to_savanna();

in_use_t version_in_use() const { return in_use.load(); }

Expand Down

0 comments on commit 26d82da

Please sign in to comment.