Skip to content

Commit

Permalink
GH-806 Rename forkdb to fork_db
Browse files Browse the repository at this point in the history
  • Loading branch information
heifner committed Oct 10, 2024
1 parent 938248f commit 5273400
Show file tree
Hide file tree
Showing 18 changed files with 287 additions and 287 deletions.
6 changes: 3 additions & 3 deletions docs/01_nodeos/04_replays/how-to-replay-from-a-blocks.log.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,15 @@
content_title: How to replay from a blocks.log file
---

Once you have obtained a copy of the `blocks.log` file which you wish to replay the blockchain from, copy it to your `data/blocks` directory, backing up any existing contents if you wish to keep them, and remove the `blocks.index`, `forkdb.dat`, `shared_memory.bin`, and `shared_memory.meta`.
Once you have obtained a copy of the `blocks.log` file which you wish to replay the blockchain from, copy it to your `data/blocks` directory, backing up any existing contents if you wish to keep them, and remove the `blocks.index`, `fork_db.dat`, `shared_memory.bin`, and `shared_memory.meta`.

The table below sumarizes the actions you should take for each of the files enumerated above:

Folder name | File name | Action
----------------------- | ------------------ | ------
----------------------- |--------------------| ------
data/blocks | blocks.index | Remove
data/blocks | blocks.log | Replace this file with the `block.log` you want to replay
data/blocks/reversible | forkdb.dat | Remove
data/blocks/reversible | fork_db.dat | Remove
data/blocks/reversible | shared_memory.bin | Remove
data/blocks/reversible | shared_memory.meta | Remove

Expand Down
326 changes: 163 additions & 163 deletions libraries/chain/controller.cpp

Large diffs are not rendered by default.

26 changes: 13 additions & 13 deletions libraries/chain/fork_database.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -263,7 +263,7 @@ namespace eosio::chain {

auto prev_bh = get_block_impl( n->previous(), include_root_t::yes );
EOS_ASSERT( prev_bh, unlinkable_block_exception,
"forkdb unlinkable block ${id} previous ${p}", ("id", n->id())("p", n->previous()) );
"fork_db unlinkable block ${id} previous ${p}", ("id", n->id())("p", n->previous()) );

if (validate) {
try {
Expand Down Expand Up @@ -641,7 +641,7 @@ namespace eosio::chain {
}

void fork_database::close() {
auto fork_db_file {data_dir / config::forkdb_filename};
auto fork_db_file {data_dir / config::fork_db_filename};
bool legacy_valid = fork_db_l.is_valid();
bool savanna_valid = fork_db_s.is_valid();

Expand Down Expand Up @@ -684,7 +684,7 @@ namespace eosio::chain {
}

bool fork_database::file_exists() const {
auto fork_db_file = data_dir / config::forkdb_filename;
auto fork_db_file = data_dir / config::fork_db_filename;
return std::filesystem::exists( fork_db_file );
};

Expand All @@ -694,7 +694,7 @@ namespace eosio::chain {

assert(!fork_db_l.is_valid() && !fork_db_s.is_valid());

auto fork_db_file = data_dir / config::forkdb_filename;
auto fork_db_file = data_dir / config::fork_db_filename;
if( std::filesystem::exists( fork_db_file ) ) {
try {
fc::cfile f;
Expand Down Expand Up @@ -760,37 +760,37 @@ namespace eosio::chain {
}

size_t fork_database::size() const {
return apply<size_t>([](const auto& forkdb) {
return forkdb.size();
return apply<size_t>([](const auto& fork_db) {
return fork_db.size();
});
}

// only called from the main thread
void fork_database::switch_from_legacy(const block_state_ptr& root) {
// no need to close fork_db because we don't want to write anything out, file is removed on open
// threads may be accessing (or locked on mutex about to access legacy forkdb) so don't delete it until program exit
// threads may be accessing (or locked on mutex about to access legacy fork_db) so don't delete it until program exit
if (in_use == in_use_t::legacy) {
fork_db_s.reset_root(root);
if (fork_db_l.has_root()) {
dlog("Switching forkdb from legacy to both");
dlog("Switching fork_db from legacy to both");
in_use = in_use_t::both;
} else {
dlog("Switching forkdb from legacy to savanna");
dlog("Switching fork_db from legacy to savanna");
in_use = in_use_t::savanna;
}
} else if (in_use == in_use_t::both) {
dlog("Switching forkdb from legacy, already both root ${rid}, forkdb root ${fid}", ("rid", root->id())("fid", fork_db_s.root()->id()));
dlog("Switching fork_db from legacy, already both root ${rid}, fork_db root ${fid}", ("rid", root->id())("fid", fork_db_s.root()->id()));
assert(fork_db_s.root()->id() == root->id()); // should always set the same root
} else {
assert(false);
}
}

block_branch_t fork_database::fetch_branch_from_head() const {
return apply<block_branch_t>([&](auto& forkdb) {
auto head = forkdb.head();
return apply<block_branch_t>([&](auto& fork_db) {
auto head = fork_db.head();
if (head)
return forkdb.fetch_block_branch(head->id());
return fork_db.fetch_block_branch(head->id());
return block_branch_t{};
});
}
Expand Down
2 changes: 1 addition & 1 deletion libraries/chain/include/eosio/chain/config.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ const static auto default_blocks_dir_name = "blocks";
const static auto reversible_blocks_dir_name = "reversible";

const static auto default_state_dir_name = "state";
const static auto forkdb_filename = "fork_db.dat";
const static auto fork_db_filename = "fork_db.dat";
const static auto safety_filename = "safety.dat";
const static auto chain_head_filename = "chain_head.dat";
const static auto default_state_size = 1*1024*1024*1024ll;
Expand Down
2 changes: 1 addition & 1 deletion libraries/chain/include/eosio/chain/controller.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -230,7 +230,7 @@ namespace eosio::chain {
void set_async_voting(async_t val);
void set_async_aggregation(async_t val);

/// Apply any blocks that are ready from the forkdb
/// Apply any blocks that are ready from the fork_db
void apply_blocks(const forked_callback_t& cb, const trx_meta_cache_lookup& trx_lookup);

struct accepted_block_result {
Expand Down
4 changes: 2 additions & 2 deletions libraries/chain/include/eosio/chain/fork_database.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ namespace eosio::chain {
bsp_t root() const;

/**
* The best branch head of blocks in the fork database, can be null if include_root_t::no and forkdb is empty
* The best branch head of blocks in the fork database, can be null if include_root_t::no and fork_db is empty
* @param include_root yes if root should be returned if no blocks in fork database
*/
bsp_t head(include_root_t include_root = include_root_t::no) const;
Expand Down Expand Up @@ -181,7 +181,7 @@ namespace eosio::chain {

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

// see fork_database_t::fetch_branch(forkdb->head()->id())
// see fork_database_t::fetch_branch(fork_db->head()->id())
block_branch_t fetch_branch_from_head() const;

template <class R, class F>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ namespace appbase {
// Add entries for each new non-unique handler type.
enum class handler_id {
unique, // identifies handler is unique, will not de-dup
process_incoming_block // process blocks already added to forkdb
process_incoming_block // process blocks already added to fork_db
};

enum class exec_queue {
Expand Down
4 changes: 2 additions & 2 deletions plugins/chain_plugin/chain_plugin.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -451,8 +451,8 @@ void clear_directory_contents( const std::filesystem::path& p ) {
namespace {
// This can be removed when versions of eosio that support reversible chainbase state file no longer supported.
void upgrade_from_reversible_to_fork_db(chain_plugin_impl* my) {
std::filesystem::path old_fork_db = my->chain_config->state_dir / config::forkdb_filename;
std::filesystem::path new_fork_db = my->blocks_dir / config::reversible_blocks_dir_name / config::forkdb_filename;
std::filesystem::path old_fork_db = my->chain_config->state_dir / config::fork_db_filename;
std::filesystem::path new_fork_db = my->blocks_dir / config::reversible_blocks_dir_name / config::fork_db_filename;
if( std::filesystem::exists( old_fork_db ) && std::filesystem::is_regular_file( old_fork_db ) ) {
bool copy_file = false;
if( std::filesystem::exists( new_fork_db ) && std::filesystem::is_regular_file( new_fork_db ) ) {
Expand Down
20 changes: 10 additions & 10 deletions plugins/net_plugin/net_plugin.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,7 @@ namespace eosio {

alignas(hardware_destructive_interference_sz)
fc::mutex sync_mtx;
uint32_t sync_known_fork_root_num GUARDED_BY(sync_mtx) {0}; // highest known forkdb root num from currently connected peers
uint32_t sync_known_fork_root_num GUARDED_BY(sync_mtx) {0}; // highest known fork_db root num from currently connected peers
uint32_t sync_last_requested_num GUARDED_BY(sync_mtx) {0}; // end block number of the last requested range, inclusive
uint32_t sync_next_expected_num GUARDED_BY(sync_mtx) {0}; // the next block number we need from peer
connection_ptr sync_source GUARDED_BY(sync_mtx); // connection we are currently syncing from
Expand Down Expand Up @@ -2113,27 +2113,27 @@ namespace eosio {
uint32_t head_num = my_impl->get_chain_head_num();
block_num_type num_blocks_not_applied = blk_num > head_num ? blk_num - head_num : 0;
if (num_blocks_not_applied < sync_fetch_span) {
fc_dlog(logger, "sync ahead allowed past sync-fetch-span ${sp}, block ${bn} head ${h}, forkdb size ${s}",
fc_dlog(logger, "sync ahead allowed past sync-fetch-span ${sp}, block ${bn} head ${h}, fork_db size ${s}",
("bn", blk_num)("sp", sync_fetch_span)("h", head_num)("s", my_impl->chain_plug->chain().fork_db_size()));
return true;
}

controller& cc = my_impl->chain_plug->chain();
if (cc.get_read_mode() == db_read_mode::IRREVERSIBLE) {
auto forkdb_head = cc.fork_db_head();
auto calculated_lib = forkdb_head.irreversible_blocknum();
auto fork_db_head = cc.fork_db_head();
auto calculated_lib = fork_db_head.irreversible_blocknum();
auto num_blocks_that_can_be_applied = calculated_lib > head_num ? calculated_lib - head_num : 0;
// add blocks that can potentially be applied as they are not in the forkdb yet
num_blocks_that_can_be_applied += blk_num > forkdb_head.block_num() ? blk_num - forkdb_head.block_num() : 0;
// add blocks that can potentially be applied as they are not in the fork_db yet
num_blocks_that_can_be_applied += blk_num > fork_db_head.block_num() ? blk_num - fork_db_head.block_num() : 0;
if (num_blocks_that_can_be_applied < sync_fetch_span) {
if (head_num )
fc_ilog(logger, "sync ahead allowed past sync-fetch-span ${sp}, block ${bn} for paused lib ${l}, head ${h}, forkdb size ${s}",
fc_ilog(logger, "sync ahead allowed past sync-fetch-span ${sp}, block ${bn} for paused lib ${l}, head ${h}, fork_db size ${s}",
("bn", blk_num)("sp", sync_fetch_span)("l", calculated_lib)("h", head_num)("s", cc.fork_db_size()));
return true;
}
}

fc_dlog(logger, "sync ahead not allowed. block ${bn}, head ${h}, fhead ${fh}, fhead->lib ${fl}, sync-fetch-span ${sp}, forkdb size ${s}",
fc_dlog(logger, "sync ahead not allowed. block ${bn}, head ${h}, fhead ${fh}, fhead->lib ${fl}, sync-fetch-span ${sp}, fork_db size ${s}",
("bn", blk_num)("h", head_num)("fh", cc.fork_db_head().block_num())("fl", cc.fork_db_head().irreversible_blocknum())
("sp", sync_fetch_span)("s", cc.fork_db_size()));
}
Expand Down Expand Up @@ -3859,7 +3859,7 @@ namespace eosio {
update_chain_info();

if (my_impl->chain_plug->chain().get_read_mode() != db_read_mode::IRREVERSIBLE) {
// irreversible notifies sync_manager when added to forkdb, non-irreversible notifies when applied
// irreversible notifies sync_manager when added to fork_db, non-irreversible notifies when applied
my_impl->dispatcher.strand.post([sync_master = my_impl->sync_master.get(), block, id]() {
const fc::microseconds age(fc::time_point::now() - block->timestamp);
sync_master->sync_recv_block(connection_ptr{}, id, block->block_num(), age);
Expand All @@ -3879,7 +3879,7 @@ namespace eosio {
update_chain_info(id);

if (my_impl->chain_plug->chain().get_read_mode() == db_read_mode::IRREVERSIBLE) {
// irreversible notifies sync_manager when added to forkdb, non-irreversible notifies when applied
// irreversible notifies sync_manager when added to fork_db, non-irreversible notifies when applied
my_impl->dispatcher.strand.post([sync_master = my_impl->sync_master.get(), block, id]() {
const fc::microseconds age(fc::time_point::now() - block->timestamp);
sync_master->sync_recv_block(connection_ptr{}, id, block->block_num(), age);
Expand Down
2 changes: 1 addition & 1 deletion programs/spring-util/actions/blocklog.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -268,7 +268,7 @@ int blocklog_actions::read_log() {

block_branch_t fork_db_branch;

if(std::filesystem::exists(std::filesystem::path(opt->blocks_dir) / config::reversible_blocks_dir_name / config::forkdb_filename)) {
if(std::filesystem::exists(std::filesystem::path(opt->blocks_dir) / config::reversible_blocks_dir_name / config::fork_db_filename)) {
ilog("opening fork_db");
fork_database fork_db(std::filesystem::path(opt->blocks_dir) / config::reversible_blocks_dir_name);

Expand Down
4 changes: 2 additions & 2 deletions unittests/blocks_log_replay_tests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -137,8 +137,8 @@ BOOST_FIXTURE_TEST_CASE(replay_stop_in_middle, blog_replay_fixture) try {
stop_and_resume_replay(last_irreversible_block_num - 1);
} FC_LOG_AND_RETHROW()

// Test replay stopping in the middle of blocks log and resuming without forkdb
BOOST_FIXTURE_TEST_CASE(replay_stop_in_middle_rm_forkdb, blog_replay_fixture) try {
// Test replay stopping in the middle of blocks log and resuming without fork_db
BOOST_FIXTURE_TEST_CASE(replay_stop_in_middle_rm_fork_db, blog_replay_fixture) try {
// block `last_irreversible_block_num - 1` is within blocks log
stop_and_resume_replay(last_irreversible_block_num - 1, true);
} FC_LOG_AND_RETHROW()
Expand Down
10 changes: 5 additions & 5 deletions unittests/finalizer_vote_tests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ struct simulator_t {

bls_keys_t keys;
finalizer my_finalizer;
fork_database_if_t forkdb;
fork_database_if_t fork_db;
finalizer_policy_ptr finpol;
std::vector<bsp> bsp_vec;

Expand All @@ -141,7 +141,7 @@ struct simulator_t {

auto genesis = make_bsp(proposal_t{0, "n0"}, bsp(), finpol);
bsp_vec.push_back(genesis);
forkdb.reset_root(genesis);
fork_db.reset_root(genesis);

block_ref genesis_ref(genesis->id(), genesis->timestamp(), genesis->id(), 1, 0);
my_finalizer.fsi = fsi_t{genesis_ref, genesis_ref, {}};
Expand All @@ -153,7 +153,7 @@ struct simulator_t {
}

vote_result propose(const proposal_t& p, std::optional<qc_claim_t> _claim = {}) {
bsp h = forkdb.head(include_root_t::yes);
bsp h = fork_db.head(include_root_t::yes);
qc_claim_t old_claim = _claim ? *_claim : h->core.latest_qc_claim();
bsp new_bsp = make_bsp(p, h, finpol, old_claim);
bsp_vec.push_back(new_bsp);
Expand All @@ -162,12 +162,12 @@ struct simulator_t {
}

result add(const proposal_t& p, std::optional<qc_claim_t> _claim = {}, const bsp& parent = {}) {
bsp h = parent ? parent : forkdb.head(include_root_t::yes);
bsp h = parent ? parent : fork_db.head(include_root_t::yes);
qc_claim_t old_claim = _claim ? *_claim : h->core.latest_qc_claim();
bsp new_bsp = make_bsp(p, h, finpol, old_claim);
bsp_vec.push_back(new_bsp);
test_block_state_accessor::set_valid(new_bsp, true);
forkdb.add(new_bsp, ignore_duplicate_t::no);
fork_db.add(new_bsp, ignore_duplicate_t::no);

auto v = vote(new_bsp);
return { new_bsp, v };
Expand Down
Loading

0 comments on commit 5273400

Please sign in to comment.