Skip to content

Commit 20db790

Browse files
committed
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.
1 parent 6ae33dc commit 20db790

File tree

1 file changed

+16
-7
lines changed

1 file changed

+16
-7
lines changed

lightning/src/ln/functional_tests.rs

Lines changed: 16 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ use crate::chain;
1515
use crate::chain::{ChannelMonitorUpdateStatus, Confirm, Listen, Watch};
1616
use crate::chain::chaininterface::LowerBoundedFeeEstimator;
1717
use crate::chain::channelmonitor;
18-
use crate::chain::channelmonitor::{CLOSED_CHANNEL_UPDATE_ID, CLTV_CLAIM_BUFFER, LATENCY_GRACE_PERIOD_BLOCKS, ANTI_REORG_DELAY};
18+
use crate::chain::channelmonitor::{Balance, CLOSED_CHANNEL_UPDATE_ID, CLTV_CLAIM_BUFFER, LATENCY_GRACE_PERIOD_BLOCKS, ANTI_REORG_DELAY};
1919
use crate::chain::transaction::OutPoint;
2020
use crate::sign::{ecdsa::EcdsaChannelSigner, EntropySource, OutputSpender, SignerProvider};
2121
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) {
31383138
mine_transaction(&nodes[1], &commitment_tx[0]);
31393139
check_closed_event!(&nodes[1], 1, ClosureReason::CommitmentTxConfirmed, false
31403140
, [nodes[2].node.get_our_node_id()], 100000);
3141-
connect_blocks(&nodes[1], 200 - nodes[2].best_block_info().1);
3141+
let htlc_expiry = get_monitor!(nodes[1], chan_2.2).get_claimable_balances().iter().filter_map(|bal|
3142+
if let Balance::MaybeTimeoutClaimableHTLC { claimable_height, .. } = bal {
3143+
Some(*claimable_height)
3144+
} else {
3145+
None
3146+
}
3147+
).next().unwrap();
3148+
connect_blocks(&nodes[1], htlc_expiry - nodes[1].best_block_info().1);
31423149
let timeout_tx = {
31433150
let mut txn = nodes[1].tx_broadcaster.txn_broadcast();
3144-
if nodes[1].connect_style.borrow().skips_blocks() {
3145-
assert_eq!(txn.len(), 1);
3146-
} else {
3147-
assert_eq!(txn.len(), 3); // Two extra fee bumps for timeout transaction
3148-
}
3151+
assert_eq!(txn.len(), 1);
31493152
txn.iter().for_each(|tx| check_spends!(tx, commitment_tx[0]));
31503153
assert_eq!(txn[0].clone().input[0].witness.last().unwrap().len(), ACCEPTED_HTLC_SCRIPT_WEIGHT);
31513154
txn.remove(0)
31523155
};
31533156

3157+
// Make sure that if we connect only one block we aren't aggressively fee-bumping the HTLC
3158+
// claim which was only just broadcasted (and as at least `MIN_CLTV_EXPIRY_DELTA` blocks to
3159+
// confirm).
3160+
connect_blocks(&nodes[1], 1);
3161+
assert_eq!(nodes[1].tx_broadcaster.txn_broadcast().len(), 0);
3162+
31543163
mine_transaction(&nodes[1], &timeout_tx);
31553164
check_added_monitors!(nodes[1], 1);
31563165
check_closed_broadcast!(nodes[1], true);

0 commit comments

Comments
 (0)