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