@@ -261,10 +261,11 @@ where C::Target: chain::Filter,
261
261
{
262
262
let err_str = "ChannelMonitor[Update] persistence failed unrecoverably. This indicates we cannot continue normal operation and must shut down." ;
263
263
let funding_outpoints = hash_set_from_iter ( self . monitors . read ( ) . unwrap ( ) . keys ( ) . cloned ( ) ) ;
264
+ let channel_count = funding_outpoints. len ( ) ;
264
265
for funding_outpoint in funding_outpoints. iter ( ) {
265
266
let monitor_lock = self . monitors . read ( ) . unwrap ( ) ;
266
267
if let Some ( monitor_state) = monitor_lock. get ( funding_outpoint) {
267
- if self . update_monitor_with_chain_data ( header, best_height, txdata, & process, funding_outpoint, & monitor_state) . is_err ( ) {
268
+ if self . update_monitor_with_chain_data ( header, best_height, txdata, & process, funding_outpoint, & monitor_state, channel_count ) . is_err ( ) {
268
269
// Take the monitors lock for writing so that we poison it and any future
269
270
// operations going forward fail immediately.
270
271
core:: mem:: drop ( monitor_lock) ;
@@ -279,7 +280,7 @@ where C::Target: chain::Filter,
279
280
let monitor_states = self . monitors . write ( ) . unwrap ( ) ;
280
281
for ( funding_outpoint, monitor_state) in monitor_states. iter ( ) {
281
282
if !funding_outpoints. contains ( funding_outpoint) {
282
- if self . update_monitor_with_chain_data ( header, best_height, txdata, & process, funding_outpoint, & monitor_state) . is_err ( ) {
283
+ if self . update_monitor_with_chain_data ( header, best_height, txdata, & process, funding_outpoint, & monitor_state, channel_count ) . is_err ( ) {
283
284
log_error ! ( self . logger, "{}" , err_str) ;
284
285
panic ! ( "{}" , err_str) ;
285
286
}
@@ -299,7 +300,7 @@ where C::Target: chain::Filter,
299
300
300
301
fn update_monitor_with_chain_data < FN > (
301
302
& self , header : & Header , best_height : Option < u32 > , txdata : & TransactionData , process : FN , funding_outpoint : & OutPoint ,
302
- monitor_state : & MonitorHolder < ChannelSigner > ,
303
+ monitor_state : & MonitorHolder < ChannelSigner > , channel_count : usize ,
303
304
) -> Result < ( ) , ( ) > where FN : Fn ( & ChannelMonitor < ChannelSigner > , & TransactionData ) -> Vec < TransactionOutputs > {
304
305
let monitor = & monitor_state. monitor ;
305
306
let logger = WithChannelMonitor :: from ( & self . logger , & monitor, None ) ;
@@ -312,9 +313,15 @@ where C::Target: chain::Filter,
312
313
let funding_txid_u32 = u32:: from_be_bytes ( [ funding_txid_hash_bytes[ 0 ] , funding_txid_hash_bytes[ 1 ] , funding_txid_hash_bytes[ 2 ] , funding_txid_hash_bytes[ 3 ] ] ) ;
313
314
funding_txid_u32. wrapping_add ( best_height. unwrap_or_default ( ) )
314
315
} ;
315
- const CHAINSYNC_MONITOR_PARTITION_FACTOR : u32 = 50 ; // ~ 8hours
316
+
317
+ let partition_factor = if channel_count < 15 {
318
+ 5
319
+ } else {
320
+ 50 // ~ 8hours
321
+ } ;
322
+
316
323
let has_pending_claims = monitor_state. monitor . has_pending_claims ( ) ;
317
- if has_pending_claims || get_partition_key ( funding_outpoint) % CHAINSYNC_MONITOR_PARTITION_FACTOR == 0 {
324
+ if has_pending_claims || get_partition_key ( funding_outpoint) % partition_factor == 0 {
318
325
log_trace ! ( logger, "Syncing Channel Monitor for channel {}" , log_funding_info!( monitor) ) ;
319
326
match self . persister . update_persisted_channel ( * funding_outpoint, None , monitor) {
320
327
ChannelMonitorUpdateStatus :: Completed =>
@@ -889,7 +896,7 @@ mod tests {
889
896
use crate :: ln:: functional_test_utils:: * ;
890
897
use crate :: ln:: msgs:: ChannelMessageHandler ;
891
898
892
- const CHAINSYNC_MONITOR_PARTITION_FACTOR : u32 = 50 ;
899
+ const CHAINSYNC_MONITOR_PARTITION_FACTOR : u32 = 5 ;
893
900
894
901
#[ test]
895
902
fn test_async_ooo_offchain_updates ( ) {
0 commit comments