global: big snapshot

This commit is contained in:
nym21
2026-03-13 12:47:01 +01:00
parent c83955eea7
commit 2b31c7f6b7
158 changed files with 4961 additions and 6939 deletions
@@ -10,7 +10,7 @@ use derive_more::{Deref, DerefMut};
use rayon::prelude::*;
use vecdb::{AnyStoredVec, Database, Exit, Rw, StorageMode};
use crate::{blocks, distribution::DynCohortVecs, indexes, prices};
use crate::{distribution::DynCohortVecs, indexes, internal::CachedWindowStarts, prices};
use super::{super::traits::CohortVecs, vecs::AddressCohortVecs};
@@ -27,6 +27,7 @@ impl AddressCohorts {
version: Version,
indexes: &indexes::Vecs,
states_path: &Path,
cached_starts: &CachedWindowStarts,
) -> Result<Self> {
let v = version + VERSION;
@@ -34,7 +35,7 @@ impl AddressCohorts {
let create =
|filter: Filter, name: &'static str, has_state: bool| -> Result<AddressCohortVecs> {
let sp = if has_state { Some(states_path) } else { None };
AddressCohortVecs::forced_import(db, filter, name, v, indexes, sp)
AddressCohortVecs::forced_import(db, filter, name, v, indexes, sp, cached_starts)
};
let full = |f: Filter, name: &'static str| create(f, name, true);
@@ -90,22 +91,12 @@ impl AddressCohorts {
/// First phase of post-processing: compute index transforms.
pub(crate) fn compute_rest_part1(
&mut self,
blocks: &blocks::Vecs,
prices: &prices::Vecs,
starting_indexes: &Indexes,
exit: &Exit,
) -> Result<()> {
self.par_iter_mut().try_for_each(|v| {
v.address_count_delta.compute(
starting_indexes.height,
&blocks.lookback._1m,
&v.address_count.height,
exit,
)
})?;
self.par_iter_mut()
.try_for_each(|v| v.compute_rest_part1(blocks, prices, starting_indexes, exit))?;
.try_for_each(|v| v.compute_rest_part1(prices, starting_indexes, exit))?;
Ok(())
}
@@ -3,15 +3,14 @@ use std::path::Path;
use brk_cohort::{CohortContext, Filter, Filtered};
use brk_error::Result;
use brk_traversable::Traversable;
use brk_types::{Cents, Height, Indexes, StoredI64, StoredU64, Version};
use brk_types::{BasisPointsSigned32, Cents, Height, Indexes, StoredI64, StoredU64, Version};
use rayon::prelude::*;
use vecdb::{AnyStoredVec, AnyVec, Database, Exit, ReadableVec, Rw, StorageMode, WritableVec};
use crate::{
blocks,
distribution::state::{AddressCohortState, MinimalRealizedState},
indexes,
internal::{ComputedPerBlock, RollingDelta1m},
internal::{CachedWindowStarts, ComputedPerBlockWithDeltas},
prices,
};
@@ -28,9 +27,7 @@ pub struct AddressCohortVecs<M: StorageMode = Rw> {
#[traversable(flatten)]
pub metrics: MinimalCohortMetrics<M>,
pub address_count: ComputedPerBlock<StoredU64, M>,
#[traversable(wrap = "address_count", rename = "delta")]
pub address_count_delta: RollingDelta1m<StoredU64, StoredI64, M>,
pub address_count: ComputedPerBlockWithDeltas<StoredU64, StoredI64, BasisPointsSigned32, M>,
}
impl AddressCohortVecs {
@@ -41,6 +38,7 @@ impl AddressCohortVecs {
version: Version,
indexes: &indexes::Vecs,
states_path: Option<&Path>,
cached_starts: &CachedWindowStarts,
) -> Result<Self> {
let full_name = CohortContext::Address.full_name(&filter, name);
@@ -50,27 +48,23 @@ impl AddressCohortVecs {
full_name: &full_name,
version,
indexes,
cached_starts,
};
let address_count = ComputedPerBlockWithDeltas::forced_import(
db,
&cfg.name("address_count"),
version,
Version::ONE,
indexes,
cached_starts,
)?;
Ok(Self {
starting_height: None,
state: states_path.map(|path| Box::new(AddressCohortState::new(path, &full_name))),
metrics: MinimalCohortMetrics::forced_import(&cfg)?,
address_count: ComputedPerBlock::forced_import(
db,
&cfg.name("address_count"),
version,
indexes,
)?,
address_count_delta: RollingDelta1m::forced_import(
db,
&cfg.name("address_count_delta"),
version + Version::ONE,
indexes,
)?,
address_count,
})
}
@@ -189,13 +183,12 @@ impl DynCohortVecs for AddressCohortVecs {
fn compute_rest_part1(
&mut self,
blocks: &blocks::Vecs,
prices: &prices::Vecs,
starting_indexes: &Indexes,
exit: &Exit,
) -> Result<()> {
self.metrics
.compute_rest_part1(blocks, prices, starting_indexes, exit)
.compute_rest_part1(prices, starting_indexes, exit)
}
fn write_state(&mut self, height: Height, cleanup: bool) -> Result<()> {
@@ -2,7 +2,7 @@ use brk_error::Result;
use brk_types::{Cents, Height, Indexes, Version};
use vecdb::Exit;
use crate::{blocks, prices};
use crate::prices;
/// Dynamic dispatch trait for cohort vectors.
///
@@ -34,7 +34,6 @@ pub trait DynCohortVecs: Send + Sync {
/// First phase of post-processing computations.
fn compute_rest_part1(
&mut self,
blocks: &blocks::Vecs,
prices: &prices::Vecs,
starting_indexes: &Indexes,
exit: &Exit,
@@ -19,13 +19,13 @@ use crate::{
metrics::{
AllCohortMetrics, BasicCohortMetrics, CohortMetricsBase,
CoreCohortMetrics, ExtendedAdjustedCohortMetrics, ExtendedCohortMetrics, ImportConfig,
MinimalCohortMetrics, ProfitabilityMetrics, RealizedFullAccum, SupplyFull,
MinimalCohortMetrics, ProfitabilityMetrics, RealizedFullAccum, SupplyCore,
TypeCohortMetrics,
},
state::UTXOCohortState,
},
indexes,
internal::AmountPerBlock,
internal::{AmountPerBlock, CachedWindowStarts},
prices,
};
@@ -70,6 +70,7 @@ impl UTXOCohorts<Rw> {
version: Version,
indexes: &indexes::Vecs,
states_path: &Path,
cached_starts: &CachedWindowStarts,
) -> Result<Self> {
let v = version + VERSION;
@@ -81,8 +82,9 @@ impl UTXOCohorts<Rw> {
full_name: &all_full_name,
version: v + Version::ONE,
indexes,
cached_starts,
};
let all_supply = SupplyFull::forced_import(&all_cfg)?;
let all_supply = SupplyCore::forced_import(&all_cfg)?;
// Phase 2: Import separate (stateful) cohorts.
@@ -96,6 +98,7 @@ impl UTXOCohorts<Rw> {
full_name: &full_name,
version: v,
indexes,
cached_starts,
};
let state = Some(Box::new(UTXOCohortState::new(states_path, &full_name)));
Ok(UTXOCohortVecs::new(
@@ -115,6 +118,7 @@ impl UTXOCohorts<Rw> {
full_name: &full_name,
version: v,
indexes,
cached_starts,
};
let state = Some(Box::new(UTXOCohortState::new(states_path, &full_name)));
Ok(UTXOCohortVecs::new(
@@ -136,6 +140,7 @@ impl UTXOCohorts<Rw> {
full_name: &full_name,
version: v,
indexes,
cached_starts,
};
let state = Some(Box::new(UTXOCohortState::new(states_path, &full_name)));
Ok(UTXOCohortVecs::new(
@@ -155,6 +160,7 @@ impl UTXOCohorts<Rw> {
full_name: &full_name,
version: v,
indexes,
cached_starts,
};
let state = Some(Box::new(UTXOCohortState::new(states_path, &full_name)));
Ok(UTXOCohortVecs::new(
@@ -186,6 +192,7 @@ impl UTXOCohorts<Rw> {
full_name: &full_name,
version: v,
indexes,
cached_starts,
};
UTXOCohortVecs::new(None, ExtendedAdjustedCohortMetrics::forced_import(&cfg)?)
};
@@ -200,6 +207,7 @@ impl UTXOCohorts<Rw> {
full_name: &full_name,
version: v,
indexes,
cached_starts,
};
UTXOCohortVecs::new(None, ExtendedCohortMetrics::forced_import(&cfg)?)
};
@@ -214,6 +222,7 @@ impl UTXOCohorts<Rw> {
full_name: &full_name,
version: v,
indexes,
cached_starts,
};
Ok(UTXOCohortVecs::new(
None,
@@ -236,6 +245,7 @@ impl UTXOCohorts<Rw> {
full_name: &full_name,
version: v,
indexes,
cached_starts,
};
Ok(UTXOCohortVecs::new(
None,
@@ -459,7 +469,6 @@ impl UTXOCohorts<Rw> {
/// First phase of post-processing: compute index transforms.
pub(crate) fn compute_rest_part1(
&mut self,
blocks: &blocks::Vecs,
prices: &prices::Vecs,
starting_indexes: &Indexes,
exit: &Exit,
@@ -497,7 +506,7 @@ impl UTXOCohorts<Rw> {
);
all.extend(self.type_.iter_mut().map(|x| x as &mut dyn DynCohortVecs));
all.into_par_iter()
.try_for_each(|v| v.compute_rest_part1(blocks, prices, starting_indexes, exit))?;
.try_for_each(|v| v.compute_rest_part1(prices, starting_indexes, exit))?;
}
// Compute matured cents from sats × price
@@ -606,19 +615,19 @@ impl UTXOCohorts<Rw> {
Box::new(|| {
age_range.par_iter_mut().try_for_each(|v| {
v.metrics
.compute_rest_part2(blocks, prices, starting_indexes, ss, exit)
.compute_rest_part2(prices, starting_indexes, ss, exit)
})
}),
Box::new(|| {
under_age.par_iter_mut().try_for_each(|v| {
v.metrics
.compute_rest_part2(blocks, prices, starting_indexes, ss, exit)
.compute_rest_part2(prices, starting_indexes, ss, exit)
})
}),
Box::new(|| {
over_age.par_iter_mut().try_for_each(|v| {
v.metrics
.compute_rest_part2(blocks, prices, starting_indexes, ss, exit)
.compute_rest_part2(prices, starting_indexes, ss, exit)
})
}),
Box::new(|| {
@@ -629,13 +638,13 @@ impl UTXOCohorts<Rw> {
Box::new(|| {
epoch.par_iter_mut().try_for_each(|v| {
v.metrics
.compute_rest_part2(blocks, prices, starting_indexes, ss, exit)
.compute_rest_part2(prices, starting_indexes, ss, exit)
})
}),
Box::new(|| {
class.par_iter_mut().try_for_each(|v| {
v.metrics
.compute_rest_part2(blocks, prices, starting_indexes, ss, exit)
.compute_rest_part2(prices, starting_indexes, ss, exit)
})
}),
Box::new(|| {
@@ -3,7 +3,7 @@ use brk_error::Result;
use brk_types::{Cents, Height, Indexes, Version};
use vecdb::{Exit, ReadableVec};
use crate::{blocks, distribution::{cohorts::traits::DynCohortVecs, metrics::CoreCohortMetrics}, prices};
use crate::{distribution::{cohorts::traits::DynCohortVecs, metrics::CoreCohortMetrics}, prices};
use super::UTXOCohortVecs;
@@ -64,13 +64,12 @@ impl DynCohortVecs for UTXOCohortVecs<CoreCohortMetrics> {
fn compute_rest_part1(
&mut self,
blocks: &blocks::Vecs,
prices: &prices::Vecs,
starting_indexes: &Indexes,
exit: &Exit,
) -> Result<()> {
self.metrics
.compute_rest_part1(blocks, prices, starting_indexes, exit)
.compute_rest_part1(prices, starting_indexes, exit)
}
fn write_state(&mut self, height: Height, cleanup: bool) -> Result<()> {
@@ -4,7 +4,6 @@ use brk_types::{Cents, Height, Indexes, Version};
use vecdb::{Exit, ReadableVec};
use crate::{
blocks,
distribution::{cohorts::traits::DynCohortVecs, metrics::MinimalCohortMetrics},
prices,
};
@@ -57,13 +56,12 @@ impl DynCohortVecs for UTXOCohortVecs<MinimalCohortMetrics> {
fn compute_rest_part1(
&mut self,
blocks: &blocks::Vecs,
prices: &prices::Vecs,
starting_indexes: &Indexes,
exit: &Exit,
) -> Result<()> {
self.metrics
.compute_rest_part1(blocks, prices, starting_indexes, exit)
.compute_rest_part1(prices, starting_indexes, exit)
}
fn write_state(&mut self, height: Height, cleanup: bool) -> Result<()> {
@@ -49,7 +49,6 @@ use brk_types::{Cents, Height, Indexes, Version};
use vecdb::{Exit, ReadableVec};
use crate::{
blocks,
distribution::{
cohorts::traits::DynCohortVecs,
metrics::{CohortMetricsBase, CohortMetricsState},
@@ -71,7 +70,10 @@ pub struct UTXOCohortVecs<M: CohortMetricsState> {
}
impl<M: CohortMetricsState> UTXOCohortVecs<M> {
pub(crate) fn new(state: Option<Box<UTXOCohortState<M::Realized, M::CostBasis>>>, metrics: M) -> Self {
pub(crate) fn new(
state: Option<Box<UTXOCohortState<M::Realized, M::CostBasis>>>,
metrics: M,
) -> Self {
Self {
state_starting_height: None,
state,
@@ -183,24 +185,20 @@ impl<M: CohortMetricsBase + Traversable> DynCohortVecs for UTXOCohortVecs<M> {
_is_day_boundary: bool,
) -> Result<()> {
if let Some(state) = self.state.as_mut() {
self.metrics.compute_and_push_unrealized(
height,
height_price,
state,
)?;
self.metrics
.compute_and_push_unrealized(height, height_price, state)?;
}
Ok(())
}
fn compute_rest_part1(
&mut self,
blocks: &blocks::Vecs,
prices: &prices::Vecs,
starting_indexes: &Indexes,
exit: &Exit,
) -> Result<()> {
self.metrics
.compute_rest_part1(blocks, prices, starting_indexes, exit)?;
.compute_rest_part1(prices, starting_indexes, exit)?;
Ok(())
}
@@ -3,7 +3,7 @@ use brk_error::Result;
use brk_types::{Cents, Height, Indexes, Version};
use vecdb::{Exit, ReadableVec};
use crate::{blocks, distribution::cohorts::traits::DynCohortVecs, distribution::metrics::TypeCohortMetrics, prices};
use crate::{distribution::cohorts::traits::DynCohortVecs, distribution::metrics::TypeCohortMetrics, prices};
use super::UTXOCohortVecs;
@@ -63,13 +63,12 @@ impl DynCohortVecs for UTXOCohortVecs<TypeCohortMetrics> {
fn compute_rest_part1(
&mut self,
blocks: &blocks::Vecs,
prices: &prices::Vecs,
starting_indexes: &Indexes,
exit: &Exit,
) -> Result<()> {
self.metrics
.compute_rest_part1(blocks, prices, starting_indexes, exit)
.compute_rest_part1(prices, starting_indexes, exit)
}
fn write_state(&mut self, height: Height, cleanup: bool) -> Result<()> {