From 18d9c166d828b5306b1f03121c4bf1cf7220262d Mon Sep 17 00:00:00 2001 From: nym21 Date: Sat, 11 Apr 2026 22:11:48 +0200 Subject: [PATCH] computer: snap --- .../src/blocks/difficulty/compute.rs | 2 +- .../src/blocks/halving/compute.rs | 2 +- crates/brk_computer/src/indexes/day1.rs | 22 ----- crates/brk_computer/src/indexes/height.rs | 2 - crates/brk_computer/src/indexes/mod.rs | 89 +++++-------------- crates/brk_computer/src/indexes/resolution.rs | 40 +-------- .../src/internal/containers/constant.rs | 44 +++++---- .../per_block/computed/resolutions.rs | 8 +- 8 files changed, 57 insertions(+), 152 deletions(-) delete mode 100644 crates/brk_computer/src/indexes/day1.rs diff --git a/crates/brk_computer/src/blocks/difficulty/compute.rs b/crates/brk_computer/src/blocks/difficulty/compute.rs index 5c213ae15..af1650e1a 100644 --- a/crates/brk_computer/src/blocks/difficulty/compute.rs +++ b/crates/brk_computer/src/blocks/difficulty/compute.rs @@ -30,7 +30,7 @@ impl Vecs { self.blocks_to_retarget.height.compute_transform( starting_indexes.height, - &indexes.height.identity, + &indexes.height.epoch, |(h, ..)| (h, StoredU32::from(h.left_before_next_diff_adj())), exit, )?; diff --git a/crates/brk_computer/src/blocks/halving/compute.rs b/crates/brk_computer/src/blocks/halving/compute.rs index 235efcf16..93914b9af 100644 --- a/crates/brk_computer/src/blocks/halving/compute.rs +++ b/crates/brk_computer/src/blocks/halving/compute.rs @@ -21,7 +21,7 @@ impl Vecs { self.blocks_to_halving.height.compute_transform( starting_indexes.height, - &indexes.height.identity, + &indexes.height.halving, |(h, ..)| (h, StoredU32::from(h.left_before_next_halving())), exit, )?; diff --git a/crates/brk_computer/src/indexes/day1.rs b/crates/brk_computer/src/indexes/day1.rs deleted file mode 100644 index c31ba3861..000000000 --- a/crates/brk_computer/src/indexes/day1.rs +++ /dev/null @@ -1,22 +0,0 @@ -use brk_traversable::Traversable; -use brk_types::{Date, Day1, Height, Version}; -use vecdb::{CachedVec, Database, EagerVec, ImportableVec, PcoVec, Rw, StorageMode}; - -use brk_error::Result; - -#[derive(Traversable)] -pub struct Vecs { - pub identity: M::Stored>>, - pub date: M::Stored>>, - pub first_height: CachedVec>>>, -} - -impl Vecs { - pub(crate) fn forced_import(db: &Database, version: Version) -> Result { - Ok(Self { - identity: EagerVec::forced_import(db, "day1_index", version)?, - date: EagerVec::forced_import(db, "date", version + Version::ONE)?, - first_height: CachedVec::wrap(EagerVec::forced_import(db, "first_height", version)?), - }) - } -} diff --git a/crates/brk_computer/src/indexes/height.rs b/crates/brk_computer/src/indexes/height.rs index b7a05c50b..c234ca772 100644 --- a/crates/brk_computer/src/indexes/height.rs +++ b/crates/brk_computer/src/indexes/height.rs @@ -9,7 +9,6 @@ use brk_error::Result; #[derive(Traversable)] pub struct Vecs { - pub identity: M::Stored>>, pub minute10: M::Stored>>, pub minute30: M::Stored>>, pub hour1: M::Stored>>, @@ -31,7 +30,6 @@ pub struct Vecs { impl Vecs { pub(crate) fn forced_import(db: &Database, version: Version) -> Result { Ok(Self { - identity: EagerVec::forced_import(db, "height", version)?, minute10: EagerVec::forced_import(db, "minute10", version)?, minute30: EagerVec::forced_import(db, "minute30", version)?, hour1: EagerVec::forced_import(db, "hour1", version)?, diff --git a/crates/brk_computer/src/indexes/mod.rs b/crates/brk_computer/src/indexes/mod.rs index b8408ab0c..a1ce10bad 100644 --- a/crates/brk_computer/src/indexes/mod.rs +++ b/crates/brk_computer/src/indexes/mod.rs @@ -1,5 +1,4 @@ mod addr; -mod day1; mod height; mod resolution; pub mod timestamp; @@ -22,9 +21,8 @@ use vecdb::{Database, Exit, ReadableVec, Rw, StorageMode}; use crate::internal::db_utils::{finalize_db, open_db}; pub use addr::Vecs as AddrVecs; -pub use day1::Vecs as Day1Vecs; pub use height::Vecs as HeightVecs; -pub use resolution::{CachedResolutionVecs, DatedResolutionVecs, ResolutionVecs}; +pub use resolution::{DatedResolutionVecs, ResolutionVecs}; pub use timestamp::Timestamps; pub use tx_heights::TxHeights; pub use tx_index::Vecs as TxIndexVecs; @@ -36,9 +34,10 @@ pub type Minute30Vecs = ResolutionVecs; pub type Hour1Vecs = ResolutionVecs; pub type Hour4Vecs = ResolutionVecs; pub type Hour12Vecs = ResolutionVecs; -pub type Day3Vecs = ResolutionVecs; -pub type EpochVecs = CachedResolutionVecs; -pub type HalvingVecs = CachedResolutionVecs; +pub type Day1Vecs = DatedResolutionVecs; +pub type Day3Vecs = DatedResolutionVecs; +pub type EpochVecs = ResolutionVecs; +pub type HalvingVecs = ResolutionVecs; pub type Week1Vecs = DatedResolutionVecs; pub type Month1Vecs = DatedResolutionVecs; pub type Month3Vecs = DatedResolutionVecs; @@ -88,21 +87,21 @@ impl Vecs { let addr = AddrVecs::forced_import(version, indexer); let height = HeightVecs::forced_import(&db, version)?; - let epoch = CachedResolutionVecs::forced_import(&db, "epoch", version)?; - let halving = CachedResolutionVecs::forced_import(&db, "halving", version)?; - let minute10 = ResolutionVecs::forced_import(&db, "minute10_index", version)?; - let minute30 = ResolutionVecs::forced_import(&db, "minute30_index", version)?; - let hour1 = ResolutionVecs::forced_import(&db, "hour1_index", version)?; - let hour4 = ResolutionVecs::forced_import(&db, "hour4_index", version)?; - let hour12 = ResolutionVecs::forced_import(&db, "hour12_index", version)?; + let epoch = ResolutionVecs::forced_import(&db, version)?; + let halving = ResolutionVecs::forced_import(&db, version)?; + let minute10 = ResolutionVecs::forced_import(&db, version)?; + let minute30 = ResolutionVecs::forced_import(&db, version)?; + let hour1 = ResolutionVecs::forced_import(&db, version)?; + let hour4 = ResolutionVecs::forced_import(&db, version)?; + let hour12 = ResolutionVecs::forced_import(&db, version)?; let day1 = Day1Vecs::forced_import(&db, version)?; - let day3 = ResolutionVecs::forced_import(&db, "day3_index", version)?; - let week1 = DatedResolutionVecs::forced_import(&db, "week1_index", version)?; - let month1 = DatedResolutionVecs::forced_import(&db, "month1_index", version)?; - let month3 = DatedResolutionVecs::forced_import(&db, "month3_index", version)?; - let month6 = DatedResolutionVecs::forced_import(&db, "month6_index", version)?; - let year1 = DatedResolutionVecs::forced_import(&db, "year1_index", version)?; - let year10 = DatedResolutionVecs::forced_import(&db, "year10_index", version)?; + let day3 = DatedResolutionVecs::forced_import(&db, version)?; + let week1 = DatedResolutionVecs::forced_import(&db, version)?; + let month1 = DatedResolutionVecs::forced_import(&db, version)?; + let month3 = DatedResolutionVecs::forced_import(&db, version)?; + let month6 = DatedResolutionVecs::forced_import(&db, version)?; + let year1 = DatedResolutionVecs::forced_import(&db, version)?; + let year10 = DatedResolutionVecs::forced_import(&db, version)?; let tx_index = TxIndexVecs::forced_import(&db, version, indexer)?; let txin_index = TxInIndexVecs::forced_import(version, indexer); let txout_index = TxOutIndexVecs::forced_import(version, indexer); @@ -226,11 +225,6 @@ impl Vecs { &indexer.vecs.transactions.txid, exit, )?; - self.height.identity.compute_from_index( - starting_indexes.height, - &indexer.vecs.blocks.weight, - exit, - )?; Ok(()) } @@ -286,7 +280,7 @@ impl Vecs { starting_day1 }; - self.compute_epoch(indexer, starting_indexes, prev_height, exit)?; + self.compute_epoch(indexer, starting_indexes, exit)?; self.height.week1.compute_transform( starting_indexes.height, @@ -332,15 +326,8 @@ impl Vecs { &mut self, indexer: &Indexer, starting_indexes: &Indexes, - prev_height: Height, exit: &Exit, ) -> Result<()> { - let starting_difficulty = self - .height - .epoch - .collect_one(prev_height) - .unwrap_or_default(); - self.height.epoch.compute_from_index( starting_indexes.height, &indexer.vecs.blocks.weight, @@ -351,16 +338,6 @@ impl Vecs { &self.height.epoch, exit, )?; - self.epoch.identity.inner.compute_from_index( - starting_difficulty, - &self.epoch.first_height, - exit, - )?; - let starting_halving = self - .height - .halving - .collect_one(prev_height) - .unwrap_or_default(); self.height.halving.compute_from_index( starting_indexes.height, @@ -372,12 +349,6 @@ impl Vecs { &self.height.halving, exit, )?; - self.halving.identity.inner.compute_from_index( - starting_halving, - &self.halving.first_height, - exit, - )?; - Ok(()) } @@ -395,14 +366,6 @@ impl Vecs { &self.height.$period, exit, )?; - self.$period.identity.compute_from_index( - self.height - .$period - .collect_one(prev_height) - .unwrap_or_default(), - &self.$period.first_height, - exit, - )?; }; } @@ -411,19 +374,15 @@ impl Vecs { basic_period!(hour1); basic_period!(hour4); basic_period!(hour12); - basic_period!(day3); self.day1.first_height.inner.compute_first_per_index( starting_indexes.height, &self.height.day1, exit, )?; - self.day1 - .identity - .compute_from_index(starting_day1, &self.day1.first_height, exit)?; self.day1.date.compute_transform( starting_day1, - &self.day1.identity, + &self.day1.first_height, |(di, ..)| (di, Date::from(di)), exit, )?; @@ -441,11 +400,6 @@ impl Vecs { .$period .collect_one(prev_height) .unwrap_or_default(); - self.$period.identity.compute_from_index( - start, - &self.$period.first_height, - exit, - )?; self.$period.date.compute_transform( start, &self.$period.first_height, @@ -455,6 +409,7 @@ impl Vecs { }}; } + dated_period!(day3); dated_period!(week1); dated_period!(month1); dated_period!(month3); diff --git a/crates/brk_computer/src/indexes/resolution.rs b/crates/brk_computer/src/indexes/resolution.rs index 5e5bae8e3..e5a2e1443 100644 --- a/crates/brk_computer/src/indexes/resolution.rs +++ b/crates/brk_computer/src/indexes/resolution.rs @@ -5,62 +5,30 @@ use vecdb::{ CachedVec, Database, EagerVec, ImportableVec, PcoVec, PcoVecValue, Rw, StorageMode, VecIndex, }; -/// Resolution with identity mapping and cached first-height lookup. +/// Resolution with cached first-height lookup. #[derive(Traversable)] pub struct ResolutionVecs { - pub identity: M::Stored>>, pub first_height: CachedVec>>>, } -/// Resolution with both identity and first-height cached (halving, epoch). -#[derive(Traversable)] -pub struct CachedResolutionVecs { - pub identity: CachedVec>>>, - pub first_height: CachedVec>>>, -} - -impl CachedResolutionVecs { - pub(crate) fn forced_import( - db: &Database, - identity_name: &str, - version: Version, - ) -> Result { - Ok(Self { - identity: CachedVec::wrap(EagerVec::forced_import(db, identity_name, version)?), - first_height: CachedVec::wrap(EagerVec::forced_import(db, "first_height", version)?), - }) - } -} - impl ResolutionVecs { - pub(crate) fn forced_import( - db: &Database, - identity_name: &str, - version: Version, - ) -> Result { + pub(crate) fn forced_import(db: &Database, version: Version) -> Result { Ok(Self { - identity: EagerVec::forced_import(db, identity_name, version)?, first_height: CachedVec::wrap(EagerVec::forced_import(db, "first_height", version)?), }) } } -/// Resolution with identity, date, and cached first-height lookup. +/// Resolution with date and cached first-height lookup. #[derive(Traversable)] pub struct DatedResolutionVecs { - pub identity: M::Stored>>, pub date: M::Stored>>, pub first_height: CachedVec>>>, } impl DatedResolutionVecs { - pub(crate) fn forced_import( - db: &Database, - identity_name: &str, - version: Version, - ) -> Result { + pub(crate) fn forced_import(db: &Database, version: Version) -> Result { Ok(Self { - identity: EagerVec::forced_import(db, identity_name, version)?, date: EagerVec::forced_import(db, "date", version)?, first_height: CachedVec::wrap(EagerVec::forced_import(db, "first_height", version)?), }) diff --git a/crates/brk_computer/src/internal/containers/constant.rs b/crates/brk_computer/src/internal/containers/constant.rs index 28d1d4761..269b2b643 100644 --- a/crates/brk_computer/src/internal/containers/constant.rs +++ b/crates/brk_computer/src/internal/containers/constant.rs @@ -15,22 +15,22 @@ pub struct ConstantVecs where T: VecValue + Formattable + Serialize + JsonSchema, { - pub height: LazyVecFrom1, - pub minute10: LazyVecFrom1, - pub minute30: LazyVecFrom1, - pub hour1: LazyVecFrom1, - pub hour4: LazyVecFrom1, - pub hour12: LazyVecFrom1, - pub day1: LazyVecFrom1, - pub day3: LazyVecFrom1, - pub week1: LazyVecFrom1, - pub month1: LazyVecFrom1, - pub month3: LazyVecFrom1, - pub month6: LazyVecFrom1, - pub year1: LazyVecFrom1, - pub year10: LazyVecFrom1, - pub halving: LazyVecFrom1, - pub epoch: LazyVecFrom1, + pub height: LazyVecFrom1, + pub minute10: LazyVecFrom1, + pub minute30: LazyVecFrom1, + pub hour1: LazyVecFrom1, + pub hour4: LazyVecFrom1, + pub hour12: LazyVecFrom1, + pub day1: LazyVecFrom1, + pub day3: LazyVecFrom1, + pub week1: LazyVecFrom1, + pub month1: LazyVecFrom1, + pub month3: LazyVecFrom1, + pub month6: LazyVecFrom1, + pub year1: LazyVecFrom1, + pub year10: LazyVecFrom1, + pub halving: LazyVecFrom1, + pub epoch: LazyVecFrom1, } impl ConstantVecs { @@ -55,16 +55,22 @@ impl ConstantVecs { { macro_rules! period { ($idx:ident) => { - LazyVecFrom1::transformed::( + LazyVecFrom1::init( name, version, - indexes.$idx.identity.read_only_boxed_clone(), + indexes.$idx.first_height.read_only_boxed_clone(), + |idx, _: Height| F::apply(idx), ) }; } Self { - height: period!(height), + height: LazyVecFrom1::init( + name, + version, + indexes.height.minute10.read_only_boxed_clone(), + |idx, _| F::apply(idx), + ), minute10: period!(minute10), minute30: period!(minute30), hour1: period!(hour1), diff --git a/crates/brk_computer/src/internal/per_block/computed/resolutions.rs b/crates/brk_computer/src/internal/per_block/computed/resolutions.rs index c679e0c24..13ff47782 100644 --- a/crates/brk_computer/src/internal/per_block/computed/resolutions.rs +++ b/crates/brk_computer/src/internal/per_block/computed/resolutions.rs @@ -81,8 +81,8 @@ pub struct Resolutions( LazyAggVec, Height, Height, T>, LazyAggVec, Height, Height, T>, LazyAggVec, Height, Height, T>, - LazyAggVec>, - LazyAggVec>, + LazyAggVec>, + LazyAggVec>, >, ) where @@ -142,8 +142,8 @@ where month6: res!(indexes.month6.first_height), year1: res!(indexes.year1.first_height), year10: res!(indexes.year10.first_height), - halving: res!(indexes.halving.identity), - epoch: res!(indexes.epoch.identity), + halving: res!(indexes.halving.first_height), + epoch: res!(indexes.epoch.first_height), }) } }