@@ -530,6 +530,7 @@ impl BestBlock {
530
530
/// updates are ready for persistence).
531
531
struct PersistenceNotifierGuard < ' a > {
532
532
persistence_notifier : & ' a PersistenceNotifier ,
533
+ persistence_update : bool ,
533
534
// We hold onto this result so the lock doesn't get released immediately.
534
535
_read_guard : RwLockReadGuard < ' a , ( ) > ,
535
536
}
@@ -540,14 +541,17 @@ impl<'a> PersistenceNotifierGuard<'a> {
540
541
541
542
Self {
542
543
persistence_notifier : notifier,
544
+ persistence_update : true ,
543
545
_read_guard : read_guard,
544
546
}
545
547
}
546
548
}
547
549
548
550
impl < ' a > Drop for PersistenceNotifierGuard < ' a > {
549
551
fn drop ( & mut self ) {
550
- self . persistence_notifier . notify ( ) ;
552
+ if self . persistence_update {
553
+ self . persistence_notifier . notify ( ) ;
554
+ }
551
555
}
552
556
}
553
557
@@ -2094,9 +2098,13 @@ impl<Signer: Sign, M: Deref, T: Deref, K: Deref, F: Deref, L: Deref> ChannelMana
2094
2098
/// BroadcastChannelUpdate events in timer_tick_occurred.
2095
2099
///
2096
2100
/// Expects the caller to have a total_consistency_lock read lock.
2097
- fn process_background_events ( & self ) {
2101
+ fn process_background_events ( & self ) -> bool {
2098
2102
let mut background_events = Vec :: new ( ) ;
2099
2103
mem:: swap ( & mut * self . pending_background_events . lock ( ) . unwrap ( ) , & mut background_events) ;
2104
+ if background_events. is_empty ( ) {
2105
+ return false ;
2106
+ }
2107
+
2100
2108
for event in background_events. drain ( ..) {
2101
2109
match event {
2102
2110
BackgroundEvent :: ClosingMonitorUpdate ( ( funding_txo, update) ) => {
@@ -2106,6 +2114,7 @@ impl<Signer: Sign, M: Deref, T: Deref, K: Deref, F: Deref, L: Deref> ChannelMana
2106
2114
} ,
2107
2115
}
2108
2116
}
2117
+ true
2109
2118
}
2110
2119
2111
2120
#[ cfg( any( test, feature = "_test_utils" ) ) ]
@@ -2121,8 +2130,8 @@ impl<Signer: Sign, M: Deref, T: Deref, K: Deref, F: Deref, L: Deref> ChannelMana
2121
2130
///
2122
2131
/// Note that in some rare cases this may generate a `chain::Watch::update_channel` call.
2123
2132
pub fn timer_tick_occurred ( & self ) {
2124
- let _persistence_guard = PersistenceNotifierGuard :: new ( & self . total_consistency_lock , & self . persistence_notifier ) ;
2125
- self . process_background_events ( ) ;
2133
+ let mut persistence_guard = PersistenceNotifierGuard :: new ( & self . total_consistency_lock , & self . persistence_notifier ) ;
2134
+ let mut did_work = self . process_background_events ( ) ;
2126
2135
2127
2136
let mut channel_state_lock = self . channel_state . lock ( ) . unwrap ( ) ;
2128
2137
let channel_state = & mut * channel_state_lock;
@@ -2138,6 +2147,7 @@ impl<Signer: Sign, M: Deref, T: Deref, K: Deref, F: Deref, L: Deref> ChannelMana
2138
2147
msg : update
2139
2148
} ) ;
2140
2149
}
2150
+ did_work = true ;
2141
2151
chan. set_update_status ( UpdateStatus :: Disabled ) ;
2142
2152
} ,
2143
2153
UpdateStatus :: EnabledStaged if chan. is_live ( ) => {
@@ -2146,11 +2156,16 @@ impl<Signer: Sign, M: Deref, T: Deref, K: Deref, F: Deref, L: Deref> ChannelMana
2146
2156
msg : update
2147
2157
} ) ;
2148
2158
}
2159
+ did_work = true ;
2149
2160
chan. set_update_status ( UpdateStatus :: Enabled ) ;
2150
2161
} ,
2151
2162
_ => { } ,
2152
2163
}
2153
2164
}
2165
+
2166
+ if !did_work {
2167
+ persistence_guard. persistence_update = false ;
2168
+ }
2154
2169
}
2155
2170
2156
2171
/// Indicates that the preimage for payment_hash is unknown or the received amount is incorrect
0 commit comments