@@ -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:: { 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,15 +1290,124 @@ 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
0xff => {
1293
1406
// Test that no channel is in a stuck state where neither party can send funds even
1294
1407
// after we resolve all pending events.
1295
1408
// First make sure there are no pending monitor updates, resetting the error state
1296
1409
// and calling force_channel_monitor_updated for each monitor.
1297
- * monitor_a. persister . update_ret . lock ( ) . unwrap ( ) = ChannelMonitorUpdateStatus :: Completed ;
1298
- * monitor_b. persister . update_ret . lock ( ) . unwrap ( ) = ChannelMonitorUpdateStatus :: Completed ;
1299
- * monitor_c. persister . update_ret . lock ( ) . unwrap ( ) = ChannelMonitorUpdateStatus :: Completed ;
1300
-
1410
+ out. locked_write ( b"Restoring monitors...\n " ) ;
1301
1411
if let Some ( ( id, _) ) = monitor_a. latest_monitors . lock ( ) . unwrap ( ) . get ( & chan_1_funding) {
1302
1412
monitor_a. chain_monitor . force_channel_monitor_updated ( chan_1_funding, * id) ;
1303
1413
nodes[ 0 ] . process_monitor_events ( ) ;
@@ -1316,7 +1426,10 @@ pub fn do_test<Out: Output>(data: &[u8], underlying_out: Out, anchors: bool) {
1316
1426
}
1317
1427
1318
1428
// Next, make sure peers are all connected to each other
1429
+ out. locked_write ( b"Reconnecting peers...\n " ) ;
1430
+
1319
1431
if chan_a_disconnected {
1432
+ out. locked_write ( b"Reconnecting node 0 and node 1...\n " ) ;
1320
1433
nodes[ 0 ] . peer_connected ( & nodes[ 1 ] . get_our_node_id ( ) , & Init {
1321
1434
features : nodes[ 1 ] . init_features ( ) , networks : None , remote_network_address : None
1322
1435
} , true ) . unwrap ( ) ;
@@ -1326,6 +1439,7 @@ pub fn do_test<Out: Output>(data: &[u8], underlying_out: Out, anchors: bool) {
1326
1439
chan_a_disconnected = false ;
1327
1440
}
1328
1441
if chan_b_disconnected {
1442
+ out. locked_write ( b"Reconnecting node 1 and node 2...\n " ) ;
1329
1443
nodes[ 1 ] . peer_connected ( & nodes[ 2 ] . get_our_node_id ( ) , & Init {
1330
1444
features : nodes[ 2 ] . init_features ( ) , networks : None , remote_network_address : None
1331
1445
} , true ) . unwrap ( ) ;
@@ -1335,8 +1449,33 @@ pub fn do_test<Out: Output>(data: &[u8], underlying_out: Out, anchors: bool) {
1335
1449
chan_b_disconnected = false ;
1336
1450
}
1337
1451
1452
+ out. locked_write ( b"Restoring signers...\n " ) ;
1453
+
1454
+ * monitor_a. persister . update_ret . lock ( ) . unwrap ( ) = ChannelMonitorUpdateStatus :: Completed ;
1455
+ * monitor_b. persister . update_ret . lock ( ) . unwrap ( ) = ChannelMonitorUpdateStatus :: Completed ;
1456
+ * monitor_c. persister . update_ret . lock ( ) . unwrap ( ) = ChannelMonitorUpdateStatus :: Completed ;
1457
+
1458
+ #[ cfg( async_signing) ]
1459
+ {
1460
+ for state in keys_manager_a. enforcement_states . lock ( ) . unwrap ( ) . values ( ) {
1461
+ state. lock ( ) . unwrap ( ) . set_signer_available ( !0 ) ;
1462
+ }
1463
+ for state in keys_manager_b. enforcement_states . lock ( ) . unwrap ( ) . values ( ) {
1464
+ state. lock ( ) . unwrap ( ) . set_signer_available ( !0 ) ;
1465
+ }
1466
+ for state in keys_manager_c. enforcement_states . lock ( ) . unwrap ( ) . values ( ) {
1467
+ state. lock ( ) . unwrap ( ) . set_signer_available ( !0 ) ;
1468
+ }
1469
+ nodes[ 0 ] . signer_unblocked ( None ) ;
1470
+ nodes[ 1 ] . signer_unblocked ( None ) ;
1471
+ nodes[ 2 ] . signer_unblocked ( None ) ;
1472
+ }
1473
+
1474
+ out. locked_write ( b"Running event queues to quiescence...\n " ) ;
1475
+
1338
1476
for i in 0 ..std:: usize:: MAX {
1339
1477
if i == 100 { panic ! ( "It may take may iterations to settle the state, but it should not take forever" ) ; }
1478
+
1340
1479
// Then, make sure any current forwards make their way to their destination
1341
1480
if process_msg_events ! ( 0 , false , ProcessMessages :: AllMessages ) { continue ; }
1342
1481
if process_msg_events ! ( 1 , false , ProcessMessages :: AllMessages ) { continue ; }
@@ -1349,13 +1488,34 @@ pub fn do_test<Out: Output>(data: &[u8], underlying_out: Out, anchors: bool) {
1349
1488
break ;
1350
1489
}
1351
1490
1491
+ out. locked_write ( b"All channels restored to normal operation.\n " ) ;
1492
+
1352
1493
// Finally, make sure that at least one end of each channel can make a substantial payment
1353
1494
assert ! (
1354
1495
send_payment( & nodes[ 0 ] , & nodes[ 1 ] , chan_a, 10_000_000 , & mut payment_id, & mut payment_idx) ||
1355
1496
send_payment( & nodes[ 1 ] , & nodes[ 0 ] , chan_a, 10_000_000 , & mut payment_id, & mut payment_idx) ) ;
1497
+ out. locked_write ( b"Successfully sent a payment between node 0 and node 1.\n " ) ;
1498
+
1356
1499
assert ! (
1357
1500
send_payment( & nodes[ 1 ] , & nodes[ 2 ] , chan_b, 10_000_000 , & mut payment_id, & mut payment_idx) ||
1358
1501
send_payment( & nodes[ 2 ] , & nodes[ 1 ] , chan_b, 10_000_000 , & mut payment_id, & mut payment_idx) ) ;
1502
+ out. locked_write ( b"Successfully sent a payment between node 1 and node 2.\n " ) ;
1503
+
1504
+ out. locked_write ( b"Flushing pending messages.\n " ) ;
1505
+ for i in 0 ..std:: usize:: MAX {
1506
+ if i == 100 { panic ! ( "It may take may iterations to settle the state, but it should not take forever" ) ; }
1507
+
1508
+ // Then, make sure any current forwards make their way to their destination
1509
+ if process_msg_events ! ( 0 , false , ProcessMessages :: AllMessages ) { continue ; }
1510
+ if process_msg_events ! ( 1 , false , ProcessMessages :: AllMessages ) { continue ; }
1511
+ if process_msg_events ! ( 2 , false , ProcessMessages :: AllMessages ) { continue ; }
1512
+ // ...making sure any pending PendingHTLCsForwardable events are handled and
1513
+ // payments claimed.
1514
+ if process_events ! ( 0 , false ) { continue ; }
1515
+ if process_events ! ( 1 , false ) { continue ; }
1516
+ if process_events ! ( 2 , false ) { continue ; }
1517
+ break ;
1518
+ }
1359
1519
1360
1520
last_htlc_clear_fee_a = fee_est_a. ret_val . load ( atomic:: Ordering :: Acquire ) ;
1361
1521
last_htlc_clear_fee_b = fee_est_b. ret_val . load ( atomic:: Ordering :: Acquire ) ;
0 commit comments