6
6
#ifndef ALTINTEGRATION_BASE_BLOCK_TREE_HPP
7
7
#define ALTINTEGRATION_BASE_BLOCK_TREE_HPP
8
8
9
+ #include < limits>
9
10
#include < unordered_map>
10
11
#include < unordered_set>
11
12
#include < veriblock/pop/algorithm.hpp>
@@ -431,8 +432,12 @@ struct BaseBlockTree {
431
432
432
433
protected:
433
434
// ! @private
434
- void finalizeBlocks (int32_t maxReorgBlocks,
435
- int32_t preserveBlocksBehindFinal) {
435
+ void finalizeBlocks (
436
+ int32_t maxReorgBlocks,
437
+ int32_t preserveBlocksBehindFinal,
438
+ // we should not finalize blocks
439
+ // above this height
440
+ int32_t maxFinalizeBlockHeight = std::numeric_limits<int32_t >::max()) {
436
441
auto * tip = this ->getBestChain ().tip ();
437
442
VBK_ASSERT_MSG (tip, " %s tree must be bootstrapped" , block_t::name ());
438
443
VBK_ASSERT (!this ->isLoadingBlocks_ );
@@ -447,6 +452,17 @@ struct BaseBlockTree {
447
452
firstBlockHeight = std::max (bootstrapBlockHeight, firstBlockHeight);
448
453
auto * finalizedIndex = this ->getBestChain ()[firstBlockHeight];
449
454
VBK_ASSERT (finalizedIndex != nullptr );
455
+ if (finalizedIndex->getHeight () >= maxFinalizeBlockHeight) {
456
+ // we should not finalize blocks with height higher than
457
+ // maxFinalizeBlockHeight
458
+ VBK_LOG_INFO (
459
+ " Skipping finalization of %s because its height >= %d (max "
460
+ " possible height to finalize)" ,
461
+ finalizedIndex->toShortPrettyString (),
462
+ maxFinalizeBlockHeight);
463
+ return ;
464
+ }
465
+
450
466
this ->finalizeBlockImpl (*finalizedIndex, preserveBlocksBehindFinal);
451
467
}
452
468
@@ -967,13 +983,17 @@ struct BaseBlockTree {
967
983
// update active chain
968
984
VBK_ASSERT (firstBlockHeight >= rootBlockHeight);
969
985
size_t deallocatedBlocks = firstBlockHeight - rootBlockHeight;
970
- if (deallocatedBlocks > 0 ) {
971
- VBK_LOG_WARN (
972
- " %s tree deallocated blocks: %d" , block_t::name (), deallocatedBlocks);
973
- }
974
986
activeChain_ = Chain<index_t >(firstBlockHeight, activeChain_.tip ());
975
987
appliedBlockCount = activeChain_.blocksCount ();
976
988
989
+ if (deallocatedBlocks > 0 ) {
990
+ VBK_LOG_WARN (" Deallocated %d blocks in %s tree. Active chain %d..%d" ,
991
+ deallocatedBlocks,
992
+ block_t::name (),
993
+ activeChain_.first ()->getHeight (),
994
+ activeChain_.tip ()->getHeight ());
995
+ }
996
+
977
997
// fourth, mark `index` and all predecessors as finalized
978
998
index_t * ptr = finalizedBlock;
979
999
while (ptr != nullptr && !ptr->finalized ) {
0 commit comments