Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 6 additions & 15 deletions src/mempool.rs
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ impl Mempool {
entries: Default::default(),
by_funding: Default::default(),
by_spending: Default::default(),
fees: FeeHistogram::empty(),
fees: FeeHistogram::default(),
vsize: metrics.gauge(
"mempool_txs_vsize",
"Total vsize of mempool transactions (in bytes)",
Expand Down Expand Up @@ -236,10 +236,6 @@ impl Default for FeeHistogram {
impl FeeHistogram {
const BINS: usize = 65; // 0..=64

fn empty() -> Self {
Self::new(std::iter::empty())
}

fn bin_index(fee: Amount, vsize: u64) -> usize {
let fee_rate = fee.to_sat() / vsize;
usize::try_from(fee_rate.leading_zeros()).unwrap()
Expand All @@ -250,15 +246,6 @@ impl FeeHistogram {
(limit / 2, limit)
}

fn new(items: impl Iterator<Item = (Amount, u64)>) -> Self {
let mut histogram = FeeHistogram::default();
for (fee, vsize) in items {
let bin_index = FeeHistogram::bin_index(fee, vsize);
histogram.insert(bin_index, vsize);
}
histogram
}

fn insert(&mut self, bin_index: usize, vsize: u64) {
// skip transactions with too low fee rate (<1 sat/vB)
if let Some(bin) = self.vsize.get_mut(bin_index) {
Expand Down Expand Up @@ -322,7 +309,11 @@ mod tests {
(Amount::from_sat(80), 10),
(Amount::from_sat(1), 100),
];
let mut hist = FeeHistogram::new(items.into_iter());
let mut hist = FeeHistogram::default();
for (amount, vsize) in items {
let bin_index = FeeHistogram::bin_index(amount, vsize);
hist.insert(bin_index, vsize);
}
assert_eq!(
json!(hist),
json!([[15, 10], [7, 40], [3, 20], [1, 10], [0, 100]])
Expand Down