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

View File

@@ -31,14 +31,13 @@ impl Vecs {
self.size
.compute(indexer, indexes, &blocks.count, starting_indexes, exit)?;
// Fees depends on size, blocks (window starts), prices (USD conversion)
// Fees depends on size, blocks (window starts)
self.fees.compute(
indexer,
indexes,
inputs,
&self.size,
blocks,
prices,
starting_indexes,
exit,
)?;

View File

@@ -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(())

View File

@@ -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)?,
})
}
}

View File

@@ -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>,
}

View File

@@ -24,7 +24,7 @@ impl Vecs {
let count = CountVecs::forced_import(&db, version, indexer, indexes)?;
let size = SizeVecs::forced_import(&db, version, indexer)?;
let fees = FeesVecs::forced_import(&db, version, indexes)?;
let fees = FeesVecs::forced_import(&db, version)?;
let versions = VersionsVecs::forced_import(&db, version, indexes)?;
let volume = VolumeVecs::forced_import(&db, version, indexes)?;

View File

@@ -4,8 +4,8 @@ use brk_types::StoredF32;
use vecdb::Exit;
use super::Vecs;
use crate::{blocks, ComputeIndexes, indexes, inputs, outputs, prices};
use crate::transactions::{count, fees};
use crate::{ComputeIndexes, blocks, indexes, inputs, outputs, prices};
impl Vecs {
#[allow(clippy::too_many_arguments)]
@@ -87,7 +87,7 @@ impl Vecs {
// inputs_per_sec: per-block input count / block interval
self.inputs_per_sec.height.compute_transform2(
starting_indexes.height,
&inputs_count.height.sum_cumulative.sum.0,
&inputs_count.full.sum_cumulative.sum.0,
&blocks.interval.height,
|(h, input_count, interval, ..)| {
let interval_f64 = f64::from(*interval);
@@ -104,7 +104,7 @@ impl Vecs {
// outputs_per_sec: per-block output count / block interval
self.outputs_per_sec.height.compute_transform2(
starting_indexes.height,
&outputs_count.total_count.height.sum_cumulative.sum.0,
&outputs_count.total_count.full.sum_cumulative.sum.0,
&blocks.interval.height,
|(h, output_count, interval, ..)| {
let interval_f64 = f64::from(*interval);

View File

@@ -9,11 +9,8 @@ use crate::internal::{
/// Volume metrics
#[derive(Traversable)]
pub struct Vecs<M: StorageMode = Rw> {
#[traversable(flatten)]
pub sent_sum: ValueFromHeightLastRolling<M>,
#[traversable(flatten)]
pub received_sum: ValueFromHeightLastRolling<M>,
#[traversable(flatten)]
pub annualized_volume: ValueFromHeightLast<M>,
pub tx_per_sec: ComputedFromHeightLast<StoredF32, M>,
pub outputs_per_sec: ComputedFromHeightLast<StoredF32, M>,