@@ -1419,26 +1419,36 @@ mod tests {
1419
1419
fn clean_stale_updates_works ( ) {
1420
1420
let test_max_pending_updates = 7 ;
1421
1421
let chanmon_cfgs = create_chanmon_cfgs ( 3 ) ;
1422
- let persister_0 = MonitorUpdatingPersister {
1423
- kv_store : & TestStore :: new ( false ) ,
1424
- logger : & TestLogger :: new ( ) ,
1425
- maximum_pending_updates : test_max_pending_updates,
1426
- min_monitor_size_for_updates_bytes : 0 ,
1427
- entropy_source : & chanmon_cfgs[ 0 ] . keys_manager ,
1428
- signer_provider : & chanmon_cfgs[ 0 ] . keys_manager ,
1429
- broadcaster : & chanmon_cfgs[ 0 ] . tx_broadcaster ,
1430
- fee_estimator : & chanmon_cfgs[ 0 ] . fee_estimator ,
1431
- } ;
1432
- let persister_1 = MonitorUpdatingPersister {
1433
- kv_store : & TestStore :: new ( false ) ,
1434
- logger : & TestLogger :: new ( ) ,
1435
- maximum_pending_updates : test_max_pending_updates,
1436
- min_monitor_size_for_updates_bytes : 0 ,
1437
- entropy_source : & chanmon_cfgs[ 1 ] . keys_manager ,
1438
- signer_provider : & chanmon_cfgs[ 1 ] . keys_manager ,
1439
- broadcaster : & chanmon_cfgs[ 1 ] . tx_broadcaster ,
1440
- fee_estimator : & chanmon_cfgs[ 1 ] . fee_estimator ,
1441
- } ;
1422
+ let store_0 = TestStore :: new ( false ) ;
1423
+ let logger_0 = TestLogger :: new ( ) ;
1424
+ let store_1 = TestStore :: new ( false ) ;
1425
+ let logger_1 = TestLogger :: new ( ) ;
1426
+
1427
+ // Test the default new() constructor (uses 4096 byte threshold)
1428
+ let persister_0 = MonitorUpdatingPersister :: new (
1429
+ & store_0,
1430
+ & logger_0,
1431
+ test_max_pending_updates,
1432
+ & chanmon_cfgs[ 0 ] . keys_manager ,
1433
+ & chanmon_cfgs[ 0 ] . keys_manager ,
1434
+ & chanmon_cfgs[ 0 ] . tx_broadcaster ,
1435
+ & chanmon_cfgs[ 0 ] . fee_estimator ,
1436
+ ) ;
1437
+ // Test the custom threshold constructor with zero threshold
1438
+ let persister_1 = MonitorUpdatingPersister :: new_with_monitor_size_threshold (
1439
+ & store_1,
1440
+ & logger_1,
1441
+ test_max_pending_updates,
1442
+ 0 , // 0 byte threshold for maximum update usage
1443
+ & chanmon_cfgs[ 1 ] . keys_manager ,
1444
+ & chanmon_cfgs[ 1 ] . keys_manager ,
1445
+ & chanmon_cfgs[ 1 ] . tx_broadcaster ,
1446
+ & chanmon_cfgs[ 1 ] . fee_estimator ,
1447
+ ) ;
1448
+
1449
+ // Verify the constructors set the thresholds correctly
1450
+ assert_eq ! ( persister_0. min_monitor_size_for_updates_bytes, 4096 ) ;
1451
+ assert_eq ! ( persister_1. min_monitor_size_for_updates_bytes, 0 ) ;
1442
1452
let mut node_cfgs = create_node_cfgs ( 2 , & chanmon_cfgs) ;
1443
1453
let chain_mon_0 = test_utils:: TestChainMonitor :: new (
1444
1454
Some ( & chanmon_cfgs[ 0 ] . chain_source ) ,
@@ -1505,32 +1515,42 @@ mod tests {
1505
1515
#[ test]
1506
1516
fn test_size_based_optimization ( ) {
1507
1517
let chanmon_cfgs = create_chanmon_cfgs ( 2 ) ;
1518
+ let store_0 = TestStore :: new ( false ) ;
1519
+ let logger_0 = TestLogger :: new ( ) ;
1520
+ let store_1 = TestStore :: new ( false ) ;
1521
+ let logger_1 = TestLogger :: new ( ) ;
1508
1522
1509
1523
// Create a persister with a huge minimum size threshold (100KB)
1510
1524
// This should force all monitors to use full persistence instead of updates
1511
- let large_threshold_persister = MonitorUpdatingPersister {
1512
- kv_store : & TestStore :: new ( false ) ,
1513
- logger : & TestLogger :: new ( ) ,
1514
- maximum_pending_updates : 5 ,
1515
- min_monitor_size_for_updates_bytes : 100_000 , // 100KB threshold - way larger than any monitor
1516
- entropy_source : & chanmon_cfgs[ 0 ] . keys_manager ,
1517
- signer_provider : & chanmon_cfgs[ 0 ] . keys_manager ,
1518
- broadcaster : & chanmon_cfgs[ 0 ] . tx_broadcaster ,
1519
- fee_estimator : & chanmon_cfgs[ 0 ] . fee_estimator ,
1520
- } ;
1525
+ // Test the new_with_monitor_size_threshold constructor with large threshold
1526
+ let large_threshold_persister = MonitorUpdatingPersister :: new_with_monitor_size_threshold (
1527
+ & store_0,
1528
+ & logger_0,
1529
+ 5 ,
1530
+ 100_000 , // 100KB threshold - way larger than any monitor
1531
+ & chanmon_cfgs[ 0 ] . keys_manager ,
1532
+ & chanmon_cfgs[ 0 ] . keys_manager ,
1533
+ & chanmon_cfgs[ 0 ] . tx_broadcaster ,
1534
+ & chanmon_cfgs[ 0 ] . fee_estimator ,
1535
+ ) ;
1521
1536
1522
1537
// Create a persister with zero minimum size threshold
1523
1538
// This should allow all monitors to use update-based persistence
1524
- let small_threshold_persister = MonitorUpdatingPersister {
1525
- kv_store : & TestStore :: new ( false ) ,
1526
- logger : & TestLogger :: new ( ) ,
1527
- maximum_pending_updates : 5 ,
1528
- min_monitor_size_for_updates_bytes : 0 , // 0 byte threshold - allows all monitors to use updates
1529
- entropy_source : & chanmon_cfgs[ 1 ] . keys_manager ,
1530
- signer_provider : & chanmon_cfgs[ 1 ] . keys_manager ,
1531
- broadcaster : & chanmon_cfgs[ 1 ] . tx_broadcaster ,
1532
- fee_estimator : & chanmon_cfgs[ 1 ] . fee_estimator ,
1533
- } ;
1539
+ // Test the new_with_monitor_size_threshold constructor with zero threshold
1540
+ let small_threshold_persister = MonitorUpdatingPersister :: new_with_monitor_size_threshold (
1541
+ & store_1,
1542
+ & logger_1,
1543
+ 5 ,
1544
+ 0 , // 0 byte threshold - allows all monitors to use updates
1545
+ & chanmon_cfgs[ 1 ] . keys_manager ,
1546
+ & chanmon_cfgs[ 1 ] . keys_manager ,
1547
+ & chanmon_cfgs[ 1 ] . tx_broadcaster ,
1548
+ & chanmon_cfgs[ 1 ] . fee_estimator ,
1549
+ ) ;
1550
+
1551
+ // Verify the constructors set the thresholds correctly
1552
+ assert_eq ! ( large_threshold_persister. min_monitor_size_for_updates_bytes, 100_000 ) ;
1553
+ assert_eq ! ( small_threshold_persister. min_monitor_size_for_updates_bytes, 0 ) ;
1534
1554
1535
1555
let mut node_cfgs = create_node_cfgs ( 2 , & chanmon_cfgs) ;
1536
1556
let chain_mon_0 = test_utils:: TestChainMonitor :: new (
0 commit comments