diff --git a/libraries/chain/controller.cpp b/libraries/chain/controller.cpp index 242f563586..6ba03268bd 100644 --- a/libraries/chain/controller.cpp +++ b/libraries/chain/controller.cpp @@ -1257,23 +1257,23 @@ struct controller_impl { } else { assert(bsp->block); if (bsp->block->is_proper_svnn_block()) { - // if chain_head is legacy, update to non-legacy chain_head, this is needed so that the correct block_state is created in apply_block - if (std::holds_alternative(chain_head.internal())) { - auto prev = forkdb.get_block(bsp->previous(), include_root_t::yes); + apply_l(chain_head, [&](const auto&) { + // if chain_head is legacy, update to non-legacy chain_head, this is needed so that the correct block_state is created in apply_block + block_state_ptr prev = forkdb.get_block(bsp->previous(), include_root_t::yes); assert(prev); chain_head = block_handle{prev}; - } + }); apply_block(br, bsp, controller::block_status::complete, trx_meta_cache_lookup{}); } else { // only called during transition when not a proper savanna block fork_db.apply_l([&](const auto& forkdb_l) { block_state_legacy_ptr legacy = forkdb_l.get_block(bsp->id()); - fork_db.switch_to_legacy(); // apply block uses to know what types to create - fc::scoped_exit> e([&]{fork_db.switch_to_both();}); + fork_db.switch_to(fork_database::in_use_t::legacy); // apply block uses to know what types to create + fc::scoped_exit> e([&]{fork_db.switch_to(fork_database::in_use_t::both);}); apply_block(br, legacy, controller::block_status::complete, trx_meta_cache_lookup{}); // irreversible apply was just done, calculate new_valid here instead of in transition_to_savanna() assert(legacy->action_receipt_digests); - auto prev = forkdb.get_block(legacy->previous(), include_root_t::yes); + block_state_ptr prev = forkdb.get_block(legacy->previous(), include_root_t::yes); assert(prev); transition_add_to_savanna_fork_db(forkdb, legacy, bsp, prev); }); @@ -1410,7 +1410,7 @@ struct controller_impl { break; } } else if ((*bitr)->block->is_proper_svnn_block() && fork_db.version_in_use() == fork_database::in_use_t::both) { - fork_db.switch_to_savanna(); + fork_db.switch_to(fork_database::in_use_t::savanna); break; } } diff --git a/libraries/chain/fork_database.cpp b/libraries/chain/fork_database.cpp index 57c9fae4b9..5cda182450 100644 --- a/libraries/chain/fork_database.cpp +++ b/libraries/chain/fork_database.cpp @@ -799,21 +799,6 @@ namespace eosio::chain { } } - // only called from the main thread - void fork_database::switch_to_savanna() { - in_use = in_use_t::savanna; - } - - // only called from the main thread - void fork_database::switch_to_legacy() { - in_use = in_use_t::legacy; - } - - // only called from the main thread - void fork_database::switch_to_both() { - in_use = in_use_t::both; - } - block_branch_t fork_database::fetch_branch_from_head() const { return apply([&](auto& forkdb) { return forkdb.fetch_block_branch(forkdb.head()->id()); diff --git a/libraries/chain/include/eosio/chain/fork_database.hpp b/libraries/chain/include/eosio/chain/fork_database.hpp index 12742b2fae..4f26eb547a 100644 --- a/libraries/chain/include/eosio/chain/fork_database.hpp +++ b/libraries/chain/include/eosio/chain/fork_database.hpp @@ -156,11 +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(); - // used in irreversible mode - void switch_to_legacy(); - // used in irreversible mode - void switch_to_both(); + void switch_to(in_use_t v) { in_use = v; } in_use_t version_in_use() const { return in_use.load(); }