global: snapshot

This commit is contained in:
nym21
2026-03-18 12:02:53 +01:00
parent 04ddc6223e
commit b397b811f9
46 changed files with 943 additions and 1197 deletions

View File

@@ -5,7 +5,10 @@ use vecdb::Database;
use super::Vecs;
use crate::{
indexes,
internal::{BlockCountTarget, CachedWindowStarts, PerBlockCumulativeWithSums, ConstantVecs},
internal::{
BlockCountTarget24h, BlockCountTarget1w, BlockCountTarget1m, BlockCountTarget1y,
CachedWindowStarts, PerBlockCumulativeWithSums, ConstantVecs, Windows,
},
};
impl Vecs {
@@ -16,11 +19,12 @@ impl Vecs {
cached_starts: &CachedWindowStarts,
) -> Result<Self> {
Ok(Self {
target: ConstantVecs::new::<BlockCountTarget>(
"block_count_target",
version,
indexes,
),
target: Windows {
_24h: ConstantVecs::new::<BlockCountTarget24h>("block_count_target_24h", version, indexes),
_1w: ConstantVecs::new::<BlockCountTarget1w>("block_count_target_1w", version, indexes),
_1m: ConstantVecs::new::<BlockCountTarget1m>("block_count_target_1m", version, indexes),
_1y: ConstantVecs::new::<BlockCountTarget1y>("block_count_target_1y", version, indexes),
},
total: PerBlockCumulativeWithSums::forced_import(
db,
"block_count",

View File

@@ -2,10 +2,10 @@ use brk_traversable::Traversable;
use brk_types::{StoredU32, StoredU64};
use vecdb::{Rw, StorageMode};
use crate::internal::{PerBlockCumulativeWithSums, ConstantVecs};
use crate::internal::{PerBlockCumulativeWithSums, ConstantVecs, Windows};
#[derive(Traversable)]
pub struct Vecs<M: StorageMode = Rw> {
pub target: ConstantVecs<StoredU64>,
pub target: Windows<ConstantVecs<StoredU64>>,
pub total: PerBlockCumulativeWithSums<StoredU32, StoredU64, M>,
}

View File

@@ -26,20 +26,12 @@ pub const DB_NAME: &str = "blocks";
pub(crate) const TARGET_BLOCKS_PER_DAY_F64: f64 = 144.0;
pub(crate) const TARGET_BLOCKS_PER_DAY_F32: f32 = 144.0;
pub(crate) const TARGET_BLOCKS_PER_MINUTE10: u64 = 1;
pub(crate) const TARGET_BLOCKS_PER_MINUTE30: u64 = 3;
pub(crate) const TARGET_BLOCKS_PER_HOUR1: u64 = 6;
pub(crate) const TARGET_BLOCKS_PER_HOUR4: u64 = 24;
pub(crate) const TARGET_BLOCKS_PER_HOUR12: u64 = 72;
pub(crate) const TARGET_BLOCKS_PER_DAY: u64 = 144;
pub(crate) const TARGET_BLOCKS_PER_DAY3: u64 = 3 * TARGET_BLOCKS_PER_DAY;
pub(crate) const TARGET_BLOCKS_PER_WEEK: u64 = 7 * TARGET_BLOCKS_PER_DAY;
pub(crate) const TARGET_BLOCKS_PER_MONTH: u64 = 30 * TARGET_BLOCKS_PER_DAY;
pub(crate) const TARGET_BLOCKS_PER_QUARTER: u64 = 3 * TARGET_BLOCKS_PER_MONTH;
pub(crate) const TARGET_BLOCKS_PER_SEMESTER: u64 = 2 * TARGET_BLOCKS_PER_QUARTER;
pub(crate) const TARGET_BLOCKS_PER_YEAR: u64 = 2 * TARGET_BLOCKS_PER_SEMESTER;
pub(crate) const TARGET_BLOCKS_PER_DECADE: u64 = 10 * TARGET_BLOCKS_PER_YEAR;
pub(crate) const TARGET_BLOCKS_PER_HALVING: u64 = 210_000;
pub(crate) const ONE_TERA_HASH: f64 = 1_000_000_000_000.0;
#[derive(Traversable)]

View File

@@ -12,16 +12,12 @@ impl Vecs {
starting_indexes: &Indexes,
exit: &Exit,
) -> Result<()> {
self.fullness
.compute(starting_indexes.height, exit, |vec| {
vec.compute_transform(
starting_indexes.height,
&indexer.vecs.blocks.weight,
|(h, weight, ..)| (h, BasisPoints16::from(weight.fullness())),
exit,
)?;
Ok(())
})?;
self.fullness.bps.compute_transform(
starting_indexes.height,
&indexer.vecs.blocks.weight,
|(h, weight, ..)| (h, BasisPoints16::from(weight.fullness())),
exit,
)?;
Ok(())
}

View File

@@ -6,7 +6,7 @@ use super::Vecs;
use crate::{
blocks::SizeVecs,
indexes,
internal::{CachedWindowStarts, LazyPerBlockRolling, PercentPerBlockRollingAverage, VBytesToWeight},
internal::{CachedWindowStarts, LazyPerBlockRolling, PercentVec, VBytesToWeight},
};
impl Vecs {
@@ -25,13 +25,7 @@ impl Vecs {
indexes,
);
let fullness = PercentPerBlockRollingAverage::forced_import(
db,
"block_fullness",
version,
indexes,
cached_starts,
)?;
let fullness = PercentVec::forced_import(db, "block_fullness", version)?;
Ok(Self { weight, fullness })
}

View File

@@ -2,10 +2,10 @@ use brk_traversable::Traversable;
use brk_types::{BasisPoints16, StoredU64, Weight};
use vecdb::{Rw, StorageMode};
use crate::internal::{LazyPerBlockRolling, PercentPerBlockRollingAverage};
use crate::internal::{LazyPerBlockRolling, PercentVec};
#[derive(Traversable)]
pub struct Vecs<M: StorageMode = Rw> {
pub weight: LazyPerBlockRolling<Weight, StoredU64>,
pub fullness: PercentPerBlockRollingAverage<BasisPoints16, M>,
pub fullness: PercentVec<BasisPoints16, M>,
}