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

@@ -7,7 +7,7 @@ use crate::{
indexes,
internal::{
BlockCountTarget24h, BlockCountTarget1w, BlockCountTarget1m, BlockCountTarget1y,
CachedWindowStarts, PerBlockCumulativeWithSums, ConstantVecs, Windows,
CachedWindowStarts, PerBlockCumulativeRolling, ConstantVecs, Windows,
},
};
@@ -25,7 +25,7 @@ impl Vecs {
_1m: ConstantVecs::new::<BlockCountTarget1m>("block_count_target_1m", version, indexes),
_1y: ConstantVecs::new::<BlockCountTarget1y>("block_count_target_1y", version, indexes),
},
total: PerBlockCumulativeWithSums::forced_import(
total: PerBlockCumulativeRolling::forced_import(
db,
"block_count",
version + Version::ONE,

View File

@@ -2,10 +2,10 @@ use brk_traversable::Traversable;
use brk_types::{StoredU32, StoredU64};
use vecdb::{Rw, StorageMode};
use crate::internal::{PerBlockCumulativeWithSums, ConstantVecs, Windows};
use crate::internal::{PerBlockCumulativeRolling, ConstantVecs, Windows};
#[derive(Traversable)]
pub struct Vecs<M: StorageMode = Rw> {
pub target: Windows<ConstantVecs<StoredU64>>,
pub total: PerBlockCumulativeWithSums<StoredU32, StoredU64, M>,
pub total: PerBlockCumulativeRolling<StoredU32, StoredU64, M>,
}

View File

@@ -6,7 +6,7 @@ use super::Vecs;
use crate::{
indexes,
internal::{
CachedWindowStarts, LazyPerBlock, OneMinusF64, PerBlock, PerBlockCumulativeWithSums,
CachedWindowStarts, LazyPerBlock, OneMinusF64, PerBlock, PerBlockCumulativeRolling,
},
};
@@ -27,10 +27,10 @@ impl Vecs {
);
Ok(Self {
coinblocks_created: PerBlockCumulativeWithSums::forced_import(
coinblocks_created: PerBlockCumulativeRolling::forced_import(
db, "coinblocks_created", version, indexes, cached_starts,
)?,
coinblocks_stored: PerBlockCumulativeWithSums::forced_import(
coinblocks_stored: PerBlockCumulativeRolling::forced_import(
db, "coinblocks_stored", version, indexes, cached_starts,
)?,
liveliness,

View File

@@ -2,12 +2,12 @@ use brk_traversable::Traversable;
use brk_types::StoredF64;
use vecdb::{Rw, StorageMode};
use crate::internal::{LazyPerBlock, PerBlock, PerBlockCumulativeWithSums};
use crate::internal::{LazyPerBlock, PerBlock, PerBlockCumulativeRolling};
#[derive(Traversable)]
pub struct Vecs<M: StorageMode = Rw> {
pub coinblocks_created: PerBlockCumulativeWithSums<StoredF64, StoredF64, M>,
pub coinblocks_stored: PerBlockCumulativeWithSums<StoredF64, StoredF64, M>,
pub coinblocks_created: PerBlockCumulativeRolling<StoredF64, StoredF64, M>,
pub coinblocks_stored: PerBlockCumulativeRolling<StoredF64, StoredF64, M>,
pub liveliness: PerBlock<StoredF64, M>,
pub vaultedness: LazyPerBlock<StoredF64>,
pub ratio: PerBlock<StoredF64, M>,

View File

@@ -5,7 +5,7 @@ use vecdb::Database;
use super::Vecs;
use crate::{
indexes,
internal::{CachedWindowStarts, PerBlockCumulativeWithSums},
internal::{CachedWindowStarts, PerBlockCumulativeRolling},
};
impl Vecs {
@@ -16,28 +16,28 @@ impl Vecs {
cached_starts: &CachedWindowStarts,
) -> Result<Self> {
Ok(Self {
destroyed: PerBlockCumulativeWithSums::forced_import(
destroyed: PerBlockCumulativeRolling::forced_import(
db,
"cointime_value_destroyed",
version,
indexes,
cached_starts,
)?,
created: PerBlockCumulativeWithSums::forced_import(
created: PerBlockCumulativeRolling::forced_import(
db,
"cointime_value_created",
version,
indexes,
cached_starts,
)?,
stored: PerBlockCumulativeWithSums::forced_import(
stored: PerBlockCumulativeRolling::forced_import(
db,
"cointime_value_stored",
version,
indexes,
cached_starts,
)?,
vocdd: PerBlockCumulativeWithSums::forced_import(
vocdd: PerBlockCumulativeRolling::forced_import(
db,
"vocdd",
version + Version::ONE,

View File

@@ -2,12 +2,12 @@ use brk_traversable::Traversable;
use brk_types::StoredF64;
use vecdb::{Rw, StorageMode};
use crate::internal::PerBlockCumulativeWithSums;
use crate::internal::PerBlockCumulativeRolling;
#[derive(Traversable)]
pub struct Vecs<M: StorageMode = Rw> {
pub destroyed: PerBlockCumulativeWithSums<StoredF64, StoredF64, M>,
pub created: PerBlockCumulativeWithSums<StoredF64, StoredF64, M>,
pub stored: PerBlockCumulativeWithSums<StoredF64, StoredF64, M>,
pub vocdd: PerBlockCumulativeWithSums<StoredF64, StoredF64, M>,
pub destroyed: PerBlockCumulativeRolling<StoredF64, StoredF64, M>,
pub created: PerBlockCumulativeRolling<StoredF64, StoredF64, M>,
pub stored: PerBlockCumulativeRolling<StoredF64, StoredF64, M>,
pub vocdd: PerBlockCumulativeRolling<StoredF64, StoredF64, M>,
}

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,

View File

@@ -1,28 +1,31 @@
use brk_error::Result;
use brk_traversable::Traversable;
use brk_types::{Cents, Height, Sats, Version};
use brk_types::{Height, Sats, Version};
use derive_more::{Deref, DerefMut};
use vecdb::{Database, EagerVec, Exit, PcoVec, Rw, StorageMode};
use crate::{
indexes,
internal::{
AmountPerBlock, CachedWindowStarts, LazyRollingAvgsAmountFromHeight,
LazyRollingSumsAmountFromHeight, SatsToCents,
AmountPerBlockCumulative, CachedWindowStarts, LazyRollingAvgsAmountFromHeight,
LazyRollingSumsAmountFromHeight,
},
prices,
};
#[derive(Traversable)]
pub struct AmountPerBlockCumulativeWithSums<M: StorageMode = Rw> {
pub base: AmountPerBlock<M>,
pub cumulative: AmountPerBlock<M>,
#[derive(Deref, DerefMut, Traversable)]
pub struct AmountPerBlockCumulativeRolling<M: StorageMode = Rw> {
#[deref]
#[deref_mut]
#[traversable(flatten)]
pub inner: AmountPerBlockCumulative<M>,
pub sum: LazyRollingSumsAmountFromHeight,
pub average: LazyRollingAvgsAmountFromHeight,
}
const VERSION: Version = Version::TWO;
impl AmountPerBlockCumulativeWithSums {
impl AmountPerBlockCumulativeRolling {
pub(crate) fn forced_import(
db: &Database,
name: &str,
@@ -32,29 +35,26 @@ impl AmountPerBlockCumulativeWithSums {
) -> Result<Self> {
let v = version + VERSION;
let base = AmountPerBlock::forced_import(db, name, v, indexes)?;
let cumulative =
AmountPerBlock::forced_import(db, &format!("{name}_cumulative"), v, indexes)?;
let inner = AmountPerBlockCumulative::forced_import(db, name, v, indexes)?;
let sum = LazyRollingSumsAmountFromHeight::new(
&format!("{name}_sum"),
v,
&cumulative.sats.height,
&cumulative.cents.height,
&inner.cumulative.sats.height,
&inner.cumulative.cents.height,
cached_starts,
indexes,
);
let average = LazyRollingAvgsAmountFromHeight::new(
&format!("{name}_average"),
v,
&cumulative.sats.height,
&cumulative.cents.height,
&inner.cumulative.sats.height,
&inner.cumulative.cents.height,
cached_starts,
indexes,
);
Ok(Self {
base,
cumulative,
inner,
sum,
average,
})
@@ -77,26 +77,6 @@ impl AmountPerBlockCumulativeWithSums {
prices: &prices::Vecs,
exit: &Exit,
) -> Result<()> {
self.cumulative
.sats
.height
.compute_cumulative(max_from, &self.base.sats.height, exit)?;
self.base
.cents
.height
.compute_binary::<Sats, Cents, SatsToCents>(
max_from,
&self.base.sats.height,
&prices.spot.cents.height,
exit,
)?;
self.cumulative
.cents
.height
.compute_cumulative(max_from, &self.base.cents.height, exit)?;
Ok(())
self.inner.compute(prices, max_from, exit)
}
}

View File

@@ -1,24 +1,24 @@
use brk_error::Result;
use brk_traversable::Traversable;
use brk_types::{Cents, Height, Sats, Version};
use brk_types::{Height, Sats, Version};
use derive_more::{Deref, DerefMut};
use vecdb::{Database, EagerVec, Exit, PcoVec, Rw, StorageMode};
use crate::{
indexes,
internal::{
AmountPerBlock, CachedWindowStarts, LazyRollingAvgsAmountFromHeight,
LazyRollingSumsAmountFromHeight, RollingDistributionAmountPerBlock, SatsToCents,
AmountPerBlockCumulativeRolling, CachedWindowStarts, RollingDistributionAmountPerBlock,
WindowStarts,
},
prices,
};
#[derive(Traversable)]
#[derive(Deref, DerefMut, Traversable)]
pub struct AmountPerBlockFull<M: StorageMode = Rw> {
pub base: AmountPerBlock<M>,
pub cumulative: AmountPerBlock<M>,
pub sum: LazyRollingSumsAmountFromHeight,
pub average: LazyRollingAvgsAmountFromHeight,
#[deref]
#[deref_mut]
#[traversable(flatten)]
pub inner: AmountPerBlockCumulativeRolling<M>,
#[traversable(flatten)]
pub distribution: RollingDistributionAmountPerBlock<M>,
}
@@ -35,33 +35,14 @@ impl AmountPerBlockFull {
) -> Result<Self> {
let v = version + VERSION;
let base = AmountPerBlock::forced_import(db, name, v, indexes)?;
let cumulative =
AmountPerBlock::forced_import(db, &format!("{name}_cumulative"), v, indexes)?;
let sum = LazyRollingSumsAmountFromHeight::new(
&format!("{name}_sum"),
v,
&cumulative.sats.height,
&cumulative.cents.height,
cached_starts,
indexes,
);
let average = LazyRollingAvgsAmountFromHeight::new(
&format!("{name}_average"),
v,
&cumulative.sats.height,
&cumulative.cents.height,
cached_starts,
indexes,
);
let rolling = RollingDistributionAmountPerBlock::forced_import(db, name, v, indexes)?;
let inner =
AmountPerBlockCumulativeRolling::forced_import(db, name, v, indexes, cached_starts)?;
let distribution =
RollingDistributionAmountPerBlock::forced_import(db, name, v, indexes)?;
Ok(Self {
base,
cumulative,
sum,
average,
distribution: rolling,
inner,
distribution,
})
}
@@ -73,33 +54,15 @@ impl AmountPerBlockFull {
exit: &Exit,
compute_sats: impl FnOnce(&mut EagerVec<PcoVec<Height, Sats>>) -> Result<()>,
) -> Result<()> {
compute_sats(&mut self.base.sats.height)?;
compute_sats(&mut self.inner.base.sats.height)?;
self.cumulative
.sats
.height
.compute_cumulative(max_from, &self.base.sats.height, exit)?;
self.base
.cents
.height
.compute_binary::<Sats, Cents, SatsToCents>(
max_from,
&self.base.sats.height,
&prices.spot.cents.height,
exit,
)?;
self.cumulative
.cents
.height
.compute_cumulative(max_from, &self.base.cents.height, exit)?;
self.inner.compute_rest(max_from, prices, exit)?;
self.distribution.compute(
max_from,
windows,
&self.base.sats.height,
&self.base.cents.height,
&self.inner.base.sats.height,
&self.inner.base.cents.height,
exit,
)?;

View File

@@ -1,6 +1,6 @@
mod base;
mod cumulative;
mod cumulative_sum;
mod cumulative_rolling;
mod full;
mod lazy;
mod lazy_derived_resolutions;
@@ -11,7 +11,7 @@ mod with_deltas;
pub use base::*;
pub use cumulative::*;
pub use cumulative_sum::*;
pub use cumulative_rolling::*;
pub use full::*;
pub use lazy::*;
pub use lazy_derived_resolutions::*;

View File

@@ -1,4 +1,4 @@
//! PerBlockCumulativeWithSums - base PerBlock + cumulative PerBlock + lazy rolling sums.
//! PerBlockCumulativeRolling - base PerBlock + cumulative PerBlock + lazy rolling sums.
//!
//! Rolling sums are derived lazily from the cumulative vec via LazyDeltaVec.
//! No rolling sum vecs are stored on disk.
@@ -24,7 +24,7 @@ use crate::{
};
#[derive(Traversable)]
pub struct PerBlockCumulativeWithSums<T, C, M: StorageMode = Rw>
pub struct PerBlockCumulativeRolling<T, C, M: StorageMode = Rw>
where
T: NumericValue + JsonSchema,
C: NumericValue + JsonSchema,
@@ -35,7 +35,7 @@ where
pub average: LazyRollingAvgsFromHeight<C>,
}
impl<T, C> PerBlockCumulativeWithSums<T, C>
impl<T, C> PerBlockCumulativeRolling<T, C>
where
T: NumericValue + JsonSchema + Into<C>,
C: NumericValue + JsonSchema,

View File

@@ -1,6 +1,6 @@
mod aggregated;
mod base;
mod cumulative_sum;
mod cumulative_rolling;
mod distribution;
mod full;
mod lazy_distribution;
@@ -12,7 +12,7 @@ mod with_deltas;
pub use aggregated::*;
pub use base::*;
pub use cumulative_sum::*;
pub use cumulative_rolling::*;
pub use distribution::*;
pub use full::*;
pub use lazy_distribution::*;

View File

@@ -6,7 +6,7 @@ use super::Vecs;
use crate::{
indexes,
internal::{
AmountPerBlockCumulative, AmountPerBlockCumulativeWithSums, AmountPerBlockFull,
AmountPerBlockCumulative, AmountPerBlockCumulativeRolling, AmountPerBlockFull,
CachedWindowStarts, FiatPerBlock, LazyPercentRollingWindows, OneMinusBp16,
PercentPerBlock, PercentRollingWindows, RatioRollingWindows,
},
@@ -33,10 +33,10 @@ impl Vecs {
);
Ok(Self {
coinbase: AmountPerBlockCumulativeWithSums::forced_import(
coinbase: AmountPerBlockCumulativeRolling::forced_import(
db, "coinbase", version, indexes, cached_starts,
)?,
subsidy: AmountPerBlockCumulativeWithSums::forced_import(
subsidy: AmountPerBlockCumulativeRolling::forced_import(
db, "subsidy", version, indexes, cached_starts,
)?,
fees: AmountPerBlockFull::forced_import(db, "fees", version, indexes, cached_starts)?,

View File

@@ -3,15 +3,15 @@ use brk_types::{BasisPoints16, BasisPoints32, Cents};
use vecdb::{Rw, StorageMode};
use crate::internal::{
AmountPerBlockCumulative, AmountPerBlockCumulativeWithSums, AmountPerBlockFull,
AmountPerBlockCumulative, AmountPerBlockCumulativeRolling, AmountPerBlockFull,
FiatPerBlock, LazyPercentRollingWindows, PercentPerBlock, PercentRollingWindows,
RatioRollingWindows,
};
#[derive(Traversable)]
pub struct Vecs<M: StorageMode = Rw> {
pub coinbase: AmountPerBlockCumulativeWithSums<M>,
pub subsidy: AmountPerBlockCumulativeWithSums<M>,
pub coinbase: AmountPerBlockCumulativeRolling<M>,
pub subsidy: AmountPerBlockCumulativeRolling<M>,
pub fees: AmountPerBlockFull<M>,
pub unclaimed: AmountPerBlockCumulative<M>,
#[traversable(wrap = "fees", rename = "dominance")]

View File

@@ -7,7 +7,7 @@ use vecdb::{BinaryTransform, Database, Exit, ReadableVec, Rw, StorageMode, Versi
use crate::{
blocks, indexes,
internal::{
AmountPerBlockCumulativeWithSums, CachedWindowStarts, MaskSats, PercentRollingWindows,
AmountPerBlockCumulativeRolling, CachedWindowStarts, MaskSats, PercentRollingWindows,
RatioU64Bp16,
},
mining, prices,
@@ -22,7 +22,7 @@ pub struct Vecs<M: StorageMode = Rw> {
#[traversable(flatten)]
pub base: minor::Vecs<M>,
pub rewards: AmountPerBlockCumulativeWithSums<M>,
pub rewards: AmountPerBlockCumulativeRolling<M>,
#[traversable(rename = "dominance")]
pub dominance_rolling: PercentRollingWindows<BasisPoints16, M>,
}
@@ -39,7 +39,7 @@ impl Vecs {
let base = minor::Vecs::forced_import(db, slug, version, indexes, cached_starts)?;
let rewards = AmountPerBlockCumulativeWithSums::forced_import(
let rewards = AmountPerBlockCumulativeRolling::forced_import(
db,
&suffix("rewards"),
version,

View File

@@ -8,7 +8,7 @@ use vecdb::{
use crate::{
blocks, indexes,
internal::{
CachedWindowStarts, PerBlockCumulativeWithSums, PercentPerBlock, RatioU64Bp16,
CachedWindowStarts, PerBlockCumulativeRolling, PercentPerBlock, RatioU64Bp16,
},
};
@@ -17,7 +17,7 @@ pub struct Vecs<M: StorageMode = Rw> {
#[traversable(skip)]
slug: PoolSlug,
pub blocks_mined: PerBlockCumulativeWithSums<StoredU32, StoredU64, M>,
pub blocks_mined: PerBlockCumulativeRolling<StoredU32, StoredU64, M>,
pub dominance: PercentPerBlock<BasisPoints16, M>,
}
@@ -31,7 +31,7 @@ impl Vecs {
) -> Result<Self> {
let suffix = |s: &str| format!("{}_{s}", slug);
let blocks_mined = PerBlockCumulativeWithSums::forced_import(
let blocks_mined = PerBlockCumulativeRolling::forced_import(
db,
&suffix("blocks_mined"),
version + Version::ONE,

View File

@@ -5,7 +5,7 @@ use vecdb::Database;
use super::Vecs;
use crate::{
indexes,
internal::{CachedWindowStarts, PerBlockCumulativeWithSums},
internal::{CachedWindowStarts, PerBlockCumulativeRolling},
};
impl Vecs {
@@ -16,23 +16,23 @@ impl Vecs {
cached_starts: &CachedWindowStarts,
) -> Result<Self> {
let p2a =
PerBlockCumulativeWithSums::forced_import(db, "p2a_count", version, indexes, cached_starts)?;
PerBlockCumulativeRolling::forced_import(db, "p2a_count", version, indexes, cached_starts)?;
let p2ms =
PerBlockCumulativeWithSums::forced_import(db, "p2ms_count", version, indexes, cached_starts)?;
PerBlockCumulativeRolling::forced_import(db, "p2ms_count", version, indexes, cached_starts)?;
let p2pk33 =
PerBlockCumulativeWithSums::forced_import(db, "p2pk33_count", version, indexes, cached_starts)?;
PerBlockCumulativeRolling::forced_import(db, "p2pk33_count", version, indexes, cached_starts)?;
let p2pk65 =
PerBlockCumulativeWithSums::forced_import(db, "p2pk65_count", version, indexes, cached_starts)?;
PerBlockCumulativeRolling::forced_import(db, "p2pk65_count", version, indexes, cached_starts)?;
let p2pkh =
PerBlockCumulativeWithSums::forced_import(db, "p2pkh_count", version, indexes, cached_starts)?;
PerBlockCumulativeRolling::forced_import(db, "p2pkh_count", version, indexes, cached_starts)?;
let p2sh =
PerBlockCumulativeWithSums::forced_import(db, "p2sh_count", version, indexes, cached_starts)?;
PerBlockCumulativeRolling::forced_import(db, "p2sh_count", version, indexes, cached_starts)?;
let p2tr =
PerBlockCumulativeWithSums::forced_import(db, "p2tr_count", version, indexes, cached_starts)?;
PerBlockCumulativeRolling::forced_import(db, "p2tr_count", version, indexes, cached_starts)?;
let p2wpkh =
PerBlockCumulativeWithSums::forced_import(db, "p2wpkh_count", version, indexes, cached_starts)?;
PerBlockCumulativeRolling::forced_import(db, "p2wpkh_count", version, indexes, cached_starts)?;
let p2wsh =
PerBlockCumulativeWithSums::forced_import(db, "p2wsh_count", version, indexes, cached_starts)?;
PerBlockCumulativeRolling::forced_import(db, "p2wsh_count", version, indexes, cached_starts)?;
Ok(Self {
p2a,
p2ms,
@@ -43,21 +43,21 @@ impl Vecs {
p2tr,
p2wpkh,
p2wsh,
op_return: PerBlockCumulativeWithSums::forced_import(
op_return: PerBlockCumulativeRolling::forced_import(
db,
"op_return_count",
version,
indexes,
cached_starts,
)?,
empty_output: PerBlockCumulativeWithSums::forced_import(
empty_output: PerBlockCumulativeRolling::forced_import(
db,
"empty_output_count",
version,
indexes,
cached_starts,
)?,
unknown_output: PerBlockCumulativeWithSums::forced_import(
unknown_output: PerBlockCumulativeRolling::forced_import(
db,
"unknown_output_count",
version,

View File

@@ -2,20 +2,20 @@ use brk_traversable::Traversable;
use brk_types::StoredU64;
use vecdb::{Rw, StorageMode};
use crate::internal::PerBlockCumulativeWithSums;
use crate::internal::PerBlockCumulativeRolling;
#[derive(Traversable)]
pub struct Vecs<M: StorageMode = Rw> {
pub p2a: PerBlockCumulativeWithSums<StoredU64, StoredU64, M>,
pub p2ms: PerBlockCumulativeWithSums<StoredU64, StoredU64, M>,
pub p2pk33: PerBlockCumulativeWithSums<StoredU64, StoredU64, M>,
pub p2pk65: PerBlockCumulativeWithSums<StoredU64, StoredU64, M>,
pub p2pkh: PerBlockCumulativeWithSums<StoredU64, StoredU64, M>,
pub p2sh: PerBlockCumulativeWithSums<StoredU64, StoredU64, M>,
pub p2tr: PerBlockCumulativeWithSums<StoredU64, StoredU64, M>,
pub p2wpkh: PerBlockCumulativeWithSums<StoredU64, StoredU64, M>,
pub p2wsh: PerBlockCumulativeWithSums<StoredU64, StoredU64, M>,
pub op_return: PerBlockCumulativeWithSums<StoredU64, StoredU64, M>,
pub empty_output: PerBlockCumulativeWithSums<StoredU64, StoredU64, M>,
pub unknown_output: PerBlockCumulativeWithSums<StoredU64, StoredU64, M>,
pub p2a: PerBlockCumulativeRolling<StoredU64, StoredU64, M>,
pub p2ms: PerBlockCumulativeRolling<StoredU64, StoredU64, M>,
pub p2pk33: PerBlockCumulativeRolling<StoredU64, StoredU64, M>,
pub p2pk65: PerBlockCumulativeRolling<StoredU64, StoredU64, M>,
pub p2pkh: PerBlockCumulativeRolling<StoredU64, StoredU64, M>,
pub p2sh: PerBlockCumulativeRolling<StoredU64, StoredU64, M>,
pub p2tr: PerBlockCumulativeRolling<StoredU64, StoredU64, M>,
pub p2wpkh: PerBlockCumulativeRolling<StoredU64, StoredU64, M>,
pub p2wsh: PerBlockCumulativeRolling<StoredU64, StoredU64, M>,
pub op_return: PerBlockCumulativeRolling<StoredU64, StoredU64, M>,
pub empty_output: PerBlockCumulativeRolling<StoredU64, StoredU64, M>,
pub unknown_output: PerBlockCumulativeRolling<StoredU64, StoredU64, M>,
}

View File

@@ -3,7 +3,7 @@ use brk_types::Version;
use vecdb::Database;
use super::Vecs;
use crate::{indexes, internal::{AmountPerBlockCumulativeWithSums, CachedWindowStarts}};
use crate::{indexes, internal::{AmountPerBlockCumulativeRolling, CachedWindowStarts}};
impl Vecs {
pub(crate) fn forced_import(
@@ -13,7 +13,7 @@ impl Vecs {
cached_starts: &CachedWindowStarts,
) -> Result<Self> {
Ok(Self {
op_return: AmountPerBlockCumulativeWithSums::forced_import(
op_return: AmountPerBlockCumulativeRolling::forced_import(
db,
"op_return_value",
version,

View File

@@ -1,9 +1,9 @@
use brk_traversable::Traversable;
use vecdb::{Rw, StorageMode};
use crate::internal::AmountPerBlockCumulativeWithSums;
use crate::internal::AmountPerBlockCumulativeRolling;
#[derive(Traversable)]
pub struct Vecs<M: StorageMode = Rw> {
pub op_return: AmountPerBlockCumulativeWithSums<M>,
pub op_return: AmountPerBlockCumulativeRolling<M>,
}

View File

@@ -3,7 +3,7 @@ use brk_types::Version;
use vecdb::Database;
use super::Vecs;
use crate::{indexes, internal::{AmountPerBlockCumulativeWithSums, CachedWindowStarts}};
use crate::{indexes, internal::{AmountPerBlockCumulativeRolling, CachedWindowStarts}};
impl Vecs {
pub(crate) fn forced_import(
@@ -13,7 +13,7 @@ impl Vecs {
cached_starts: &CachedWindowStarts,
) -> Result<Self> {
Ok(Self {
total: AmountPerBlockCumulativeWithSums::forced_import(
total: AmountPerBlockCumulativeRolling::forced_import(
db,
"unspendable_supply",
version,

View File

@@ -1,10 +1,10 @@
use brk_traversable::Traversable;
use vecdb::{Rw, StorageMode};
use crate::internal::AmountPerBlockCumulativeWithSums;
use crate::internal::AmountPerBlockCumulativeRolling;
#[derive(Traversable)]
#[traversable(transparent)]
pub struct Vecs<M: StorageMode = Rw> {
pub total: AmountPerBlockCumulativeWithSums<M>,
pub total: AmountPerBlockCumulativeRolling<M>,
}

View File

@@ -5,7 +5,7 @@ use vecdb::Database;
use super::Vecs;
use crate::{
indexes,
internal::{CachedWindowStarts, PerBlockCumulativeWithSums},
internal::{CachedWindowStarts, PerBlockCumulativeRolling},
};
impl Vecs {
@@ -16,9 +16,9 @@ impl Vecs {
cached_starts: &CachedWindowStarts,
) -> Result<Self> {
Ok(Self {
v1: PerBlockCumulativeWithSums::forced_import(db, "tx_v1", version, indexes, cached_starts)?,
v2: PerBlockCumulativeWithSums::forced_import(db, "tx_v2", version, indexes, cached_starts)?,
v3: PerBlockCumulativeWithSums::forced_import(db, "tx_v3", version, indexes, cached_starts)?,
v1: PerBlockCumulativeRolling::forced_import(db, "tx_v1", version, indexes, cached_starts)?,
v2: PerBlockCumulativeRolling::forced_import(db, "tx_v2", version, indexes, cached_starts)?,
v3: PerBlockCumulativeRolling::forced_import(db, "tx_v3", version, indexes, cached_starts)?,
})
}
}

View File

@@ -2,11 +2,11 @@ use brk_traversable::Traversable;
use brk_types::StoredU64;
use vecdb::{Rw, StorageMode};
use crate::internal::PerBlockCumulativeWithSums;
use crate::internal::PerBlockCumulativeRolling;
#[derive(Traversable)]
pub struct Vecs<M: StorageMode = Rw> {
pub v1: PerBlockCumulativeWithSums<StoredU64, StoredU64, M>,
pub v2: PerBlockCumulativeWithSums<StoredU64, StoredU64, M>,
pub v3: PerBlockCumulativeWithSums<StoredU64, StoredU64, M>,
pub v1: PerBlockCumulativeRolling<StoredU64, StoredU64, M>,
pub v2: PerBlockCumulativeRolling<StoredU64, StoredU64, M>,
pub v3: PerBlockCumulativeRolling<StoredU64, StoredU64, M>,
}

View File

@@ -5,7 +5,7 @@ use vecdb::Database;
use super::Vecs;
use crate::{
indexes,
internal::{AmountPerBlockCumulativeWithSums, CachedWindowStarts, PerBlock, Windows},
internal::{AmountPerBlockCumulativeRolling, CachedWindowStarts, PerBlock, Windows},
};
impl Vecs {
@@ -17,7 +17,7 @@ impl Vecs {
) -> Result<Self> {
let v = version + Version::TWO;
Ok(Self {
transfer_volume: AmountPerBlockCumulativeWithSums::forced_import(
transfer_volume: AmountPerBlockCumulativeRolling::forced_import(
db,
"transfer_volume_bis",
version,

View File

@@ -2,11 +2,11 @@ use brk_traversable::Traversable;
use brk_types::StoredF32;
use vecdb::{Rw, StorageMode};
use crate::internal::{AmountPerBlockCumulativeWithSums, PerBlock, Windows};
use crate::internal::{AmountPerBlockCumulativeRolling, PerBlock, Windows};
#[derive(Traversable)]
pub struct Vecs<M: StorageMode = Rw> {
pub transfer_volume: AmountPerBlockCumulativeWithSums<M>,
pub transfer_volume: AmountPerBlockCumulativeRolling<M>,
pub tx_per_sec: Windows<PerBlock<StoredF32, M>>,
pub outputs_per_sec: Windows<PerBlock<StoredF32, M>>,
pub inputs_per_sec: Windows<PerBlock<StoredF32, M>>,