Skip to content

Commit

Permalink
Fix min relay fee to be 1s/vB
Browse files Browse the repository at this point in the history
Bitcoin Core relay policy does not require 16s/vB, which it was
previously set to.
  • Loading branch information
arik-so committed Jan 21, 2025
1 parent c64402f commit d93516b
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 27 deletions.
2 changes: 1 addition & 1 deletion lightning/src/chain/chaininterface.rs
Original file line number Diff line number Diff line change
Expand Up @@ -176,7 +176,7 @@ pub trait FeeEstimator {
}

/// Minimum relay fee as required by bitcoin network mempool policy.
pub const INCREMENTAL_RELAY_FEE_SAT_PER_1000_WEIGHT: u64 = 4000;
pub const INCREMENTAL_RELAY_FEE_SAT_PER_1000_WEIGHT: u64 = 253;
/// Minimum feerate that takes a sane approach to bitcoind weight-to-vbytes rounding.
/// See the following Core Lightning commit for an explanation:
/// <https://github.com/ElementsProject/lightning/commit/2e687b9b352c9092b5e8bd4a688916ac50b44af0>
Expand Down
62 changes: 36 additions & 26 deletions lightning/src/ln/functional_tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1307,18 +1307,22 @@ fn test_duplicate_htlc_different_direction_onchain() {

let chan_1 = create_announced_chan_between_nodes(&nodes, 0, 1);

// post-bump fee (288 satoshis) + dust threshold for output type (294 satoshis) = 582
let payment_value_sats = 582;
let payment_value_msats = payment_value_sats * 1000;

// balancing
send_payment(&nodes[0], &vec!(&nodes[1])[..], 8000000);

let (payment_preimage, payment_hash, ..) = route_payment(&nodes[0], &vec!(&nodes[1])[..], 900_000);

let (route, _, _, _) = get_route_and_payment_hash!(nodes[1], nodes[0], 800_000);
let (route, _, _, _) = get_route_and_payment_hash!(nodes[1], nodes[0], payment_value_msats);
let node_a_payment_secret = nodes[0].node.create_inbound_payment_for_hash(payment_hash, None, 7200, None).unwrap();
send_along_route_with_secret(&nodes[1], route, &[&[&nodes[0]]], 800_000, payment_hash, node_a_payment_secret);
send_along_route_with_secret(&nodes[1], route, &[&[&nodes[0]]], payment_value_msats, payment_hash, node_a_payment_secret);

// Provide preimage to node 0 by claiming payment
nodes[0].node.claim_funds(payment_preimage);
expect_payment_claimed!(nodes[0], payment_hash, 800_000);
expect_payment_claimed!(nodes[0], payment_hash, payment_value_msats);
check_added_monitors!(nodes[0], 1);

// Broadcast node 1 commitment txn
Expand All @@ -1327,7 +1331,7 @@ fn test_duplicate_htlc_different_direction_onchain() {
assert_eq!(remote_txn[0].output.len(), 4); // 1 local, 1 remote, 1 htlc inbound, 1 htlc outbound
let mut has_both_htlcs = 0; // check htlcs match ones committed
for outp in remote_txn[0].output.iter() {
if outp.value.to_sat() == 800_000 / 1000 {
if outp.value.to_sat() == payment_value_sats {
has_both_htlcs += 1;
} else if outp.value.to_sat() == 900_000 / 1000 {
has_both_htlcs += 1;
Expand All @@ -1347,18 +1351,15 @@ fn test_duplicate_htlc_different_direction_onchain() {
check_spends!(claim_txn[1], remote_txn[0]);
check_spends!(claim_txn[2], remote_txn[0]);
let preimage_tx = &claim_txn[0];
let (preimage_bump_tx, timeout_tx) = if claim_txn[1].input[0].previous_output == preimage_tx.input[0].previous_output {
(&claim_txn[1], &claim_txn[2])
} else {
(&claim_txn[2], &claim_txn[1])
};
let timeout_tx = claim_txn.iter().skip(1).find(|t| t.input[0].previous_output != preimage_tx.input[0].previous_output).unwrap();
let preimage_bump_tx = claim_txn.iter().skip(1).find(|t| t.input[0].previous_output == preimage_tx.input[0].previous_output).unwrap();

assert_eq!(preimage_tx.input.len(), 1);
assert_eq!(preimage_bump_tx.input.len(), 1);

assert_eq!(preimage_tx.input.len(), 1);
assert_eq!(preimage_tx.input[0].witness.last().unwrap().len(), OFFERED_HTLC_SCRIPT_WEIGHT); // HTLC 1 <--> 0, preimage tx
assert_eq!(remote_txn[0].output[preimage_tx.input[0].previous_output.vout as usize].value.to_sat(), 800);
assert_eq!(remote_txn[0].output[preimage_tx.input[0].previous_output.vout as usize].value.to_sat(), payment_value_sats);

assert_eq!(timeout_tx.input.len(), 1);
assert_eq!(timeout_tx.input[0].witness.last().unwrap().len(), ACCEPTED_HTLC_SCRIPT_WEIGHT); // HTLC 0 <--> 1, timeout tx
Expand Down Expand Up @@ -7923,22 +7924,31 @@ fn test_bump_penalty_txn_on_remote_commitment() {
let node_chanmgrs = create_node_chanmgrs(2, &node_cfgs, &[None, None]);
let nodes = create_network(2, &node_cfgs, &node_chanmgrs);

let chan = create_announced_chan_between_nodes_with_value(&nodes, 0, 1, 1000000, 59000000);
let (payment_preimage, payment_hash, ..) = route_payment(&nodes[0], &[&nodes[1]], 3_000_000);
route_payment(&nodes[1], &vec!(&nodes[0])[..], 3000000).0;

// Remote commitment txn with 4 outputs : to_local, to_remote, 1 outgoing HTLC, 1 incoming HTLC
let remote_txn = get_local_commitment_txn!(nodes[0], chan.2);
assert_eq!(remote_txn[0].output.len(), 4);
assert_eq!(remote_txn[0].input.len(), 1);
assert_eq!(remote_txn[0].input[0].previous_output.txid, chan.3.compute_txid());

// Claim a HTLC without revocation (provide B monitor with preimage)
nodes[1].node.claim_funds(payment_preimage);
expect_payment_claimed!(nodes[1], payment_hash, 3_000_000);
mine_transaction(&nodes[1], &remote_txn[0]);
check_added_monitors!(nodes[1], 2);
connect_blocks(&nodes[1], TEST_FINAL_CLTV); // Confirm blocks until the HTLC expires
let remote_txn = {
// post-bump fee (288 satoshis) + dust threshold for output type (294 satoshis) = 582
let htlc_value_a_msats = 582_000;
let htlc_value_b_msats = 583_000;

let chan = create_announced_chan_between_nodes_with_value(&nodes, 0, 1, 1000000, 59000000);
let (payment_preimage, payment_hash, ..) = route_payment(&nodes[0], &[&nodes[1]], htlc_value_a_msats);
route_payment(&nodes[1], &vec!(&nodes[0])[..], htlc_value_b_msats);

// Remote commitment txn with 4 outputs : to_local, to_remote, 1 outgoing HTLC, 1 incoming HTLC
let remote_txn = get_local_commitment_txn!(nodes[0], chan.2);
assert_eq!(remote_txn[0].output.len(), 4);
assert_eq!(remote_txn[0].input.len(), 1);
assert_eq!(remote_txn[0].input[0].previous_output.txid, chan.3.compute_txid());

// Claim a HTLC without revocation (provide B monitor with preimage)
nodes[1].node.claim_funds(payment_preimage);
expect_payment_claimed!(nodes[1], payment_hash, htlc_value_a_msats);
mine_transaction(&nodes[1], &remote_txn[0]);
check_added_monitors!(nodes[1], 2);
connect_blocks(&nodes[1], TEST_FINAL_CLTV); // Confirm blocks until the HTLC expires
// depending on the block connection style, node 1 may have broadcast either 3 or 10 txs

remote_txn
};

// One or more claim tx should have been broadcast, check it
let timeout;
Expand Down

0 comments on commit d93516b

Please sign in to comment.