@@ -6553,3 +6553,111 @@ fn test_bump_penalty_txn_on_revoked_htlcs() {
6553
6553
}
6554
6554
check_closed_broadcast ! ( nodes[ 0 ] ) ;
6555
6555
}
6556
+
6557
+ #[ test]
6558
+ fn test_bump_penalty_txn_on_remote_commitment ( ) {
6559
+ // In case of claim txn with too low feerates for getting into mempools, RBF-bump them to be sure
6560
+ // we're able to claim outputs on remote commitment transaction before timelocks expiration
6561
+
6562
+ // Create 2 HTLCs
6563
+ // Provide preimage for one
6564
+ // Check aggregation
6565
+
6566
+ let nodes = create_network ( 2 , & [ None , None ] ) ;
6567
+
6568
+ let chan = create_announced_chan_between_nodes_with_value ( & nodes, 0 , 1 , 1000000 , 59000000 , LocalFeatures :: new ( ) , LocalFeatures :: new ( ) ) ;
6569
+ let payment_preimage = route_payment ( & nodes[ 0 ] , & vec ! ( & nodes[ 1 ] ) [ ..] , 3000000 ) . 0 ;
6570
+ route_payment ( & nodes[ 1 ] , & vec ! ( & nodes[ 0 ] ) [ ..] , 3000000 ) . 0 ;
6571
+
6572
+ // Remote commitment txn with 4 outputs : to_local, to_remote, 1 outgoing HTLC, 1 incoming HTLC
6573
+ let remote_txn = nodes[ 0 ] . node . channel_state . lock ( ) . unwrap ( ) . by_id . get ( & chan. 2 ) . unwrap ( ) . last_local_commitment_txn . clone ( ) ;
6574
+ assert_eq ! ( remote_txn[ 0 ] . output. len( ) , 4 ) ;
6575
+ assert_eq ! ( remote_txn[ 0 ] . input. len( ) , 1 ) ;
6576
+ assert_eq ! ( remote_txn[ 0 ] . input[ 0 ] . previous_output. txid, chan. 3 . txid( ) ) ;
6577
+
6578
+ // Claim a HTLC without revocation (provide B monitor with preimage)
6579
+ nodes[ 1 ] . node . claim_funds ( payment_preimage, 3_000_000 ) ;
6580
+ let header = BlockHeader { version : 0x20000000 , prev_blockhash : Default :: default ( ) , merkle_root : Default :: default ( ) , time : 42 , bits : 42 , nonce : 42 } ;
6581
+ nodes[ 1 ] . block_notifier . block_connected ( & Block { header, txdata : vec ! [ remote_txn[ 0 ] . clone( ) ] } , 1 ) ;
6582
+ check_added_monitors ! ( nodes[ 1 ] , 1 ) ;
6583
+
6584
+ // One or more claim tx should have been broadcast, check it
6585
+ let timeout;
6586
+ let preimage;
6587
+ let feerate_timeout;
6588
+ let feerate_preimage;
6589
+ {
6590
+ let mut node_txn = nodes[ 1 ] . tx_broadcaster . txn_broadcasted . lock ( ) . unwrap ( ) ;
6591
+ assert_eq ! ( node_txn. len( ) , 6 ) ; // 2 * claim tx (broadcasted from ChannelMonitor) * 2 (block-reparsing) + local commitment tx + local HTLC-timeout (broadcasted from ChannelManager)
6592
+ assert_eq ! ( node_txn[ 0 ] , node_txn[ 4 ] ) ;
6593
+ assert_eq ! ( node_txn[ 1 ] , node_txn[ 5 ] ) ;
6594
+ assert_eq ! ( node_txn[ 0 ] . input. len( ) , 1 ) ;
6595
+ assert_eq ! ( node_txn[ 1 ] . input. len( ) , 1 ) ;
6596
+ check_spends ! ( node_txn[ 0 ] , remote_txn[ 0 ] . clone( ) ) ;
6597
+ check_spends ! ( node_txn[ 1 ] , remote_txn[ 0 ] . clone( ) ) ;
6598
+ if node_txn[ 0 ] . input [ 0 ] . witness . last ( ) . unwrap ( ) . len ( ) == ACCEPTED_HTLC_SCRIPT_WEIGHT {
6599
+ timeout = node_txn[ 0 ] . txid ( ) ;
6600
+ let index = node_txn[ 0 ] . input [ 0 ] . previous_output . vout ;
6601
+ let fee = remote_txn[ 0 ] . output [ index as usize ] . value - node_txn[ 0 ] . output [ 0 ] . value ;
6602
+ feerate_timeout = fee * 1000 / node_txn[ 0 ] . get_weight ( ) as u64 ;
6603
+
6604
+ preimage = node_txn[ 1 ] . txid ( ) ;
6605
+ let index = node_txn[ 1 ] . input [ 0 ] . previous_output . vout ;
6606
+ let fee = remote_txn[ 0 ] . output [ index as usize ] . value - node_txn[ 1 ] . output [ 0 ] . value ;
6607
+ feerate_preimage = fee * 1000 / node_txn[ 1 ] . get_weight ( ) as u64 ;
6608
+ } else {
6609
+ timeout = node_txn[ 1 ] . txid ( ) ;
6610
+ let index = node_txn[ 1 ] . input [ 0 ] . previous_output . vout ;
6611
+ let fee = remote_txn[ 0 ] . output [ index as usize ] . value - node_txn[ 1 ] . output [ 0 ] . value ;
6612
+ feerate_timeout = fee * 1000 / node_txn[ 1 ] . get_weight ( ) as u64 ;
6613
+
6614
+ preimage = node_txn[ 0 ] . txid ( ) ;
6615
+ let index = node_txn[ 0 ] . input [ 0 ] . previous_output . vout ;
6616
+ let fee = remote_txn[ 0 ] . output [ index as usize ] . value - node_txn[ 0 ] . output [ 0 ] . value ;
6617
+ feerate_preimage = fee * 1000 / node_txn[ 0 ] . get_weight ( ) as u64 ;
6618
+ }
6619
+ node_txn. clear ( ) ;
6620
+ } ;
6621
+ assert_ne ! ( feerate_timeout, 0 ) ;
6622
+ assert_ne ! ( feerate_preimage, 0 ) ;
6623
+
6624
+ // After exhaustion of height timer, new bumped claim txn should have been broadcast, check it
6625
+ connect_blocks ( & nodes[ 1 ] . block_notifier , 15 , 1 , true , header. bitcoin_hash ( ) ) ;
6626
+ {
6627
+ let mut node_txn = nodes[ 1 ] . tx_broadcaster . txn_broadcasted . lock ( ) . unwrap ( ) ;
6628
+ assert_eq ! ( node_txn. len( ) , 2 ) ;
6629
+ assert_eq ! ( node_txn[ 0 ] . input. len( ) , 1 ) ;
6630
+ assert_eq ! ( node_txn[ 1 ] . input. len( ) , 1 ) ;
6631
+ check_spends ! ( node_txn[ 0 ] , remote_txn[ 0 ] . clone( ) ) ;
6632
+ check_spends ! ( node_txn[ 1 ] , remote_txn[ 0 ] . clone( ) ) ;
6633
+ if node_txn[ 0 ] . input [ 0 ] . witness . last ( ) . unwrap ( ) . len ( ) == ACCEPTED_HTLC_SCRIPT_WEIGHT {
6634
+ let index = node_txn[ 0 ] . input [ 0 ] . previous_output . vout ;
6635
+ let fee = remote_txn[ 0 ] . output [ index as usize ] . value - node_txn[ 0 ] . output [ 0 ] . value ;
6636
+ let new_feerate = fee * 1000 / node_txn[ 0 ] . get_weight ( ) as u64 ;
6637
+ assert ! ( new_feerate * 100 > feerate_timeout * 125 ) ;
6638
+ assert_ne ! ( timeout, node_txn[ 0 ] . txid( ) ) ;
6639
+
6640
+ let index = node_txn[ 1 ] . input [ 0 ] . previous_output . vout ;
6641
+ let fee = remote_txn[ 0 ] . output [ index as usize ] . value - node_txn[ 1 ] . output [ 0 ] . value ;
6642
+ let new_feerate = fee * 1000 / node_txn[ 1 ] . get_weight ( ) as u64 ;
6643
+ assert ! ( new_feerate * 100 > feerate_preimage * 125 ) ;
6644
+ assert_ne ! ( preimage, node_txn[ 1 ] . txid( ) ) ;
6645
+ } else {
6646
+ let index = node_txn[ 1 ] . input [ 0 ] . previous_output . vout ;
6647
+ let fee = remote_txn[ 0 ] . output [ index as usize ] . value - node_txn[ 1 ] . output [ 0 ] . value ;
6648
+ let new_feerate = fee * 1000 / node_txn[ 1 ] . get_weight ( ) as u64 ;
6649
+ assert ! ( new_feerate * 100 > feerate_timeout * 125 ) ;
6650
+ assert_ne ! ( timeout, node_txn[ 1 ] . txid( ) ) ;
6651
+
6652
+ let index = node_txn[ 0 ] . input [ 0 ] . previous_output . vout ;
6653
+ let fee = remote_txn[ 0 ] . output [ index as usize ] . value - node_txn[ 0 ] . output [ 0 ] . value ;
6654
+ let new_feerate = fee * 1000 / node_txn[ 0 ] . get_weight ( ) as u64 ;
6655
+ assert ! ( new_feerate * 100 > feerate_preimage * 125 ) ;
6656
+ assert_ne ! ( preimage, node_txn[ 0 ] . txid( ) ) ;
6657
+ }
6658
+ node_txn. clear ( ) ;
6659
+ }
6660
+
6661
+ nodes[ 1 ] . node . get_and_clear_pending_events ( ) ;
6662
+ nodes[ 1 ] . node . get_and_clear_pending_msg_events ( ) ;
6663
+ }
0 commit comments