@@ -224,10 +224,9 @@ impl<'a> chain::Watch<EnforcingSigner> for TestChainMonitor<'a> {
224
224
}
225
225
226
226
pub struct TestPersister {
227
- pub update_ret : Mutex < chain:: ChannelMonitorUpdateStatus > ,
228
- /// If this is set to Some(), after the next return, we'll always return this until update_ret
229
- /// is changed:
230
- pub next_update_ret : Mutex < Option < chain:: ChannelMonitorUpdateStatus > > ,
227
+ /// The queue of update statuses we'll return. If only one is queued, we'll always return it. If
228
+ /// none are queued, ::Completed will always be returned.
229
+ pub update_rets : Mutex < VecDeque < chain:: ChannelMonitorUpdateStatus > > ,
231
230
/// When we get an update_persisted_channel call with no ChannelMonitorUpdate, we insert the
232
231
/// MonitorUpdateId here.
233
232
pub chain_sync_monitor_persistences : Mutex < HashMap < OutPoint , HashSet < MonitorUpdateId > > > ,
@@ -238,35 +237,39 @@ pub struct TestPersister {
238
237
impl TestPersister {
239
238
pub fn new ( ) -> Self {
240
239
Self {
241
- update_ret : Mutex :: new ( chain:: ChannelMonitorUpdateStatus :: Completed ) ,
242
- next_update_ret : Mutex :: new ( None ) ,
240
+ update_rets : Mutex :: new ( VecDeque :: new ( ) ) ,
243
241
chain_sync_monitor_persistences : Mutex :: new ( HashMap :: new ( ) ) ,
244
242
offchain_monitor_updates : Mutex :: new ( HashMap :: new ( ) ) ,
245
243
}
246
244
}
247
245
246
+ /// Clear the queue of update statuses and set the one we'll always return.
248
247
pub fn set_update_ret ( & self , ret : chain:: ChannelMonitorUpdateStatus ) {
249
- * self . update_ret . lock ( ) . unwrap ( ) = ret;
248
+ let mut update_rets = self . update_rets . lock ( ) . unwrap ( ) ;
249
+ update_rets. clear ( ) ;
250
+ update_rets. push_front ( ret) ;
250
251
}
251
252
252
- pub fn set_next_update_ret ( & self , next_ret : Option < chain:: ChannelMonitorUpdateStatus > ) {
253
- * self . next_update_ret . lock ( ) . unwrap ( ) = next_ret;
253
+ /// Queue an update status to return.
254
+ pub fn set_next_update_ret ( & self , next_ret : chain:: ChannelMonitorUpdateStatus ) {
255
+ self . update_rets . lock ( ) . unwrap ( ) . push_back ( next_ret) ;
254
256
}
255
257
}
256
258
impl < Signer : keysinterface:: Sign > chainmonitor:: Persist < Signer > for TestPersister {
257
259
fn persist_new_channel ( & self , _funding_txo : OutPoint , _data : & channelmonitor:: ChannelMonitor < Signer > , _id : MonitorUpdateId ) -> chain:: ChannelMonitorUpdateStatus {
258
- let ret = self . update_ret . lock ( ) . unwrap ( ) . clone ( ) ;
259
- if let Some ( next_ret) = self . next_update_ret . lock ( ) . unwrap ( ) . take ( ) {
260
- * self . update_ret . lock ( ) . unwrap ( ) = next_ret;
261
- }
262
- ret
260
+ let mut update_rets = self . update_rets . lock ( ) . unwrap ( ) ;
261
+ if update_rets. len ( ) > 1 { return update_rets. pop_front ( ) . unwrap ( ) }
262
+ else if update_rets. len ( ) == 1 { return * update_rets. front ( ) . clone ( ) . unwrap ( ) }
263
+ chain:: ChannelMonitorUpdateStatus :: Completed
263
264
}
264
265
265
266
fn update_persisted_channel ( & self , funding_txo : OutPoint , update : & Option < channelmonitor:: ChannelMonitorUpdate > , _data : & channelmonitor:: ChannelMonitor < Signer > , update_id : MonitorUpdateId ) -> chain:: ChannelMonitorUpdateStatus {
266
- let ret = self . update_ret . lock ( ) . unwrap ( ) . clone ( ) ;
267
- if let Some ( next_ret) = self . next_update_ret . lock ( ) . unwrap ( ) . take ( ) {
268
- * self . update_ret . lock ( ) . unwrap ( ) = next_ret;
269
- }
267
+ let ret = {
268
+ let mut update_rets = self . update_rets . lock ( ) . unwrap ( ) ;
269
+ if update_rets. len ( ) > 1 { update_rets. pop_front ( ) . unwrap ( ) }
270
+ else if update_rets. len ( ) == 1 { * update_rets. front ( ) . clone ( ) . unwrap ( ) }
271
+ else { chain:: ChannelMonitorUpdateStatus :: Completed }
272
+ } ;
270
273
if update. is_none ( ) {
271
274
self . chain_sync_monitor_persistences . lock ( ) . unwrap ( ) . entry ( funding_txo) . or_insert ( HashSet :: new ( ) ) . insert ( update_id) ;
272
275
} else {
0 commit comments