@@ -224,10 +224,9 @@ impl<'a> chain::Watch<EnforcingSigner> for TestChainMonitor<'a> {
224224}
225225
226226pub 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 > > ,
231230 /// When we get an update_persisted_channel call with no ChannelMonitorUpdate, we insert the
232231 /// MonitorUpdateId here.
233232 pub chain_sync_monitor_persistences : Mutex < HashMap < OutPoint , HashSet < MonitorUpdateId > > > ,
@@ -238,35 +237,39 @@ pub struct TestPersister {
238237impl TestPersister {
239238 pub fn new ( ) -> Self {
240239 Self {
241- update_ret : Mutex :: new ( chain:: ChannelMonitorUpdateStatus :: Completed ) ,
242- next_update_ret : Mutex :: new ( None ) ,
240+ update_rets : Mutex :: new ( VecDeque :: new ( ) ) ,
243241 chain_sync_monitor_persistences : Mutex :: new ( HashMap :: new ( ) ) ,
244242 offchain_monitor_updates : Mutex :: new ( HashMap :: new ( ) ) ,
245243 }
246244 }
247245
246+ /// Clear the queue of update statuses and set the one we'll always return.
248247 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) ;
250251 }
251252
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) ;
254256 }
255257}
256258impl < Signer : keysinterface:: Sign > chainmonitor:: Persist < Signer > for TestPersister {
257259 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
263264 }
264265
265266 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+ } ;
270273 if update. is_none ( ) {
271274 self . chain_sync_monitor_persistences . lock ( ) . unwrap ( ) . entry ( funding_txo) . or_insert ( HashSet :: new ( ) ) . insert ( update_id) ;
272275 } else {
0 commit comments