@@ -6342,6 +6342,54 @@ mod tests {
6342
6342
assert_eq ! ( node_txn[ 2 ] . clone( ) . input[ 0 ] . witness. last( ) . unwrap( ) . len( ) , 133 ) ;
6343
6343
}
6344
6344
6345
+ #[ test]
6346
+ fn test_commitment_revoked_fail_backward ( ) {
6347
+ // Test that in case of a revoked commitment tx, we detect the resolution of output by justice tx
6348
+ // and fail backward accordingly.
6349
+
6350
+ let nodes = create_network ( 3 ) ;
6351
+
6352
+ // Create some initial channels
6353
+ create_announced_chan_between_nodes ( & nodes, 0 , 1 ) ;
6354
+ let chan_2 = create_announced_chan_between_nodes ( & nodes, 1 , 2 ) ;
6355
+
6356
+ // Rebalance the network a bit by relaying one payment through all the channels...
6357
+ send_payment ( & nodes[ 0 ] , & vec ! ( & nodes[ 1 ] , & nodes[ 2 ] ) [ ..] , 8000000 ) ;
6358
+ send_payment ( & nodes[ 0 ] , & vec ! ( & nodes[ 1 ] , & nodes[ 2 ] ) [ ..] , 8000000 ) ;
6359
+
6360
+ let ( payment_preimage, _payment_hash) = route_payment ( & nodes[ 0 ] , & vec ! ( & nodes[ 1 ] , & nodes[ 2 ] ) [ ..] , 3000000 ) ;
6361
+ // Get the will-be-revoked local txn from nodes[2]
6362
+ let revoked_local_txn = nodes[ 2 ] . node . channel_state . lock ( ) . unwrap ( ) . by_id . get ( & chan_2. 2 ) . unwrap ( ) . last_local_commitment_txn . clone ( ) ;
6363
+ // Revoke the old state
6364
+ claim_payment ( & nodes[ 0 ] , & vec ! ( & nodes[ 1 ] , & nodes[ 2 ] ) [ ..] , payment_preimage) ;
6365
+
6366
+ route_payment ( & nodes[ 0 ] , & vec ! ( & nodes[ 1 ] , & nodes[ 2 ] ) [ ..] , 3000000 ) ;
6367
+
6368
+ let header = BlockHeader { version : 0x20000000 , prev_blockhash : Default :: default ( ) , merkle_root : Default :: default ( ) , time : 42 , bits : 42 , nonce : 42 } ;
6369
+ nodes[ 1 ] . chain_monitor . block_connected_with_filtering ( & Block { header, txdata : vec ! [ revoked_local_txn[ 0 ] . clone( ) ] } , 1 ) ;
6370
+ {
6371
+ let mut added_monitors = nodes[ 1 ] . chan_monitor . added_monitors . lock ( ) . unwrap ( ) ;
6372
+ assert_eq ! ( added_monitors. len( ) , 1 ) ;
6373
+ added_monitors. clear ( ) ;
6374
+ }
6375
+ let events = nodes[ 1 ] . node . get_and_clear_pending_msg_events ( ) ;
6376
+ assert_eq ! ( events. len( ) , 2 ) ;
6377
+ match events[ 0 ] {
6378
+ MessageSendEvent :: BroadcastChannelUpdate { msg : msgs:: ChannelUpdate { .. } } => { } ,
6379
+ _ => panic ! ( "Unexpected event" ) ,
6380
+ }
6381
+ match events[ 1 ] {
6382
+ 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, .. } } => {
6383
+ assert ! ( update_add_htlcs. is_empty( ) ) ;
6384
+ assert ! ( !update_fail_htlcs. is_empty( ) ) ;
6385
+ assert ! ( update_fulfill_htlcs. is_empty( ) ) ;
6386
+ assert ! ( update_fail_malformed_htlcs. is_empty( ) ) ;
6387
+ assert_eq ! ( nodes[ 0 ] . node. get_our_node_id( ) , * node_id) ;
6388
+ } ,
6389
+ _ => panic ! ( "Unexpected event" ) ,
6390
+ }
6391
+ }
6392
+
6345
6393
#[ test]
6346
6394
fn test_htlc_ignore_latest_remote_commitment ( ) {
6347
6395
// Test that HTLC transactions spending the latest remote commitment transaction are simply
0 commit comments