@@ -3215,8 +3215,8 @@ mod tests {
3215
3215
res
3216
3216
}
3217
3217
3218
- /// Tests that the given node has broadcast a claim transaction against the provided revoked
3219
- /// HTLC transaction.
3218
+ /// Tests that the given node has broadcast a claim transaction against the provided
3219
+ /// HTLC transaction issued from a revoked commitment tx
3220
3220
fn test_revoked_htlc_claim_txn_broadcast ( node : & Node , revoked_tx : Transaction ) {
3221
3221
let mut node_txn = node. tx_broadcaster . txn_broadcasted . lock ( ) . unwrap ( ) ;
3222
3222
assert_eq ! ( node_txn. len( ) , 1 ) ;
@@ -3441,6 +3441,46 @@ mod tests {
3441
3441
assert_eq ! ( nodes[ 1 ] . node. list_channels( ) . len( ) , 0 ) ;
3442
3442
}
3443
3443
3444
+ #[ test]
3445
+ fn channel_monitor_claim_revoked_commitment_tx ( ) {
3446
+
3447
+ let nodes = create_network ( 2 ) ;
3448
+
3449
+ // Create some new channel:
3450
+ let chan_1 = create_announced_chan_between_nodes ( & nodes, 0 , 1 ) ;
3451
+
3452
+ // Rebalance the network to generate htlc in the two directions
3453
+ send_payment ( & nodes[ 0 ] , & vec ! ( & nodes[ 1 ] ) [ ..] , 8000000 ) ;
3454
+ // node[0] is gonna to revoke an old state thus node[1] should be able to claim both offered/received HTLC outputs on top of commitment tx
3455
+ let payment_preimage_1 = route_payment ( & nodes[ 0 ] , & vec ! ( & nodes[ 1 ] ) [ ..] , 3000000 ) . 0 ;
3456
+ let _payment_preimage_2 = route_payment ( & nodes[ 1 ] , & vec ! ( & nodes[ 0 ] ) [ ..] , 3000000 ) . 0 ;
3457
+
3458
+ // Get the will-be-revoked local txn from node[0]
3459
+ let revoked_local_txn = nodes[ 0 ] . node . channel_state . lock ( ) . unwrap ( ) . by_id . iter ( ) . next ( ) . unwrap ( ) . 1 . last_local_commitment_txn . clone ( ) ;
3460
+
3461
+ //Revoke the old state
3462
+ claim_payment ( & nodes[ 0 ] , & vec ! ( & nodes[ 1 ] ) [ ..] , payment_preimage_1) ;
3463
+
3464
+ {
3465
+ let header = BlockHeader { version : 0x20000000 , prev_blockhash : Default :: default ( ) , merkle_root : Default :: default ( ) , time : 42 , bits : 42 , nonce : 42 } ;
3466
+
3467
+ nodes[ 0 ] . chain_monitor . block_connected_with_filtering ( & Block { header, txdata : vec ! [ revoked_local_txn[ 0 ] . clone( ) ] } , 1 ) ;
3468
+ test_txn_broadcast ( & nodes[ 0 ] , & chan_1, Some ( revoked_local_txn[ 0 ] . clone ( ) ) , HTLCType :: TIMEOUT ) ;
3469
+
3470
+ nodes[ 1 ] . chain_monitor . block_connected_with_filtering ( & Block { header, txdata : vec ! [ revoked_local_txn[ 0 ] . clone( ) ] } , 1 ) ;
3471
+ let node_txn = nodes[ 1 ] . tx_broadcaster . txn_broadcasted . lock ( ) . unwrap ( ) ;
3472
+ assert_eq ! ( node_txn. len( ) , 4 ) ; // ChannelManager is broadcasting last_local_commitment_txn.. and revocation tx is broacasted twice as block has been re-scanned.
3473
+ assert_eq ! ( node_txn[ 0 ] . input. len( ) , 2 ) ; //TODO: really should be 4 when we implement to_local and to_remote via revocation key claiming
3474
+
3475
+ let mut funding_tx_map = HashMap :: new ( ) ;
3476
+ funding_tx_map. insert ( revoked_local_txn[ 0 ] . txid ( ) , revoked_local_txn[ 0 ] . clone ( ) ) ;
3477
+ node_txn[ 0 ] . verify ( & funding_tx_map) . unwrap ( ) ;
3478
+ }
3479
+ get_announce_close_broadcast_events ( & nodes, 0 , 1 ) ;
3480
+ assert_eq ! ( nodes[ 0 ] . node. list_channels( ) . len( ) , 0 ) ;
3481
+ assert_eq ! ( nodes[ 1 ] . node. list_channels( ) . len( ) , 0 ) ;
3482
+ }
3483
+
3444
3484
#[ test]
3445
3485
fn test_htlc_ignore_latest_remote_commitment ( ) {
3446
3486
// Test that HTLC transactions spending the latest remote commitment transaction are simply
0 commit comments