@@ -189,7 +189,7 @@ struct TestChainMonitor {
189
189
Arc < TestPersister > ,
190
190
> ,
191
191
> ,
192
- pub latest_monitors : Mutex < HashMap < OutPoint , LatestMonitorState > > ,
192
+ pub latest_monitors : Mutex < HashMap < ChannelId , LatestMonitorState > > ,
193
193
}
194
194
impl TestChainMonitor {
195
195
pub fn new (
@@ -213,12 +213,12 @@ impl TestChainMonitor {
213
213
}
214
214
impl chain:: Watch < TestChannelSigner > for TestChainMonitor {
215
215
fn watch_channel (
216
- & self , funding_txo : OutPoint , monitor : channelmonitor:: ChannelMonitor < TestChannelSigner > ,
216
+ & self , channel_id : ChannelId , monitor : channelmonitor:: ChannelMonitor < TestChannelSigner > ,
217
217
) -> Result < chain:: ChannelMonitorUpdateStatus , ( ) > {
218
218
let mut ser = VecWriter ( Vec :: new ( ) ) ;
219
219
monitor. write ( & mut ser) . unwrap ( ) ;
220
220
let monitor_id = monitor. get_latest_update_id ( ) ;
221
- let res = self . chain_monitor . watch_channel ( funding_txo , monitor) ;
221
+ let res = self . chain_monitor . watch_channel ( channel_id , monitor) ;
222
222
let state = match res {
223
223
Ok ( chain:: ChannelMonitorUpdateStatus :: Completed ) => LatestMonitorState {
224
224
persisted_monitor_id : monitor_id,
@@ -231,17 +231,17 @@ impl chain::Watch<TestChannelSigner> for TestChainMonitor {
231
231
Ok ( chain:: ChannelMonitorUpdateStatus :: UnrecoverableError ) => panic ! ( ) ,
232
232
Err ( ( ) ) => panic ! ( ) ,
233
233
} ;
234
- if self . latest_monitors . lock ( ) . unwrap ( ) . insert ( funding_txo , state) . is_some ( ) {
234
+ if self . latest_monitors . lock ( ) . unwrap ( ) . insert ( channel_id , state) . is_some ( ) {
235
235
panic ! ( "Already had monitor pre-watch_channel" ) ;
236
236
}
237
237
res
238
238
}
239
239
240
240
fn update_channel (
241
- & self , funding_txo : OutPoint , update : & channelmonitor:: ChannelMonitorUpdate ,
241
+ & self , channel_id : ChannelId , update : & channelmonitor:: ChannelMonitorUpdate ,
242
242
) -> chain:: ChannelMonitorUpdateStatus {
243
243
let mut map_lock = self . latest_monitors . lock ( ) . unwrap ( ) ;
244
- let map_entry = map_lock. get_mut ( & funding_txo ) . expect ( "Didn't have monitor on update call" ) ;
244
+ let map_entry = map_lock. get_mut ( & channel_id ) . expect ( "Didn't have monitor on update call" ) ;
245
245
let latest_monitor_data = map_entry
246
246
. pending_monitors
247
247
. last ( )
@@ -265,7 +265,7 @@ impl chain::Watch<TestChannelSigner> for TestChainMonitor {
265
265
. unwrap ( ) ;
266
266
let mut ser = VecWriter ( Vec :: new ( ) ) ;
267
267
deserialized_monitor. write ( & mut ser) . unwrap ( ) ;
268
- let res = self . chain_monitor . update_channel ( funding_txo , update) ;
268
+ let res = self . chain_monitor . update_channel ( channel_id , update) ;
269
269
match res {
270
270
chain:: ChannelMonitorUpdateStatus :: Completed => {
271
271
map_entry. persisted_monitor_id = update. update_id ;
@@ -711,9 +711,9 @@ pub fn do_test<Out: Output>(data: &[u8], underlying_out: Out, anchors: bool) {
711
711
712
712
let mut monitors = new_hash_map( ) ;
713
713
let mut old_monitors = $old_monitors. latest_monitors. lock( ) . unwrap( ) ;
714
- for ( outpoint , mut prev_state) in old_monitors. drain( ) {
714
+ for ( channel_id , mut prev_state) in old_monitors. drain( ) {
715
715
monitors. insert(
716
- outpoint ,
716
+ channel_id ,
717
717
<( BlockHash , ChannelMonitor <TestChannelSigner >) >:: read(
718
718
& mut Cursor :: new( & prev_state. persisted_monitor) ,
719
719
( & * $keys_manager, & * $keys_manager) ,
@@ -725,11 +725,11 @@ pub fn do_test<Out: Output>(data: &[u8], underlying_out: Out, anchors: bool) {
725
725
// considering them discarded. LDK should replay these for us as they're stored in
726
726
// the `ChannelManager`.
727
727
prev_state. pending_monitors. clear( ) ;
728
- chain_monitor. latest_monitors. lock( ) . unwrap( ) . insert( outpoint , prev_state) ;
728
+ chain_monitor. latest_monitors. lock( ) . unwrap( ) . insert( channel_id , prev_state) ;
729
729
}
730
730
let mut monitor_refs = new_hash_map( ) ;
731
- for ( outpoint , monitor) in monitors. iter( ) {
732
- monitor_refs. insert( * outpoint , monitor) ;
731
+ for ( channel_id , monitor) in monitors. iter( ) {
732
+ monitor_refs. insert( * channel_id , monitor) ;
733
733
}
734
734
735
735
let read_args = ChannelManagerReadArgs {
@@ -752,9 +752,9 @@ pub fn do_test<Out: Output>(data: &[u8], underlying_out: Out, anchors: bool) {
752
752
. 1 ,
753
753
chain_monitor. clone( ) ,
754
754
) ;
755
- for ( funding_txo , mon) in monitors. drain( ) {
755
+ for ( channel_id , mon) in monitors. drain( ) {
756
756
assert_eq!(
757
- chain_monitor. chain_monitor. watch_channel( funding_txo , mon) ,
757
+ chain_monitor. chain_monitor. watch_channel( channel_id , mon) ,
758
758
Ok ( ChannelMonitorUpdateStatus :: Completed )
759
759
) ;
760
760
}
@@ -825,7 +825,6 @@ pub fn do_test<Out: Output>(data: &[u8], underlying_out: Out, anchors: bool) {
825
825
} ;
826
826
827
827
$source. handle_accept_channel( $dest. get_our_node_id( ) , & accept_channel) ;
828
- let funding_output;
829
828
{
830
829
let mut events = $source. get_and_clear_pending_events( ) ;
831
830
assert_eq!( events. len( ) , 1 ) ;
@@ -845,7 +844,6 @@ pub fn do_test<Out: Output>(data: &[u8], underlying_out: Out, anchors: bool) {
845
844
script_pubkey: output_script,
846
845
} ] ,
847
846
} ;
848
- funding_output = OutPoint { txid: tx. compute_txid( ) , index: 0 } ;
849
847
$source
850
848
. funding_transaction_generated(
851
849
temporary_channel_id,
@@ -890,13 +888,19 @@ pub fn do_test<Out: Output>(data: &[u8], underlying_out: Out, anchors: bool) {
890
888
$source. handle_funding_signed( $dest. get_our_node_id( ) , & funding_signed) ;
891
889
let events = $source. get_and_clear_pending_events( ) ;
892
890
assert_eq!( events. len( ) , 1 ) ;
893
- if let events:: Event :: ChannelPending { ref counterparty_node_id, .. } = events[ 0 ] {
891
+ let channel_id = if let events:: Event :: ChannelPending {
892
+ ref counterparty_node_id,
893
+ ref channel_id,
894
+ ..
895
+ } = events[ 0 ]
896
+ {
894
897
assert_eq!( counterparty_node_id, & $dest. get_our_node_id( ) ) ;
898
+ channel_id. clone( )
895
899
} else {
896
900
panic!( "Wrong event type" ) ;
897
- }
901
+ } ;
898
902
899
- funding_output
903
+ channel_id
900
904
} } ;
901
905
}
902
906
@@ -963,8 +967,8 @@ pub fn do_test<Out: Output>(data: &[u8], underlying_out: Out, anchors: bool) {
963
967
964
968
let mut nodes = [ node_a, node_b, node_c] ;
965
969
966
- let chan_1_funding = make_channel ! ( nodes[ 0 ] , nodes[ 1 ] , keys_manager_b, 0 ) ;
967
- let chan_2_funding = make_channel ! ( nodes[ 1 ] , nodes[ 2 ] , keys_manager_c, 1 ) ;
970
+ let chan_1_id = make_channel ! ( nodes[ 0 ] , nodes[ 1 ] , keys_manager_b, 0 ) ;
971
+ let chan_2_id = make_channel ! ( nodes[ 1 ] , nodes[ 2 ] , keys_manager_c, 1 ) ;
968
972
969
973
for node in nodes. iter ( ) {
970
974
confirm_txn ! ( node) ;
@@ -1363,14 +1367,14 @@ pub fn do_test<Out: Output>(data: &[u8], underlying_out: Out, anchors: bool) {
1363
1367
}
1364
1368
} ;
1365
1369
1366
- let complete_all_monitor_updates = |monitor : & Arc < TestChainMonitor > , chan_funding | {
1367
- if let Some ( state) = monitor. latest_monitors . lock ( ) . unwrap ( ) . get_mut ( chan_funding ) {
1370
+ let complete_all_monitor_updates = |monitor : & Arc < TestChainMonitor > , chan_id | {
1371
+ if let Some ( state) = monitor. latest_monitors . lock ( ) . unwrap ( ) . get_mut ( chan_id ) {
1368
1372
assert ! (
1369
1373
state. pending_monitors. windows( 2 ) . all( |pair| pair[ 0 ] . 0 < pair[ 1 ] . 0 ) ,
1370
1374
"updates should be sorted by id"
1371
1375
) ;
1372
1376
for ( id, data) in state. pending_monitors . drain ( ..) {
1373
- monitor. chain_monitor . channel_monitor_updated ( * chan_funding , id) . unwrap ( ) ;
1377
+ monitor. chain_monitor . channel_monitor_updated ( * chan_id , id) . unwrap ( ) ;
1374
1378
if id > state. persisted_monitor_id {
1375
1379
state. persisted_monitor_id = id;
1376
1380
state. persisted_monitor = data;
@@ -1410,10 +1414,10 @@ pub fn do_test<Out: Output>(data: &[u8], underlying_out: Out, anchors: bool) {
1410
1414
ChannelMonitorUpdateStatus :: Completed
1411
1415
} ,
1412
1416
1413
- 0x08 => complete_all_monitor_updates ( & monitor_a, & chan_1_funding ) ,
1414
- 0x09 => complete_all_monitor_updates ( & monitor_b, & chan_1_funding ) ,
1415
- 0x0a => complete_all_monitor_updates ( & monitor_b, & chan_2_funding ) ,
1416
- 0x0b => complete_all_monitor_updates ( & monitor_c, & chan_2_funding ) ,
1417
+ 0x08 => complete_all_monitor_updates ( & monitor_a, & chan_1_id ) ,
1418
+ 0x09 => complete_all_monitor_updates ( & monitor_b, & chan_1_id ) ,
1419
+ 0x0a => complete_all_monitor_updates ( & monitor_b, & chan_2_id ) ,
1420
+ 0x0b => complete_all_monitor_updates ( & monitor_c, & chan_2_id ) ,
1417
1421
1418
1422
0x0c => {
1419
1423
if !chan_a_disconnected {
@@ -1683,21 +1687,21 @@ pub fn do_test<Out: Output>(data: &[u8], underlying_out: Out, anchors: bool) {
1683
1687
nodes[ 2 ] . maybe_update_chan_fees ( ) ;
1684
1688
} ,
1685
1689
1686
- 0xf0 => complete_monitor_update ( & monitor_a, & chan_1_funding , & complete_first) ,
1687
- 0xf1 => complete_monitor_update ( & monitor_a, & chan_1_funding , & complete_second) ,
1688
- 0xf2 => complete_monitor_update ( & monitor_a, & chan_1_funding , & Vec :: pop) ,
1690
+ 0xf0 => complete_monitor_update ( & monitor_a, & chan_1_id , & complete_first) ,
1691
+ 0xf1 => complete_monitor_update ( & monitor_a, & chan_1_id , & complete_second) ,
1692
+ 0xf2 => complete_monitor_update ( & monitor_a, & chan_1_id , & Vec :: pop) ,
1689
1693
1690
- 0xf4 => complete_monitor_update ( & monitor_b, & chan_1_funding , & complete_first) ,
1691
- 0xf5 => complete_monitor_update ( & monitor_b, & chan_1_funding , & complete_second) ,
1692
- 0xf6 => complete_monitor_update ( & monitor_b, & chan_1_funding , & Vec :: pop) ,
1694
+ 0xf4 => complete_monitor_update ( & monitor_b, & chan_1_id , & complete_first) ,
1695
+ 0xf5 => complete_monitor_update ( & monitor_b, & chan_1_id , & complete_second) ,
1696
+ 0xf6 => complete_monitor_update ( & monitor_b, & chan_1_id , & Vec :: pop) ,
1693
1697
1694
- 0xf8 => complete_monitor_update ( & monitor_b, & chan_2_funding , & complete_first) ,
1695
- 0xf9 => complete_monitor_update ( & monitor_b, & chan_2_funding , & complete_second) ,
1696
- 0xfa => complete_monitor_update ( & monitor_b, & chan_2_funding , & Vec :: pop) ,
1698
+ 0xf8 => complete_monitor_update ( & monitor_b, & chan_2_id , & complete_first) ,
1699
+ 0xf9 => complete_monitor_update ( & monitor_b, & chan_2_id , & complete_second) ,
1700
+ 0xfa => complete_monitor_update ( & monitor_b, & chan_2_id , & Vec :: pop) ,
1697
1701
1698
- 0xfc => complete_monitor_update ( & monitor_c, & chan_2_funding , & complete_first) ,
1699
- 0xfd => complete_monitor_update ( & monitor_c, & chan_2_funding , & complete_second) ,
1700
- 0xfe => complete_monitor_update ( & monitor_c, & chan_2_funding , & Vec :: pop) ,
1702
+ 0xfc => complete_monitor_update ( & monitor_c, & chan_2_id , & complete_first) ,
1703
+ 0xfd => complete_monitor_update ( & monitor_c, & chan_2_id , & complete_second) ,
1704
+ 0xfe => complete_monitor_update ( & monitor_c, & chan_2_id , & Vec :: pop) ,
1701
1705
1702
1706
0xff => {
1703
1707
// Test that no channel is in a stuck state where neither party can send funds even
@@ -1711,10 +1715,10 @@ pub fn do_test<Out: Output>(data: &[u8], underlying_out: Out, anchors: bool) {
1711
1715
* monitor_c. persister . update_ret . lock ( ) . unwrap ( ) =
1712
1716
ChannelMonitorUpdateStatus :: Completed ;
1713
1717
1714
- complete_all_monitor_updates ( & monitor_a, & chan_1_funding ) ;
1715
- complete_all_monitor_updates ( & monitor_b, & chan_1_funding ) ;
1716
- complete_all_monitor_updates ( & monitor_b, & chan_2_funding ) ;
1717
- complete_all_monitor_updates ( & monitor_c, & chan_2_funding ) ;
1718
+ complete_all_monitor_updates ( & monitor_a, & chan_1_id ) ;
1719
+ complete_all_monitor_updates ( & monitor_b, & chan_1_id ) ;
1720
+ complete_all_monitor_updates ( & monitor_b, & chan_2_id ) ;
1721
+ complete_all_monitor_updates ( & monitor_c, & chan_2_id ) ;
1718
1722
1719
1723
// Next, make sure peers are all connected to each other
1720
1724
if chan_a_disconnected {
0 commit comments