@@ -18,6 +18,7 @@ use crate::chain::channelmonitor::{
1818 Balance , ANTI_REORG_DELAY , CLTV_CLAIM_BUFFER , COUNTERPARTY_CLAIMABLE_WITHIN_BLOCKS_PINNABLE ,
1919 LATENCY_GRACE_PERIOD_BLOCKS ,
2020} ;
21+ use crate :: chain:: transaction:: OutPoint ;
2122use crate :: chain:: { ChannelMonitorUpdateStatus , Confirm , Listen , Watch } ;
2223use crate :: events:: {
2324 ClosureReason , Event , HTLCHandlingFailureType , PathFailure , PaymentFailureReason ,
@@ -6631,9 +6632,13 @@ pub fn test_channel_conf_timeout() {
66316632
66326633 let node_a_id = nodes[ 0 ] . node . get_our_node_id ( ) ;
66336634
6634- let _funding_tx =
6635+ let funding_tx =
66356636 create_chan_between_nodes_with_value_init ( & nodes[ 0 ] , & nodes[ 1 ] , 1_000_000 , 100_000 ) ;
66366637
6638+ // Inbound channels which haven't advanced state at all and never were funded will generate
6639+ // claimable `Balance`s until they're closed.
6640+ assert ! ( !nodes[ 1 ] . chain_monitor. chain_monitor. get_claimable_balances( & [ ] ) . is_empty( ) ) ;
6641+
66376642 // The outbound node should wait forever for confirmation:
66386643 // This matches `channel::FUNDING_CONF_DEADLINE_BLOCKS` and BOLT 2's suggested timeout, thus is
66396644 // copied here instead of directly referencing the constant.
@@ -6645,6 +6650,10 @@ pub fn test_channel_conf_timeout() {
66456650 check_added_monitors ( & nodes[ 1 ] , 0 ) ;
66466651 assert ! ( nodes[ 0 ] . node. get_and_clear_pending_msg_events( ) . is_empty( ) ) ;
66476652
6653+ nodes[ 1 ] . chain_monitor . chain_monitor . archive_fully_resolved_channel_monitors ( ) ;
6654+ assert_eq ! ( nodes[ 1 ] . chain_monitor. chain_monitor. list_monitors( ) . len( ) , 1 ) ;
6655+ assert ! ( !nodes[ 1 ] . chain_monitor. chain_monitor. get_claimable_balances( & [ ] ) . is_empty( ) ) ;
6656+
66486657 connect_blocks ( & nodes[ 1 ] , 1 ) ;
66496658 check_added_monitors ( & nodes[ 1 ] , 1 ) ;
66506659 check_closed_event ! ( nodes[ 1 ] , 1 , ClosureReason :: FundingTimedOut , [ node_a_id] , 1000000 ) ;
@@ -6663,6 +6672,22 @@ pub fn test_channel_conf_timeout() {
66636672 } ,
66646673 _ => panic ! ( "Unexpected event" ) ,
66656674 }
6675+
6676+ // Once an inbound never-confirmed channel is closed, it will no longer generate any claimable
6677+ // `Balance`s.
6678+ assert ! ( nodes[ 1 ] . chain_monitor. chain_monitor. get_claimable_balances( & [ ] ) . is_empty( ) ) ;
6679+
6680+ // Once the funding times out the monitor should be immediately archived.
6681+ nodes[ 1 ] . chain_monitor . chain_monitor . archive_fully_resolved_channel_monitors ( ) ;
6682+ assert_eq ! ( nodes[ 1 ] . chain_monitor. chain_monitor. list_monitors( ) . len( ) , 0 ) ;
6683+ assert ! ( nodes[ 1 ] . chain_monitor. chain_monitor. get_claimable_balances( & [ ] ) . is_empty( ) ) ;
6684+
6685+ // Remove the corresponding outputs and transactions the chain source is
6686+ // watching. This is to make sure the `Drop` function assertions pass.
6687+ nodes[ 1 ] . chain_source . remove_watched_txn_and_outputs (
6688+ OutPoint { txid : funding_tx. compute_txid ( ) , index : 0 } ,
6689+ funding_tx. output [ 0 ] . script_pubkey . clone ( ) ,
6690+ ) ;
66666691}
66676692
66686693#[ xtest( feature = "_externalize_tests" ) ]
0 commit comments