Skip to content

Commit

Permalink
Add a test for the fee-bump rate of timeout HTLC claims on cp txn
Browse files Browse the repository at this point in the history
In a previous commit we updated the fee-bump-rate of claims against
HTLC timeouts on counterparty commitment transactions so that
instead of immediately attempting to bump every block we consider
the fact that we actually have at least `MIN_CLTV_EXPIRY_DELTA`
blocks to do so, and bumping at the appropriate rate given that.

Here we test that by adding an extra check to an existing test
that we do not bump in the very next block after the HTLC timeout
claim was initially broadcasted.
  • Loading branch information
TheBlueMatt committed Oct 18, 2024
1 parent 6ae33dc commit 20db790
Showing 1 changed file with 16 additions and 7 deletions.
23 changes: 16 additions & 7 deletions lightning/src/ln/functional_tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ use crate::chain;
use crate::chain::{ChannelMonitorUpdateStatus, Confirm, Listen, Watch};
use crate::chain::chaininterface::LowerBoundedFeeEstimator;
use crate::chain::channelmonitor;
use crate::chain::channelmonitor::{CLOSED_CHANNEL_UPDATE_ID, CLTV_CLAIM_BUFFER, LATENCY_GRACE_PERIOD_BLOCKS, ANTI_REORG_DELAY};
use crate::chain::channelmonitor::{Balance, CLOSED_CHANNEL_UPDATE_ID, CLTV_CLAIM_BUFFER, LATENCY_GRACE_PERIOD_BLOCKS, ANTI_REORG_DELAY};
use crate::chain::transaction::OutPoint;
use crate::sign::{ecdsa::EcdsaChannelSigner, EntropySource, OutputSpender, SignerProvider};
use crate::events::{Event, FundingInfo, MessageSendEvent, MessageSendEventsProvider, PathFailure, PaymentPurpose, ClosureReason, HTLCDestination, PaymentFailureReason};
Expand Down Expand Up @@ -3138,19 +3138,28 @@ fn do_test_htlc_on_chain_timeout(connect_style: ConnectStyle) {
mine_transaction(&nodes[1], &commitment_tx[0]);
check_closed_event!(&nodes[1], 1, ClosureReason::CommitmentTxConfirmed, false
, [nodes[2].node.get_our_node_id()], 100000);
connect_blocks(&nodes[1], 200 - nodes[2].best_block_info().1);
let htlc_expiry = get_monitor!(nodes[1], chan_2.2).get_claimable_balances().iter().filter_map(|bal|
if let Balance::MaybeTimeoutClaimableHTLC { claimable_height, .. } = bal {
Some(*claimable_height)
} else {
None
}
).next().unwrap();
connect_blocks(&nodes[1], htlc_expiry - nodes[1].best_block_info().1);
let timeout_tx = {
let mut txn = nodes[1].tx_broadcaster.txn_broadcast();
if nodes[1].connect_style.borrow().skips_blocks() {
assert_eq!(txn.len(), 1);
} else {
assert_eq!(txn.len(), 3); // Two extra fee bumps for timeout transaction
}
assert_eq!(txn.len(), 1);
txn.iter().for_each(|tx| check_spends!(tx, commitment_tx[0]));
assert_eq!(txn[0].clone().input[0].witness.last().unwrap().len(), ACCEPTED_HTLC_SCRIPT_WEIGHT);
txn.remove(0)
};

// Make sure that if we connect only one block we aren't aggressively fee-bumping the HTLC
// claim which was only just broadcasted (and as at least `MIN_CLTV_EXPIRY_DELTA` blocks to
// confirm).
connect_blocks(&nodes[1], 1);
assert_eq!(nodes[1].tx_broadcaster.txn_broadcast().len(), 0);

mine_transaction(&nodes[1], &timeout_tx);
check_added_monitors!(nodes[1], 1);
check_closed_broadcast!(nodes[1], true);
Expand Down

0 comments on commit 20db790

Please sign in to comment.