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