Skip to content

Commit

Permalink
Merge pull request #163 from AntelopeIO/GH-155-fork-warn
Browse files Browse the repository at this point in the history
Improve fork database logging
  • Loading branch information
heifner authored May 19, 2024
2 parents ea3324e + f3836b4 commit f818239
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 3 deletions.
4 changes: 3 additions & 1 deletion libraries/chain/controller.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1698,7 +1698,9 @@ struct controller_impl {

auto pending_head = forkdb.pending_head();
if( pending_head && blog_head && start_block_num <= blog_head->block_num() ) {
ilog( "fork database head ${h}, root ${r}", ("h", pending_head->block_num())( "r", forkdb.root()->block_num() ) );
ilog("fork database head ${hn}:${h}, root ${rn}:${r}",
("hn", pending_head->block_num())("h", pending_head->id())
("rn", forkdb.root()->block_num())("r", forkdb.root()->id()));
if( pending_head->block_num() < chain_head.block_num() || chain_head.block_num() < forkdb.root()->block_num() ) {
ilog( "resetting fork database with new last irreversible block as the new root: ${id}", ("id", chain_head.id()) );
fork_db_reset_root_to_chain_head();
Expand Down
7 changes: 5 additions & 2 deletions libraries/chain/fork_database.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -209,6 +209,9 @@ namespace eosio::chain {
void fork_database_impl<BSP>::close_impl(std::ofstream& out) {
assert(!!head && !!root); // if head or root are null, we don't save and shouldn't get here

ilog("Writing fork_database with root ${rn}:${r} and head ${hn}:${h}",
("rn", root->block_num())("r", root->id())("hn", head->block_num())("h", head->id()));

fc::raw::pack( out, *root );

uint32_t num_blocks_in_fork_db = index.size();
Expand Down Expand Up @@ -719,8 +722,7 @@ namespace eosio::chain {
auto in_use_value = in_use.load();
// check that fork_dbs are in a consistent state
if (!legacy_valid && !savanna_valid) {
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) );
ilog("No fork_database to persist");
return;
} 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
Expand All @@ -729,6 +731,7 @@ namespace eosio::chain {
(savanna_valid && (in_use_value == in_use_t::savanna)) ||
(legacy_valid && savanna_valid && (in_use_value == in_use_t::both)) );

ilog("Persisting to fork_database file: ${f}", ("f", fork_db_file));
std::ofstream out( fork_db_file.generic_string().c_str(), std::ios::out | std::ios::binary | std::ofstream::trunc );

fc::raw::pack( out, magic_number );
Expand Down

0 comments on commit f818239

Please sign in to comment.