@@ -6289,6 +6289,54 @@ mod tests {
6289
6289
assert_eq ! ( node_txn[ 2 ] . clone( ) . input[ 0 ] . witness. last( ) . unwrap( ) . len( ) , 133 ) ;
6290
6290
}
6291
6291
6292
+ #[ test]
6293
+ fn test_commitment_revoked_fail_backward ( ) {
6294
+ // Test that in case of a revoked commitment tx, we detect the resolution of output by justice tx
6295
+ // and fail backward accordingly.
6296
+
6297
+ let nodes = create_network ( 3 ) ;
6298
+
6299
+ // Create some initial channels
6300
+ create_announced_chan_between_nodes ( & nodes, 0 , 1 ) ;
6301
+ let chan_2 = create_announced_chan_between_nodes ( & nodes, 1 , 2 ) ;
6302
+
6303
+ // Rebalance the network a bit by relaying one payment through all the channels...
6304
+ send_payment ( & nodes[ 0 ] , & vec ! ( & nodes[ 1 ] , & nodes[ 2 ] ) [ ..] , 8000000 ) ;
6305
+ send_payment ( & nodes[ 0 ] , & vec ! ( & nodes[ 1 ] , & nodes[ 2 ] ) [ ..] , 8000000 ) ;
6306
+
6307
+ let ( payment_preimage, _payment_hash) = route_payment ( & nodes[ 0 ] , & vec ! ( & nodes[ 1 ] , & nodes[ 2 ] ) [ ..] , 3000000 ) ;
6308
+ // Get the will-be-revoked local txn from nodes[2]
6309
+ let revoked_local_txn = nodes[ 2 ] . node . channel_state . lock ( ) . unwrap ( ) . by_id . get ( & chan_2. 2 ) . unwrap ( ) . last_local_commitment_txn . clone ( ) ;
6310
+ // Revoke the old state
6311
+ claim_payment ( & nodes[ 0 ] , & vec ! ( & nodes[ 1 ] , & nodes[ 2 ] ) [ ..] , payment_preimage) ;
6312
+
6313
+ route_payment ( & nodes[ 0 ] , & vec ! ( & nodes[ 1 ] , & nodes[ 2 ] ) [ ..] , 3000000 ) ;
6314
+
6315
+ let header = BlockHeader { version : 0x20000000 , prev_blockhash : Default :: default ( ) , merkle_root : Default :: default ( ) , time : 42 , bits : 42 , nonce : 42 } ;
6316
+ nodes[ 1 ] . chain_monitor . block_connected_with_filtering ( & Block { header, txdata : vec ! [ revoked_local_txn[ 0 ] . clone( ) ] } , 1 ) ;
6317
+ {
6318
+ let mut added_monitors = nodes[ 1 ] . chan_monitor . added_monitors . lock ( ) . unwrap ( ) ;
6319
+ assert_eq ! ( added_monitors. len( ) , 1 ) ;
6320
+ added_monitors. clear ( ) ;
6321
+ }
6322
+ let events = nodes[ 1 ] . node . get_and_clear_pending_msg_events ( ) ;
6323
+ assert_eq ! ( events. len( ) , 2 ) ;
6324
+ match events[ 0 ] {
6325
+ MessageSendEvent :: BroadcastChannelUpdate { msg : msgs:: ChannelUpdate { .. } } => { } ,
6326
+ _ => panic ! ( "Unexpected event" ) ,
6327
+ }
6328
+ match events[ 1 ] {
6329
+ MessageSendEvent :: UpdateHTLCs { ref node_id, updates : msgs:: CommitmentUpdate { ref update_add_htlcs, ref update_fail_htlcs, ref update_fulfill_htlcs, ref update_fail_malformed_htlcs, .. } } => {
6330
+ assert ! ( update_add_htlcs. is_empty( ) ) ;
6331
+ assert ! ( !update_fail_htlcs. is_empty( ) ) ;
6332
+ assert ! ( update_fulfill_htlcs. is_empty( ) ) ;
6333
+ assert ! ( update_fail_malformed_htlcs. is_empty( ) ) ;
6334
+ assert_eq ! ( nodes[ 0 ] . node. get_our_node_id( ) , * node_id) ;
6335
+ } ,
6336
+ _ => panic ! ( "Unexpected event" ) ,
6337
+ }
6338
+ }
6339
+
6292
6340
#[ test]
6293
6341
fn test_htlc_ignore_latest_remote_commitment ( ) {
6294
6342
// Test that HTLC transactions spending the latest remote commitment transaction are simply
0 commit comments