Skip to content

Commit

Permalink
GH-2159 Misc cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
heifner committed Mar 4, 2024
1 parent 59b3c17 commit e990500
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 12 deletions.
16 changes: 9 additions & 7 deletions libraries/chain/controller.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1218,15 +1218,15 @@ struct controller_impl {
("lib_num", lib_num)("bn", fork_db_root_block_num()) );
}

uint32_t if_lib = block_header::num_from_id(if_irreversible_block_id);
const uint32_t new_lib = if_lib > 0 ? if_lib : fork_db_head_irreversible_blocknum();
uint32_t if_lib_num = block_header::num_from_id(if_irreversible_block_id);
const uint32_t new_lib_num = if_lib_num > 0 ? if_lib_num : fork_db_head_irreversible_blocknum();

if( new_lib <= lib_num )
if( new_lib_num <= lib_num )
return;

auto mark_branch_irreversible = [&, this](auto& forkdb) {
auto branch = (if_lib > 0) ? forkdb.fetch_branch( if_irreversible_block_id, new_lib)
: forkdb.fetch_branch( fork_db_head(forkdb, irreversible_mode())->id(), new_lib );
auto branch = (if_lib_num > 0) ? forkdb.fetch_branch( if_irreversible_block_id, new_lib_num)
: forkdb.fetch_branch( fork_db_head(forkdb, irreversible_mode())->id(), new_lib_num );
try {
auto should_process = [&](auto& bsp) {
// Only make irreversible blocks that have been validated. Blocks in the fork database may not be on our current best head
Expand Down Expand Up @@ -3932,9 +3932,11 @@ struct controller_impl {
}

void set_if_irreversible_block_id(const block_id_type& id) {
if( block_header::num_from_id(id) > block_header::num_from_id(if_irreversible_block_id) ) {
const block_num_type id_num = block_header::num_from_id(id);
const block_num_type current_num = block_header::num_from_id(if_irreversible_block_id);
if( id_num > current_num ) {
dlog("set irreversible block ${bn}: ${id}, old ${obn}: ${oid}", ("bn", id_num)("id", id)("obn", current_num)("oid", if_irreversible_block_id));
if_irreversible_block_id = id;
dlog("irreversible block ${bn} : ${id}", ("bn", block_header::num_from_id(id))("id", id));
}
}

Expand Down
11 changes: 6 additions & 5 deletions plugins/producer_plugin/producer_plugin.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -669,10 +669,13 @@ class producer_plugin_impl : public std::enable_shared_from_this<producer_plugin

bool on_incoming_block(const signed_block_ptr& block, const block_id_type& id, const std::optional<block_handle>& obt) {
auto now = fc::time_point::now();
auto& chain = chain_plug->chain();
_time_tracker.add_idle_time(now);

assert(block);
auto blk_num = block->block_num();

_time_tracker.add_idle_time(now);
if (now - block->timestamp < fc::minutes(5) || (blk_num % 1000 == 0)) // only log every 1000 during sync
fc_dlog(_log, "received incoming block ${n} ${id}", ("n", blk_num)("id", id));

// start a new speculative block, speculative start_block may have been interrupted
auto ensure = fc::make_scoped_exit([this]() {
Expand All @@ -684,6 +687,7 @@ class producer_plugin_impl : public std::enable_shared_from_this<producer_plugin
}
});

auto& chain = chain_plug->chain();
// de-dupe here... no point in aborting block if we already know the block; avoid exception in create_block_handle_future
if (chain.block_exists(id)) {
return true; // return true because the block is accepted
Expand All @@ -704,9 +708,6 @@ class producer_plugin_impl : public std::enable_shared_from_this<producer_plugin
return true; // return true because block was accepted
}

if (now - block->timestamp < fc::minutes(5) || (blk_num % 1000 == 0)) // only log every 1000 during sync
fc_dlog(_log, "received incoming block ${n} ${id}", ("n", blk_num)("id", id));

// abort the pending block
abort_block();

Expand Down

0 comments on commit e990500

Please sign in to comment.