@@ -49,7 +49,7 @@ use lightning::ln::functional_test_utils::*;
49
49
use lightning:: offers:: invoice:: { BlindedPayInfo , UnsignedBolt12Invoice } ;
50
50
use lightning:: offers:: invoice_request:: UnsignedInvoiceRequest ;
51
51
use lightning:: onion_message:: messenger:: { Destination , MessageRouter , OnionMessagePath } ;
52
- use lightning:: util:: test_channel_signer:: { TestChannelSigner , EnforcementState } ;
52
+ use lightning:: util:: test_channel_signer:: { TestChannelSigner , EnforcementState , ops } ;
53
53
use lightning:: util:: errors:: APIError ;
54
54
use lightning:: util:: logger:: Logger ;
55
55
use lightning:: util:: config:: UserConfig ;
@@ -72,6 +72,8 @@ use std::sync::atomic;
72
72
use std:: io:: Cursor ;
73
73
use bitcoin:: bech32:: u5;
74
74
75
+ #[ allow( unused) ]
76
+ const ASYNC_OPS : u32 = ops:: GET_PER_COMMITMENT_POINT | ops:: RELEASE_COMMITMENT_SECRET | ops:: SIGN_COUNTERPARTY_COMMITMENT ;
75
77
const MAX_FEE : u32 = 10_000 ;
76
78
struct FuzzEstimator {
77
79
ret_val : atomic:: AtomicU32 ,
@@ -297,7 +299,6 @@ impl SignerProvider for KeyProvider {
297
299
inner,
298
300
state,
299
301
disable_revocation_policy_check : false ,
300
- available : Arc :: new ( Mutex :: new ( true ) ) ,
301
302
} )
302
303
}
303
304
@@ -829,7 +830,7 @@ pub fn do_test<Out: Output>(data: &[u8], underlying_out: Out, anchors: bool) {
829
830
for ( idx, dest) in nodes. iter( ) . enumerate( ) {
830
831
if dest. get_our_node_id( ) == node_id {
831
832
for update_add in update_add_htlcs. iter( ) {
832
- out. locked_write( format!( "Delivering update_add_htlc to node {}.\n " , idx) . as_bytes( ) ) ;
833
+ out. locked_write( format!( "Delivering update_add_htlc to node {} from node {} .\n " , idx, $node ) . as_bytes( ) ) ;
833
834
if !$corrupt_forward {
834
835
dest. handle_update_add_htlc( & nodes[ $node] . get_our_node_id( ) , update_add) ;
835
836
} else {
@@ -844,19 +845,19 @@ pub fn do_test<Out: Output>(data: &[u8], underlying_out: Out, anchors: bool) {
844
845
}
845
846
}
846
847
for update_fulfill in update_fulfill_htlcs. iter( ) {
847
- out. locked_write( format!( "Delivering update_fulfill_htlc to node {}.\n " , idx) . as_bytes( ) ) ;
848
+ out. locked_write( format!( "Delivering update_fulfill_htlc to node {} from node {} .\n " , idx, $node ) . as_bytes( ) ) ;
848
849
dest. handle_update_fulfill_htlc( & nodes[ $node] . get_our_node_id( ) , update_fulfill) ;
849
850
}
850
851
for update_fail in update_fail_htlcs. iter( ) {
851
- out. locked_write( format!( "Delivering update_fail_htlc to node {}.\n " , idx) . as_bytes( ) ) ;
852
+ out. locked_write( format!( "Delivering update_fail_htlc to node {} from node {} .\n " , idx, $node ) . as_bytes( ) ) ;
852
853
dest. handle_update_fail_htlc( & nodes[ $node] . get_our_node_id( ) , update_fail) ;
853
854
}
854
855
for update_fail_malformed in update_fail_malformed_htlcs. iter( ) {
855
- out. locked_write( format!( "Delivering update_fail_malformed_htlc to node {}.\n " , idx) . as_bytes( ) ) ;
856
+ out. locked_write( format!( "Delivering update_fail_malformed_htlc to node {} from node {} .\n " , idx, $node ) . as_bytes( ) ) ;
856
857
dest. handle_update_fail_malformed_htlc( & nodes[ $node] . get_our_node_id( ) , update_fail_malformed) ;
857
858
}
858
859
if let Some ( msg) = update_fee {
859
- out. locked_write( format!( "Delivering update_fee to node {}.\n " , idx) . as_bytes( ) ) ;
860
+ out. locked_write( format!( "Delivering update_fee to node {} from node {} .\n " , idx, $node ) . as_bytes( ) ) ;
860
861
dest. handle_update_fee( & nodes[ $node] . get_our_node_id( ) , & msg) ;
861
862
}
862
863
let processed_change = !update_add_htlcs. is_empty( ) || !update_fulfill_htlcs. is_empty( ) ||
@@ -873,7 +874,7 @@ pub fn do_test<Out: Output>(data: &[u8], underlying_out: Out, anchors: bool) {
873
874
} } ) ;
874
875
break ;
875
876
}
876
- out. locked_write( format!( "Delivering commitment_signed to node {}.\n " , idx) . as_bytes( ) ) ;
877
+ out. locked_write( format!( "Delivering commitment_signed to node {} from node {} .\n " , idx, $node ) . as_bytes( ) ) ;
877
878
dest. handle_commitment_signed( & nodes[ $node] . get_our_node_id( ) , & commitment_signed) ;
878
879
break ;
879
880
}
@@ -882,15 +883,15 @@ pub fn do_test<Out: Output>(data: &[u8], underlying_out: Out, anchors: bool) {
882
883
events:: MessageSendEvent :: SendRevokeAndACK { ref node_id, ref msg } => {
883
884
for ( idx, dest) in nodes. iter( ) . enumerate( ) {
884
885
if dest. get_our_node_id( ) == * node_id {
885
- out. locked_write( format!( "Delivering revoke_and_ack to node {}.\n " , idx) . as_bytes( ) ) ;
886
+ out. locked_write( format!( "Delivering revoke_and_ack to node {} from node {} .\n " , idx, $node ) . as_bytes( ) ) ;
886
887
dest. handle_revoke_and_ack( & nodes[ $node] . get_our_node_id( ) , msg) ;
887
888
}
888
889
}
889
890
} ,
890
891
events:: MessageSendEvent :: SendChannelReestablish { ref node_id, ref msg } => {
891
892
for ( idx, dest) in nodes. iter( ) . enumerate( ) {
892
893
if dest. get_our_node_id( ) == * node_id {
893
- out. locked_write( format!( "Delivering channel_reestablish to node {}.\n " , idx) . as_bytes( ) ) ;
894
+ out. locked_write( format!( "Delivering channel_reestablish to node {} from node {} .\n " , idx, $node ) . as_bytes( ) ) ;
894
895
dest. handle_channel_reestablish( & nodes[ $node] . get_our_node_id( ) , msg) ;
895
896
}
896
897
}
@@ -913,7 +914,7 @@ pub fn do_test<Out: Output>(data: &[u8], underlying_out: Out, anchors: bool) {
913
914
_ => if out. may_fail. load( atomic:: Ordering :: Acquire ) {
914
915
return ;
915
916
} else {
916
- panic!( "Unhandled message event { :?}" , event)
917
+ panic!( "Unhandled message event on node {}, { :?}" , $node , event)
917
918
} ,
918
919
}
919
920
if $limit_events != ProcessMessages :: AllMessages {
@@ -1289,6 +1290,118 @@ pub fn do_test<Out: Output>(data: &[u8], underlying_out: Out, anchors: bool) {
1289
1290
} ,
1290
1291
0x89 => { fee_est_c. ret_val . store ( 253 , atomic:: Ordering :: Release ) ; nodes[ 2 ] . maybe_update_chan_fees ( ) ; } ,
1291
1292
1293
+ #[ cfg( async_signing) ]
1294
+ 0xa0 => {
1295
+ let states = keys_manager_a. enforcement_states . lock ( ) . unwrap ( ) ;
1296
+ assert_eq ! ( states. len( ) , 1 ) ;
1297
+ states. values ( ) . next ( ) . unwrap ( ) . lock ( ) . unwrap ( ) . set_signer_unavailable ( ASYNC_OPS ) ;
1298
+ }
1299
+ #[ cfg( async_signing) ]
1300
+ 0xa1 => {
1301
+ let states = keys_manager_a. enforcement_states . lock ( ) . unwrap ( ) ;
1302
+ assert_eq ! ( states. len( ) , 1 ) ;
1303
+ states. values ( ) . next ( ) . unwrap ( ) . lock ( ) . unwrap ( ) . set_signer_available ( ops:: GET_PER_COMMITMENT_POINT ) ;
1304
+ nodes[ 0 ] . signer_unblocked ( None ) ;
1305
+ }
1306
+ #[ cfg( async_signing) ]
1307
+ 0xa2 => {
1308
+ let states = keys_manager_a. enforcement_states . lock ( ) . unwrap ( ) ;
1309
+ assert_eq ! ( states. len( ) , 1 ) ;
1310
+ states. values ( ) . next ( ) . unwrap ( ) . lock ( ) . unwrap ( ) . set_signer_available ( ops:: RELEASE_COMMITMENT_SECRET ) ;
1311
+ nodes[ 0 ] . signer_unblocked ( None ) ;
1312
+ }
1313
+ #[ cfg( async_signing) ]
1314
+ 0xa3 => {
1315
+ let states = keys_manager_a. enforcement_states . lock ( ) . unwrap ( ) ;
1316
+ assert_eq ! ( states. len( ) , 1 ) ;
1317
+ states. values ( ) . next ( ) . unwrap ( ) . lock ( ) . unwrap ( ) . set_signer_available ( ops:: SIGN_COUNTERPARTY_COMMITMENT ) ;
1318
+ nodes[ 0 ] . signer_unblocked ( None ) ;
1319
+ }
1320
+
1321
+ #[ cfg( async_signing) ]
1322
+ 0xa4 => {
1323
+ let states = keys_manager_b. enforcement_states . lock ( ) . unwrap ( ) ;
1324
+ assert_eq ! ( states. len( ) , 2 ) ;
1325
+ states. values ( ) . next ( ) . unwrap ( ) . lock ( ) . unwrap ( ) . set_signer_unavailable ( ASYNC_OPS ) ;
1326
+ }
1327
+ #[ cfg( async_signing) ]
1328
+ 0xa5 => {
1329
+ let states = keys_manager_b. enforcement_states . lock ( ) . unwrap ( ) ;
1330
+ assert_eq ! ( states. len( ) , 2 ) ;
1331
+ states. values ( ) . next ( ) . unwrap ( ) . lock ( ) . unwrap ( ) . set_signer_available ( ops:: GET_PER_COMMITMENT_POINT ) ;
1332
+ nodes[ 1 ] . signer_unblocked ( None ) ;
1333
+ }
1334
+ #[ cfg( async_signing) ]
1335
+ 0xa6 => {
1336
+ let states = keys_manager_b. enforcement_states . lock ( ) . unwrap ( ) ;
1337
+ assert_eq ! ( states. len( ) , 2 ) ;
1338
+ states. values ( ) . next ( ) . unwrap ( ) . lock ( ) . unwrap ( ) . set_signer_available ( ops:: RELEASE_COMMITMENT_SECRET ) ;
1339
+ nodes[ 1 ] . signer_unblocked ( None ) ;
1340
+ }
1341
+ #[ cfg( async_signing) ]
1342
+ 0xa7 => {
1343
+ let states = keys_manager_b. enforcement_states . lock ( ) . unwrap ( ) ;
1344
+ assert_eq ! ( states. len( ) , 2 ) ;
1345
+ states. values ( ) . next ( ) . unwrap ( ) . lock ( ) . unwrap ( ) . set_signer_available ( ops:: SIGN_COUNTERPARTY_COMMITMENT ) ;
1346
+ nodes[ 1 ] . signer_unblocked ( None ) ;
1347
+ }
1348
+
1349
+ #[ cfg( async_signing) ]
1350
+ 0xa8 => {
1351
+ let states = keys_manager_b. enforcement_states . lock ( ) . unwrap ( ) ;
1352
+ assert_eq ! ( states. len( ) , 2 ) ;
1353
+ states. values ( ) . last ( ) . unwrap ( ) . lock ( ) . unwrap ( ) . set_signer_unavailable ( ASYNC_OPS ) ;
1354
+ }
1355
+ #[ cfg( async_signing) ]
1356
+ 0xa9 => {
1357
+ let states = keys_manager_b. enforcement_states . lock ( ) . unwrap ( ) ;
1358
+ assert_eq ! ( states. len( ) , 2 ) ;
1359
+ states. values ( ) . last ( ) . unwrap ( ) . lock ( ) . unwrap ( ) . set_signer_available ( ops:: GET_PER_COMMITMENT_POINT ) ;
1360
+ nodes[ 1 ] . signer_unblocked ( None ) ;
1361
+ }
1362
+ #[ cfg( async_signing) ]
1363
+ 0xaa => {
1364
+ let states = keys_manager_b. enforcement_states . lock ( ) . unwrap ( ) ;
1365
+ assert_eq ! ( states. len( ) , 2 ) ;
1366
+ states. values ( ) . last ( ) . unwrap ( ) . lock ( ) . unwrap ( ) . set_signer_available ( ops:: RELEASE_COMMITMENT_SECRET ) ;
1367
+ nodes[ 1 ] . signer_unblocked ( None ) ;
1368
+ }
1369
+ #[ cfg( async_signing) ]
1370
+ 0xab => {
1371
+ let states = keys_manager_b. enforcement_states . lock ( ) . unwrap ( ) ;
1372
+ assert_eq ! ( states. len( ) , 2 ) ;
1373
+ states. values ( ) . last ( ) . unwrap ( ) . lock ( ) . unwrap ( ) . set_signer_available ( ops:: SIGN_COUNTERPARTY_COMMITMENT ) ;
1374
+ nodes[ 1 ] . signer_unblocked ( None ) ;
1375
+ }
1376
+
1377
+ #[ cfg( async_signing) ]
1378
+ 0xac => {
1379
+ let states = keys_manager_c. enforcement_states . lock ( ) . unwrap ( ) ;
1380
+ assert_eq ! ( states. len( ) , 1 ) ;
1381
+ states. values ( ) . next ( ) . unwrap ( ) . lock ( ) . unwrap ( ) . set_signer_unavailable ( ASYNC_OPS ) ;
1382
+ }
1383
+ #[ cfg( async_signing) ]
1384
+ 0xad => {
1385
+ let states = keys_manager_c. enforcement_states . lock ( ) . unwrap ( ) ;
1386
+ assert_eq ! ( states. len( ) , 1 ) ;
1387
+ states. values ( ) . next ( ) . unwrap ( ) . lock ( ) . unwrap ( ) . set_signer_available ( ops:: GET_PER_COMMITMENT_POINT ) ;
1388
+ nodes[ 2 ] . signer_unblocked ( None ) ;
1389
+ }
1390
+ #[ cfg( async_signing) ]
1391
+ 0xae => {
1392
+ let states = keys_manager_c. enforcement_states . lock ( ) . unwrap ( ) ;
1393
+ assert_eq ! ( states. len( ) , 1 ) ;
1394
+ states. values ( ) . next ( ) . unwrap ( ) . lock ( ) . unwrap ( ) . set_signer_available ( ops:: RELEASE_COMMITMENT_SECRET ) ;
1395
+ nodes[ 2 ] . signer_unblocked ( None ) ;
1396
+ }
1397
+ #[ cfg( async_signing) ]
1398
+ 0xaf => {
1399
+ let states = keys_manager_c. enforcement_states . lock ( ) . unwrap ( ) ;
1400
+ assert_eq ! ( states. len( ) , 1 ) ;
1401
+ states. values ( ) . next ( ) . unwrap ( ) . lock ( ) . unwrap ( ) . set_signer_available ( ops:: SIGN_COUNTERPARTY_COMMITMENT ) ;
1402
+ nodes[ 2 ] . signer_unblocked ( None ) ;
1403
+ }
1404
+
1292
1405
0xf0 => {
1293
1406
let pending_updates = monitor_a. chain_monitor . list_pending_monitor_updates ( ) . remove ( & chan_1_funding) . unwrap ( ) ;
1294
1407
if let Some ( id) = pending_updates. get ( 0 ) {
@@ -1382,10 +1495,7 @@ pub fn do_test<Out: Output>(data: &[u8], underlying_out: Out, anchors: bool) {
1382
1495
// after we resolve all pending events.
1383
1496
// First make sure there are no pending monitor updates, resetting the error state
1384
1497
// and calling force_channel_monitor_updated for each monitor.
1385
- * monitor_a. persister . update_ret . lock ( ) . unwrap ( ) = ChannelMonitorUpdateStatus :: Completed ;
1386
- * monitor_b. persister . update_ret . lock ( ) . unwrap ( ) = ChannelMonitorUpdateStatus :: Completed ;
1387
- * monitor_c. persister . update_ret . lock ( ) . unwrap ( ) = ChannelMonitorUpdateStatus :: Completed ;
1388
-
1498
+ out. locked_write ( b"Restoring monitors...\n " ) ;
1389
1499
if let Some ( ( id, _) ) = monitor_a. latest_monitors . lock ( ) . unwrap ( ) . get ( & chan_1_funding) {
1390
1500
monitor_a. chain_monitor . force_channel_monitor_updated ( chan_1_funding, * id) ;
1391
1501
nodes[ 0 ] . process_monitor_events ( ) ;
@@ -1404,7 +1514,10 @@ pub fn do_test<Out: Output>(data: &[u8], underlying_out: Out, anchors: bool) {
1404
1514
}
1405
1515
1406
1516
// Next, make sure peers are all connected to each other
1517
+ out. locked_write ( b"Reconnecting peers...\n " ) ;
1518
+
1407
1519
if chan_a_disconnected {
1520
+ out. locked_write ( b"Reconnecting node 0 and node 1...\n " ) ;
1408
1521
nodes[ 0 ] . peer_connected ( & nodes[ 1 ] . get_our_node_id ( ) , & Init {
1409
1522
features : nodes[ 1 ] . init_features ( ) , networks : None , remote_network_address : None
1410
1523
} , true ) . unwrap ( ) ;
@@ -1414,6 +1527,7 @@ pub fn do_test<Out: Output>(data: &[u8], underlying_out: Out, anchors: bool) {
1414
1527
chan_a_disconnected = false ;
1415
1528
}
1416
1529
if chan_b_disconnected {
1530
+ out. locked_write ( b"Reconnecting node 1 and node 2...\n " ) ;
1417
1531
nodes[ 1 ] . peer_connected ( & nodes[ 2 ] . get_our_node_id ( ) , & Init {
1418
1532
features : nodes[ 2 ] . init_features ( ) , networks : None , remote_network_address : None
1419
1533
} , true ) . unwrap ( ) ;
@@ -1423,8 +1537,33 @@ pub fn do_test<Out: Output>(data: &[u8], underlying_out: Out, anchors: bool) {
1423
1537
chan_b_disconnected = false ;
1424
1538
}
1425
1539
1540
+ out. locked_write ( b"Restoring signers...\n " ) ;
1541
+
1542
+ * monitor_a. persister . update_ret . lock ( ) . unwrap ( ) = ChannelMonitorUpdateStatus :: Completed ;
1543
+ * monitor_b. persister . update_ret . lock ( ) . unwrap ( ) = ChannelMonitorUpdateStatus :: Completed ;
1544
+ * monitor_c. persister . update_ret . lock ( ) . unwrap ( ) = ChannelMonitorUpdateStatus :: Completed ;
1545
+
1546
+ #[ cfg( async_signing) ]
1547
+ {
1548
+ for state in keys_manager_a. enforcement_states . lock ( ) . unwrap ( ) . values ( ) {
1549
+ state. lock ( ) . unwrap ( ) . set_signer_available ( !0 ) ;
1550
+ }
1551
+ for state in keys_manager_b. enforcement_states . lock ( ) . unwrap ( ) . values ( ) {
1552
+ state. lock ( ) . unwrap ( ) . set_signer_available ( !0 ) ;
1553
+ }
1554
+ for state in keys_manager_c. enforcement_states . lock ( ) . unwrap ( ) . values ( ) {
1555
+ state. lock ( ) . unwrap ( ) . set_signer_available ( !0 ) ;
1556
+ }
1557
+ nodes[ 0 ] . signer_unblocked ( None ) ;
1558
+ nodes[ 1 ] . signer_unblocked ( None ) ;
1559
+ nodes[ 2 ] . signer_unblocked ( None ) ;
1560
+ }
1561
+
1562
+ out. locked_write ( b"Running event queues to quiescence...\n " ) ;
1563
+
1426
1564
for i in 0 ..std:: usize:: MAX {
1427
1565
if i == 100 { panic ! ( "It may take may iterations to settle the state, but it should not take forever" ) ; }
1566
+
1428
1567
// Then, make sure any current forwards make their way to their destination
1429
1568
if process_msg_events ! ( 0 , false , ProcessMessages :: AllMessages ) { continue ; }
1430
1569
if process_msg_events ! ( 1 , false , ProcessMessages :: AllMessages ) { continue ; }
@@ -1437,13 +1576,34 @@ pub fn do_test<Out: Output>(data: &[u8], underlying_out: Out, anchors: bool) {
1437
1576
break ;
1438
1577
}
1439
1578
1579
+ out. locked_write ( b"All channels restored to normal operation.\n " ) ;
1580
+
1440
1581
// Finally, make sure that at least one end of each channel can make a substantial payment
1441
1582
assert ! (
1442
1583
send_payment( & nodes[ 0 ] , & nodes[ 1 ] , chan_a, 10_000_000 , & mut payment_id, & mut payment_idx) ||
1443
1584
send_payment( & nodes[ 1 ] , & nodes[ 0 ] , chan_a, 10_000_000 , & mut payment_id, & mut payment_idx) ) ;
1585
+ out. locked_write ( b"Successfully sent a payment between node 0 and node 1.\n " ) ;
1586
+
1444
1587
assert ! (
1445
1588
send_payment( & nodes[ 1 ] , & nodes[ 2 ] , chan_b, 10_000_000 , & mut payment_id, & mut payment_idx) ||
1446
1589
send_payment( & nodes[ 2 ] , & nodes[ 1 ] , chan_b, 10_000_000 , & mut payment_id, & mut payment_idx) ) ;
1590
+ out. locked_write ( b"Successfully sent a payment between node 1 and node 2.\n " ) ;
1591
+
1592
+ out. locked_write ( b"Flushing pending messages.\n " ) ;
1593
+ for i in 0 ..std:: usize:: MAX {
1594
+ if i == 100 { panic ! ( "It may take may iterations to settle the state, but it should not take forever" ) ; }
1595
+
1596
+ // Then, make sure any current forwards make their way to their destination
1597
+ if process_msg_events ! ( 0 , false , ProcessMessages :: AllMessages ) { continue ; }
1598
+ if process_msg_events ! ( 1 , false , ProcessMessages :: AllMessages ) { continue ; }
1599
+ if process_msg_events ! ( 2 , false , ProcessMessages :: AllMessages ) { continue ; }
1600
+ // ...making sure any pending PendingHTLCsForwardable events are handled and
1601
+ // payments claimed.
1602
+ if process_events ! ( 0 , false ) { continue ; }
1603
+ if process_events ! ( 1 , false ) { continue ; }
1604
+ if process_events ! ( 2 , false ) { continue ; }
1605
+ break ;
1606
+ }
1447
1607
1448
1608
last_htlc_clear_fee_a = fee_est_a. ret_val . load ( atomic:: Ordering :: Acquire ) ;
1449
1609
last_htlc_clear_fee_b = fee_est_b. ret_val . load ( atomic:: Ordering :: Acquire ) ;
0 commit comments