Skip to content

Commit

Permalink
GH-2286 Misc cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
heifner committed Mar 26, 2024
1 parent 6f47ddb commit e92e4ad
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 28 deletions.
16 changes: 8 additions & 8 deletions libraries/chain/controller.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<block_state_legacy_ptr>(chain_head.internal())) {
auto prev = forkdb.get_block(bsp->previous(), include_root_t::yes);
apply_l<void>(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<void>([&](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<std::function<void()>> 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<std::function<void()>> 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);
});
Expand Down Expand Up @@ -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;
}
}
Expand Down
15 changes: 0 additions & 15 deletions libraries/chain/fork_database.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<block_branch_t>([&](auto& forkdb) {
return forkdb.fetch_block_branch(forkdb.head()->id());
Expand Down
6 changes: 1 addition & 5 deletions libraries/chain/include/eosio/chain/fork_database.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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(); }

Expand Down

0 comments on commit e92e4ad

Please sign in to comment.