global: snapshot

This commit is contained in:
nym21
2026-03-05 16:11:25 +01:00
parent 6f2a87be4f
commit eedb8d22c1
61 changed files with 2035 additions and 2757 deletions
+9 -100
View File
@@ -2,14 +2,14 @@ use brk_error::Result;
use brk_traversable::Traversable;
use brk_types::{BasisPoints16, Height, Indexes, PoolSlug, StoredU32};
use vecdb::{
AnyVec, BinaryTransform, Database, Exit, ReadableVec, Rw, StorageMode, VecIndex, Version,
BinaryTransform, Database, Exit, ReadableVec, Rw, StorageMode, Version,
};
use crate::{
blocks, indexes,
internal::{
ComputedFromHeight, ComputedFromHeightCumulativeSum, MaskSats, PercentFromHeight,
PercentRollingWindows, RatioU32Bp16, RollingWindows, ValueFromHeightCumulativeSum,
ComputedFromHeightCumulativeSum, MaskSats, PercentFromHeight,
PercentRollingWindows, RatioU32Bp16, ValueFromHeightCumulativeSum,
},
mining, prices,
};
@@ -19,13 +19,9 @@ pub struct Vecs<M: StorageMode = Rw> {
slug: PoolSlug,
pub blocks_mined: ComputedFromHeightCumulativeSum<StoredU32, M>,
pub blocks_mined_sum: RollingWindows<StoredU32, M>,
pub subsidy: ValueFromHeightCumulativeSum<M>,
pub fee: ValueFromHeightCumulativeSum<M>,
pub coinbase: ValueFromHeightCumulativeSum<M>,
pub rewards: ValueFromHeightCumulativeSum<M>,
pub dominance: PercentFromHeight<BasisPoints16, M>,
pub dominance_rolling: PercentRollingWindows<BasisPoints16, M>,
pub blocks_since_last_mined: ComputedFromHeight<StoredU32, M>,
}
impl Vecs {
@@ -45,17 +41,8 @@ impl Vecs {
indexes,
)?;
let blocks_mined_sum =
RollingWindows::forced_import(db, &suffix("blocks_mined_sum"), version, indexes)?;
let subsidy =
ValueFromHeightCumulativeSum::forced_import(db, &suffix("subsidy"), version, indexes)?;
let fee =
ValueFromHeightCumulativeSum::forced_import(db, &suffix("fee"), version, indexes)?;
let coinbase =
ValueFromHeightCumulativeSum::forced_import(db, &suffix("coinbase"), version, indexes)?;
let rewards =
ValueFromHeightCumulativeSum::forced_import(db, &suffix("rewards"), version, indexes)?;
let dominance =
PercentFromHeight::forced_import(db, &suffix("dominance"), version, indexes)?;
@@ -67,16 +54,7 @@ impl Vecs {
dominance_rolling,
slug,
blocks_mined,
blocks_mined_sum,
coinbase,
subsidy,
fee,
blocks_since_last_mined: ComputedFromHeight::forced_import(
db,
&suffix("blocks_since_last_mined"),
version,
indexes,
)?,
rewards,
})
}
@@ -112,13 +90,6 @@ impl Vecs {
Ok(())
})?;
self.blocks_mined_sum.compute_rolling_sum(
starting_indexes.height,
&window_starts,
&self.blocks_mined.height,
exit,
)?;
self.dominance
.compute_binary::<StoredU32, StoredU32, RatioU32Bp16>(
starting_indexes.height,
@@ -131,7 +102,7 @@ impl Vecs {
.dominance_rolling
.as_mut_array()
.into_iter()
.zip(self.blocks_mined_sum.as_array())
.zip(self.blocks_mined.sum.as_array())
.zip(blocks.count.block_count_sum.as_array())
{
dom.compute_binary::<StoredU32, StoredU32, RatioU32Bp16>(
@@ -142,39 +113,7 @@ impl Vecs {
)?;
}
self.subsidy.compute(
starting_indexes.height,
&window_starts,
prices,
exit,
|vec| {
Ok(vec.compute_transform2(
starting_indexes.height,
&self.blocks_mined.height,
&mining.rewards.subsidy.base.sats.height,
|(h, mask, val, ..)| (h, MaskSats::apply(mask, val)),
exit,
)?)
},
)?;
self.fee.compute(
starting_indexes.height,
&window_starts,
prices,
exit,
|vec| {
Ok(vec.compute_transform2(
starting_indexes.height,
&self.blocks_mined.height,
&mining.rewards.fees.base.sats.height,
|(h, mask, val, ..)| (h, MaskSats::apply(mask, val)),
exit,
)?)
},
)?;
self.coinbase.compute(
self.rewards.compute(
starting_indexes.height,
&window_starts,
prices,
@@ -190,36 +129,6 @@ impl Vecs {
},
)?;
{
let resume_from = self
.blocks_since_last_mined
.height
.len()
.min(starting_indexes.height.to_usize());
let mut prev = if resume_from > 0 {
self.blocks_since_last_mined
.height
.collect_one_at(resume_from - 1)
.unwrap()
} else {
StoredU32::ZERO
};
self.blocks_since_last_mined.height.compute_transform(
starting_indexes.height,
&self.blocks_mined.height,
|(h, mined, ..)| {
let blocks = if mined.is_zero() {
prev + StoredU32::ONE
} else {
StoredU32::ZERO
};
prev = blocks;
(h, blocks)
},
exit,
)?;
}
Ok(())
}
}