global: snapshot

This commit is contained in:
nym21
2026-03-16 19:33:24 +01:00
parent 5848d25612
commit 5609e6c010
12 changed files with 132 additions and 58 deletions

View File

@@ -1,6 +1,6 @@
use brk_error::Result;
use brk_traversable::Traversable;
use brk_types::{Bitcoin, Indexes, Sats, StoredF64, Version};
use brk_types::{Bitcoin, Indexes, StoredF64, Version};
use vecdb::{AnyStoredVec, AnyVec, Exit, Rw, StorageMode, WritableVec};
use crate::{
@@ -11,7 +11,7 @@ use crate::{
#[derive(Traversable)]
pub struct ActivityCore<M: StorageMode = Rw> {
pub transfer_volume: PerBlockCumulativeWithSums<Sats, Sats, M>,
pub transfer_volume: AmountPerBlockCumulativeWithSums<M>,
pub coindays_destroyed: PerBlockCumulativeWithSums<StoredF64, StoredF64, M>,
#[traversable(wrap = "transfer_volume", rename = "in_profit")]
pub transfer_volume_in_profit: AmountPerBlockCumulativeWithSums<M>,
@@ -33,6 +33,7 @@ impl ActivityCore {
pub(crate) fn min_len(&self) -> usize {
self.transfer_volume
.base
.sats
.height
.len()
.min(self.coindays_destroyed.base.height.len())
@@ -45,7 +46,7 @@ impl ActivityCore {
&mut self,
state: &CohortState<impl RealizedOps, impl CostBasisOps>,
) {
self.transfer_volume.base.height.push(state.sent);
self.transfer_volume.base.sats.height.push(state.sent);
self.coindays_destroyed.base.height.push(
StoredF64::from(Bitcoin::from(state.satdays_destroyed)),
);
@@ -63,7 +64,8 @@ impl ActivityCore {
pub(crate) fn collect_vecs_mut(&mut self) -> Vec<&mut dyn AnyStoredVec> {
vec![
&mut self.transfer_volume.base.height as &mut dyn AnyStoredVec,
&mut self.transfer_volume.base.sats.height as &mut dyn AnyStoredVec,
&mut self.transfer_volume.base.cents.height,
&mut self.coindays_destroyed.base.height,
&mut self.transfer_volume_in_profit.base.sats.height,
&mut self.transfer_volume_in_profit.base.cents.height,
@@ -82,11 +84,11 @@ impl ActivityCore {
others: &[&Self],
exit: &Exit,
) -> Result<()> {
self.transfer_volume.base.height.compute_sum_of_others(
self.transfer_volume.base.sats.height.compute_sum_of_others(
starting_indexes.height,
&others
.iter()
.map(|v| &v.transfer_volume.base.height)
.map(|v| &v.transfer_volume.base.sats.height)
.collect::<Vec<_>>(),
exit,
)?;
@@ -100,11 +102,12 @@ impl ActivityCore {
pub(crate) fn compute_rest_part1(
&mut self,
prices: &prices::Vecs,
starting_indexes: &Indexes,
exit: &Exit,
) -> Result<()> {
self.transfer_volume
.compute_rest(starting_indexes.height, exit)?;
.compute_rest(starting_indexes.height, prices, exit)?;
self.coindays_destroyed
.compute_rest(starting_indexes.height, exit)?;
Ok(())

View File

@@ -6,7 +6,10 @@ use vecdb::{AnyStoredVec, Exit, ReadableCloneableVec, Rw, StorageMode};
use crate::internal::{Identity, LazyPerBlock, PerBlock};
use crate::distribution::{metrics::ImportConfig, state::{CohortState, CostBasisOps, RealizedOps}};
use crate::{
distribution::{metrics::ImportConfig, state::{CohortState, CostBasisOps, RealizedOps}},
prices,
};
use super::ActivityCore;
@@ -71,10 +74,11 @@ impl ActivityFull {
pub(crate) fn compute_rest_part1(
&mut self,
prices: &prices::Vecs,
starting_indexes: &Indexes,
exit: &Exit,
) -> Result<()> {
self.inner.compute_rest_part1(starting_indexes, exit)
self.inner.compute_rest_part1(prices, starting_indexes, exit)
}
pub(crate) fn compute_rest_part2(
@@ -85,7 +89,7 @@ impl ActivityFull {
self.dormancy.height.compute_transform2(
starting_indexes.height,
&self.inner.coindays_destroyed.base.height,
&self.inner.transfer_volume.base.height,
&self.inner.transfer_volume.base.sats.height,
|(i, cdd, sent_sats, ..)| {
let sent_btc = f64::from(Bitcoin::from(sent_sats));
if sent_btc == 0.0 {

View File

@@ -8,7 +8,10 @@ use brk_error::Result;
use brk_types::{Indexes, Version};
use vecdb::Exit;
use crate::distribution::state::{CohortState, CostBasisOps, RealizedOps};
use crate::{
distribution::state::{CohortState, CostBasisOps, RealizedOps},
prices,
};
pub trait ActivityLike: Send + Sync {
fn as_core(&self) -> &ActivityCore;
@@ -27,6 +30,7 @@ pub trait ActivityLike: Send + Sync {
) -> Result<()>;
fn compute_rest_part1(
&mut self,
prices: &prices::Vecs,
starting_indexes: &Indexes,
exit: &Exit,
) -> Result<()>;
@@ -45,8 +49,8 @@ impl ActivityLike for ActivityCore {
fn compute_from_stateful(&mut self, starting_indexes: &Indexes, others: &[&ActivityCore], exit: &Exit) -> Result<()> {
self.compute_from_stateful(starting_indexes, others, exit)
}
fn compute_rest_part1(&mut self, starting_indexes: &Indexes, exit: &Exit) -> Result<()> {
self.compute_rest_part1(starting_indexes, exit)
fn compute_rest_part1(&mut self, prices: &prices::Vecs, starting_indexes: &Indexes, exit: &Exit) -> Result<()> {
self.compute_rest_part1(prices, starting_indexes, exit)
}
}
@@ -63,7 +67,7 @@ impl ActivityLike for ActivityFull {
fn compute_from_stateful(&mut self, starting_indexes: &Indexes, others: &[&ActivityCore], exit: &Exit) -> Result<()> {
self.compute_from_stateful(starting_indexes, others, exit)
}
fn compute_rest_part1(&mut self, starting_indexes: &Indexes, exit: &Exit) -> Result<()> {
self.compute_rest_part1(starting_indexes, exit)
fn compute_rest_part1(&mut self, prices: &prices::Vecs, starting_indexes: &Indexes, exit: &Exit) -> Result<()> {
self.compute_rest_part1(prices, starting_indexes, exit)
}
}

View File

@@ -109,7 +109,7 @@ impl CoreCohortMetrics {
.compute(prices, starting_indexes.height, exit)?;
self.activity
.compute_rest_part1(starting_indexes, exit)?;
.compute_rest_part1(prices, starting_indexes, exit)?;
self.activity
.compute_sent_profitability(prices, starting_indexes, exit)?;

View File

@@ -223,7 +223,7 @@ pub trait CohortMetricsBase:
self.supply_mut()
.compute(prices, starting_indexes.height, exit)?;
self.activity_mut()
.compute_rest_part1(starting_indexes, exit)?;
.compute_rest_part1(prices, starting_indexes, exit)?;
self.activity_core_mut()
.compute_sent_profitability(prices, starting_indexes, exit)?;