@@ -158,6 +158,59 @@ fn revoked_output_htlc_resolution_timing() {
158
158
expect_payment_failed ! ( nodes[ 1 ] , payment_hash_1, false ) ;
159
159
}
160
160
161
+ #[ test]
162
+ fn archive_fully_resolved_monitors ( ) {
163
+ // Test we can archive fully resolved channel monitor.
164
+ let chanmon_cfgs = create_chanmon_cfgs ( 2 ) ;
165
+ let node_cfgs = create_node_cfgs ( 2 , & chanmon_cfgs) ;
166
+ let mut user_config = test_default_channel_config ( ) ;
167
+ let node_chanmgrs = create_node_chanmgrs ( 2 , & node_cfgs, & [ Some ( user_config) , Some ( user_config) ] ) ;
168
+ let mut nodes = create_network ( 2 , & node_cfgs, & node_chanmgrs) ;
169
+
170
+ let ( _, _, chan_id, funding_tx) =
171
+ create_announced_chan_between_nodes_with_value ( & nodes, 0 , 1 , 1_000_000 , 1_000_000 ) ;
172
+
173
+ nodes[ 0 ] . node . close_channel ( & chan_id, & nodes[ 1 ] . node . get_our_node_id ( ) ) . unwrap ( ) ;
174
+ let node_0_shutdown = get_event_msg ! ( nodes[ 0 ] , MessageSendEvent :: SendShutdown , nodes[ 1 ] . node. get_our_node_id( ) ) ;
175
+ nodes[ 1 ] . node . handle_shutdown ( & nodes[ 0 ] . node . get_our_node_id ( ) , & node_0_shutdown) ;
176
+ let node_1_shutdown = get_event_msg ! ( nodes[ 1 ] , MessageSendEvent :: SendShutdown , nodes[ 0 ] . node. get_our_node_id( ) ) ;
177
+ nodes[ 0 ] . node . handle_shutdown ( & nodes[ 1 ] . node . get_our_node_id ( ) , & node_1_shutdown) ;
178
+
179
+ let node_0_closing_signed = get_event_msg ! ( nodes[ 0 ] , MessageSendEvent :: SendClosingSigned , nodes[ 1 ] . node. get_our_node_id( ) ) ;
180
+ nodes[ 1 ] . node . handle_closing_signed ( & nodes[ 0 ] . node . get_our_node_id ( ) , & node_0_closing_signed) ;
181
+ let node_1_closing_signed = get_event_msg ! ( nodes[ 1 ] , MessageSendEvent :: SendClosingSigned , nodes[ 0 ] . node. get_our_node_id( ) ) ;
182
+ nodes[ 0 ] . node . handle_closing_signed ( & nodes[ 1 ] . node . get_our_node_id ( ) , & node_1_closing_signed) ;
183
+ let ( _, node_0_2nd_closing_signed) = get_closing_signed_broadcast ! ( nodes[ 0 ] . node, nodes[ 1 ] . node. get_our_node_id( ) ) ;
184
+ nodes[ 1 ] . node . handle_closing_signed ( & nodes[ 0 ] . node . get_our_node_id ( ) , & node_0_2nd_closing_signed. unwrap ( ) ) ;
185
+ let ( _, _) = get_closing_signed_broadcast ! ( nodes[ 1 ] . node, nodes[ 0 ] . node. get_our_node_id( ) ) ;
186
+
187
+ let shutdown_tx = nodes[ 0 ] . tx_broadcaster . txn_broadcasted . lock ( ) . unwrap ( ) . split_off ( 0 ) ;
188
+
189
+ mine_transaction ( & nodes[ 0 ] , & shutdown_tx[ 0 ] ) ;
190
+ mine_transaction ( & nodes[ 1 ] , & shutdown_tx[ 0 ] ) ;
191
+
192
+ connect_blocks ( & nodes[ 0 ] , 6 ) ;
193
+ connect_blocks ( & nodes[ 1 ] , 6 ) ;
194
+
195
+ check_closed_event ! ( nodes[ 0 ] , 1 , ClosureReason :: LocallyInitiatedCooperativeClosure , [ nodes[ 1 ] . node. get_our_node_id( ) ] , 1000000 ) ;
196
+ check_closed_event ! ( nodes[ 1 ] , 1 , ClosureReason :: CounterpartyInitiatedCooperativeClosure , [ nodes[ 0 ] . node. get_our_node_id( ) ] , 1000000 ) ;
197
+
198
+ assert_eq ! ( nodes[ 0 ] . chain_monitor. chain_monitor. list_monitors( ) . len( ) , 1 ) ;
199
+ // First archive should set balances_empty_height to current block height
200
+ nodes[ 0 ] . chain_monitor . chain_monitor . archive_fully_resolved_channel_monitors ( ) ;
201
+ connect_blocks ( & nodes[ 0 ] , 2016 ) ;
202
+ // Second call after 2016 blocks, should archive the monitor
203
+ nodes[ 0 ] . chain_monitor . chain_monitor . archive_fully_resolved_channel_monitors ( ) ;
204
+ // Should have no monitors left
205
+ assert_eq ! ( nodes[ 0 ] . chain_monitor. chain_monitor. list_monitors( ) . len( ) , 0 ) ;
206
+ // Remove the corresponding outputs and transactions the chain source is
207
+ // watching. This is to make sure the `Drop` function assertions pass.
208
+ nodes. get_mut ( 0 ) . unwrap ( ) . chain_source . remove_watched_txn_and_outputs (
209
+ OutPoint { txid : funding_tx. txid ( ) , index : 0 } ,
210
+ funding_tx. output [ 0 ] . script_pubkey . clone ( )
211
+ ) ;
212
+ }
213
+
161
214
fn do_chanmon_claim_value_coop_close ( anchors : bool ) {
162
215
// Tests `get_claimable_balances` returns the correct values across a simple cooperative claim.
163
216
// Specifically, this tests that the channel non-HTLC balances show up in
0 commit comments