@@ -2147,6 +2147,10 @@ impl ChainListener for ChannelManager {
2147
2147
hash_to_remove. push ( ( None , htlc_with_hash. clone ( ) ) ) ;
2148
2148
} else if tx. input . len ( ) > 0 && tx. input [ 0 ] . witness . len ( ) == 3 && tx. input [ 0 ] . witness [ 2 ] . len ( ) == 138 && payment_hash160 == tx. input [ 0 ] . witness [ 2 ] [ 69 ..89 ] {
2149
2149
hash_to_remove. push ( ( None , htlc_with_hash. clone ( ) ) ) ;
2150
+ } else if let Some ( hashs) = self . monitor . is_revoked_tx ( & tx) {
2151
+ for hash in hashs {
2152
+ hash_to_remove. push ( ( None , hash) ) ;
2153
+ }
2150
2154
}
2151
2155
}
2152
2156
}
@@ -4544,6 +4548,54 @@ mod tests {
4544
4548
assert_eq ! ( node_txn[ 2 ] . clone( ) . input[ 0 ] . witness. last( ) . unwrap( ) . len( ) , 133 ) ;
4545
4549
}
4546
4550
4551
+ #[ test]
4552
+ fn test_commitment_revoked_fail_backward ( ) {
4553
+ // Test that in case of a revoked commitment tx, we detect the resolution of output by justice tx
4554
+ // and fail backward accordingly.
4555
+
4556
+ let nodes = create_network ( 3 ) ;
4557
+
4558
+ // Create some initial channels
4559
+ create_announced_chan_between_nodes ( & nodes, 0 , 1 ) ;
4560
+ let chan_2 = create_announced_chan_between_nodes ( & nodes, 1 , 2 ) ;
4561
+
4562
+ // Rebalance the network a bit by relaying one payment through all the channels...
4563
+ send_payment ( & nodes[ 0 ] , & vec ! ( & nodes[ 1 ] , & nodes[ 2 ] ) [ ..] , 8000000 ) ;
4564
+ send_payment ( & nodes[ 0 ] , & vec ! ( & nodes[ 1 ] , & nodes[ 2 ] ) [ ..] , 8000000 ) ;
4565
+
4566
+ let ( payment_preimage, _payment_hash) = route_payment ( & nodes[ 0 ] , & vec ! ( & nodes[ 1 ] , & nodes[ 2 ] ) [ ..] , 3000000 ) ;
4567
+ // Get the will-be-revoked local txn from nodes[2]
4568
+ let revoked_local_txn = nodes[ 2 ] . node . channel_state . lock ( ) . unwrap ( ) . by_id . get ( & chan_2. 2 ) . unwrap ( ) . last_local_commitment_txn . clone ( ) ;
4569
+ // Revoke the old state
4570
+ claim_payment ( & nodes[ 0 ] , & vec ! ( & nodes[ 1 ] , & nodes[ 2 ] ) [ ..] , payment_preimage) ;
4571
+
4572
+ route_payment ( & nodes[ 0 ] , & vec ! ( & nodes[ 1 ] , & nodes[ 2 ] ) [ ..] , 3000000 ) ;
4573
+
4574
+ let header = BlockHeader { version : 0x20000000 , prev_blockhash : Default :: default ( ) , merkle_root : Default :: default ( ) , time : 42 , bits : 42 , nonce : 42 } ;
4575
+ nodes[ 1 ] . chain_monitor . block_connected_with_filtering ( & Block { header, txdata : vec ! [ revoked_local_txn[ 0 ] . clone( ) ] } , 1 ) ;
4576
+ {
4577
+ let mut added_monitors = nodes[ 1 ] . chan_monitor . added_monitors . lock ( ) . unwrap ( ) ;
4578
+ assert_eq ! ( added_monitors. len( ) , 1 ) ;
4579
+ added_monitors. clear ( ) ;
4580
+ }
4581
+ let events = nodes[ 1 ] . node . get_and_clear_pending_events ( ) ;
4582
+ assert_eq ! ( events. len( ) , 2 ) ;
4583
+ match events[ 0 ] {
4584
+ Event :: UpdateHTLCs { ref node_id, updates : msgs:: CommitmentUpdate { ref update_add_htlcs, ref update_fail_htlcs, ref update_fulfill_htlcs, ref update_fail_malformed_htlcs, .. } } => {
4585
+ assert ! ( update_add_htlcs. is_empty( ) ) ;
4586
+ assert ! ( !update_fail_htlcs. is_empty( ) ) ;
4587
+ assert ! ( update_fulfill_htlcs. is_empty( ) ) ;
4588
+ assert ! ( update_fail_malformed_htlcs. is_empty( ) ) ;
4589
+ assert_eq ! ( nodes[ 0 ] . node. get_our_node_id( ) , * node_id) ;
4590
+ } ,
4591
+ _ => panic ! ( "Unexpected event" ) ,
4592
+ }
4593
+ match events[ 1 ] {
4594
+ Event :: BroadcastChannelUpdate { msg : msgs:: ChannelUpdate { .. } } => { } ,
4595
+ _ => panic ! ( "Unexpected event" ) ,
4596
+ }
4597
+ }
4598
+
4547
4599
#[ test]
4548
4600
fn test_htlc_ignore_latest_remote_commitment ( ) {
4549
4601
// Test that HTLC transactions spending the latest remote commitment transaction are simply
0 commit comments