Add mempool fees histogram estimation
This commit is contained in:
parent
f56125eb11
commit
f0e6de2281
|
@ -25,6 +25,7 @@ fn main() {
|
|||
"update took {:.3} ms",
|
||||
(dt.as_secs() as f64 + 1e-9f64 * dt.subsec_nanos() as f64) * 1e3
|
||||
);
|
||||
info!("histogram: {:?}", tracker.fee_histogram());
|
||||
thread::sleep(Duration::from_secs(1));
|
||||
}
|
||||
}
|
||||
|
|
|
@ -44,6 +44,14 @@ impl MempoolEntry {
|
|||
pub fn fee_per_vbyte(&self) -> f32 {
|
||||
self.fee as f32 / self.vsize as f32
|
||||
}
|
||||
|
||||
pub fn fee(&self) -> u64 {
|
||||
self.fee
|
||||
}
|
||||
|
||||
pub fn vsize(&self) -> u32 {
|
||||
self.vsize
|
||||
}
|
||||
}
|
||||
|
||||
impl Daemon {
|
||||
|
|
|
@ -5,11 +5,10 @@ use std::collections::hash_map::Entry;
|
|||
use std::collections::{HashMap, HashSet};
|
||||
use std::iter::FromIterator;
|
||||
|
||||
use query::{FundingOutput, SpendingInput};
|
||||
use types::FullHash;
|
||||
|
||||
error_chain!{}
|
||||
|
||||
const VSIZE_BIN_WIDTH: u32 = 100_000; // in vbytes
|
||||
|
||||
pub struct Stats {
|
||||
tx: Transaction,
|
||||
entry: MempoolEntry,
|
||||
|
@ -28,6 +27,26 @@ impl<'a> Tracker<'a> {
|
|||
}
|
||||
}
|
||||
|
||||
/// Returns vector of (fee_rate, vsize) pairs, where fee_{n-1} > fee_n and vsize_n is the
|
||||
/// cumulative virtual size of mempool transaction with fee in the interval [fee_{n-1}, fee_n].
|
||||
/// Note: fee_0 is implied to be infinity.
|
||||
pub fn fee_histogram(&self) -> Vec<(f32, u32)> {
|
||||
let mut entries: Vec<&MempoolEntry> = self.txids.values().map(|stat| &stat.entry).collect();
|
||||
entries.sort_unstable_by(|e1, e2| {
|
||||
e2.fee_per_vbyte().partial_cmp(&e1.fee_per_vbyte()).unwrap()
|
||||
});
|
||||
let mut histogram = Vec::new();
|
||||
let mut cumulative_vsize = 0;
|
||||
for e in entries {
|
||||
cumulative_vsize += e.vsize();
|
||||
if cumulative_vsize > VSIZE_BIN_WIDTH {
|
||||
histogram.push((e.fee_per_vbyte(), cumulative_vsize));
|
||||
cumulative_vsize = 0;
|
||||
}
|
||||
}
|
||||
histogram
|
||||
}
|
||||
|
||||
pub fn update_from_daemon(&mut self) -> Result<()> {
|
||||
let new_txids = HashSet::<Sha256dHash>::from_iter(self.daemon
|
||||
.getmempooltxids()
|
||||
|
|
Loading…
Reference in New Issue
Block a user