global: snapshot part 4

This commit is contained in:
nym21
2026-03-20 14:27:10 +01:00
parent 1d671ea41f
commit 8f93ff9f68
47 changed files with 683 additions and 637 deletions

View File

@@ -6,7 +6,7 @@ use vecdb::{Database, Exit, Rw, StorageMode};
use crate::{
indexes,
internal::{CachedWindowStarts, PerBlockCumulativeWithSums},
internal::{CachedWindowStarts, PerBlockCumulativeRolling},
};
use super::TotalAddrCountVecs;
@@ -14,9 +14,9 @@ use super::TotalAddrCountVecs;
/// New address count per block (global + per-type)
#[derive(Traversable)]
pub struct NewAddrCountVecs<M: StorageMode = Rw> {
pub all: PerBlockCumulativeWithSums<StoredU64, StoredU64, M>,
pub all: PerBlockCumulativeRolling<StoredU64, StoredU64, M>,
#[traversable(flatten)]
pub by_addr_type: ByAddrType<PerBlockCumulativeWithSums<StoredU64, StoredU64, M>>,
pub by_addr_type: ByAddrType<PerBlockCumulativeRolling<StoredU64, StoredU64, M>>,
}
impl NewAddrCountVecs {
@@ -26,7 +26,7 @@ impl NewAddrCountVecs {
indexes: &indexes::Vecs,
cached_starts: &CachedWindowStarts,
) -> Result<Self> {
let all = PerBlockCumulativeWithSums::forced_import(
let all = PerBlockCumulativeRolling::forced_import(
db,
"new_addr_count",
version,
@@ -35,7 +35,7 @@ impl NewAddrCountVecs {
)?;
let by_addr_type = ByAddrType::new_with_name(|name| {
PerBlockCumulativeWithSums::forced_import(
PerBlockCumulativeRolling::forced_import(
db,
&format!("{name}_new_addr_count"),
version,

View File

@@ -25,7 +25,7 @@ use crate::{
state::UTXOCohortState,
},
indexes,
internal::{AmountPerBlockCumulativeWithSums, CachedWindowStarts},
internal::{AmountPerBlockCumulativeRolling, CachedWindowStarts},
prices,
};
@@ -50,7 +50,7 @@ pub struct UTXOCohorts<M: StorageMode = Rw> {
#[traversable(rename = "type")]
pub type_: SpendableType<UTXOCohortVecs<TypeCohortMetrics<M>>>,
pub profitability: ProfitabilityMetrics<M>,
pub matured: AgeRange<AmountPerBlockCumulativeWithSums<M>>,
pub matured: AgeRange<AmountPerBlockCumulativeRolling<M>>,
#[traversable(skip)]
pub(super) fenwick: CostBasisFenwick,
/// Cached partition_point positions for tick_tock boundary searches.
@@ -259,8 +259,8 @@ impl UTXOCohorts<Rw> {
let prefix = CohortContext::Utxo.prefix();
let matured = AgeRange::try_new(&|_f: Filter,
name: &'static str|
-> Result<AmountPerBlockCumulativeWithSums> {
AmountPerBlockCumulativeWithSums::forced_import(
-> Result<AmountPerBlockCumulativeRolling> {
AmountPerBlockCumulativeRolling::forced_import(
db,
&format!("{prefix}_{name}_matured_supply"),
v,
@@ -713,10 +713,11 @@ impl UTXOCohorts<Rw> {
}
vecs.extend(self.profitability.collect_all_vecs_mut());
for v in self.matured.iter_mut() {
vecs.push(&mut v.base.sats.height);
vecs.push(&mut v.base.cents.height);
vecs.push(&mut v.cumulative.sats.height);
vecs.push(&mut v.cumulative.cents.height);
let inner = &mut v.inner;
vecs.push(&mut inner.base.sats.height);
vecs.push(&mut inner.base.cents.height);
vecs.push(&mut inner.cumulative.sats.height);
vecs.push(&mut inner.cumulative.cents.height);
}
vecs.into_par_iter()
}

View File

@@ -6,7 +6,7 @@ use vecdb::{AnyStoredVec, AnyVec, Exit, Rw, StorageMode, WritableVec};
use crate::{
distribution::{metrics::ImportConfig, state::{CohortState, CostBasisOps, RealizedOps}},
internal::{AmountPerBlockCumulativeWithSums, PerBlockCumulativeWithSums},
internal::{AmountPerBlockCumulativeRolling, PerBlockCumulativeRolling},
prices,
};
@@ -19,11 +19,11 @@ pub struct ActivityCore<M: StorageMode = Rw> {
#[traversable(flatten)]
pub minimal: ActivityMinimal<M>,
pub coindays_destroyed: PerBlockCumulativeWithSums<StoredF64, StoredF64, M>,
pub coindays_destroyed: PerBlockCumulativeRolling<StoredF64, StoredF64, M>,
#[traversable(wrap = "transfer_volume", rename = "in_profit")]
pub transfer_volume_in_profit: AmountPerBlockCumulativeWithSums<M>,
pub transfer_volume_in_profit: AmountPerBlockCumulativeRolling<M>,
#[traversable(wrap = "transfer_volume", rename = "in_loss")]
pub transfer_volume_in_loss: AmountPerBlockCumulativeWithSums<M>,
pub transfer_volume_in_loss: AmountPerBlockCumulativeRolling<M>,
}
impl ActivityCore {
@@ -69,10 +69,10 @@ impl ActivityCore {
pub(crate) fn collect_vecs_mut(&mut self) -> Vec<&mut dyn AnyStoredVec> {
let mut vecs = self.minimal.collect_vecs_mut();
vecs.push(&mut self.coindays_destroyed.base.height);
vecs.push(&mut self.transfer_volume_in_profit.base.sats.height);
vecs.push(&mut self.transfer_volume_in_profit.base.cents.height);
vecs.push(&mut self.transfer_volume_in_loss.base.sats.height);
vecs.push(&mut self.transfer_volume_in_loss.base.cents.height);
vecs.push(&mut self.transfer_volume_in_profit.inner.base.sats.height);
vecs.push(&mut self.transfer_volume_in_profit.inner.base.cents.height);
vecs.push(&mut self.transfer_volume_in_loss.inner.base.sats.height);
vecs.push(&mut self.transfer_volume_in_loss.inner.base.cents.height);
vecs
}

View File

@@ -5,13 +5,13 @@ use vecdb::{AnyStoredVec, AnyVec, Exit, Rw, StorageMode, WritableVec};
use crate::{
distribution::{metrics::ImportConfig, state::{CohortState, CostBasisOps, RealizedOps}},
internal::AmountPerBlockCumulativeWithSums,
internal::AmountPerBlockCumulativeRolling,
prices,
};
#[derive(Traversable)]
pub struct ActivityMinimal<M: StorageMode = Rw> {
pub transfer_volume: AmountPerBlockCumulativeWithSums<M>,
pub transfer_volume: AmountPerBlockCumulativeRolling<M>,
}
impl ActivityMinimal {
@@ -39,9 +39,10 @@ impl ActivityMinimal {
}
pub(crate) fn collect_vecs_mut(&mut self) -> Vec<&mut dyn AnyStoredVec> {
let inner = &mut self.transfer_volume.inner;
vec![
&mut self.transfer_volume.base.sats.height as &mut dyn AnyStoredVec,
&mut self.transfer_volume.base.cents.height,
&mut inner.base.sats.height as &mut dyn AnyStoredVec,
&mut inner.base.cents.height,
]
}

View File

@@ -7,9 +7,9 @@ use vecdb::{BytesVec, BytesVecValue, Database, ImportableVec};
use crate::{
indexes,
internal::{
AmountPerBlock, AmountPerBlockCumulative, AmountPerBlockCumulativeWithSums,
AmountPerBlock, AmountPerBlockCumulative, AmountPerBlockCumulativeRolling,
CachedWindowStarts, CentsType, FiatPerBlock, FiatPerBlockCumulativeWithSums, NumericValue,
PerBlock, PerBlockCumulativeWithSums, PercentPerBlock, PercentRollingWindows, Price,
PerBlock, PerBlockCumulativeRolling, PercentPerBlock, PercentRollingWindows, Price,
PriceWithRatioExtendedPerBlock, PriceWithRatioPerBlock, RatioPerBlock,
RollingWindow24hPerBlock, RollingWindows, RollingWindowsFrom1w,
},
@@ -54,7 +54,7 @@ impl<T: NumericValue + JsonSchema> ConfigImport for PerBlock<T> {
Self::forced_import(cfg.db, &cfg.name(suffix), cfg.version + offset, cfg.indexes)
}
}
impl<T, C> ConfigImport for PerBlockCumulativeWithSums<T, C>
impl<T, C> ConfigImport for PerBlockCumulativeRolling<T, C>
where
T: NumericValue + JsonSchema + Into<C>,
C: NumericValue + JsonSchema,
@@ -79,7 +79,7 @@ impl<T: NumericValue + JsonSchema> ConfigImport for RollingWindow24hPerBlock<T>
Self::forced_import(cfg.db, &cfg.name(suffix), cfg.version + offset, cfg.indexes)
}
}
impl ConfigImport for AmountPerBlockCumulativeWithSums {
impl ConfigImport for AmountPerBlockCumulativeRolling {
fn config_import(cfg: &ImportConfig, suffix: &str, offset: Version) -> Result<Self> {
Self::forced_import(
cfg.db,

View File

@@ -24,8 +24,8 @@ pub struct CostBasis<M: StorageMode = Rw> {
pub in_loss: CostBasisSide<M>,
pub min: Price<PerBlock<Cents, M>>,
pub max: Price<PerBlock<Cents, M>>,
pub percentiles: PercentilesVecs<M>,
pub invested_capital: PercentilesVecs<M>,
pub per_coin: PercentilesVecs<M>,
pub per_dollar: PercentilesVecs<M>,
pub supply_density: PercentPerBlock<BasisPoints16, M>,
}
@@ -42,15 +42,15 @@ impl CostBasis {
},
min: cfg.import("cost_basis_min", Version::ZERO)?,
max: cfg.import("cost_basis_max", Version::ZERO)?,
percentiles: PercentilesVecs::forced_import(
per_coin: PercentilesVecs::forced_import(
cfg.db,
&cfg.name("cost_basis"),
&cfg.name("cost_basis_per_coin"),
cfg.version,
cfg.indexes,
)?,
invested_capital: PercentilesVecs::forced_import(
per_dollar: PercentilesVecs::forced_import(
cfg.db,
&cfg.name("invested_capital"),
&cfg.name("cost_basis_per_dollar"),
cfg.version,
cfg.indexes,
)?,
@@ -84,8 +84,8 @@ impl CostBasis {
sat_prices: &[Cents; PERCENTILES_LEN],
usd_prices: &[Cents; PERCENTILES_LEN],
) {
self.percentiles.push(sat_prices);
self.invested_capital.push(usd_prices);
self.per_coin.push(sat_prices);
self.per_dollar.push(usd_prices);
}
#[inline(always)]
@@ -94,9 +94,9 @@ impl CostBasis {
}
pub(crate) fn validate_computed_versions(&mut self, base_version: Version) -> Result<()> {
self.percentiles
self.per_coin
.validate_computed_version_or_reset(base_version)?;
self.invested_capital
self.per_dollar
.validate_computed_version_or_reset(base_version)?;
Ok(())
}
@@ -112,13 +112,13 @@ impl CostBasis {
&mut self.supply_density.bps.height,
];
vecs.extend(
self.percentiles
self.per_coin
.vecs
.iter_mut()
.map(|v| &mut v.cents.height as &mut dyn AnyStoredVec),
);
vecs.extend(
self.invested_capital
self.per_dollar
.vecs
.iter_mut()
.map(|v| &mut v.cents.height as &mut dyn AnyStoredVec),

View File

@@ -5,14 +5,14 @@ use vecdb::{Exit, ReadableVec, Rw, StorageMode};
use crate::{
distribution::metrics::ImportConfig,
internal::{PerBlockCumulativeWithSums, RatioCents64, RollingWindows},
internal::{PerBlockCumulativeRolling, RatioCents64, RollingWindows},
};
#[derive(Traversable)]
pub struct AdjustedSopr<M: StorageMode = Rw> {
pub ratio: RollingWindows<StoredF64, M>,
pub transfer_volume: PerBlockCumulativeWithSums<Cents, Cents, M>,
pub value_destroyed: PerBlockCumulativeWithSums<Cents, Cents, M>,
pub transfer_volume: PerBlockCumulativeRolling<Cents, Cents, M>,
pub value_destroyed: PerBlockCumulativeRolling<Cents, Cents, M>,
}
impl AdjustedSopr {

View File

@@ -10,7 +10,7 @@ use crate::{
distribution::state::{CohortState, CostBasisOps, RealizedOps},
internal::{
FiatPerBlockCumulativeWithSumsAndDeltas, LazyPerBlock, NegCentsUnsignedToDollars,
PerBlockCumulativeWithSums, RatioCents64, RollingWindow24hPerBlock, Windows,
PerBlockCumulativeRolling, RatioCents64, RollingWindow24hPerBlock, Windows,
},
prices,
};
@@ -28,7 +28,7 @@ pub struct NegRealizedLoss {
#[derive(Traversable)]
pub struct RealizedSoprCore<M: StorageMode = Rw> {
pub value_destroyed: PerBlockCumulativeWithSums<Cents, Cents, M>,
pub value_destroyed: PerBlockCumulativeRolling<Cents, Cents, M>,
pub ratio: RollingWindow24hPerBlock<StoredF64, M>,
}
@@ -81,7 +81,7 @@ impl RealizedCore {
cfg.cached_starts,
)?;
let value_destroyed = PerBlockCumulativeWithSums::forced_import(
let value_destroyed = PerBlockCumulativeRolling::forced_import(
cfg.db,
&cfg.name("value_destroyed"),
cfg.version + v1,

View File

@@ -11,7 +11,7 @@ use crate::{
blocks,
distribution::state::{CohortState, CostBasisData, RealizedState, WithCapital},
internal::{
AmountPerBlockCumulativeWithSums, FiatPerBlockCumulativeWithSums, PercentPerBlock,
AmountPerBlockCumulativeRolling, FiatPerBlockCumulativeWithSums, PercentPerBlock,
PercentRollingWindows, PriceWithRatioExtendedPerBlock, RatioCents64, RatioCentsBp32,
RatioCentsSignedCentsBps32, RatioCentsSignedDollarsBps32, RatioDollarsBp32,
RatioPerBlockPercentiles, RatioPerBlockStdDevBands, RatioSma, RollingWindows,
@@ -274,7 +274,7 @@ impl RealizedFull {
starting_indexes: &Indexes,
height_to_supply: &impl ReadableVec<Height, Bitcoin>,
height_to_market_cap: &impl ReadableVec<Height, Dollars>,
activity_transfer_volume: &AmountPerBlockCumulativeWithSums,
activity_transfer_volume: &AmountPerBlockCumulativeRolling,
exit: &Exit,
) -> Result<()> {
self.core.compute_rest_part2(

View File

@@ -23,7 +23,7 @@ use crate::{
state::BlockState,
},
indexes, inputs,
internal::{CachedWindowStarts, PerBlockCumulativeWithSums, db_utils::{finalize_db, open_db}},
internal::{CachedWindowStarts, PerBlockCumulativeRolling, db_utils::{finalize_db, open_db}},
outputs, prices, transactions,
};
@@ -70,7 +70,7 @@ pub struct Vecs<M: StorageMode = Rw> {
#[traversable(wrap = "cohorts", rename = "addr")]
pub addr_cohorts: AddrCohorts<M>,
#[traversable(wrap = "cointime/activity")]
pub coinblocks_destroyed: PerBlockCumulativeWithSums<StoredF64, StoredF64, M>,
pub coinblocks_destroyed: PerBlockCumulativeRolling<StoredF64, StoredF64, M>,
pub addrs: AddrMetricsVecs<M>,
/// In-memory block state for UTXO processing. Persisted via supply_state.
@@ -173,7 +173,7 @@ impl Vecs {
utxo_cohorts,
addr_cohorts,
coinblocks_destroyed: PerBlockCumulativeWithSums::forced_import(
coinblocks_destroyed: PerBlockCumulativeRolling::forced_import(
&db,
"coinblocks_destroyed",
version + Version::TWO,