@@ -49,7 +49,7 @@ use lightning::ln::functional_test_utils::*;
4949use lightning:: offers:: invoice:: { BlindedPayInfo , UnsignedBolt12Invoice } ;
5050use lightning:: offers:: invoice_request:: UnsignedInvoiceRequest ;
5151use 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 } ;
5353use lightning:: util:: errors:: APIError ;
5454use lightning:: util:: logger:: Logger ;
5555use lightning:: util:: config:: UserConfig ;
@@ -72,6 +72,8 @@ use std::sync::atomic;
7272use std:: io:: Cursor ;
7373use bitcoin:: bech32:: u5;
7474
75+ #[ allow( unused) ]
76+ const ASYNC_OPS : u32 = ops:: GET_PER_COMMITMENT_POINT | ops:: RELEASE_COMMITMENT_SECRET | ops:: SIGN_COUNTERPARTY_COMMITMENT ;
7577const MAX_FEE : u32 = 10_000 ;
7678struct FuzzEstimator {
7779 ret_val : atomic:: AtomicU32 ,
@@ -297,7 +299,6 @@ impl SignerProvider for KeyProvider {
297299 inner,
298300 state,
299301 disable_revocation_policy_check : false ,
300- available : Arc :: new ( Mutex :: new ( true ) ) ,
301302 } )
302303 }
303304
@@ -829,7 +830,7 @@ pub fn do_test<Out: Output>(data: &[u8], underlying_out: Out, anchors: bool) {
829830 for ( idx, dest) in nodes. iter( ) . enumerate( ) {
830831 if dest. get_our_node_id( ) == node_id {
831832 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( ) ) ;
833834 if !$corrupt_forward {
834835 dest. handle_update_add_htlc( & nodes[ $node] . get_our_node_id( ) , update_add) ;
835836 } else {
@@ -844,19 +845,19 @@ pub fn do_test<Out: Output>(data: &[u8], underlying_out: Out, anchors: bool) {
844845 }
845846 }
846847 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( ) ) ;
848849 dest. handle_update_fulfill_htlc( & nodes[ $node] . get_our_node_id( ) , update_fulfill) ;
849850 }
850851 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( ) ) ;
852853 dest. handle_update_fail_htlc( & nodes[ $node] . get_our_node_id( ) , update_fail) ;
853854 }
854855 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( ) ) ;
856857 dest. handle_update_fail_malformed_htlc( & nodes[ $node] . get_our_node_id( ) , update_fail_malformed) ;
857858 }
858859 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( ) ) ;
860861 dest. handle_update_fee( & nodes[ $node] . get_our_node_id( ) , & msg) ;
861862 }
862863 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) {
873874 } } ) ;
874875 break ;
875876 }
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( ) ) ;
877878 dest. handle_commitment_signed( & nodes[ $node] . get_our_node_id( ) , & commitment_signed) ;
878879 break ;
879880 }
@@ -882,15 +883,15 @@ pub fn do_test<Out: Output>(data: &[u8], underlying_out: Out, anchors: bool) {
882883 events:: MessageSendEvent :: SendRevokeAndACK { ref node_id, ref msg } => {
883884 for ( idx, dest) in nodes. iter( ) . enumerate( ) {
884885 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( ) ) ;
886887 dest. handle_revoke_and_ack( & nodes[ $node] . get_our_node_id( ) , msg) ;
887888 }
888889 }
889890 } ,
890891 events:: MessageSendEvent :: SendChannelReestablish { ref node_id, ref msg } => {
891892 for ( idx, dest) in nodes. iter( ) . enumerate( ) {
892893 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( ) ) ;
894895 dest. handle_channel_reestablish( & nodes[ $node] . get_our_node_id( ) , msg) ;
895896 }
896897 }
@@ -1289,15 +1290,124 @@ pub fn do_test<Out: Output>(data: &[u8], underlying_out: Out, anchors: bool) {
12891290 } ,
12901291 0x89 => { fee_est_c. ret_val . store ( 253 , atomic:: Ordering :: Release ) ; nodes[ 2 ] . maybe_update_chan_fees ( ) ; } ,
12911292
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+
12921405 0xff => {
12931406 // Test that no channel is in a stuck state where neither party can send funds even
12941407 // after we resolve all pending events.
12951408 // First make sure there are no pending monitor updates, resetting the error state
12961409 // 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 ( format ! ( "Restoring monitors...\n " ) . as_bytes ( ) ) ;
13011411 if let Some ( ( id, _) ) = monitor_a. latest_monitors . lock ( ) . unwrap ( ) . get ( & chan_1_funding) {
13021412 monitor_a. chain_monitor . force_channel_monitor_updated ( chan_1_funding, * id) ;
13031413 nodes[ 0 ] . process_monitor_events ( ) ;
@@ -1316,7 +1426,10 @@ pub fn do_test<Out: Output>(data: &[u8], underlying_out: Out, anchors: bool) {
13161426 }
13171427
13181428 // Next, make sure peers are all connected to each other
1429+ out. locked_write ( format ! ( "Reconnecting peers...\n " ) . as_bytes ( ) ) ;
1430+
13191431 if chan_a_disconnected {
1432+ out. locked_write ( format ! ( "Reconnecting node 0 and node 1...\n " ) . as_bytes ( ) ) ;
13201433 nodes[ 0 ] . peer_connected ( & nodes[ 1 ] . get_our_node_id ( ) , & Init {
13211434 features : nodes[ 1 ] . init_features ( ) , networks : None , remote_network_address : None
13221435 } , true ) . unwrap ( ) ;
@@ -1326,6 +1439,7 @@ pub fn do_test<Out: Output>(data: &[u8], underlying_out: Out, anchors: bool) {
13261439 chan_a_disconnected = false ;
13271440 }
13281441 if chan_b_disconnected {
1442+ out. locked_write ( format ! ( "Reconnecting node 1 and node 2...\n " ) . as_bytes ( ) ) ;
13291443 nodes[ 1 ] . peer_connected ( & nodes[ 2 ] . get_our_node_id ( ) , & Init {
13301444 features : nodes[ 2 ] . init_features ( ) , networks : None , remote_network_address : None
13311445 } , true ) . unwrap ( ) ;
@@ -1335,8 +1449,33 @@ pub fn do_test<Out: Output>(data: &[u8], underlying_out: Out, anchors: bool) {
13351449 chan_b_disconnected = false ;
13361450 }
13371451
1452+ out. locked_write ( format ! ( "Restoring signers...\n " ) . as_bytes ( ) ) ;
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 ( format ! ( "Running event queues to quiescence...\n " ) . as_bytes ( ) ) ;
1475+
13381476 for i in 0 ..std:: usize:: MAX {
13391477 if i == 100 { panic ! ( "It may take may iterations to settle the state, but it should not take forever" ) ; }
1478+
13401479 // Then, make sure any current forwards make their way to their destination
13411480 if process_msg_events ! ( 0 , false , ProcessMessages :: AllMessages ) { continue ; }
13421481 if process_msg_events ! ( 1 , false , ProcessMessages :: AllMessages ) { continue ; }
@@ -1349,6 +1488,8 @@ pub fn do_test<Out: Output>(data: &[u8], underlying_out: Out, anchors: bool) {
13491488 break ;
13501489 }
13511490
1491+ out. locked_write ( format ! ( "All channels restored to normal operation.\n " ) . as_bytes ( ) ) ;
1492+
13521493 // Finally, make sure that at least one end of each channel can make a substantial payment
13531494 assert ! (
13541495 send_payment( & nodes[ 0 ] , & nodes[ 1 ] , chan_a, 10_000_000 , & mut payment_id, & mut payment_idx) ||
0 commit comments