@@ -5747,6 +5747,42 @@ mod tests {
5747
5747
test_revoked_htlc_claim_txn_broadcast ( & nodes[ 1 ] , node_txn[ 1 ] . clone ( ) ) ;
5748
5748
}
5749
5749
get_announce_close_broadcast_events ( & nodes, 0 , 1 ) ;
5750
+
5751
+ // We test justice_tx build by A on B's revoked HTLC-Success tx
5752
+ // Create some new channels:
5753
+ let chan_6 = create_announced_chan_between_nodes ( & nodes, 0 , 1 ) ;
5754
+
5755
+ // A pending HTLC which will be revoked:
5756
+ let payment_preimage_4 = route_payment ( & nodes[ 0 ] , & vec ! ( & nodes[ 1 ] ) [ ..] , 3000000 ) . 0 ;
5757
+ // Get the will-be-revoked local txn from B
5758
+ let revoked_local_txn = nodes[ 1 ] . node . channel_state . lock ( ) . unwrap ( ) . by_id . iter ( ) . next ( ) . unwrap ( ) . 1 . last_local_commitment_txn . clone ( ) ;
5759
+ assert_eq ! ( revoked_local_txn. len( ) , 1 ) ; // Only commitment tx
5760
+ assert_eq ! ( revoked_local_txn[ 0 ] . input. len( ) , 1 ) ;
5761
+ assert_eq ! ( revoked_local_txn[ 0 ] . input[ 0 ] . previous_output. txid, chan_6. 3 . txid( ) ) ;
5762
+ assert_eq ! ( revoked_local_txn[ 0 ] . output. len( ) , 2 ) ; // Only HTLC and output back to A are present
5763
+ // Revoke the old state
5764
+ claim_payment ( & nodes[ 0 ] , & vec ! ( & nodes[ 1 ] ) [ ..] , payment_preimage_4) ;
5765
+ {
5766
+ let mut header = BlockHeader { version : 0x20000000 , prev_blockhash : Default :: default ( ) , merkle_root : Default :: default ( ) , time : 42 , bits : 42 , nonce : 42 } ;
5767
+ nodes[ 0 ] . chain_monitor . block_connected_with_filtering ( & Block { header, txdata : vec ! [ revoked_local_txn[ 0 ] . clone( ) ] } , 1 ) ;
5768
+ {
5769
+ let mut node_txn = nodes[ 0 ] . tx_broadcaster . txn_broadcasted . lock ( ) . unwrap ( ) ;
5770
+ assert_eq ! ( node_txn. len( ) , 3 ) ;
5771
+ assert_eq ! ( node_txn. pop( ) . unwrap( ) , node_txn[ 0 ] ) ; // An outpoint registration will result in a 2nd block_connected
5772
+ assert_eq ! ( node_txn[ 0 ] . input. len( ) , 1 ) ; // We claim the received HTLC output
5773
+
5774
+ check_spends ! ( node_txn[ 0 ] , revoked_local_txn[ 0 ] . clone( ) ) ;
5775
+ node_txn. swap_remove ( 0 ) ;
5776
+ }
5777
+ test_txn_broadcast ( & nodes[ 0 ] , & chan_6, None , HTLCType :: NONE ) ;
5778
+
5779
+ nodes[ 1 ] . chain_monitor . block_connected_with_filtering ( & Block { header, txdata : vec ! [ revoked_local_txn[ 0 ] . clone( ) ] } , 1 ) ;
5780
+ let node_txn = test_txn_broadcast ( & nodes[ 1 ] , & chan_6, Some ( revoked_local_txn[ 0 ] . clone ( ) ) , HTLCType :: SUCCESS ) ;
5781
+ header = BlockHeader { version : 0x20000000 , prev_blockhash : header. bitcoin_hash ( ) , merkle_root : Default :: default ( ) , time : 42 , bits : 42 , nonce : 42 } ;
5782
+ nodes[ 0 ] . chain_monitor . block_connected_with_filtering ( & Block { header, txdata : vec ! [ node_txn[ 1 ] . clone( ) ] } , 1 ) ;
5783
+ test_revoked_htlc_claim_txn_broadcast ( & nodes[ 0 ] , node_txn[ 1 ] . clone ( ) ) ;
5784
+ }
5785
+ get_announce_close_broadcast_events ( & nodes, 0 , 1 ) ;
5750
5786
assert_eq ! ( nodes[ 0 ] . node. list_channels( ) . len( ) , 0 ) ;
5751
5787
assert_eq ! ( nodes[ 1 ] . node. list_channels( ) . len( ) , 0 ) ;
5752
5788
}
0 commit comments