Add a test for the fee-bump rate of timeout HTLC claims on cp txn

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.
This commit is contained in:
Matt Corallo 2024-10-18 15:57:25 +00:00
parent 6ae33dc1e0
commit 20db790c53

View file

@ -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};
@ -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);