From e9905006348af5e4f3d004a2e2cb78925369c0de Mon Sep 17 00:00:00 2001 From: Kevin Heifner Date: Mon, 4 Mar 2024 09:33:51 -0600 Subject: [PATCH] GH-2159 Misc cleanup --- libraries/chain/controller.cpp | 16 +++++++++------- plugins/producer_plugin/producer_plugin.cpp | 11 ++++++----- 2 files changed, 15 insertions(+), 12 deletions(-) diff --git a/libraries/chain/controller.cpp b/libraries/chain/controller.cpp index 397ad57944..0b6d1f537f 100644 --- a/libraries/chain/controller.cpp +++ b/libraries/chain/controller.cpp @@ -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 @@ -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)); } } diff --git a/plugins/producer_plugin/producer_plugin.cpp b/plugins/producer_plugin/producer_plugin.cpp index 3f84932f66..a06f83aa92 100644 --- a/plugins/producer_plugin/producer_plugin.cpp +++ b/plugins/producer_plugin/producer_plugin.cpp @@ -669,10 +669,13 @@ class producer_plugin_impl : public std::enable_shared_from_this& 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]() { @@ -684,6 +687,7 @@ class producer_plugin_impl : public std::enable_shared_from_thischain(); // 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 @@ -704,9 +708,6 @@ class producer_plugin_impl : public std::enable_shared_from_thistimestamp < 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();