@@ -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 ,
@@ -6649,9 +6650,13 @@ pub fn test_channel_conf_timeout() {
66496650
66506651 let node_a_id = nodes[ 0 ] . node . get_our_node_id ( ) ;
66516652
6652- let _funding_tx =
6653+ let funding_tx =
66536654 create_chan_between_nodes_with_value_init ( & nodes[ 0 ] , & nodes[ 1 ] , 1_000_000 , 100_000 ) ;
66546655
6656+ // Inbound channels which haven't advanced state at all and never were funded will generate
6657+ // claimable `Balance`s until they're closed.
6658+ assert ! ( !nodes[ 1 ] . chain_monitor. chain_monitor. get_claimable_balances( & [ ] ) . is_empty( ) ) ;
6659+
66556660 // The outbound node should wait forever for confirmation:
66566661 // This matches `channel::FUNDING_CONF_DEADLINE_BLOCKS` and BOLT 2's suggested timeout, thus is
66576662 // copied here instead of directly referencing the constant.
@@ -6663,6 +6668,10 @@ pub fn test_channel_conf_timeout() {
66636668 check_added_monitors ( & nodes[ 1 ] , 0 ) ;
66646669 assert ! ( nodes[ 0 ] . node. get_and_clear_pending_msg_events( ) . is_empty( ) ) ;
66656670
6671+ nodes[ 1 ] . chain_monitor . chain_monitor . archive_fully_resolved_channel_monitors ( ) ;
6672+ assert_eq ! ( nodes[ 1 ] . chain_monitor. chain_monitor. list_monitors( ) . len( ) , 1 ) ;
6673+ assert ! ( !nodes[ 1 ] . chain_monitor. chain_monitor. get_claimable_balances( & [ ] ) . is_empty( ) ) ;
6674+
66666675 connect_blocks ( & nodes[ 1 ] , 1 ) ;
66676676 check_added_monitors ( & nodes[ 1 ] , 1 ) ;
66686677 check_closed_event ! ( nodes[ 1 ] , 1 , ClosureReason :: FundingTimedOut , [ node_a_id] , 1000000 ) ;
@@ -6681,6 +6690,22 @@ pub fn test_channel_conf_timeout() {
66816690 } ,
66826691 _ => panic ! ( "Unexpected event" ) ,
66836692 }
6693+
6694+ // Once an inbound never-confirmed channel is closed, it will no longer generate any claimable
6695+ // `Balance`s.
6696+ assert ! ( nodes[ 1 ] . chain_monitor. chain_monitor. get_claimable_balances( & [ ] ) . is_empty( ) ) ;
6697+
6698+ // Once the funding times out the monitor should be immediately archived.
6699+ nodes[ 1 ] . chain_monitor . chain_monitor . archive_fully_resolved_channel_monitors ( ) ;
6700+ assert_eq ! ( nodes[ 1 ] . chain_monitor. chain_monitor. list_monitors( ) . len( ) , 0 ) ;
6701+ assert ! ( nodes[ 1 ] . chain_monitor. chain_monitor. get_claimable_balances( & [ ] ) . is_empty( ) ) ;
6702+
6703+ // Remove the corresponding outputs and transactions the chain source is
6704+ // watching. This is to make sure the `Drop` function assertions pass.
6705+ nodes[ 1 ] . chain_source . remove_watched_txn_and_outputs (
6706+ OutPoint { txid : funding_tx. compute_txid ( ) , index : 0 } ,
6707+ funding_tx. output [ 0 ] . script_pubkey . clone ( ) ,
6708+ ) ;
66846709}
66856710
66866711#[ xtest( feature = "_externalize_tests" ) ]
0 commit comments