@@ -52,7 +52,7 @@ use secp256k1::Secp256k1;
52
52
53
53
use std:: mem;
54
54
use std:: cmp:: Ordering ;
55
- use std:: collections:: { HashSet , HashMap } ;
55
+ use std:: collections:: { HashSet , hash_map , HashMap } ;
56
56
use std:: sync:: { Arc , Mutex } ;
57
57
use std:: sync:: atomic;
58
58
use std:: io:: Cursor ;
@@ -80,6 +80,7 @@ impl Writer for VecWriter {
80
80
}
81
81
}
82
82
83
+ static mut IN_RESTORE : bool = false ;
83
84
pub struct TestChannelMonitor {
84
85
pub simple_monitor : Arc < channelmonitor:: SimpleManyChannelMonitor < OutPoint > > ,
85
86
pub update_ret : Mutex < Result < ( ) , channelmonitor:: ChannelMonitorUpdateErr > > ,
@@ -107,7 +108,18 @@ impl channelmonitor::ManyChannelMonitor for TestChannelMonitor {
107
108
let mut ser = VecWriter ( Vec :: new ( ) ) ;
108
109
monitor. write_for_disk ( & mut ser) . unwrap ( ) ;
109
110
self . latest_good_update . lock ( ) . unwrap ( ) . insert ( funding_txo, ser. 0 ) ;
110
- self . latest_update_good . lock ( ) . unwrap ( ) . insert ( funding_txo, true ) ;
111
+ match self . latest_update_good . lock ( ) . unwrap ( ) . entry ( funding_txo) {
112
+ hash_map:: Entry :: Vacant ( mut e) => { e. insert ( true ) ; } ,
113
+ hash_map:: Entry :: Occupied ( mut e) => {
114
+ if !e. get ( ) && unsafe { IN_RESTORE } {
115
+ // Technically we can't consider an update to be "good" unless we're doing
116
+ // it in response to a test_restore_channel_monitor as the channel may
117
+ // still be waiting on such a call, so only set us to good if we're in the
118
+ // middle of a restore call.
119
+ e. insert ( true ) ;
120
+ }
121
+ } ,
122
+ }
111
123
self . should_update_manager . store ( true , atomic:: Ordering :: Relaxed ) ;
112
124
} else {
113
125
self . latest_update_good . lock ( ) . unwrap ( ) . insert ( funding_txo, false ) ;
@@ -619,9 +631,9 @@ pub fn do_test(data: &[u8]) {
619
631
0x03 => * monitor_a. update_ret . lock ( ) . unwrap ( ) = Ok ( ( ) ) ,
620
632
0x04 => * monitor_b. update_ret . lock ( ) . unwrap ( ) = Ok ( ( ) ) ,
621
633
0x05 => * monitor_c. update_ret . lock ( ) . unwrap ( ) = Ok ( ( ) ) ,
622
- 0x06 => nodes[ 0 ] . test_restore_channel_monitor ( ) ,
623
- 0x07 => nodes[ 1 ] . test_restore_channel_monitor ( ) ,
624
- 0x08 => nodes[ 2 ] . test_restore_channel_monitor ( ) ,
634
+ 0x06 => { unsafe { IN_RESTORE = true } ; nodes[ 0 ] . test_restore_channel_monitor ( ) ; unsafe { IN_RESTORE = false } ; } ,
635
+ 0x07 => { unsafe { IN_RESTORE = true } ; nodes[ 1 ] . test_restore_channel_monitor ( ) ; unsafe { IN_RESTORE = false } ; } ,
636
+ 0x08 => { unsafe { IN_RESTORE = true } ; nodes[ 2 ] . test_restore_channel_monitor ( ) ; unsafe { IN_RESTORE = false } ; } ,
625
637
0x09 => send_payment ! ( nodes[ 0 ] , ( & nodes[ 1 ] , chan_a) ) ,
626
638
0x0a => send_payment ! ( nodes[ 1 ] , ( & nodes[ 0 ] , chan_a) ) ,
627
639
0x0b => send_payment ! ( nodes[ 1 ] , ( & nodes[ 2 ] , chan_b) ) ,
0 commit comments