File tree 2 files changed +20
-11
lines changed
2 files changed +20
-11
lines changed Original file line number Diff line number Diff line change @@ -91,6 +91,7 @@ pub(crate) enum Statistic {
91
91
Runes = 13 ,
92
92
SatRanges = 14 ,
93
93
UnboundInscriptions = 16 ,
94
+ LastSavepointHeight = 17 ,
94
95
}
95
96
96
97
impl Statistic {
Original file line number Diff line number Diff line change @@ -83,17 +83,21 @@ impl Reorg {
83
83
return Ok ( ( ) ) ;
84
84
}
85
85
86
- if ( height < SAVEPOINT_INTERVAL || height % SAVEPOINT_INTERVAL == 0 )
87
- && u32:: try_from (
88
- index
89
- . settings
90
- . bitcoin_rpc_client ( None ) ?
91
- . get_blockchain_info ( ) ?
92
- . headers ,
93
- )
94
- . unwrap ( )
95
- . saturating_sub ( height)
96
- <= CHAIN_TIP_DISTANCE
86
+ let height = u64:: from ( height) ;
87
+
88
+ let last_savepoint_height = index
89
+ . begin_read ( ) ?
90
+ . 0
91
+ . open_table ( STATISTIC_TO_COUNT ) ?
92
+ . get ( & Statistic :: LastSavepointHeight . key ( ) ) ?
93
+ . map ( |last_savepoint_height| last_savepoint_height. value ( ) )
94
+ . unwrap_or ( 0 ) ;
95
+
96
+ let blocks = index. client . get_blockchain_info ( ) ?. headers ;
97
+
98
+ if ( height < SAVEPOINT_INTERVAL . into ( )
99
+ || height. saturating_sub ( last_savepoint_height) >= SAVEPOINT_INTERVAL . into ( ) )
100
+ && blocks. saturating_sub ( height) <= CHAIN_TIP_DISTANCE . into ( )
97
101
{
98
102
let wtx = index. begin_write ( ) ?;
99
103
@@ -111,6 +115,10 @@ impl Reorg {
111
115
log:: debug!( "creating savepoint at height {}" , height) ;
112
116
wtx. persistent_savepoint ( ) ?;
113
117
118
+ wtx
119
+ . open_table ( STATISTIC_TO_COUNT ) ?
120
+ . insert ( & Statistic :: LastSavepointHeight . key ( ) , & height) ?;
121
+
114
122
Index :: increment_statistic ( & wtx, Statistic :: Commits , 1 ) ?;
115
123
wtx. commit ( ) ?;
116
124
}
You can’t perform that action at this time.
0 commit comments