@@ -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 ,
@@ -6631,9 +6632,13 @@ pub fn test_channel_conf_timeout() {
6631
6632
6632
6633
let node_a_id = nodes[ 0 ] . node . get_our_node_id ( ) ;
6633
6634
6634
- let _funding_tx =
6635
+ let funding_tx =
6635
6636
create_chan_between_nodes_with_value_init ( & nodes[ 0 ] , & nodes[ 1 ] , 1_000_000 , 100_000 ) ;
6636
6637
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
+
6637
6642
// The outbound node should wait forever for confirmation:
6638
6643
// This matches `channel::FUNDING_CONF_DEADLINE_BLOCKS` and BOLT 2's suggested timeout, thus is
6639
6644
// copied here instead of directly referencing the constant.
@@ -6645,6 +6650,10 @@ pub fn test_channel_conf_timeout() {
6645
6650
check_added_monitors ( & nodes[ 1 ] , 0 ) ;
6646
6651
assert ! ( nodes[ 0 ] . node. get_and_clear_pending_msg_events( ) . is_empty( ) ) ;
6647
6652
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
+
6648
6657
connect_blocks ( & nodes[ 1 ] , 1 ) ;
6649
6658
check_added_monitors ( & nodes[ 1 ] , 1 ) ;
6650
6659
check_closed_event ! ( nodes[ 1 ] , 1 , ClosureReason :: FundingTimedOut , [ node_a_id] , 1000000 ) ;
@@ -6663,6 +6672,22 @@ pub fn test_channel_conf_timeout() {
6663
6672
} ,
6664
6673
_ => panic ! ( "Unexpected event" ) ,
6665
6674
}
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
+ ) ;
6666
6691
}
6667
6692
6668
6693
#[ xtest( feature = "_externalize_tests" ) ]
0 commit comments