@@ -81,16 +81,16 @@ impl Writer for VecWriter {
81
81
}
82
82
83
83
static mut IN_RESTORE : bool = false ;
84
- pub struct TestChannelMonitor {
85
- pub simple_monitor : Arc < channelmonitor:: SimpleManyChannelMonitor < OutPoint > > ,
84
+ pub struct TestChannelMonitor < ' a > {
85
+ pub simple_monitor : Arc < channelmonitor:: SimpleManyChannelMonitor < ' a , OutPoint > > ,
86
86
pub update_ret : Mutex < Result < ( ) , channelmonitor:: ChannelMonitorUpdateErr > > ,
87
87
pub latest_good_update : Mutex < HashMap < OutPoint , Vec < u8 > > > ,
88
88
pub latest_update_good : Mutex < HashMap < OutPoint , bool > > ,
89
89
pub latest_updates_good_at_last_ser : Mutex < HashMap < OutPoint , bool > > ,
90
90
pub should_update_manager : atomic:: AtomicBool ,
91
91
}
92
- impl TestChannelMonitor {
93
- pub fn new ( chain_monitor : Arc < chaininterface:: ChainWatchInterface > , broadcaster : Arc < chaininterface:: BroadcasterInterface > , logger : Arc < Logger > , feeest : Arc < chaininterface:: FeeEstimator > ) -> Self {
92
+ impl < ' a > TestChannelMonitor < ' a > {
93
+ pub fn new ( chain_monitor : Arc < chaininterface:: ChainWatchInterface < ' a > > , broadcaster : Arc < chaininterface:: BroadcasterInterface > , logger : Arc < Logger > , feeest : Arc < chaininterface:: FeeEstimator > ) -> Self {
94
94
Self {
95
95
simple_monitor : channelmonitor:: SimpleManyChannelMonitor :: new ( chain_monitor, broadcaster, logger, feeest) ,
96
96
update_ret : Mutex :: new ( Ok ( ( ) ) ) ,
@@ -101,7 +101,7 @@ impl TestChannelMonitor {
101
101
}
102
102
}
103
103
}
104
- impl channelmonitor:: ManyChannelMonitor for TestChannelMonitor {
104
+ impl < ' a > channelmonitor:: ManyChannelMonitor for TestChannelMonitor < ' a > {
105
105
fn add_update_monitor ( & self , funding_txo : OutPoint , monitor : channelmonitor:: ChannelMonitor ) -> Result < ( ) , channelmonitor:: ChannelMonitorUpdateErr > {
106
106
let ret = self . update_ret . lock ( ) . unwrap ( ) . clone ( ) ;
107
107
if let Ok ( ( ) ) = ret {
@@ -198,55 +198,6 @@ pub fn do_test(data: &[u8]) {
198
198
} }
199
199
}
200
200
201
- macro_rules! reload_node {
202
- ( $ser: expr, $node_id: expr, $old_monitors: expr) => { {
203
- let logger: Arc <Logger > = Arc :: new( test_logger:: TestLogger :: new( $node_id. to_string( ) ) ) ;
204
- let watch = Arc :: new( ChainWatchInterfaceUtil :: new( Network :: Bitcoin , Arc :: clone( & logger) ) ) ;
205
- let monitor = Arc :: new( TestChannelMonitor :: new( watch. clone( ) , broadcast. clone( ) , logger. clone( ) , fee_est. clone( ) ) ) ;
206
-
207
- let keys_manager = Arc :: new( KeyProvider { node_id: $node_id, session_id: atomic:: AtomicU8 :: new( 0 ) , channel_id: atomic:: AtomicU8 :: new( 0 ) } ) ;
208
- let mut config = UserConfig :: new( ) ;
209
- config. channel_options. fee_proportional_millionths = 0 ;
210
- config. channel_options. announced_channel = true ;
211
- config. peer_channel_config_limits. min_dust_limit_satoshis = 0 ;
212
-
213
- let mut monitors = HashMap :: new( ) ;
214
- let mut old_monitors = $old_monitors. latest_good_update. lock( ) . unwrap( ) ;
215
- for ( outpoint, monitor_ser) in old_monitors. drain( ) {
216
- monitors. insert( outpoint, <( Sha256d , ChannelMonitor ) >:: read( & mut Cursor :: new( & monitor_ser) , Arc :: clone( & logger) ) . expect( "Failed to read monitor" ) . 1 ) ;
217
- monitor. latest_good_update. lock( ) . unwrap( ) . insert( outpoint, monitor_ser) ;
218
- }
219
- let mut monitor_refs = HashMap :: new( ) ;
220
- for ( outpoint, monitor) in monitors. iter( ) {
221
- monitor_refs. insert( * outpoint, monitor) ;
222
- }
223
-
224
- let read_args = ChannelManagerReadArgs {
225
- keys_manager,
226
- fee_estimator: fee_est. clone( ) ,
227
- monitor: monitor. clone( ) ,
228
- chain_monitor: watch,
229
- tx_broadcaster: broadcast. clone( ) ,
230
- logger,
231
- default_config: config,
232
- channel_monitors: & monitor_refs,
233
- } ;
234
-
235
- let res = ( <( Sha256d , ChannelManager ) >:: read( & mut Cursor :: new( & $ser. 0 ) , read_args) . expect( "Failed to read manager" ) . 1 , monitor) ;
236
- for ( _, was_good) in $old_monitors. latest_updates_good_at_last_ser. lock( ) . unwrap( ) . iter( ) {
237
- if !was_good {
238
- // If the last time we updated a monitor we didn't successfully update (and we
239
- // have sense updated our serialized copy of the ChannelManager) we may
240
- // force-close the channel on our counterparty cause we know we're missing
241
- // something. Thus, we just return here since we can't continue to test.
242
- return ;
243
- }
244
- }
245
- res
246
- } }
247
- }
248
-
249
-
250
201
let mut channel_txn = Vec :: new ( ) ;
251
202
macro_rules! make_channel {
252
203
( $source: expr, $dest: expr, $chan_id: expr) => { {
@@ -356,11 +307,11 @@ pub fn do_test(data: &[u8]) {
356
307
357
308
// 3 nodes is enough to hit all the possible cases, notably unknown-source-unknown-dest
358
309
// forwarding.
359
- let ( mut node_a, mut monitor_a) = make_node ! ( 0 ) ;
360
- let ( mut node_b, mut monitor_b) = make_node ! ( 1 ) ;
361
- let ( mut node_c, mut monitor_c) = make_node ! ( 2 ) ;
310
+ let ( node_a, monitor_a) = make_node ! ( 0 ) ;
311
+ let ( node_b, monitor_b) = make_node ! ( 1 ) ;
312
+ let ( node_c, monitor_c) = make_node ! ( 2 ) ;
362
313
363
- let mut nodes = [ node_a, node_b, node_c] ;
314
+ let nodes = [ node_a, node_b, node_c] ;
364
315
365
316
make_channel ! ( nodes[ 0 ] , nodes[ 1 ] , 0 ) ;
366
317
make_channel ! ( nodes[ 1 ] , nodes[ 2 ] , 1 ) ;
@@ -688,10 +639,6 @@ pub fn do_test(data: &[u8]) {
688
639
chan_a_disconnected = true ;
689
640
drain_msg_events_on_disconnect ! ( 0 ) ;
690
641
}
691
- let ( new_node_a, new_monitor_a) = reload_node ! ( node_a_ser, 0 , monitor_a) ;
692
- node_a = Arc :: new ( new_node_a) ;
693
- nodes[ 0 ] = node_a. clone ( ) ;
694
- monitor_a = new_monitor_a;
695
642
} ,
696
643
0x20 => {
697
644
if !chan_a_disconnected {
@@ -706,21 +653,13 @@ pub fn do_test(data: &[u8]) {
706
653
nodes[ 2 ] . get_and_clear_pending_msg_events ( ) ;
707
654
bc_events. clear ( ) ;
708
655
}
709
- let ( new_node_b, new_monitor_b) = reload_node ! ( node_b_ser, 1 , monitor_b) ;
710
- node_b = Arc :: new ( new_node_b) ;
711
- nodes[ 1 ] = node_b. clone ( ) ;
712
- monitor_b = new_monitor_b;
713
656
} ,
714
657
0x21 => {
715
658
if !chan_b_disconnected {
716
659
nodes[ 1 ] . peer_disconnected ( & nodes[ 2 ] . get_our_node_id ( ) , false ) ;
717
660
chan_b_disconnected = true ;
718
661
drain_msg_events_on_disconnect ! ( 2 ) ;
719
662
}
720
- let ( new_node_c, new_monitor_c) = reload_node ! ( node_c_ser, 2 , monitor_c) ;
721
- node_c = Arc :: new ( new_node_c) ;
722
- nodes[ 2 ] = node_c. clone ( ) ;
723
- monitor_c = new_monitor_c;
724
663
} ,
725
664
_ => test_return ! ( ) ,
726
665
}
0 commit comments