Skip to content

Commit 19de435

Browse files
committed
Move feerate helpers to chain module
We plan to use these outside of the `bump_transaction` module in the next commit, and they really should belong in the same module as `FeeEstimator`.
1 parent 07606c1 commit 19de435

File tree

2 files changed

+10
-10
lines changed

2 files changed

+10
-10
lines changed

lightning/src/chain/chaininterface.rs

+9
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,18 @@
1414
//! disconnections, transaction broadcasting, and feerate information requests.
1515
1616
use core::{cmp, ops::Deref};
17+
use core::convert::TryInto;
1718

1819
use bitcoin::blockdata::transaction::Transaction;
1920

21+
// TODO: Define typed abstraction over feerates to handle their conversions.
22+
pub(crate) fn compute_feerate_sat_per_1000_weight(fee_sat: u64, weight: u64) -> u32 {
23+
(fee_sat * 1000 / weight).try_into().unwrap_or(u32::max_value())
24+
}
25+
pub(crate) const fn fee_for_weight(feerate_sat_per_1000_weight: u32, weight: u64) -> u64 {
26+
((feerate_sat_per_1000_weight as u64 * weight) + 1000 - 1) / 1000
27+
}
28+
2029
/// An interface to send a transaction to the Bitcoin network.
2130
pub trait BroadcasterInterface {
2231
/// Sends a list of transactions out to (hopefully) be mined.

lightning/src/events/bump_transaction.rs

+1-10
Original file line numberDiff line numberDiff line change
@@ -12,10 +12,9 @@
1212
//! [`Event`]: crate::events::Event
1313
1414
use alloc::collections::BTreeMap;
15-
use core::convert::TryInto;
1615
use core::ops::Deref;
1716

18-
use crate::chain::chaininterface::BroadcasterInterface;
17+
use crate::chain::chaininterface::{BroadcasterInterface, compute_feerate_sat_per_1000_weight, fee_for_weight};
1918
use crate::chain::ClaimId;
2019
use crate::io_extras::sink;
2120
use crate::ln::channel::ANCHOR_OUTPUT_VALUE_SATOSHI;
@@ -44,14 +43,6 @@ const BASE_INPUT_SIZE: u64 = 32 /* txid */ + 4 /* vout */ + 4 /* sequence */;
4443

4544
const BASE_INPUT_WEIGHT: u64 = BASE_INPUT_SIZE * WITNESS_SCALE_FACTOR as u64;
4645

47-
// TODO: Define typed abstraction over feerates to handle their conversions.
48-
fn compute_feerate_sat_per_1000_weight(fee_sat: u64, weight: u64) -> u32 {
49-
(fee_sat * 1000 / weight).try_into().unwrap_or(u32::max_value())
50-
}
51-
const fn fee_for_weight(feerate_sat_per_1000_weight: u32, weight: u64) -> u64 {
52-
((feerate_sat_per_1000_weight as u64 * weight) + 1000 - 1) / 1000
53-
}
54-
5546
/// The parameters required to derive a channel signer via [`SignerProvider`].
5647
#[derive(Clone, Debug, PartialEq, Eq)]
5748
pub struct ChannelDerivationParameters {

0 commit comments

Comments
 (0)