global: MASSIVE snapshot

This commit is contained in:
nym21
2026-02-23 17:22:12 +01:00
parent be0d749f9c
commit 3b7aa8242a
703 changed files with 29130 additions and 30779 deletions
@@ -1,102 +1,61 @@
use brk_error::Result;
use brk_indexer::Indexer;
use brk_types::{StoredF32, StoredU32};
use vecdb::{Exit, TypedVecIterator};
use vecdb::Exit;
use super::super::TARGET_BLOCKS_PER_DAY_F32;
use super::Vecs;
use crate::{ComputeIndexes, indexes};
impl Vecs {
pub fn compute(
pub(crate) fn compute(
&mut self,
indexer: &Indexer,
indexes: &indexes::Vecs,
starting_indexes: &ComputeIndexes,
exit: &Exit,
) -> Result<()> {
// Derive dateindex/period stats from raw difficulty
self.raw.derive_from(
indexes,
starting_indexes,
// raw is fully lazy from indexer height source — no compute needed
// Compute difficulty as hash rate equivalent
let multiplier = 2.0_f64.powi(32) / 600.0;
self.as_hash.height.compute_transform(
starting_indexes.height,
&indexer.vecs.blocks.difficulty,
|(i, v, ..)| (i, StoredF32::from(*v * multiplier)),
exit,
)?;
// Compute difficulty as hash rate equivalent
self.as_hash
.compute_all(indexes, starting_indexes, exit, |v| {
let multiplier = 2.0_f64.powi(32) / 600.0;
v.compute_transform(
starting_indexes.height,
&indexer.vecs.blocks.difficulty,
|(i, v, ..)| (i, StoredF32::from(*v * multiplier)),
exit,
)?;
Ok(())
})?;
// Compute difficulty adjustment percentage
self.adjustment
.compute_all(indexes, starting_indexes, exit, |v| {
v.compute_percentage_change(
starting_indexes.height,
&indexer.vecs.blocks.difficulty,
1,
exit,
)?;
Ok(())
})?;
self.adjustment.height.compute_percentage_change(
starting_indexes.height,
&indexer.vecs.blocks.difficulty,
1,
exit,
)?;
// Compute epoch by dateindex
let mut height_to_difficultyepoch_iter = indexes.height.difficultyepoch.into_iter();
self.epoch.compute_all(starting_indexes, exit, |vec| {
let mut height_count_iter = indexes.dateindex.height_count.into_iter();
vec.compute_transform(
starting_indexes.dateindex,
&indexes.dateindex.first_height,
|(di, height, ..)| {
(
di,
height_to_difficultyepoch_iter
.get_unwrap(height + (*height_count_iter.get_unwrap(di) - 1)),
)
},
exit,
)?;
Ok(())
})?;
// Compute epoch by height
self.epoch.height.compute_transform(
starting_indexes.height,
&indexes.height.difficultyepoch,
|(h, epoch, ..)| (h, epoch),
exit,
)?;
// Compute blocks before next adjustment
self.blocks_before_next_adjustment.compute_all(
indexes,
starting_indexes,
self.blocks_before_next_adjustment.height.compute_transform(
starting_indexes.height,
&indexes.height.identity,
|(h, ..)| (h, StoredU32::from(h.left_before_next_diff_adj())),
exit,
|v| {
v.compute_transform(
starting_indexes.height,
&indexes.height.identity,
|(h, ..)| (h, StoredU32::from(h.left_before_next_diff_adj())),
exit,
)?;
Ok(())
},
)?;
// Compute days before next adjustment
self.days_before_next_adjustment.compute_all(
indexes,
starting_indexes,
self.days_before_next_adjustment.height.compute_transform(
starting_indexes.height,
&self.blocks_before_next_adjustment.height,
|(h, blocks, ..)| (h, (*blocks as f32 / TARGET_BLOCKS_PER_DAY_F32).into()),
exit,
|v| {
v.compute_transform(
starting_indexes.height,
&self.blocks_before_next_adjustment.height,
|(h, blocks, ..)| (h, (*blocks as f32 / TARGET_BLOCKS_PER_DAY_F32).into()),
exit,
)?;
Ok(())
},
)?;
Ok(())
@@ -1,19 +1,16 @@
use brk_error::Result;
use brk_indexer::Indexer;
use brk_types::Version;
use vecdb::{Database, IterableCloneableVec};
use vecdb::{Database, ReadableCloneableVec};
use super::Vecs;
use crate::{
indexes,
internal::{
ComputedFromHeightLast, ComputedFromHeightSum, ComputedFromDateLast,
ComputedHeightDerivedLast,
},
internal::{ComputedFromHeightLast, ComputedFromHeightSum, ComputedHeightDerivedLast},
};
impl Vecs {
pub fn forced_import(
pub(crate) fn forced_import(
db: &Database,
version: Version,
indexer: &Indexer,
@@ -23,15 +20,14 @@ impl Vecs {
Ok(Self {
raw: ComputedHeightDerivedLast::forced_import(
db,
"difficulty",
indexer.vecs.blocks.difficulty.boxed_clone(),
indexer.vecs.blocks.difficulty.read_only_boxed_clone(),
version,
indexes,
)?,
),
as_hash: ComputedFromHeightLast::forced_import(db, "difficulty_as_hash", version, indexes)?,
adjustment: ComputedFromHeightSum::forced_import(db, "difficulty_adjustment", version, indexes)?,
epoch: ComputedFromDateLast::forced_import(db, "difficultyepoch", version, indexes)?,
epoch: ComputedFromHeightLast::forced_import(db, "difficulty_epoch", version, indexes)?,
blocks_before_next_adjustment: ComputedFromHeightLast::forced_import(
db,
"blocks_before_next_difficulty_adjustment",
@@ -1,18 +1,17 @@
use brk_traversable::Traversable;
use brk_types::{DifficultyEpoch, StoredF32, StoredF64, StoredU32};
use vecdb::{Rw, StorageMode};
use crate::internal::{
ComputedFromHeightLast, ComputedFromHeightSum, ComputedFromDateLast, ComputedHeightDerivedLast,
};
use crate::internal::{ComputedFromHeightLast, ComputedFromHeightSum, ComputedHeightDerivedLast};
/// Difficulty metrics: raw difficulty, derived stats, adjustment, and countdown
#[derive(Clone, Traversable)]
pub struct Vecs {
/// Raw difficulty with dateindex/period stats - merges with indexer's raw
#[derive(Traversable)]
pub struct Vecs<M: StorageMode = Rw> {
/// Raw difficulty with day1/period stats - merges with indexer's raw
pub raw: ComputedHeightDerivedLast<StoredF64>,
pub as_hash: ComputedFromHeightLast<StoredF32>,
pub adjustment: ComputedFromHeightSum<StoredF32>,
pub epoch: ComputedFromDateLast<DifficultyEpoch>,
pub blocks_before_next_adjustment: ComputedFromHeightLast<StoredU32>,
pub days_before_next_adjustment: ComputedFromHeightLast<StoredF32>,
pub as_hash: ComputedFromHeightLast<StoredF32, M>,
pub adjustment: ComputedFromHeightSum<StoredF32, M>,
pub epoch: ComputedFromHeightLast<DifficultyEpoch, M>,
pub blocks_before_next_adjustment: ComputedFromHeightLast<StoredU32, M>,
pub days_before_next_adjustment: ComputedFromHeightLast<StoredF32, M>,
}