@@ -18,6 +18,7 @@ use crate::chain::channelmonitor::{
18
18
Balance , ANTI_REORG_DELAY , CLTV_CLAIM_BUFFER , COUNTERPARTY_CLAIMABLE_WITHIN_BLOCKS_PINNABLE ,
19
19
LATENCY_GRACE_PERIOD_BLOCKS ,
20
20
} ;
21
+ use crate :: chain:: transaction:: OutPoint ;
21
22
use crate :: chain:: { ChannelMonitorUpdateStatus , Confirm , Listen , Watch } ;
22
23
use crate :: events:: {
23
24
ClosureReason , Event , HTLCHandlingFailureType , PathFailure , PaymentFailureReason ,
@@ -6649,9 +6650,13 @@ pub fn test_channel_conf_timeout() {
6649
6650
6650
6651
let node_a_id = nodes[ 0 ] . node . get_our_node_id ( ) ;
6651
6652
6652
- let _funding_tx =
6653
+ let funding_tx =
6653
6654
create_chan_between_nodes_with_value_init ( & nodes[ 0 ] , & nodes[ 1 ] , 1_000_000 , 100_000 ) ;
6654
6655
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
+
6655
6660
// The outbound node should wait forever for confirmation:
6656
6661
// This matches `channel::FUNDING_CONF_DEADLINE_BLOCKS` and BOLT 2's suggested timeout, thus is
6657
6662
// copied here instead of directly referencing the constant.
@@ -6663,6 +6668,10 @@ pub fn test_channel_conf_timeout() {
6663
6668
check_added_monitors ( & nodes[ 1 ] , 0 ) ;
6664
6669
assert ! ( nodes[ 0 ] . node. get_and_clear_pending_msg_events( ) . is_empty( ) ) ;
6665
6670
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
+
6666
6675
connect_blocks ( & nodes[ 1 ] , 1 ) ;
6667
6676
check_added_monitors ( & nodes[ 1 ] , 1 ) ;
6668
6677
check_closed_event ! ( nodes[ 1 ] , 1 , ClosureReason :: FundingTimedOut , [ node_a_id] , 1000000 ) ;
@@ -6681,6 +6690,22 @@ pub fn test_channel_conf_timeout() {
6681
6690
} ,
6682
6691
_ => panic ! ( "Unexpected event" ) ,
6683
6692
}
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
+ ) ;
6684
6709
}
6685
6710
6686
6711
#[ xtest( feature = "_externalize_tests" ) ]
0 commit comments