From 3ea7531a3bc029e4787239fcd7f6bf0fd25387ee Mon Sep 17 00:00:00 2001 From: nullcoset Date: Mon, 4 Aug 2025 15:22:55 +0200 Subject: [PATCH 1/2] fix for the missed_blocks being too big, set to zero. v3 --- libraries/chain/db_update.cpp | 31 ++++++++++++++++++++++++++++--- 1 file changed, 28 insertions(+), 3 deletions(-) diff --git a/libraries/chain/db_update.cpp b/libraries/chain/db_update.cpp index 9e52b933e..2583ca065 100644 --- a/libraries/chain/db_update.cpp +++ b/libraries/chain/db_update.cpp @@ -39,6 +39,8 @@ #include +#include + namespace graphene { namespace chain { void database::update_global_dynamic_data( const signed_block& b, const uint32_t missed_blocks ) @@ -63,9 +65,32 @@ void database::update_global_dynamic_data( const signed_block& b, const uint32_t dgp.head_block_id = b.id(); dgp.time = b.timestamp; dgp.current_witness = b.witness; - dgp.recent_slots_filled = ( - (dgp.recent_slots_filled << 1) - + 1) << missed_blocks; + + + static_assert(sizeof(dgp.recent_slots_filled)*CHAR_BIT==128, "This safe-check code below assumes size of recent_slots_filled is 128 bit"); + const typeof(missed_blocks) max_missed_blocks = 126; // 128-1 would be max, but another -1 to not think about any signed-overflow + + if (missed_blocks > max_missed_blocks) { + elog("big value of missed_blocks=${missed_blocks}", ("missed_blocks",missed_blocks)); + static bool _warned_once = [max_missed_blocks]() { // print explanation, exactly once (thread safe, C++14: 6.7.4) + elog( + "This (big value of missed_blocks) happens e.g. when your node runs as witness, " + "but you are far behind the expected blockchain time - perhaps you use own custom Genesis block, but the " + "initial_timestamp is more than ${max_missed_blocks} blocks behind. " + "As developer of a new chain, you can consider setting initial_timestamp in Genesis to be a very recent time point, " + "or perhaps even set it a bit into the future. Or maybe see the runtime flag 'genesis-timestamp' while only testing." + , ("max_missed_blocks",max_missed_blocks) + ); + return 0; + }(); + (void)_warned_once; // quiet unused-warning + dgp.recent_slots_filled = 0; // any value shifted by that many missed_blocks becomes a zero + } + else { + dgp.recent_slots_filled = ( + (dgp.recent_slots_filled << 1) + + 1) << missed_blocks; + } dgp.current_aslot += missed_blocks+1; }); From b034af1e2c10b08c9587d67ce0a89c4498230b95 Mon Sep 17 00:00:00 2001 From: nullcoset Date: Mon, 4 Aug 2025 20:23:14 +0200 Subject: [PATCH 2/2] fix for the missed_blocks being too big, zero, less verbose --- libraries/chain/db_update.cpp | 22 +++------------------- 1 file changed, 3 insertions(+), 19 deletions(-) diff --git a/libraries/chain/db_update.cpp b/libraries/chain/db_update.cpp index 2583ca065..100c4b8a3 100644 --- a/libraries/chain/db_update.cpp +++ b/libraries/chain/db_update.cpp @@ -66,25 +66,9 @@ void database::update_global_dynamic_data( const signed_block& b, const uint32_t dgp.time = b.timestamp; dgp.current_witness = b.witness; - - static_assert(sizeof(dgp.recent_slots_filled)*CHAR_BIT==128, "This safe-check code below assumes size of recent_slots_filled is 128 bit"); - const typeof(missed_blocks) max_missed_blocks = 126; // 128-1 would be max, but another -1 to not think about any signed-overflow - - if (missed_blocks > max_missed_blocks) { - elog("big value of missed_blocks=${missed_blocks}", ("missed_blocks",missed_blocks)); - static bool _warned_once = [max_missed_blocks]() { // print explanation, exactly once (thread safe, C++14: 6.7.4) - elog( - "This (big value of missed_blocks) happens e.g. when your node runs as witness, " - "but you are far behind the expected blockchain time - perhaps you use own custom Genesis block, but the " - "initial_timestamp is more than ${max_missed_blocks} blocks behind. " - "As developer of a new chain, you can consider setting initial_timestamp in Genesis to be a very recent time point, " - "or perhaps even set it a bit into the future. Or maybe see the runtime flag 'genesis-timestamp' while only testing." - , ("max_missed_blocks",max_missed_blocks) - ); - return 0; - }(); - (void)_warned_once; // quiet unused-warning - dgp.recent_slots_filled = 0; // any value shifted by that many missed_blocks becomes a zero + if (missed_blocks >= 128) { // we must avoid calculating bitshift (A<