mirror of
https://github.com/bitcoinresearchkit/brk.git
synced 2026-07-17 05:58:11 -07:00
computer: snapshot
This commit is contained in:
@@ -60,13 +60,21 @@ impl Vecs {
|
||||
)?;
|
||||
|
||||
// Skip coinbase (first tx per block) since it has no fee
|
||||
self.fee.compute_with_skip(
|
||||
let window_starts = blocks.count.window_starts();
|
||||
self.fee.compute(
|
||||
starting_indexes.height,
|
||||
&self.fee_txindex,
|
||||
&indexer.vecs.transactions.first_txindex,
|
||||
&indexes.height.txindex_count,
|
||||
&window_starts,
|
||||
exit,
|
||||
1,
|
||||
|full| {
|
||||
full.compute_with_skip(
|
||||
starting_indexes.height,
|
||||
&self.fee_txindex,
|
||||
&indexer.vecs.transactions.first_txindex,
|
||||
&indexes.height.txindex_count,
|
||||
exit,
|
||||
1,
|
||||
)
|
||||
},
|
||||
)?;
|
||||
|
||||
// Skip coinbase (first tx per block) since it has no feerate
|
||||
@@ -82,21 +90,12 @@ impl Vecs {
|
||||
// Compute fee USD sum per block: price * Bitcoin::from(sats)
|
||||
self.fee_usd_sum.compute_transform2(
|
||||
starting_indexes.height,
|
||||
self.fee.sum_cumulative.sum.inner(),
|
||||
self.fee.height.sum_cumulative.sum.inner(),
|
||||
&prices.usd.price,
|
||||
|(h, sats, price, ..)| (h, price * Bitcoin::from(sats)),
|
||||
exit,
|
||||
)?;
|
||||
|
||||
// Rolling fee stats (from per-block sum)
|
||||
let window_starts = blocks.count.window_starts();
|
||||
self.fee_rolling.compute(
|
||||
starting_indexes.height,
|
||||
&window_starts,
|
||||
self.fee.sum_cumulative.sum.inner(),
|
||||
exit,
|
||||
)?;
|
||||
|
||||
// Rolling fee rate distribution (from per-block average)
|
||||
self.fee_rate_rolling.compute_distribution(
|
||||
starting_indexes.height,
|
||||
|
||||
@@ -5,7 +5,7 @@ use vecdb::{Database, EagerVec, ImportableVec};
|
||||
use super::Vecs;
|
||||
use crate::{
|
||||
indexes,
|
||||
internal::{Distribution, Full, RollingDistribution, RollingFull},
|
||||
internal::{ComputedFromHeightFull, Distribution, RollingDistribution},
|
||||
};
|
||||
|
||||
/// Bump this when fee/feerate aggregation logic changes (e.g., skip coinbase).
|
||||
@@ -22,9 +22,8 @@ impl Vecs {
|
||||
input_value: EagerVec::forced_import(db, "input_value", version)?,
|
||||
output_value: EagerVec::forced_import(db, "output_value", version)?,
|
||||
fee_txindex: EagerVec::forced_import(db, "fee", v)?,
|
||||
fee: Full::forced_import(db, "fee", v)?,
|
||||
fee: ComputedFromHeightFull::forced_import(db, "fee", v, indexes)?,
|
||||
fee_usd_sum: EagerVec::forced_import(db, "fee_usd_sum", v)?,
|
||||
fee_rolling: RollingFull::forced_import(db, "fee", v, indexes)?,
|
||||
fee_rate_txindex: EagerVec::forced_import(db, "fee_rate", v)?,
|
||||
fee_rate: Distribution::forced_import(db, "fee_rate", v)?,
|
||||
fee_rate_rolling: RollingDistribution::forced_import(db, "fee_rate", v, indexes)?,
|
||||
|
||||
@@ -2,16 +2,15 @@ use brk_traversable::Traversable;
|
||||
use brk_types::{Dollars, FeeRate, Height, Sats, TxIndex};
|
||||
use vecdb::{EagerVec, PcoVec, Rw, StorageMode};
|
||||
|
||||
use crate::internal::{Distribution, Full, RollingDistribution, RollingFull};
|
||||
use crate::internal::{ComputedFromHeightFull, Distribution, RollingDistribution};
|
||||
|
||||
#[derive(Traversable)]
|
||||
pub struct Vecs<M: StorageMode = Rw> {
|
||||
pub input_value: M::Stored<EagerVec<PcoVec<TxIndex, Sats>>>,
|
||||
pub output_value: M::Stored<EagerVec<PcoVec<TxIndex, Sats>>>,
|
||||
pub fee_txindex: M::Stored<EagerVec<PcoVec<TxIndex, Sats>>>,
|
||||
pub fee: Full<Height, Sats, M>,
|
||||
pub fee: ComputedFromHeightFull<Sats, M>,
|
||||
pub fee_usd_sum: M::Stored<EagerVec<PcoVec<Height, Dollars>>>,
|
||||
pub fee_rolling: RollingFull<Sats, M>,
|
||||
pub fee_rate_txindex: M::Stored<EagerVec<PcoVec<TxIndex, FeeRate>>>,
|
||||
pub fee_rate: Distribution<Height, FeeRate, M>,
|
||||
pub fee_rate_rolling: RollingDistribution<FeeRate, M>,
|
||||
|
||||
Reference in New Issue
Block a user