global: snapshot part 6

This commit is contained in:
nym21
2026-03-20 17:02:32 +01:00
parent 17106f887a
commit f683adba13
34 changed files with 197 additions and 204 deletions
@@ -11,7 +11,7 @@ use crate::{
#[derive(Traversable)]
pub struct AmountPerBlockCumulative<M: StorageMode = Rw> {
pub base: AmountPerBlock<M>,
pub block: AmountPerBlock<M>,
pub cumulative: AmountPerBlock<M>,
}
@@ -27,7 +27,7 @@ impl AmountPerBlockCumulative {
let v = version + VERSION;
Ok(Self {
base: AmountPerBlock::forced_import(db, name, v, indexes)?,
block: AmountPerBlock::forced_import(db, name, v, indexes)?,
cumulative: AmountPerBlock::forced_import(
db,
&format!("{name}_cumulative"),
@@ -46,11 +46,11 @@ impl AmountPerBlockCumulative {
self.cumulative
.sats
.height
.compute_cumulative(max_from, &self.base.sats.height, exit)?;
.compute_cumulative(max_from, &self.block.sats.height, exit)?;
self.base.cents.compute_binary::<Sats, Cents, SatsToCents>(
self.block.cents.compute_binary::<Sats, Cents, SatsToCents>(
max_from,
&self.base.sats.height,
&self.block.sats.height,
&prices.spot.cents.height,
exit,
)?;
@@ -58,7 +58,7 @@ impl AmountPerBlockCumulative {
self.cumulative
.cents
.height
.compute_cumulative(max_from, &self.base.cents.height, exit)?;
.compute_cumulative(max_from, &self.block.cents.height, exit)?;
Ok(())
}
@@ -67,7 +67,7 @@ impl AmountPerBlockCumulativeRolling {
exit: &Exit,
compute_sats: impl FnOnce(&mut EagerVec<PcoVec<Height, Sats>>) -> Result<()>,
) -> Result<()> {
compute_sats(&mut self.base.sats.height)?;
compute_sats(&mut self.block.sats.height)?;
self.compute_rest(max_from, prices, exit)
}
@@ -54,15 +54,15 @@ impl AmountPerBlockFull {
exit: &Exit,
compute_sats: impl FnOnce(&mut EagerVec<PcoVec<Height, Sats>>) -> Result<()>,
) -> Result<()> {
compute_sats(&mut self.inner.base.sats.height)?;
compute_sats(&mut self.inner.block.sats.height)?;
self.inner.compute_rest(max_from, prices, exit)?;
self.distribution.compute(
max_from,
windows,
&self.inner.base.sats.height,
&self.inner.base.cents.height,
&self.inner.block.sats.height,
&self.inner.block.cents.height,
exit,
)?;
@@ -29,7 +29,7 @@ where
T: NumericValue + JsonSchema,
C: NumericValue + JsonSchema,
{
pub base: PerBlock<T, M>,
pub block: PerBlock<T, M>,
pub cumulative: PerBlock<C, M>,
pub sum: LazyRollingSumsFromHeight<C>,
pub average: LazyRollingAvgsFromHeight<C>,
@@ -47,7 +47,7 @@ where
indexes: &indexes::Vecs,
cached_starts: &CachedWindowStarts,
) -> Result<Self> {
let base = PerBlock::forced_import(db, name, version, indexes)?;
let block = PerBlock::forced_import(db, name, version, indexes)?;
let cumulative =
PerBlock::forced_import(db, &format!("{name}_cumulative"), version, indexes)?;
let sum = LazyRollingSumsFromHeight::new(
@@ -66,7 +66,7 @@ where
);
Ok(Self {
base,
block,
cumulative,
sum,
average,
@@ -83,7 +83,7 @@ where
where
C: Default,
{
compute_base(&mut self.base.height)?;
compute_base(&mut self.block.height)?;
self.compute_rest(max_from, exit)
}
@@ -94,7 +94,7 @@ where
{
self.cumulative
.height
.compute_cumulative(max_from, &self.base.height, exit)?;
.compute_cumulative(max_from, &self.block.height, exit)?;
Ok(())
}
}
@@ -18,7 +18,7 @@ pub struct PerBlockFull<T, M: StorageMode = Rw>
where
T: NumericValue + JsonSchema,
{
pub base: PerBlock<T, M>,
pub block: PerBlock<T, M>,
pub cumulative: PerBlock<T, M>,
#[traversable(flatten)]
pub rolling: RollingComplete<T, M>,
@@ -35,7 +35,7 @@ where
indexes: &indexes::Vecs,
cached_starts: &CachedWindowStarts,
) -> Result<Self> {
let base = PerBlock::forced_import(db, name, version, indexes)?;
let block = PerBlock::forced_import(db, name, version, indexes)?;
let cumulative =
PerBlock::forced_import(db, &format!("{name}_cumulative"), version, indexes)?;
let rolling = RollingComplete::forced_import(
@@ -48,7 +48,7 @@ where
)?;
Ok(Self {
base,
block,
cumulative,
rolling,
})
@@ -66,12 +66,12 @@ where
T: From<f64> + Default + Copy + Ord,
f64: From<T>,
{
compute_base(&mut self.base.height)?;
compute_base(&mut self.block.height)?;
self.cumulative
.height
.compute_cumulative(max_from, &self.base.height, exit)?;
.compute_cumulative(max_from, &self.block.height, exit)?;
self.rolling
.compute(max_from, windows, &self.base.height, exit)?;
.compute(max_from, windows, &self.block.height, exit)?;
Ok(())
}
}
@@ -19,7 +19,7 @@ pub struct PerBlockRollingAverage<T, M: StorageMode = Rw>
where
T: NumericValue + JsonSchema,
{
pub base: M::Stored<EagerVec<PcoVec<Height, T>>>,
pub block: M::Stored<EagerVec<PcoVec<Height, T>>>,
#[traversable(hidden)]
pub cumulative: M::Stored<EagerVec<PcoVec<Height, T>>>,
#[traversable(flatten)]
@@ -37,7 +37,7 @@ where
indexes: &indexes::Vecs,
cached_starts: &CachedWindowStarts,
) -> Result<Self> {
let base: EagerVec<PcoVec<Height, T>> = EagerVec::forced_import(db, name, version)?;
let block: EagerVec<PcoVec<Height, T>> = EagerVec::forced_import(db, name, version)?;
let cumulative: EagerVec<PcoVec<Height, T>> =
EagerVec::forced_import(db, &format!("{name}_cumulative"), version + Version::ONE)?;
let average = LazyRollingAvgsFromHeight::new(
@@ -49,7 +49,7 @@ where
);
Ok(Self {
base,
block,
cumulative,
average,
})
@@ -62,14 +62,14 @@ where
exit: &Exit,
compute_height: impl FnOnce(&mut EagerVec<PcoVec<Height, T>>) -> Result<()>,
) -> Result<()> {
compute_height(&mut self.base)?;
compute_height(&mut self.block)?;
self.compute_rest(max_from, exit)
}
/// Compute cumulative from already-populated height data. Rolling averages are lazy.
pub(crate) fn compute_rest(&mut self, max_from: Height, exit: &Exit) -> Result<()> {
self.cumulative
.compute_cumulative(max_from, &self.base, exit)?;
.compute_cumulative(max_from, &self.block, exit)?;
Ok(())
}
}
@@ -10,7 +10,7 @@ use crate::{
#[derive(Traversable)]
pub struct FiatPerBlockCumulativeWithSums<C: CentsType, M: StorageMode = Rw> {
pub base: FiatPerBlock<C, M>,
pub block: FiatPerBlock<C, M>,
pub cumulative: FiatPerBlock<C, M>,
pub sum: LazyRollingSumsFiatFromHeight<C>,
}
@@ -23,7 +23,7 @@ impl<C: CentsType> FiatPerBlockCumulativeWithSums<C> {
indexes: &indexes::Vecs,
cached_starts: &CachedWindowStarts,
) -> Result<Self> {
let base = FiatPerBlock::forced_import(db, name, version, indexes)?;
let block = FiatPerBlock::forced_import(db, name, version, indexes)?;
let cumulative = FiatPerBlock::forced_import(
db,
&format!("{name}_cumulative"),
@@ -37,7 +37,7 @@ impl<C: CentsType> FiatPerBlockCumulativeWithSums<C> {
cached_starts,
indexes,
);
Ok(Self { base, cumulative, sum })
Ok(Self { block, cumulative, sum })
}
pub(crate) fn compute_rest(&mut self, max_from: Height, exit: &Exit) -> Result<()>
@@ -47,7 +47,7 @@ impl<C: CentsType> FiatPerBlockCumulativeWithSums<C> {
self.cumulative
.cents
.height
.compute_cumulative(max_from, &self.base.cents.height, exit)?;
.compute_cumulative(max_from, &self.block.cents.height, exit)?;
Ok(())
}
}