global: snapshot

This commit is contained in:
nym21
2026-03-13 16:27:10 +01:00
parent b2a1251774
commit 3709ceff8e
168 changed files with 2007 additions and 2008 deletions

View File

@@ -19,7 +19,7 @@ use vecdb::{AnyStoredVec, AnyVec, Database, Exit, Rw, StorageMode, WritableVec};
use crate::{
indexes,
internal::{CachedWindowStarts, ComputedPerBlockRollingAverage},
internal::{CachedWindowStarts, PerBlockRollingAverage},
};
/// Per-block activity counts - reset each block.
@@ -65,10 +65,10 @@ impl AddressTypeToActivityCounts {
/// Activity count vectors for a single category (e.g., one address type or "all").
#[derive(Traversable)]
pub struct ActivityCountVecs<M: StorageMode = Rw> {
pub reactivated: ComputedPerBlockRollingAverage<StoredU32, M>,
pub sending: ComputedPerBlockRollingAverage<StoredU32, M>,
pub receiving: ComputedPerBlockRollingAverage<StoredU32, M>,
pub both: ComputedPerBlockRollingAverage<StoredU32, M>,
pub reactivated: PerBlockRollingAverage<StoredU32, M>,
pub sending: PerBlockRollingAverage<StoredU32, M>,
pub receiving: PerBlockRollingAverage<StoredU32, M>,
pub both: PerBlockRollingAverage<StoredU32, M>,
}
impl ActivityCountVecs {
@@ -80,28 +80,28 @@ impl ActivityCountVecs {
cached_starts: &CachedWindowStarts,
) -> Result<Self> {
Ok(Self {
reactivated: ComputedPerBlockRollingAverage::forced_import(
reactivated: PerBlockRollingAverage::forced_import(
db,
&format!("{name}_reactivated"),
version,
indexes,
cached_starts,
)?,
sending: ComputedPerBlockRollingAverage::forced_import(
sending: PerBlockRollingAverage::forced_import(
db,
&format!("{name}_sending"),
version,
indexes,
cached_starts,
)?,
receiving: ComputedPerBlockRollingAverage::forced_import(
receiving: PerBlockRollingAverage::forced_import(
db,
&format!("{name}_receiving"),
version,
indexes,
cached_starts,
)?,
both: ComputedPerBlockRollingAverage::forced_import(
both: PerBlockRollingAverage::forced_import(
db,
&format!("{name}_both"),
version,

View File

@@ -9,11 +9,11 @@ use vecdb::{
WritableVec,
};
use crate::{indexes, internal::ComputedPerBlock};
use crate::{indexes, internal::PerBlock};
#[derive(Deref, DerefMut, Traversable)]
pub struct AddressCountVecs<M: StorageMode = Rw>(
#[traversable(flatten)] pub ComputedPerBlock<StoredU64, M>,
#[traversable(flatten)] pub PerBlock<StoredU64, M>,
);
impl AddressCountVecs {
@@ -23,7 +23,7 @@ impl AddressCountVecs {
version: Version,
indexes: &indexes::Vecs,
) -> Result<Self> {
Ok(Self(ComputedPerBlock::forced_import(
Ok(Self(PerBlock::forced_import(
db, name, version, indexes,
)?))
}

View File

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

View File

@@ -4,16 +4,16 @@ use brk_traversable::Traversable;
use brk_types::{Height, StoredU64, Version};
use vecdb::{Database, Exit, Rw, StorageMode};
use crate::{indexes, internal::ComputedPerBlock};
use crate::{indexes, internal::PerBlock};
use super::AddressCountsVecs;
/// Total address count (global + per-type) with all derived indexes
#[derive(Traversable)]
pub struct TotalAddressCountVecs<M: StorageMode = Rw> {
pub all: ComputedPerBlock<StoredU64, M>,
pub all: PerBlock<StoredU64, M>,
#[traversable(flatten)]
pub by_addresstype: ByAddressType<ComputedPerBlock<StoredU64, M>>,
pub by_addresstype: ByAddressType<PerBlock<StoredU64, M>>,
}
impl TotalAddressCountVecs {
@@ -22,11 +22,11 @@ impl TotalAddressCountVecs {
version: Version,
indexes: &indexes::Vecs,
) -> Result<Self> {
let all = ComputedPerBlock::forced_import(db, "total_address_count", version, indexes)?;
let all = PerBlock::forced_import(db, "total_address_count", version, indexes)?;
let by_addresstype: ByAddressType<ComputedPerBlock<StoredU64>> =
let by_addresstype: ByAddressType<PerBlock<StoredU64>> =
ByAddressType::new_with_name(|name| {
ComputedPerBlock::forced_import(
PerBlock::forced_import(
db,
&format!("{name}_total_address_count"),
version,

View File

@@ -10,7 +10,7 @@ use vecdb::{AnyStoredVec, AnyVec, Database, Exit, ReadableVec, Rw, StorageMode,
use crate::{
distribution::state::{AddressCohortState, MinimalRealizedState},
indexes,
internal::{CachedWindowStarts, ComputedPerBlockWithDeltas},
internal::{CachedWindowStarts, PerBlockWithDeltas},
prices,
};
@@ -27,7 +27,7 @@ pub struct AddressCohortVecs<M: StorageMode = Rw> {
#[traversable(flatten)]
pub metrics: MinimalCohortMetrics<M>,
pub address_count: ComputedPerBlockWithDeltas<StoredU64, StoredI64, BasisPointsSigned32, M>,
pub address_count: PerBlockWithDeltas<StoredU64, StoredI64, BasisPointsSigned32, M>,
}
impl AddressCohortVecs {
@@ -51,7 +51,7 @@ impl AddressCohortVecs {
cached_starts,
};
let address_count = ComputedPerBlockWithDeltas::forced_import(
let address_count = PerBlockWithDeltas::forced_import(
db,
&cfg.name("address_count"),
version,

View File

@@ -3,7 +3,7 @@ use brk_types::{Cents, CentsCompact, Sats};
use crate::{
distribution::state::PendingDelta,
internal::{FenwickNode, FenwickTree, PERCENTILES, PERCENTILES_LEN},
internal::{PERCENTILES, PERCENTILES_LEN, algo::{FenwickNode, FenwickTree}},
};
use super::COST_BASIS_PRICE_DIGITS;

View File

@@ -538,7 +538,7 @@ impl UTXOCohorts<Rw> {
.minimal
.sopr
.value_created
.raw
.base
.height
.read_only_clone();
let under_1h_value_destroyed = self
@@ -549,7 +549,7 @@ impl UTXOCohorts<Rw> {
.minimal
.sopr
.value_destroyed
.raw
.base
.height
.read_only_clone();

View File

@@ -66,7 +66,7 @@ pub(crate) fn process_blocks(
let height_to_first_txindex = &indexer.vecs.transactions.first_txindex;
let height_to_first_txoutindex = &indexer.vecs.outputs.first_txoutindex;
let height_to_first_txinindex = &indexer.vecs.inputs.first_txinindex;
let height_to_tx_count = &transactions.count.total.raw.height;
let height_to_tx_count = &transactions.count.total.base.height;
let height_to_output_count = &outputs.count.total.full.sum;
let height_to_input_count = &inputs.count.full.sum;
let txindex_to_output_count = &indexes.txindex.output_count;
@@ -364,7 +364,7 @@ pub(crate) fn process_blocks(
blocks_old as u128 * u64::from(sent.spendable_supply.value) as u128
})
.sum();
vecs.coinblocks_destroyed.raw.height.truncate_push(
vecs.coinblocks_destroyed.base.height.truncate_push(
height,
StoredF64::from(total_satblocks as f64 / Sats::ONE_BTC_U128 as f64),
)?;

View File

@@ -82,7 +82,7 @@ pub(crate) fn write(
.chain(
[
&mut vecs.supply_state as &mut dyn AnyStoredVec,
&mut vecs.coinblocks_destroyed.raw.height,
&mut vecs.coinblocks_destroyed.base.height,
]
.into_par_iter(),
)

View File

@@ -5,14 +5,14 @@ use vecdb::{AnyStoredVec, AnyVec, Exit, Rw, StorageMode, WritableVec};
use crate::{
distribution::{metrics::ImportConfig, state::{CohortState, CostBasisOps, RealizedOps}},
internal::{AmountPerBlockCumulativeWithSums, ComputedPerBlockCumulativeWithSums},
internal::{AmountPerBlockCumulativeWithSums, PerBlockCumulativeWithSums},
prices,
};
#[derive(Traversable)]
pub struct ActivityCore<M: StorageMode = Rw> {
pub sent: ComputedPerBlockCumulativeWithSums<Sats, Sats, M>,
pub coindays_destroyed: ComputedPerBlockCumulativeWithSums<StoredF64, StoredF64, M>,
pub sent: PerBlockCumulativeWithSums<Sats, Sats, M>,
pub coindays_destroyed: PerBlockCumulativeWithSums<StoredF64, StoredF64, M>,
#[traversable(wrap = "sent", rename = "in_profit")]
pub sent_in_profit: AmountPerBlockCumulativeWithSums<M>,
#[traversable(wrap = "sent", rename = "in_loss")]
@@ -32,12 +32,12 @@ impl ActivityCore {
pub(crate) fn min_len(&self) -> usize {
self.sent
.raw
.base
.height
.len()
.min(self.coindays_destroyed.raw.height.len())
.min(self.sent_in_profit.raw.sats.height.len())
.min(self.sent_in_loss.raw.sats.height.len())
.min(self.coindays_destroyed.base.height.len())
.min(self.sent_in_profit.base.sats.height.len())
.min(self.sent_in_loss.base.sats.height.len())
}
pub(crate) fn truncate_push(
@@ -45,18 +45,18 @@ impl ActivityCore {
height: Height,
state: &CohortState<impl RealizedOps, impl CostBasisOps>,
) -> Result<()> {
self.sent.raw.height.truncate_push(height, state.sent)?;
self.coindays_destroyed.raw.height.truncate_push(
self.sent.base.height.truncate_push(height, state.sent)?;
self.coindays_destroyed.base.height.truncate_push(
height,
StoredF64::from(Bitcoin::from(state.satdays_destroyed)),
)?;
self.sent_in_profit
.raw
.base
.sats
.height
.truncate_push(height, state.realized.sent_in_profit())?;
self.sent_in_loss
.raw
.base
.sats
.height
.truncate_push(height, state.realized.sent_in_loss())?;
@@ -65,12 +65,12 @@ impl ActivityCore {
pub(crate) fn collect_vecs_mut(&mut self) -> Vec<&mut dyn AnyStoredVec> {
vec![
&mut self.sent.raw.height as &mut dyn AnyStoredVec,
&mut self.coindays_destroyed.raw.height,
&mut self.sent_in_profit.raw.sats.height,
&mut self.sent_in_profit.raw.cents.height,
&mut self.sent_in_loss.raw.sats.height,
&mut self.sent_in_loss.raw.cents.height,
&mut self.sent.base.height as &mut dyn AnyStoredVec,
&mut self.coindays_destroyed.base.height,
&mut self.sent_in_profit.base.sats.height,
&mut self.sent_in_profit.base.cents.height,
&mut self.sent_in_loss.base.sats.height,
&mut self.sent_in_loss.base.cents.height,
]
}
@@ -84,18 +84,18 @@ impl ActivityCore {
others: &[&Self],
exit: &Exit,
) -> Result<()> {
self.sent.raw.height.compute_sum_of_others(
self.sent.base.height.compute_sum_of_others(
starting_indexes.height,
&others
.iter()
.map(|v| &v.sent.raw.height)
.map(|v| &v.sent.base.height)
.collect::<Vec<_>>(),
exit,
)?;
sum_others!(self, starting_indexes, others, exit; coindays_destroyed.raw.height);
sum_others!(self, starting_indexes, others, exit; sent_in_profit.raw.sats.height);
sum_others!(self, starting_indexes, others, exit; sent_in_loss.raw.sats.height);
sum_others!(self, starting_indexes, others, exit; coindays_destroyed.base.height);
sum_others!(self, starting_indexes, others, exit; sent_in_profit.base.sats.height);
sum_others!(self, starting_indexes, others, exit; sent_in_loss.base.sats.height);
Ok(())
}

View File

@@ -4,7 +4,7 @@ use brk_types::{Bitcoin, Height, Indexes, Sats, StoredF32, StoredF64, Version};
use derive_more::{Deref, DerefMut};
use vecdb::{AnyStoredVec, Exit, ReadableCloneableVec, ReadableVec, Rw, StorageMode};
use crate::internal::{ComputedPerBlock, Identity, LazyPerBlock};
use crate::internal::{PerBlock, Identity, LazyPerBlock};
use crate::distribution::{metrics::ImportConfig, state::{CohortState, CostBasisOps, RealizedOps}};
@@ -19,8 +19,8 @@ pub struct ActivityFull<M: StorageMode = Rw> {
pub coinyears_destroyed: LazyPerBlock<StoredF64, StoredF64>,
pub dormancy: ComputedPerBlock<StoredF32, M>,
pub velocity: ComputedPerBlock<StoredF32, M>,
pub dormancy: PerBlock<StoredF32, M>,
pub velocity: PerBlock<StoredF32, M>,
}
impl ActivityFull {
@@ -88,8 +88,8 @@ impl ActivityFull {
) -> Result<()> {
self.dormancy.height.compute_transform2(
starting_indexes.height,
&self.inner.coindays_destroyed.raw.height,
&self.inner.sent.raw.height,
&self.inner.coindays_destroyed.base.height,
&self.inner.sent.base.height,
|(i, cdd, sent_sats, ..)| {
let sent_btc = f64::from(Bitcoin::from(sent_sats));
if sent_btc == 0.0 {
@@ -103,7 +103,7 @@ impl ActivityFull {
self.velocity.height.compute_transform2(
starting_indexes.height,
&self.inner.sent.raw.height,
&self.inner.sent.base.height,
supply_total_sats,
|(i, sent_sats, supply_sats, ..)| {
let supply = supply_sats.as_u128() as f64;

View File

@@ -128,8 +128,8 @@ impl AllCohortMetrics {
self.asopr.compute_rest_part2(
starting_indexes,
&self.realized.minimal.sopr.value_created.raw.height,
&self.realized.minimal.sopr.value_destroyed.raw.height,
&self.realized.minimal.sopr.value_created.base.height,
&self.realized.minimal.sopr.value_destroyed.base.height,
under_1h_value_created,
under_1h_value_destroyed,
exit,

View File

@@ -80,8 +80,8 @@ impl ExtendedAdjustedCohortMetrics {
self.asopr.compute_rest_part2(
starting_indexes,
&self.inner.realized.minimal.sopr.value_created.raw.height,
&self.inner.realized.minimal.sopr.value_destroyed.raw.height,
&self.inner.realized.minimal.sopr.value_created.base.height,
&self.inner.realized.minimal.sopr.value_destroyed.base.height,
under_1h_value_created,
under_1h_value_destroyed,
exit,

View File

@@ -8,8 +8,8 @@ use crate::{
indexes,
internal::{
AmountPerBlock, AmountPerBlockCumulative, AmountPerBlockCumulativeWithSums,
CachedWindowStarts, CentsType, ComputedPerBlock,
ComputedPerBlockCumulative, ComputedPerBlockCumulativeWithSums,
CachedWindowStarts, CentsType, PerBlock,
PerBlockCumulative, PerBlockCumulativeWithSums,
FiatPerBlock, FiatPerBlockCumulativeWithSums, NumericValue,
PercentPerBlock, PercentRollingWindows, Price,
PriceWithRatioExtendedPerBlock, PriceWithRatioPerBlock, RatioPerBlock,
@@ -47,21 +47,21 @@ impl_config_import!(
PercentPerBlock<BasisPoints32>,
PercentPerBlock<BasisPointsSigned32>,
PercentRollingWindows<BasisPoints32>,
Price<ComputedPerBlock<Cents>>,
Price<PerBlock<Cents>>,
);
// Generic types (macro_rules can't parse generic bounds, so written out)
impl<T: NumericValue + JsonSchema> ConfigImport for ComputedPerBlock<T> {
impl<T: NumericValue + JsonSchema> ConfigImport for PerBlock<T> {
fn config_import(cfg: &ImportConfig, suffix: &str, offset: Version) -> Result<Self> {
Self::forced_import(cfg.db, &cfg.name(suffix), cfg.version + offset, cfg.indexes)
}
}
impl<T: NumericValue + JsonSchema> ConfigImport for ComputedPerBlockCumulative<T> {
impl<T: NumericValue + JsonSchema> ConfigImport for PerBlockCumulative<T> {
fn config_import(cfg: &ImportConfig, suffix: &str, offset: Version) -> Result<Self> {
Self::forced_import(cfg.db, &cfg.name(suffix), cfg.version + offset, cfg.indexes)
}
}
impl<T, C> ConfigImport for ComputedPerBlockCumulativeWithSums<T, C>
impl<T, C> ConfigImport for PerBlockCumulativeWithSums<T, C>
where
T: NumericValue + JsonSchema + Into<C>,
C: NumericValue + JsonSchema,

View File

@@ -3,7 +3,7 @@ use brk_traversable::Traversable;
use brk_types::{BasisPoints16, Cents, Height, Version};
use vecdb::{AnyStoredVec, AnyVec, Rw, StorageMode, WritableVec};
use crate::internal::{ComputedPerBlock, PercentPerBlock, PercentilesVecs, Price, PERCENTILES_LEN};
use crate::internal::{PerBlock, PercentPerBlock, PercentilesVecs, Price, PERCENTILES_LEN};
use super::ImportConfig;
@@ -11,8 +11,8 @@ use super::ImportConfig;
/// Used by all/sth/lth cohorts only.
#[derive(Traversable)]
pub struct CostBasis<M: StorageMode = Rw> {
pub min: Price<ComputedPerBlock<Cents, M>>,
pub max: Price<ComputedPerBlock<Cents, M>>,
pub min: Price<PerBlock<Cents, M>>,
pub max: Price<PerBlock<Cents, M>>,
pub percentiles: PercentilesVecs<M>,
pub invested_capital: PercentilesVecs<M>,
pub supply_density: PercentPerBlock<BasisPoints16, M>,

View File

@@ -8,19 +8,19 @@ use crate::{
metrics::ImportConfig,
state::{CohortState, CostBasisOps, RealizedOps},
},
internal::ComputedPerBlockWithDeltas,
internal::PerBlockWithDeltas,
};
/// Base output metrics: utxo_count + delta.
#[derive(Traversable)]
pub struct OutputsBase<M: StorageMode = Rw> {
pub unspent_count: ComputedPerBlockWithDeltas<StoredU64, StoredI64, BasisPointsSigned32, M>,
pub unspent_count: PerBlockWithDeltas<StoredU64, StoredI64, BasisPointsSigned32, M>,
}
impl OutputsBase {
pub(crate) fn forced_import(cfg: &ImportConfig) -> Result<Self> {
Ok(Self {
unspent_count: ComputedPerBlockWithDeltas::forced_import(
unspent_count: PerBlockWithDeltas::forced_import(
cfg.db,
&cfg.name("utxo_count"),
cfg.version,

View File

@@ -4,13 +4,13 @@ use brk_traversable::Traversable;
use brk_types::{Dollars, Height, Sats, Version};
use vecdb::{AnyStoredVec, AnyVec, Database, Rw, StorageMode, WritableVec};
use crate::{indexes, internal::ComputedPerBlock};
use crate::{indexes, internal::PerBlock};
/// Supply + realized cap for a single profitability bucket.
#[derive(Traversable)]
pub struct ProfitabilityBucket<M: StorageMode = Rw> {
pub supply: ComputedPerBlock<Sats, M>,
pub realized_cap: ComputedPerBlock<Dollars, M>,
pub supply: PerBlock<Sats, M>,
pub realized_cap: PerBlock<Dollars, M>,
}
impl<M: StorageMode> ProfitabilityBucket<M> {
@@ -27,13 +27,13 @@ impl ProfitabilityBucket {
indexes: &indexes::Vecs,
) -> Result<Self> {
Ok(Self {
supply: ComputedPerBlock::forced_import(
supply: PerBlock::forced_import(
db,
&format!("{name}_supply"),
version,
indexes,
)?,
realized_cap: ComputedPerBlock::forced_import(
realized_cap: PerBlock::forced_import(
db,
&format!("{name}_realized_cap"),
version,

View File

@@ -5,13 +5,13 @@ use vecdb::{Exit, ReadableVec, Rw, StorageMode};
use crate::{
distribution::metrics::ImportConfig,
internal::{ComputedPerBlockCumulativeWithSums, RatioCents64, RollingWindows},
internal::{PerBlockCumulativeWithSums, RatioCents64, RollingWindows},
};
#[derive(Traversable)]
pub struct AdjustedSopr<M: StorageMode = Rw> {
pub value_created: ComputedPerBlockCumulativeWithSums<Cents, Cents, M>,
pub value_destroyed: ComputedPerBlockCumulativeWithSums<Cents, Cents, M>,
pub value_created: PerBlockCumulativeWithSums<Cents, Cents, M>,
pub value_destroyed: PerBlockCumulativeWithSums<Cents, Cents, M>,
pub ratio: RollingWindows<StoredF64, M>,
}
@@ -35,13 +35,13 @@ impl AdjustedSopr {
exit: &Exit,
) -> Result<()> {
// Compute value_created = base.value_created - under_1h.value_created
self.value_created.raw.height.compute_subtract(
self.value_created.base.height.compute_subtract(
starting_indexes.height,
base_value_created,
under_1h_value_created,
exit,
)?;
self.value_destroyed.raw.height.compute_subtract(
self.value_destroyed.base.height.compute_subtract(
starting_indexes.height,
base_value_destroyed,
under_1h_value_destroyed,

View File

@@ -46,7 +46,7 @@ impl RealizedCore {
let neg_realized_loss = LazyPerBlock::from_height_source::<NegCentsUnsignedToDollars>(
&cfg.name("neg_realized_loss"),
cfg.version + Version::ONE,
minimal.loss.raw.cents.height.read_only_boxed_clone(),
minimal.loss.base.cents.height.read_only_boxed_clone(),
cfg.indexes,
);
@@ -103,10 +103,10 @@ impl RealizedCore {
self.minimal
.compute_rest_part1(starting_indexes, exit)?;
self.net_pnl.raw.cents.height.compute_transform2(
self.net_pnl.base.cents.height.compute_transform2(
starting_indexes.height,
&self.minimal.profit.raw.cents.height,
&self.minimal.loss.raw.cents.height,
&self.minimal.profit.base.cents.height,
&self.minimal.loss.base.cents.height,
|(i, profit, loss, ..)| {
(
i,

View File

@@ -14,8 +14,8 @@ use crate::{
blocks,
distribution::state::{WithCapital, CohortState, CostBasisData, RealizedState},
internal::{
CentsUnsignedToDollars, ComputedPerBlock, ComputedPerBlockCumulative,
ComputedPerBlockCumulativeWithSums, FiatPerBlockCumulativeWithSums,
CentsUnsignedToDollars, PerBlock, PerBlockCumulative,
PerBlockCumulativeWithSums, FiatPerBlockCumulativeWithSums,
LazyPerBlock, PercentPerBlock, PercentRollingWindows, Price,
PriceWithRatioExtendedPerBlock, RatioCents64, RatioCentsBp32,
RatioCentsSignedCentsBps32, RatioCentsSignedDollarsBps32, RatioDollarsBp32,
@@ -32,16 +32,16 @@ use super::RealizedCore;
#[derive(Traversable)]
pub struct RealizedProfit<M: StorageMode = Rw> {
pub rel_to_rcap: PercentPerBlock<BasisPoints32, M>,
pub value_created: ComputedPerBlockCumulativeWithSums<Cents, Cents, M>,
pub value_destroyed: ComputedPerBlockCumulativeWithSums<Cents, Cents, M>,
pub value_created: PerBlockCumulativeWithSums<Cents, Cents, M>,
pub value_destroyed: PerBlockCumulativeWithSums<Cents, Cents, M>,
pub distribution_flow: LazyPerBlock<Dollars, Cents>,
}
#[derive(Traversable)]
pub struct RealizedLoss<M: StorageMode = Rw> {
pub rel_to_rcap: PercentPerBlock<BasisPoints32, M>,
pub value_created: ComputedPerBlockCumulativeWithSums<Cents, Cents, M>,
pub value_destroyed: ComputedPerBlockCumulativeWithSums<Cents, Cents, M>,
pub value_created: PerBlockCumulativeWithSums<Cents, Cents, M>,
pub value_destroyed: PerBlockCumulativeWithSums<Cents, Cents, M>,
pub capitulation_flow: LazyPerBlock<Dollars, Cents>,
}
@@ -63,15 +63,15 @@ pub struct RealizedSopr<M: StorageMode = Rw> {
#[derive(Traversable)]
pub struct RealizedPeakRegret<M: StorageMode = Rw> {
#[traversable(flatten)]
pub value: ComputedPerBlockCumulative<Cents, M>,
pub value: PerBlockCumulative<Cents, M>,
pub rel_to_rcap: PercentPerBlock<BasisPoints32, M>,
}
#[derive(Traversable)]
pub struct RealizedInvestor<M: StorageMode = Rw> {
pub price: PriceWithRatioExtendedPerBlock<M>,
pub lower_price_band: Price<ComputedPerBlock<Cents, M>>,
pub upper_price_band: Price<ComputedPerBlock<Cents, M>>,
pub lower_price_band: Price<PerBlock<Cents, M>>,
pub upper_price_band: Price<PerBlock<Cents, M>>,
#[traversable(hidden)]
pub cap_raw: M::Stored<BytesVec<Height, CentsSquaredSats>>,
}
@@ -115,13 +115,13 @@ impl RealizedFull {
let core = RealizedCore::forced_import(cfg)?;
// Profit
let profit_value_destroyed: ComputedPerBlockCumulativeWithSums<Cents, Cents> =
let profit_value_destroyed: PerBlockCumulativeWithSums<Cents, Cents> =
cfg.import("profit_value_destroyed", v1)?;
let profit_flow = LazyPerBlock::from_computed::<CentsUnsignedToDollars>(
&cfg.name("distribution_flow"),
cfg.version,
profit_value_destroyed.raw.height.read_only_boxed_clone(),
&profit_value_destroyed.raw,
profit_value_destroyed.base.height.read_only_boxed_clone(),
&profit_value_destroyed.base,
);
let profit = RealizedProfit {
rel_to_rcap: cfg.import("realized_profit_rel_to_rcap", Version::new(2))?,
@@ -131,13 +131,13 @@ impl RealizedFull {
};
// Loss
let loss_value_destroyed: ComputedPerBlockCumulativeWithSums<Cents, Cents> =
let loss_value_destroyed: PerBlockCumulativeWithSums<Cents, Cents> =
cfg.import("loss_value_destroyed", v1)?;
let capitulation_flow = LazyPerBlock::from_computed::<CentsUnsignedToDollars>(
&cfg.name("capitulation_flow"),
cfg.version,
loss_value_destroyed.raw.height.read_only_boxed_clone(),
&loss_value_destroyed.raw,
loss_value_destroyed.base.height.read_only_boxed_clone(),
&loss_value_destroyed.base,
);
let loss = RealizedLoss {
rel_to_rcap: cfg.import("realized_loss_rel_to_rcap", Version::new(2))?,
@@ -222,16 +222,16 @@ impl RealizedFull {
pub(crate) fn min_stateful_len(&self) -> usize {
self.profit
.value_created
.raw
.base
.height
.len()
.min(self.profit.value_destroyed.raw.height.len())
.min(self.loss.value_created.raw.height.len())
.min(self.loss.value_destroyed.raw.height.len())
.min(self.profit.value_destroyed.base.height.len())
.min(self.loss.value_created.base.height.len())
.min(self.loss.value_destroyed.base.height.len())
.min(self.investor.price.cents.height.len())
.min(self.cap_raw.len())
.min(self.investor.cap_raw.len())
.min(self.peak_regret.value.raw.height.len())
.min(self.peak_regret.value.base.height.len())
}
pub(crate) fn truncate_push(
@@ -242,22 +242,22 @@ impl RealizedFull {
self.core.truncate_push(height, state)?;
self.profit
.value_created
.raw
.base
.height
.truncate_push(height, state.realized.profit_value_created())?;
self.profit
.value_destroyed
.raw
.base
.height
.truncate_push(height, state.realized.profit_value_destroyed())?;
self.loss
.value_created
.raw
.base
.height
.truncate_push(height, state.realized.loss_value_created())?;
self.loss
.value_destroyed
.raw
.base
.height
.truncate_push(height, state.realized.loss_value_destroyed())?;
self.investor
@@ -272,7 +272,7 @@ impl RealizedFull {
.truncate_push(height, state.realized.investor_cap_raw())?;
self.peak_regret
.value
.raw
.base
.height
.truncate_push(height, state.realized.peak_regret())?;
@@ -281,14 +281,14 @@ impl RealizedFull {
pub(crate) fn collect_vecs_mut(&mut self) -> Vec<&mut dyn AnyStoredVec> {
let mut vecs = self.core.collect_vecs_mut();
vecs.push(&mut self.profit.value_created.raw.height as &mut dyn AnyStoredVec);
vecs.push(&mut self.profit.value_destroyed.raw.height);
vecs.push(&mut self.loss.value_created.raw.height);
vecs.push(&mut self.loss.value_destroyed.raw.height);
vecs.push(&mut self.profit.value_created.base.height as &mut dyn AnyStoredVec);
vecs.push(&mut self.profit.value_destroyed.base.height);
vecs.push(&mut self.loss.value_created.base.height);
vecs.push(&mut self.loss.value_destroyed.base.height);
vecs.push(&mut self.investor.price.cents.height);
vecs.push(&mut self.cap_raw as &mut dyn AnyStoredVec);
vecs.push(&mut self.investor.cap_raw as &mut dyn AnyStoredVec);
vecs.push(&mut self.peak_regret.value.raw.height);
vecs.push(&mut self.peak_regret.value.base.height);
vecs
}
@@ -311,22 +311,22 @@ impl RealizedFull {
) -> Result<()> {
self.profit
.value_created
.raw
.base
.height
.truncate_push(height, accum.profit_value_created)?;
self.profit
.value_destroyed
.raw
.base
.height
.truncate_push(height, accum.profit_value_destroyed)?;
self.loss
.value_created
.raw
.base
.height
.truncate_push(height, accum.loss_value_created)?;
self.loss
.value_destroyed
.raw
.base
.height
.truncate_push(height, accum.loss_value_destroyed)?;
self.cap_raw
@@ -351,7 +351,7 @@ impl RealizedFull {
self.peak_regret
.value
.raw
.base
.height
.truncate_push(height, accum.peak_regret)?;
@@ -410,7 +410,7 @@ impl RealizedFull {
.rel_to_rcap
.compute_binary::<Cents, Cents, RatioCentsBp32>(
starting_indexes.height,
&self.core.minimal.profit.raw.cents.height,
&self.core.minimal.profit.base.cents.height,
&self.core.minimal.cap.cents.height,
exit,
)?;
@@ -418,7 +418,7 @@ impl RealizedFull {
.rel_to_rcap
.compute_binary::<Cents, Cents, RatioCentsBp32>(
starting_indexes.height,
&self.core.minimal.loss.raw.cents.height,
&self.core.minimal.loss.base.cents.height,
&self.core.minimal.cap.cents.height,
exit,
)?;
@@ -426,7 +426,7 @@ impl RealizedFull {
.rel_to_rcap
.compute_binary::<CentsSigned, Cents, RatioCentsSignedCentsBps32>(
starting_indexes.height,
&self.core.net_pnl.raw.cents.height,
&self.core.net_pnl.base.cents.height,
&self.core.minimal.cap.cents.height,
exit,
)?;
@@ -446,10 +446,10 @@ impl RealizedFull {
.compute_rest(starting_indexes.height, exit)?;
// Gross PnL
self.gross_pnl.raw.cents.height.compute_add(
self.gross_pnl.base.cents.height.compute_add(
starting_indexes.height,
&self.core.minimal.profit.raw.cents.height,
&self.core.minimal.loss.raw.cents.height,
&self.core.minimal.profit.base.cents.height,
&self.core.minimal.loss.base.cents.height,
exit,
)?;
self.gross_pnl
@@ -478,7 +478,7 @@ impl RealizedFull {
.rel_to_rcap
.compute_binary::<Cents, Cents, RatioCentsBp32>(
starting_indexes.height,
&self.peak_regret.value.raw.height,
&self.peak_regret.value.base.height,
&self.core.minimal.cap.cents.height,
exit,
)?;

View File

@@ -11,7 +11,7 @@ use vecdb::{
use crate::{
distribution::state::{CohortState, CostBasisOps, RealizedOps},
internal::{
ComputedPerBlockCumulativeWithSums, FiatPerBlockCumulativeWithSums,
PerBlockCumulativeWithSums, FiatPerBlockCumulativeWithSums,
FiatPerBlockWithDeltas, Identity, LazyPerBlock, PriceWithRatioPerBlock,
},
prices,
@@ -21,8 +21,8 @@ use crate::distribution::metrics::ImportConfig;
#[derive(Traversable)]
pub struct RealizedSoprMinimal<M: StorageMode = Rw> {
pub value_created: ComputedPerBlockCumulativeWithSums<Cents, Cents, M>,
pub value_destroyed: ComputedPerBlockCumulativeWithSums<Cents, Cents, M>,
pub value_created: PerBlockCumulativeWithSums<Cents, Cents, M>,
pub value_destroyed: PerBlockCumulativeWithSums<Cents, Cents, M>,
}
#[derive(Traversable)]
@@ -74,24 +74,24 @@ impl RealizedMinimal {
.cents
.height
.len()
.min(self.profit.raw.cents.height.len())
.min(self.loss.raw.cents.height.len())
.min(self.sopr.value_created.raw.height.len())
.min(self.sopr.value_destroyed.raw.height.len())
.min(self.profit.base.cents.height.len())
.min(self.loss.base.cents.height.len())
.min(self.sopr.value_created.base.height.len())
.min(self.sopr.value_destroyed.base.height.len())
}
pub(crate) fn truncate_push(&mut self, height: Height, state: &CohortState<impl RealizedOps, impl CostBasisOps>) -> Result<()> {
self.cap.cents.height.truncate_push(height, state.realized.cap())?;
self.profit.raw.cents.height.truncate_push(height, state.realized.profit())?;
self.loss.raw.cents.height.truncate_push(height, state.realized.loss())?;
self.profit.base.cents.height.truncate_push(height, state.realized.profit())?;
self.loss.base.cents.height.truncate_push(height, state.realized.loss())?;
self.sopr
.value_created
.raw
.base
.height
.truncate_push(height, state.realized.value_created())?;
self.sopr
.value_destroyed
.raw
.base
.height
.truncate_push(height, state.realized.value_destroyed())?;
Ok(())
@@ -100,10 +100,10 @@ impl RealizedMinimal {
pub(crate) fn collect_vecs_mut(&mut self) -> Vec<&mut dyn AnyStoredVec> {
vec![
&mut self.cap.cents.height as &mut dyn AnyStoredVec,
&mut self.profit.raw.cents.height,
&mut self.loss.raw.cents.height,
&mut self.sopr.value_created.raw.height,
&mut self.sopr.value_destroyed.raw.height,
&mut self.profit.base.cents.height,
&mut self.loss.base.cents.height,
&mut self.sopr.value_created.base.height,
&mut self.sopr.value_destroyed.base.height,
]
}
@@ -114,10 +114,10 @@ impl RealizedMinimal {
exit: &Exit,
) -> Result<()> {
sum_others!(self, starting_indexes, others, exit; cap.cents.height);
sum_others!(self, starting_indexes, others, exit; profit.raw.cents.height);
sum_others!(self, starting_indexes, others, exit; loss.raw.cents.height);
sum_others!(self, starting_indexes, others, exit; sopr.value_created.raw.height);
sum_others!(self, starting_indexes, others, exit; sopr.value_destroyed.raw.height);
sum_others!(self, starting_indexes, others, exit; profit.base.cents.height);
sum_others!(self, starting_indexes, others, exit; loss.base.cents.height);
sum_others!(self, starting_indexes, others, exit; sopr.value_created.base.height);
sum_others!(self, starting_indexes, others, exit; sopr.value_destroyed.base.height);
Ok(())
}

View File

@@ -42,14 +42,14 @@ impl RelativeExtendedOwnMarketCap {
self.unrealized_profit_rel_to_own_mcap
.compute_binary::<Dollars, Dollars, RatioDollarsBp16>(
max_from,
&unrealized.profit.raw.usd.height,
&unrealized.profit.base.usd.height,
own_market_cap,
exit,
)?;
self.unrealized_loss_rel_to_own_mcap
.compute_binary::<Dollars, Dollars, RatioDollarsBp32>(
max_from,
&unrealized.loss.raw.usd.height,
&unrealized.loss.base.usd.height,
own_market_cap,
exit,
)?;

View File

@@ -43,14 +43,14 @@ impl RelativeExtendedOwnPnl {
self.unrealized_profit_rel_to_own_gross_pnl
.compute_binary::<Dollars, Dollars, RatioDollarsBp16>(
max_from,
&unrealized.profit.raw.usd.height,
&unrealized.profit.base.usd.height,
gross_pnl_usd,
exit,
)?;
self.unrealized_loss_rel_to_own_gross_pnl
.compute_binary::<Dollars, Dollars, RatioDollarsBp16>(
max_from,
&unrealized.loss.raw.usd.height,
&unrealized.loss.base.usd.height,
gross_pnl_usd,
exit,
)?;

View File

@@ -64,14 +64,14 @@ impl RelativeFull {
self.unrealized_profit_rel_to_mcap
.compute_binary::<Dollars, Dollars, RatioDollarsBp16>(
max_from,
&unrealized.profit.raw.usd.height,
&unrealized.profit.base.usd.height,
market_cap,
exit,
)?;
self.unrealized_loss_rel_to_mcap
.compute_binary::<Dollars, Dollars, RatioDollarsBp16>(
max_from,
&unrealized.loss.raw.usd.height,
&unrealized.loss.base.usd.height,
market_cap,
exit,
)?;

View File

@@ -34,21 +34,21 @@ impl UnrealizedBasic {
pub(crate) fn min_stateful_len(&self) -> usize {
self.profit
.raw
.base
.cents
.height
.len()
.min(self.loss.raw.cents.height.len())
.min(self.loss.base.cents.height.len())
}
pub(crate) fn truncate_push(&mut self, height: Height, state: &UnrealizedState) -> Result<()> {
self.profit
.raw
.base
.cents
.height
.truncate_push(height, state.unrealized_profit)?;
self.loss
.raw
.base
.cents
.height
.truncate_push(height, state.unrealized_loss)?;
@@ -57,8 +57,8 @@ impl UnrealizedBasic {
pub(crate) fn collect_vecs_mut(&mut self) -> Vec<&mut dyn AnyStoredVec> {
vec![
&mut self.profit.raw.cents.height as &mut dyn AnyStoredVec,
&mut self.loss.raw.cents.height,
&mut self.profit.base.cents.height as &mut dyn AnyStoredVec,
&mut self.loss.base.cents.height,
]
}
@@ -68,8 +68,8 @@ impl UnrealizedBasic {
others: &[&Self],
exit: &Exit,
) -> Result<()> {
sum_others!(self, starting_indexes, others, exit; profit.raw.cents.height);
sum_others!(self, starting_indexes, others, exit; loss.raw.cents.height);
sum_others!(self, starting_indexes, others, exit; profit.base.cents.height);
sum_others!(self, starting_indexes, others, exit; loss.base.cents.height);
Ok(())
}

View File

@@ -35,8 +35,8 @@ impl UnrealizedCore {
let neg_unrealized_loss = LazyPerBlock::from_computed::<NegCentsUnsignedToDollars>(
&cfg.name("neg_unrealized_loss"),
cfg.version,
basic.loss.raw.cents.height.read_only_boxed_clone(),
&basic.loss.raw.cents,
basic.loss.base.cents.height.read_only_boxed_clone(),
&basic.loss.base.cents,
);
let net_unrealized_pnl = cfg.import("net_unrealized_pnl", Version::ZERO)?;
@@ -90,8 +90,8 @@ impl UnrealizedCore {
.height
.compute_binary::<Cents, Cents, CentsSubtractToCentsSigned>(
starting_indexes.height,
&self.basic.profit.raw.cents.height,
&self.basic.loss.raw.cents.height,
&self.basic.profit.base.cents.height,
&self.basic.loss.base.cents.height,
exit,
)?;

View File

@@ -96,8 +96,8 @@ impl UnrealizedFull {
self.gross_pnl.cents.height.compute_add(
starting_indexes.height,
&self.inner.core.basic.profit.raw.cents.height,
&self.inner.core.basic.loss.raw.cents.height,
&self.inner.core.basic.profit.base.cents.height,
&self.inner.core.basic.loss.base.cents.height,
exit,
)?;

View File

@@ -23,7 +23,7 @@ use crate::{
state::BlockState,
},
indexes, inputs,
internal::{CachedWindowStarts, ComputedPerBlockCumulative, finalize_db, open_db},
internal::{CachedWindowStarts, PerBlockCumulative, db_utils::{finalize_db, open_db}},
outputs, prices, transactions,
};
@@ -70,7 +70,7 @@ pub struct Vecs<M: StorageMode = Rw> {
#[traversable(wrap = "cohorts", rename = "address")]
pub address_cohorts: AddressCohorts<M>,
#[traversable(wrap = "cointime")]
pub coinblocks_destroyed: ComputedPerBlockCumulative<StoredF64, M>,
pub coinblocks_destroyed: PerBlockCumulative<StoredF64, M>,
pub addresses: AddressMetricsVecs<M>,
/// In-memory block state for UTXO processing. Persisted via supply_state.
@@ -173,7 +173,7 @@ impl Vecs {
utxo_cohorts,
address_cohorts,
coinblocks_destroyed: ComputedPerBlockCumulative::forced_import(
coinblocks_destroyed: PerBlockCumulative::forced_import(
&db,
"coinblocks_destroyed",
version + Version::TWO,
@@ -489,6 +489,6 @@ impl Vecs {
.min(Height::from(self.addresses.funded.min_stateful_len()))
.min(Height::from(self.addresses.empty.min_stateful_len()))
.min(Height::from(self.addresses.activity.min_stateful_len()))
.min(Height::from(self.coinblocks_destroyed.raw.height.len()))
.min(Height::from(self.coinblocks_destroyed.base.height.len()))
}
}