@@ -6493,3 +6493,111 @@ fn test_bump_penalty_txn_on_revoked_htlcs() {
6493
6493
}
6494
6494
check_closed_broadcast ! ( nodes[ 0 ] ) ;
6495
6495
}
6496
+
6497
+ #[ test]
6498
+ fn test_bump_penalty_txn_on_remote_commitment ( ) {
6499
+ // In case of claim txn with too low feerates for getting into mempools, RBF-bump them to be sure
6500
+ // we're able to claim outputs on remote commitment transaction before timelocks expiration
6501
+
6502
+ // Create 2 HTLCs
6503
+ // Provide preimage for one
6504
+ // Check aggregation
6505
+
6506
+ let nodes = create_network ( 2 , & [ None , None ] ) ;
6507
+
6508
+ let chan = create_announced_chan_between_nodes_with_value ( & nodes, 0 , 1 , 1000000 , 59000000 , LocalFeatures :: new ( ) , LocalFeatures :: new ( ) ) ;
6509
+ let payment_preimage = route_payment ( & nodes[ 0 ] , & vec ! ( & nodes[ 1 ] ) [ ..] , 3000000 ) . 0 ;
6510
+ route_payment ( & nodes[ 1 ] , & vec ! ( & nodes[ 0 ] ) [ ..] , 3000000 ) . 0 ;
6511
+
6512
+ // Remote commitment txn with 4 outputs : to_local, to_remote, 1 outgoing HTLC, 1 incoming HTLC
6513
+ let remote_txn = nodes[ 0 ] . node . channel_state . lock ( ) . unwrap ( ) . by_id . get ( & chan. 2 ) . unwrap ( ) . last_local_commitment_txn . clone ( ) ;
6514
+ assert_eq ! ( remote_txn[ 0 ] . output. len( ) , 4 ) ;
6515
+ assert_eq ! ( remote_txn[ 0 ] . input. len( ) , 1 ) ;
6516
+ assert_eq ! ( remote_txn[ 0 ] . input[ 0 ] . previous_output. txid, chan. 3 . txid( ) ) ;
6517
+
6518
+ // Claim a HTLC without revocation (provide B monitor with preimage)
6519
+ nodes[ 1 ] . node . claim_funds ( payment_preimage, 3_000_000 ) ;
6520
+ let header = BlockHeader { version : 0x20000000 , prev_blockhash : Default :: default ( ) , merkle_root : Default :: default ( ) , time : 42 , bits : 42 , nonce : 42 } ;
6521
+ nodes[ 1 ] . block_notifier . block_connected ( & Block { header, txdata : vec ! [ remote_txn[ 0 ] . clone( ) ] } , 1 ) ;
6522
+ check_added_monitors ! ( nodes[ 1 ] , 1 ) ;
6523
+
6524
+ // One or more claim tx should have been broadcast, check it
6525
+ let timeout;
6526
+ let preimage;
6527
+ let feerate_timeout;
6528
+ let feerate_preimage;
6529
+ {
6530
+ let mut node_txn = nodes[ 1 ] . tx_broadcaster . txn_broadcasted . lock ( ) . unwrap ( ) ;
6531
+ assert_eq ! ( node_txn. len( ) , 6 ) ; // 2 * claim tx (broadcasted from ChannelMonitor) * 2 (block-reparsing) + local commitment tx + local HTLC-timeout (broadcasted from ChannelManager)
6532
+ assert_eq ! ( node_txn[ 0 ] , node_txn[ 4 ] ) ;
6533
+ assert_eq ! ( node_txn[ 1 ] , node_txn[ 5 ] ) ;
6534
+ assert_eq ! ( node_txn[ 0 ] . input. len( ) , 1 ) ;
6535
+ assert_eq ! ( node_txn[ 1 ] . input. len( ) , 1 ) ;
6536
+ check_spends ! ( node_txn[ 0 ] , remote_txn[ 0 ] . clone( ) ) ;
6537
+ check_spends ! ( node_txn[ 1 ] , remote_txn[ 0 ] . clone( ) ) ;
6538
+ if node_txn[ 0 ] . input [ 0 ] . witness . last ( ) . unwrap ( ) . len ( ) == ACCEPTED_HTLC_SCRIPT_WEIGHT {
6539
+ timeout = node_txn[ 0 ] . txid ( ) ;
6540
+ let index = node_txn[ 0 ] . input [ 0 ] . previous_output . vout ;
6541
+ let fee = remote_txn[ 0 ] . output [ index as usize ] . value - node_txn[ 0 ] . output [ 0 ] . value ;
6542
+ feerate_timeout = fee * 1000 / node_txn[ 0 ] . get_weight ( ) as u64 ;
6543
+
6544
+ preimage = node_txn[ 1 ] . txid ( ) ;
6545
+ let index = node_txn[ 1 ] . input [ 0 ] . previous_output . vout ;
6546
+ let fee = remote_txn[ 0 ] . output [ index as usize ] . value - node_txn[ 1 ] . output [ 0 ] . value ;
6547
+ feerate_preimage = fee * 1000 / node_txn[ 1 ] . get_weight ( ) as u64 ;
6548
+ } else {
6549
+ timeout = node_txn[ 1 ] . txid ( ) ;
6550
+ let index = node_txn[ 1 ] . input [ 0 ] . previous_output . vout ;
6551
+ let fee = remote_txn[ 0 ] . output [ index as usize ] . value - node_txn[ 1 ] . output [ 0 ] . value ;
6552
+ feerate_timeout = fee * 1000 / node_txn[ 1 ] . get_weight ( ) as u64 ;
6553
+
6554
+ preimage = node_txn[ 0 ] . txid ( ) ;
6555
+ let index = node_txn[ 0 ] . input [ 0 ] . previous_output . vout ;
6556
+ let fee = remote_txn[ 0 ] . output [ index as usize ] . value - node_txn[ 0 ] . output [ 0 ] . value ;
6557
+ feerate_preimage = fee * 1000 / node_txn[ 0 ] . get_weight ( ) as u64 ;
6558
+ }
6559
+ node_txn. clear ( ) ;
6560
+ } ;
6561
+ assert_ne ! ( feerate_timeout, 0 ) ;
6562
+ assert_ne ! ( feerate_preimage, 0 ) ;
6563
+
6564
+ // After exhaustion of height timer, new bumped claim txn should have been broadcast, check it
6565
+ connect_blocks ( & nodes[ 1 ] . block_notifier , 15 , 1 , true , header. bitcoin_hash ( ) ) ;
6566
+ {
6567
+ let mut node_txn = nodes[ 1 ] . tx_broadcaster . txn_broadcasted . lock ( ) . unwrap ( ) ;
6568
+ assert_eq ! ( node_txn. len( ) , 2 ) ;
6569
+ assert_eq ! ( node_txn[ 0 ] . input. len( ) , 1 ) ;
6570
+ assert_eq ! ( node_txn[ 1 ] . input. len( ) , 1 ) ;
6571
+ check_spends ! ( node_txn[ 0 ] , remote_txn[ 0 ] . clone( ) ) ;
6572
+ check_spends ! ( node_txn[ 1 ] , remote_txn[ 0 ] . clone( ) ) ;
6573
+ if node_txn[ 0 ] . input [ 0 ] . witness . last ( ) . unwrap ( ) . len ( ) == ACCEPTED_HTLC_SCRIPT_WEIGHT {
6574
+ let index = node_txn[ 0 ] . input [ 0 ] . previous_output . vout ;
6575
+ let fee = remote_txn[ 0 ] . output [ index as usize ] . value - node_txn[ 0 ] . output [ 0 ] . value ;
6576
+ let new_feerate = fee * 1000 / node_txn[ 0 ] . get_weight ( ) as u64 ;
6577
+ assert ! ( new_feerate * 100 > feerate_timeout * 125 ) ;
6578
+ assert_ne ! ( timeout, node_txn[ 0 ] . txid( ) ) ;
6579
+
6580
+ let index = node_txn[ 1 ] . input [ 0 ] . previous_output . vout ;
6581
+ let fee = remote_txn[ 0 ] . output [ index as usize ] . value - node_txn[ 1 ] . output [ 0 ] . value ;
6582
+ let new_feerate = fee * 1000 / node_txn[ 1 ] . get_weight ( ) as u64 ;
6583
+ assert ! ( new_feerate * 100 > feerate_preimage * 125 ) ;
6584
+ assert_ne ! ( preimage, node_txn[ 1 ] . txid( ) ) ;
6585
+ } else {
6586
+ let index = node_txn[ 1 ] . input [ 0 ] . previous_output . vout ;
6587
+ let fee = remote_txn[ 0 ] . output [ index as usize ] . value - node_txn[ 1 ] . output [ 0 ] . value ;
6588
+ let new_feerate = fee * 1000 / node_txn[ 1 ] . get_weight ( ) as u64 ;
6589
+ assert ! ( new_feerate * 100 > feerate_timeout * 125 ) ;
6590
+ assert_ne ! ( timeout, node_txn[ 1 ] . txid( ) ) ;
6591
+
6592
+ let index = node_txn[ 0 ] . input [ 0 ] . previous_output . vout ;
6593
+ let fee = remote_txn[ 0 ] . output [ index as usize ] . value - node_txn[ 0 ] . output [ 0 ] . value ;
6594
+ let new_feerate = fee * 1000 / node_txn[ 0 ] . get_weight ( ) as u64 ;
6595
+ assert ! ( new_feerate * 100 > feerate_preimage * 125 ) ;
6596
+ assert_ne ! ( preimage, node_txn[ 0 ] . txid( ) ) ;
6597
+ }
6598
+ node_txn. clear ( ) ;
6599
+ }
6600
+
6601
+ nodes[ 1 ] . node . get_and_clear_pending_events ( ) ;
6602
+ nodes[ 1 ] . node . get_and_clear_pending_msg_events ( ) ;
6603
+ }
0 commit comments