global: snapshot

This commit is contained in:
nym21
2026-03-10 11:53:46 +01:00
parent 5ede3dc416
commit 8f93a5947e
16 changed files with 2123 additions and 2015 deletions

View File

@@ -1,10 +1,10 @@
use brk_error::Result;
use brk_indexer::Indexer;
use brk_types::{BasisPoints16, CheckedSub, Halving, Indexes, Sats};
use brk_types::{BasisPoints16, CheckedSub, Dollars, Halving, Indexes, Sats};
use vecdb::{Exit, ReadableVec, VecIndex};
use super::Vecs;
use crate::{blocks, indexes, internal::RatioSatsBp16, prices, transactions};
use crate::{blocks, indexes, internal::{RatioDollarsBp32, RatioSatsBp16}, prices, transactions};
impl Vecs {
#[allow(clippy::too_many_arguments)]
@@ -122,20 +122,13 @@ impl Vecs {
)?;
// Rolling fee dominance = sum(fees) / sum(coinbase)
for ((fee_dom, fees_w), coinbase_w) in self
.fee_dominance_rolling
.as_mut_array()
.into_iter()
.zip(self.fees.rolling.as_array())
.zip(self.coinbase.sum.as_array())
{
fee_dom.compute_binary::<Sats, Sats, RatioSatsBp16>(
self.fee_dominance_rolling
.compute_binary::<Sats, Sats, RatioSatsBp16, _, _>(
starting_indexes.height,
&fees_w.sum.sats.height,
&coinbase_w.sats.height,
self.fees.rolling.as_array().map(|w| &w.sum.sats.height),
self.coinbase.sum.as_array().map(|w| &w.sats.height),
exit,
)?;
}
// All-time cumulative subsidy dominance
self.subsidy_dominance
@@ -168,6 +161,15 @@ impl Vecs {
exit,
)?;
// Fee Ratio Multiple: sum(coinbase) / sum(fees) per rolling window
self.fee_ratio_multiple
.compute_binary::<Dollars, Dollars, RatioDollarsBp32, _, _>(
starting_indexes.height,
self.coinbase.sum.as_array().map(|w| &w.usd.height),
self.fees.rolling.as_array().map(|w| &w.sum.usd.height),
exit,
)?;
Ok(())
}
}

View File

@@ -7,7 +7,7 @@ use crate::{
indexes,
internal::{
AmountPerBlockCumulative, AmountPerBlockCumulativeSum, AmountPerBlockFull,
FiatPerBlock, PercentPerBlock, PercentRollingWindows,
FiatPerBlock, PercentPerBlock, PercentRollingWindows, RatioRollingWindows,
},
};
@@ -49,6 +49,12 @@ impl Vecs {
indexes,
)?,
subsidy_sma_1y: FiatPerBlock::forced_import(db, "subsidy_sma_1y", version, indexes)?,
fee_ratio_multiple: RatioRollingWindows::forced_import(
db,
"fee_ratio_multiple",
version,
indexes,
)?,
})
}
}

View File

@@ -1,10 +1,10 @@
use brk_traversable::Traversable;
use brk_types::{BasisPoints16, Cents};
use brk_types::{BasisPoints16, BasisPoints32, Cents};
use vecdb::{Rw, StorageMode};
use crate::internal::{
AmountPerBlockCumulative, AmountPerBlockCumulativeSum, AmountPerBlockFull,
FiatPerBlock, PercentPerBlock, PercentRollingWindows,
FiatPerBlock, PercentPerBlock, PercentRollingWindows, RatioRollingWindows,
};
#[derive(Traversable)]
@@ -20,4 +20,5 @@ pub struct Vecs<M: StorageMode = Rw> {
#[traversable(rename = "subsidy_dominance")]
pub subsidy_dominance_rolling: PercentRollingWindows<BasisPoints16, M>,
pub subsidy_sma_1y: FiatPerBlock<Cents, M>,
pub fee_ratio_multiple: RatioRollingWindows<BasisPoints32, M>,
}