computer: snapshot

This commit is contained in:
nym21
2026-02-27 01:23:36 +01:00
parent 78fc5ffcf7
commit 72c17096ea
52 changed files with 3011 additions and 2967 deletions
@@ -1,11 +1,11 @@
use brk_error::Result;
use brk_indexer::Indexer;
use brk_types::{Bitcoin, FeeRate, Sats};
use brk_types::{FeeRate, Sats};
use vecdb::{Exit, unlikely};
use super::super::size;
use super::Vecs;
use crate::{blocks, indexes, inputs, prices, ComputeIndexes};
use crate::{ComputeIndexes, blocks, indexes, inputs};
impl Vecs {
#[allow(clippy::too_many_arguments)]
@@ -16,7 +16,6 @@ impl Vecs {
txins: &inputs::Vecs,
size_vecs: &size::Vecs,
blocks: &blocks::Vecs,
prices: &prices::Vecs,
starting_indexes: &ComputeIndexes,
exit: &Exit,
) -> Result<()> {
@@ -36,7 +35,7 @@ impl Vecs {
exit,
)?;
self.fee_txindex.compute_transform2(
self.fee.txindex.compute_transform2(
starting_indexes.txindex,
&self.input_value,
&self.output_value,
@@ -51,57 +50,34 @@ impl Vecs {
exit,
)?;
self.fee_rate_txindex.compute_transform2(
self.fee_rate.txindex.compute_transform2(
starting_indexes.txindex,
&self.fee_txindex,
&self.fee.txindex,
&size_vecs.vsize.txindex,
|(txindex, fee, vsize, ..)| (txindex, FeeRate::from((fee, vsize))),
exit,
)?;
// Skip coinbase (first tx per block) since it has no fee
let window_starts = blocks.count.window_starts();
self.fee.compute(
starting_indexes.height,
&window_starts,
exit,
|full| {
full.compute_with_skip(
starting_indexes.height,
&self.fee_txindex,
&indexer.vecs.transactions.first_txindex,
&indexes.height.txindex_count,
exit,
1,
)
},
)?;
let block_windows = blocks.count.block_window_starts();
// Skip coinbase (first tx per block) since it has no feerate
self.fee_rate.compute_with_skip(
starting_indexes.height,
&self.fee_rate_txindex,
&indexer.vecs.transactions.first_txindex,
&indexes.height.txindex_count,
// Skip coinbase (first tx per block) since it has fee=0
self.fee.derive_from_with_skip(
indexer,
indexes,
starting_indexes,
&block_windows,
exit,
1,
)?;
// Compute fee USD sum per block: price * Bitcoin::from(sats)
self.fee_usd_sum.compute_transform2(
starting_indexes.height,
self.fee.height.sum_cumulative.sum.inner(),
&prices.usd.price,
|(h, sats, price, ..)| (h, price * Bitcoin::from(sats)),
exit,
)?;
// Rolling fee rate distribution (from per-block average)
self.fee_rate_rolling.compute_distribution(
starting_indexes.height,
&window_starts,
&self.fee_rate.average.0,
// Skip coinbase (first tx per block) since it has no feerate
self.fee_rate.derive_from_with_skip(
indexer,
indexes,
starting_indexes,
&block_windows,
exit,
1,
)?;
Ok(())
@@ -3,30 +3,19 @@ use brk_types::Version;
use vecdb::{Database, EagerVec, ImportableVec};
use super::Vecs;
use crate::{
indexes,
internal::{ComputedFromHeightFull, Distribution, RollingDistribution},
};
use crate::internal::ComputedFromTxDistribution;
/// Bump this when fee/feerate aggregation logic changes (e.g., skip coinbase).
const VERSION: Version = Version::new(2);
impl Vecs {
pub(crate) fn forced_import(
db: &Database,
version: Version,
indexes: &indexes::Vecs,
) -> Result<Self> {
pub(crate) fn forced_import(db: &Database, version: Version) -> Result<Self> {
let v = version + VERSION;
Ok(Self {
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: ComputedFromHeightFull::forced_import(db, "fee", v, indexes)?,
fee_usd_sum: EagerVec::forced_import(db, "fee_usd_sum", v)?,
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)?,
fee: ComputedFromTxDistribution::forced_import(db, "fee", v)?,
fee_rate: ComputedFromTxDistribution::forced_import(db, "fee_rate", v)?,
})
}
}
@@ -1,17 +1,13 @@
use brk_traversable::Traversable;
use brk_types::{Dollars, FeeRate, Height, Sats, TxIndex};
use brk_types::{FeeRate, Sats, TxIndex};
use vecdb::{EagerVec, PcoVec, Rw, StorageMode};
use crate::internal::{ComputedFromHeightFull, Distribution, RollingDistribution};
use crate::internal::ComputedFromTxDistribution;
#[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: ComputedFromHeightFull<Sats, M>,
pub fee_usd_sum: M::Stored<EagerVec<PcoVec<Height, Dollars>>>,
pub fee_rate_txindex: M::Stored<EagerVec<PcoVec<TxIndex, FeeRate>>>,
pub fee_rate: Distribution<Height, FeeRate, M>,
pub fee_rate_rolling: RollingDistribution<FeeRate, M>,
pub fee: ComputedFromTxDistribution<Sats, M>,
pub fee_rate: ComputedFromTxDistribution<FeeRate, M>,
}