@@ -13,6 +13,7 @@ use std::collections::{hash_map::Entry, BTreeMap, BTreeSet, HashMap, HashSet};
13
13
14
14
pub struct StacksBlockPool {
15
15
canonical_fork_id : usize ,
16
+ number_of_blocks_since_last_reorg : u16 ,
16
17
orphans : BTreeSet < BlockIdentifier > ,
17
18
block_store : HashMap < BlockIdentifier , StacksBlockData > ,
18
19
forks : BTreeMap < usize , ChainSegment > ,
@@ -28,6 +29,7 @@ impl StacksBlockPool {
28
29
forks. insert ( 0 , ChainSegment :: new ( ) ) ;
29
30
StacksBlockPool {
30
31
canonical_fork_id : 0 ,
32
+ number_of_blocks_since_last_reorg : 0 ,
31
33
block_store : HashMap :: new ( ) ,
32
34
orphans : BTreeSet :: new ( ) ,
33
35
forks,
@@ -214,7 +216,9 @@ impl StacksBlockPool {
214
216
_ => return Ok ( None ) ,
215
217
} ;
216
218
217
- self . collect_and_prune_confirmed_blocks ( & mut chain_event, ctx) ;
219
+ if self . number_of_blocks_since_last_reorg > 4 {
220
+ self . collect_and_prune_confirmed_blocks ( & mut chain_event, ctx) ;
221
+ }
218
222
219
223
Ok ( Some ( chain_event) )
220
224
}
@@ -844,6 +848,8 @@ impl StacksBlockPool {
844
848
if let Ok ( divergence) = canonical_segment. try_identify_divergence ( other_segment, false , ctx)
845
849
{
846
850
if divergence. block_ids_to_rollback . is_empty ( ) {
851
+ self . number_of_blocks_since_last_reorg =
852
+ self . number_of_blocks_since_last_reorg . saturating_add ( 1 ) ;
847
853
let mut new_blocks = vec ! [ ] ;
848
854
for i in 0 ..divergence. block_ids_to_apply . len ( ) {
849
855
let block_identifier = & divergence. block_ids_to_apply [ i] ;
@@ -893,6 +899,7 @@ impl StacksBlockPool {
893
899
} ,
894
900
) ) ;
895
901
} else {
902
+ self . number_of_blocks_since_last_reorg = 0 ;
896
903
let blocks_to_rollback = divergence
897
904
. block_ids_to_rollback
898
905
. iter ( )
0 commit comments