@@ -198,7 +198,7 @@ struct TestChainMonitor {
198
198
Arc < TestPersister > ,
199
199
> ,
200
200
> ,
201
- pub latest_monitors : Mutex < HashMap < OutPoint , LatestMonitorState > > ,
201
+ pub latest_monitors : Mutex < HashMap < ChannelId , LatestMonitorState > > ,
202
202
}
203
203
impl TestChainMonitor {
204
204
pub fn new (
@@ -222,12 +222,12 @@ impl TestChainMonitor {
222
222
}
223
223
impl chain:: Watch < TestChannelSigner > for TestChainMonitor {
224
224
fn watch_channel (
225
- & self , funding_txo : OutPoint , monitor : channelmonitor:: ChannelMonitor < TestChannelSigner > ,
225
+ & self , channel_id : ChannelId , monitor : channelmonitor:: ChannelMonitor < TestChannelSigner > ,
226
226
) -> Result < chain:: ChannelMonitorUpdateStatus , ( ) > {
227
227
let mut ser = VecWriter ( Vec :: new ( ) ) ;
228
228
monitor. write ( & mut ser) . unwrap ( ) ;
229
229
let monitor_id = monitor. get_latest_update_id ( ) ;
230
- let res = self . chain_monitor . watch_channel ( funding_txo , monitor) ;
230
+ let res = self . chain_monitor . watch_channel ( channel_id , monitor) ;
231
231
let state = match res {
232
232
Ok ( chain:: ChannelMonitorUpdateStatus :: Completed ) => LatestMonitorState {
233
233
persisted_monitor_id : monitor_id,
@@ -240,17 +240,17 @@ impl chain::Watch<TestChannelSigner> for TestChainMonitor {
240
240
Ok ( chain:: ChannelMonitorUpdateStatus :: UnrecoverableError ) => panic ! ( ) ,
241
241
Err ( ( ) ) => panic ! ( ) ,
242
242
} ;
243
- if self . latest_monitors . lock ( ) . unwrap ( ) . insert ( funding_txo , state) . is_some ( ) {
243
+ if self . latest_monitors . lock ( ) . unwrap ( ) . insert ( channel_id , state) . is_some ( ) {
244
244
panic ! ( "Already had monitor pre-watch_channel" ) ;
245
245
}
246
246
res
247
247
}
248
248
249
249
fn update_channel (
250
- & self , funding_txo : OutPoint , update : & channelmonitor:: ChannelMonitorUpdate ,
250
+ & self , channel_id : ChannelId , update : & channelmonitor:: ChannelMonitorUpdate ,
251
251
) -> chain:: ChannelMonitorUpdateStatus {
252
252
let mut map_lock = self . latest_monitors . lock ( ) . unwrap ( ) ;
253
- let map_entry = map_lock. get_mut ( & funding_txo ) . expect ( "Didn't have monitor on update call" ) ;
253
+ let map_entry = map_lock. get_mut ( & channel_id ) . expect ( "Didn't have monitor on update call" ) ;
254
254
let latest_monitor_data = map_entry
255
255
. pending_monitors
256
256
. last ( )
@@ -274,7 +274,7 @@ impl chain::Watch<TestChannelSigner> for TestChainMonitor {
274
274
. unwrap ( ) ;
275
275
let mut ser = VecWriter ( Vec :: new ( ) ) ;
276
276
deserialized_monitor. write ( & mut ser) . unwrap ( ) ;
277
- let res = self . chain_monitor . update_channel ( funding_txo , update) ;
277
+ let res = self . chain_monitor . update_channel ( channel_id , update) ;
278
278
match res {
279
279
chain:: ChannelMonitorUpdateStatus :: Completed => {
280
280
map_entry. persisted_monitor_id = update. update_id ;
@@ -763,9 +763,9 @@ pub fn do_test<Out: Output>(data: &[u8], underlying_out: Out, anchors: bool) {
763
763
. 1 ,
764
764
chain_monitor. clone( ) ,
765
765
) ;
766
- for ( funding_txo , mon) in monitors. drain( ) {
766
+ for ( channel_id , mon) in monitors. drain( ) {
767
767
assert_eq!(
768
- chain_monitor. chain_monitor. watch_channel( funding_txo , mon) ,
768
+ chain_monitor. chain_monitor. watch_channel( channel_id , mon) ,
769
769
Ok ( ChannelMonitorUpdateStatus :: Completed )
770
770
) ;
771
771
}
@@ -836,7 +836,6 @@ pub fn do_test<Out: Output>(data: &[u8], underlying_out: Out, anchors: bool) {
836
836
} ;
837
837
838
838
$source. handle_accept_channel( $dest. get_our_node_id( ) , & accept_channel) ;
839
- let funding_output;
840
839
{
841
840
let mut events = $source. get_and_clear_pending_events( ) ;
842
841
assert_eq!( events. len( ) , 1 ) ;
@@ -856,7 +855,6 @@ pub fn do_test<Out: Output>(data: &[u8], underlying_out: Out, anchors: bool) {
856
855
script_pubkey: output_script,
857
856
} ] ,
858
857
} ;
859
- funding_output = OutPoint { txid: tx. compute_txid( ) , index: 0 } ;
860
858
$source
861
859
. funding_transaction_generated(
862
860
temporary_channel_id,
@@ -901,13 +899,19 @@ pub fn do_test<Out: Output>(data: &[u8], underlying_out: Out, anchors: bool) {
901
899
$source. handle_funding_signed( $dest. get_our_node_id( ) , & funding_signed) ;
902
900
let events = $source. get_and_clear_pending_events( ) ;
903
901
assert_eq!( events. len( ) , 1 ) ;
904
- if let events:: Event :: ChannelPending { ref counterparty_node_id, .. } = events[ 0 ] {
902
+ let channel_id = if let events:: Event :: ChannelPending {
903
+ ref counterparty_node_id,
904
+ ref channel_id,
905
+ ..
906
+ } = events[ 0 ]
907
+ {
905
908
assert_eq!( counterparty_node_id, & $dest. get_our_node_id( ) ) ;
909
+ channel_id. clone( )
906
910
} else {
907
911
panic!( "Wrong event type" ) ;
908
- }
912
+ } ;
909
913
910
- funding_output
914
+ channel_id
911
915
} } ;
912
916
}
913
917
@@ -974,8 +978,8 @@ pub fn do_test<Out: Output>(data: &[u8], underlying_out: Out, anchors: bool) {
974
978
975
979
let mut nodes = [ node_a, node_b, node_c] ;
976
980
977
- let chan_1_funding = make_channel ! ( nodes[ 0 ] , nodes[ 1 ] , keys_manager_b, 0 ) ;
978
- let chan_2_funding = make_channel ! ( nodes[ 1 ] , nodes[ 2 ] , keys_manager_c, 1 ) ;
981
+ let chan_1_id = make_channel ! ( nodes[ 0 ] , nodes[ 1 ] , keys_manager_b, 0 ) ;
982
+ let chan_2_id = make_channel ! ( nodes[ 1 ] , nodes[ 2 ] , keys_manager_c, 1 ) ;
979
983
980
984
for node in nodes. iter ( ) {
981
985
confirm_txn ! ( node) ;
@@ -1374,14 +1378,14 @@ pub fn do_test<Out: Output>(data: &[u8], underlying_out: Out, anchors: bool) {
1374
1378
}
1375
1379
} ;
1376
1380
1377
- let complete_all_monitor_updates = |monitor : & Arc < TestChainMonitor > , chan_funding | {
1378
- if let Some ( state) = monitor. latest_monitors . lock ( ) . unwrap ( ) . get_mut ( chan_funding ) {
1381
+ let complete_all_monitor_updates = |monitor : & Arc < TestChainMonitor > , chan_id | {
1382
+ if let Some ( state) = monitor. latest_monitors . lock ( ) . unwrap ( ) . get_mut ( chan_id ) {
1379
1383
assert ! (
1380
1384
state. pending_monitors. windows( 2 ) . all( |pair| pair[ 0 ] . 0 < pair[ 1 ] . 0 ) ,
1381
1385
"updates should be sorted by id"
1382
1386
) ;
1383
1387
for ( id, data) in state. pending_monitors . drain ( ..) {
1384
- monitor. chain_monitor . channel_monitor_updated ( * chan_funding , id) . unwrap ( ) ;
1388
+ monitor. chain_monitor . channel_monitor_updated ( * chan_id , id) . unwrap ( ) ;
1385
1389
if id > state. persisted_monitor_id {
1386
1390
state. persisted_monitor_id = id;
1387
1391
state. persisted_monitor = data;
@@ -1421,10 +1425,10 @@ pub fn do_test<Out: Output>(data: &[u8], underlying_out: Out, anchors: bool) {
1421
1425
ChannelMonitorUpdateStatus :: Completed
1422
1426
} ,
1423
1427
1424
- 0x08 => complete_all_monitor_updates ( & monitor_a, & chan_1_funding ) ,
1425
- 0x09 => complete_all_monitor_updates ( & monitor_b, & chan_1_funding ) ,
1426
- 0x0a => complete_all_monitor_updates ( & monitor_b, & chan_2_funding ) ,
1427
- 0x0b => complete_all_monitor_updates ( & monitor_c, & chan_2_funding ) ,
1428
+ 0x08 => complete_all_monitor_updates ( & monitor_a, & chan_1_id ) ,
1429
+ 0x09 => complete_all_monitor_updates ( & monitor_b, & chan_1_id ) ,
1430
+ 0x0a => complete_all_monitor_updates ( & monitor_b, & chan_2_id ) ,
1431
+ 0x0b => complete_all_monitor_updates ( & monitor_c, & chan_2_id ) ,
1428
1432
1429
1433
0x0c => {
1430
1434
if !chan_a_disconnected {
@@ -1694,21 +1698,21 @@ pub fn do_test<Out: Output>(data: &[u8], underlying_out: Out, anchors: bool) {
1694
1698
nodes[ 2 ] . maybe_update_chan_fees ( ) ;
1695
1699
} ,
1696
1700
1697
- 0xf0 => complete_monitor_update ( & monitor_a, & chan_1_funding , & complete_first) ,
1698
- 0xf1 => complete_monitor_update ( & monitor_a, & chan_1_funding , & complete_second) ,
1699
- 0xf2 => complete_monitor_update ( & monitor_a, & chan_1_funding , & Vec :: pop) ,
1701
+ 0xf0 => complete_monitor_update ( & monitor_a, & chan_1_id , & complete_first) ,
1702
+ 0xf1 => complete_monitor_update ( & monitor_a, & chan_1_id , & complete_second) ,
1703
+ 0xf2 => complete_monitor_update ( & monitor_a, & chan_1_id , & Vec :: pop) ,
1700
1704
1701
- 0xf4 => complete_monitor_update ( & monitor_b, & chan_1_funding , & complete_first) ,
1702
- 0xf5 => complete_monitor_update ( & monitor_b, & chan_1_funding , & complete_second) ,
1703
- 0xf6 => complete_monitor_update ( & monitor_b, & chan_1_funding , & Vec :: pop) ,
1705
+ 0xf4 => complete_monitor_update ( & monitor_b, & chan_1_id , & complete_first) ,
1706
+ 0xf5 => complete_monitor_update ( & monitor_b, & chan_1_id , & complete_second) ,
1707
+ 0xf6 => complete_monitor_update ( & monitor_b, & chan_1_id , & Vec :: pop) ,
1704
1708
1705
- 0xf8 => complete_monitor_update ( & monitor_b, & chan_2_funding , & complete_first) ,
1706
- 0xf9 => complete_monitor_update ( & monitor_b, & chan_2_funding , & complete_second) ,
1707
- 0xfa => complete_monitor_update ( & monitor_b, & chan_2_funding , & Vec :: pop) ,
1709
+ 0xf8 => complete_monitor_update ( & monitor_b, & chan_2_id , & complete_first) ,
1710
+ 0xf9 => complete_monitor_update ( & monitor_b, & chan_2_id , & complete_second) ,
1711
+ 0xfa => complete_monitor_update ( & monitor_b, & chan_2_id , & Vec :: pop) ,
1708
1712
1709
- 0xfc => complete_monitor_update ( & monitor_c, & chan_2_funding , & complete_first) ,
1710
- 0xfd => complete_monitor_update ( & monitor_c, & chan_2_funding , & complete_second) ,
1711
- 0xfe => complete_monitor_update ( & monitor_c, & chan_2_funding , & Vec :: pop) ,
1713
+ 0xfc => complete_monitor_update ( & monitor_c, & chan_2_id , & complete_first) ,
1714
+ 0xfd => complete_monitor_update ( & monitor_c, & chan_2_id , & complete_second) ,
1715
+ 0xfe => complete_monitor_update ( & monitor_c, & chan_2_id , & Vec :: pop) ,
1712
1716
1713
1717
0xff => {
1714
1718
// Test that no channel is in a stuck state where neither party can send funds even
@@ -1722,10 +1726,10 @@ pub fn do_test<Out: Output>(data: &[u8], underlying_out: Out, anchors: bool) {
1722
1726
* monitor_c. persister . update_ret . lock ( ) . unwrap ( ) =
1723
1727
ChannelMonitorUpdateStatus :: Completed ;
1724
1728
1725
- complete_all_monitor_updates ( & monitor_a, & chan_1_funding ) ;
1726
- complete_all_monitor_updates ( & monitor_b, & chan_1_funding ) ;
1727
- complete_all_monitor_updates ( & monitor_b, & chan_2_funding ) ;
1728
- complete_all_monitor_updates ( & monitor_c, & chan_2_funding ) ;
1729
+ complete_all_monitor_updates ( & monitor_a, & chan_1_id ) ;
1730
+ complete_all_monitor_updates ( & monitor_b, & chan_1_id ) ;
1731
+ complete_all_monitor_updates ( & monitor_b, & chan_2_id ) ;
1732
+ complete_all_monitor_updates ( & monitor_c, & chan_2_id ) ;
1729
1733
1730
1734
// Next, make sure peers are all connected to each other
1731
1735
if chan_a_disconnected {
0 commit comments