From 12aae503c95d592d2ebaadd443c5190c97e2c96c Mon Sep 17 00:00:00 2001 From: nym21 Date: Fri, 10 Apr 2026 10:27:07 +0200 Subject: [PATCH] global: snapshot pre cached change --- Cargo.lock | 6 ----- Cargo.toml | 4 ++-- .../src/internal/per_block/rolling/windows.rs | 4 +--- crates/brk_indexer/src/processor/metadata.rs | 2 ++ crates/brk_indexer/src/vecs/blocks.rs | 23 +++++++------------ crates/brk_query/src/impl/block/timestamp.rs | 2 +- crates/brk_query/src/impl/tx.rs | 4 ++-- crates/brk_traversable/src/lib.rs | 21 ++++++++++++++--- 8 files changed, 34 insertions(+), 32 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 1b8b5c2e5..67d7d5f52 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -2544,8 +2544,6 @@ dependencies = [ [[package]] name = "rawdb" version = "0.9.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f23b5d5fae99af33e8d0c82763b890c469dcf18b48600ed78b0d70fce4dbe189" dependencies = [ "libc", "log", @@ -3438,8 +3436,6 @@ checksum = "8f54a172d0620933a27a4360d3db3e2ae0dd6cceae9730751a036bbf182c4b23" [[package]] name = "vecdb" version = "0.9.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a5fe60956ddba8c141ca8020aaf5bea55683475b83d19006c5f44b85c71bf974" dependencies = [ "itoa", "libc", @@ -3461,8 +3457,6 @@ dependencies = [ [[package]] name = "vecdb_derive" version = "0.9.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "789897c1999d5d74f977020ad3d449846df046194103a4afcbac6d49baeaaffc" dependencies = [ "quote", "syn", diff --git a/Cargo.toml b/Cargo.toml index d9811a2ff..5ed589e4a 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -87,8 +87,8 @@ tower-http = { version = "0.6.8", features = ["catch-panic", "compression-br", " tower-layer = "0.3" tracing = { version = "0.1", default-features = false, features = ["std"] } ureq = { version = "3.3.0", features = ["json"] } -vecdb = { version = "0.9.3", features = ["derive", "serde_json", "pco", "schemars"] } -# vecdb = { path = "../anydb/crates/vecdb", features = ["derive", "serde_json", "pco", "schemars"] } +# vecdb = { version = "0.9.3", features = ["derive", "serde_json", "pco", "schemars"] } +vecdb = { path = "../anydb/crates/vecdb", features = ["derive", "serde_json", "pco", "schemars"] } [workspace.metadata.release] shared-version = true diff --git a/crates/brk_computer/src/internal/per_block/rolling/windows.rs b/crates/brk_computer/src/internal/per_block/rolling/windows.rs index b0f7a6942..df527f0ee 100644 --- a/crates/brk_computer/src/internal/per_block/rolling/windows.rs +++ b/crates/brk_computer/src/internal/per_block/rolling/windows.rs @@ -9,9 +9,7 @@ use brk_traversable::Traversable; use brk_types::{Height, Version}; use derive_more::{Deref, DerefMut}; use schemars::JsonSchema; -use vecdb::{Database, EagerVec, PcoVec, Rw, StorageMode}; - -use vecdb::CachedVec; +use vecdb::{CachedVec, Database, EagerVec, PcoVec, Rw, StorageMode}; use crate::{ indexes, diff --git a/crates/brk_indexer/src/processor/metadata.rs b/crates/brk_indexer/src/processor/metadata.rs index a96f6f91d..33f628695 100644 --- a/crates/brk_indexer/src/processor/metadata.rs +++ b/crates/brk_indexer/src/processor/metadata.rs @@ -31,6 +31,7 @@ impl BlockProcessor<'_> { self.vecs .blocks .blockhash + .inner .checked_push(height, blockhash.clone())?; self.vecs .blocks @@ -43,6 +44,7 @@ impl BlockProcessor<'_> { self.vecs .blocks .timestamp + .inner .checked_push(height, Timestamp::from(self.block.header.time))?; Ok(()) diff --git a/crates/brk_indexer/src/vecs/blocks.rs b/crates/brk_indexer/src/vecs/blocks.rs index c6274ed4e..c4df740a9 100644 --- a/crates/brk_indexer/src/vecs/blocks.rs +++ b/crates/brk_indexer/src/vecs/blocks.rs @@ -14,17 +14,13 @@ use crate::parallel_import; #[derive(Traversable)] pub struct BlocksVecs { - pub blockhash: M::Stored>, - #[traversable(skip)] - pub cached_blockhash: CachedVec, + pub blockhash: CachedVec>>, pub coinbase_tag: M::Stored>, #[traversable(wrap = "difficulty", rename = "value")] pub difficulty: M::Stored>, /// Doesn't guarantee continuity due to possible reorgs and more generally the nature of mining #[traversable(wrap = "time")] - pub timestamp: M::Stored>, - #[traversable(skip)] - pub cached_timestamp: CachedVec, + pub timestamp: CachedVec>>, #[traversable(wrap = "size", rename = "base")] pub total: M::Stored>, #[traversable(wrap = "weight", rename = "base")] @@ -61,16 +57,11 @@ impl BlocksVecs { segwit_size = PcoVec::forced_import(db, "segwit_size", version), segwit_weight = PcoVec::forced_import(db, "segwit_weight", version), }; - let cached_blockhash = CachedVec::new(&blockhash); - let cached_timestamp = CachedVec::new(×tamp); - Ok(Self { - blockhash, - cached_blockhash, + blockhash: CachedVec::wrap(blockhash), coinbase_tag, difficulty, - timestamp, - cached_timestamp, + timestamp: CachedVec::wrap(timestamp), total, weight, position, @@ -82,12 +73,14 @@ impl BlocksVecs { pub fn truncate(&mut self, height: Height, stamp: Stamp) -> Result<()> { self.blockhash + .inner .truncate_if_needed_with_stamp(height, stamp)?; self.coinbase_tag .truncate_if_needed_with_stamp(height, stamp)?; self.difficulty .truncate_if_needed_with_stamp(height, stamp)?; self.timestamp + .inner .truncate_if_needed_with_stamp(height, stamp)?; self.total.truncate_if_needed_with_stamp(height, stamp)?; self.weight.truncate_if_needed_with_stamp(height, stamp)?; @@ -103,10 +96,10 @@ impl BlocksVecs { pub fn par_iter_mut_any(&mut self) -> impl ParallelIterator { [ - &mut self.blockhash as &mut dyn AnyStoredVec, + &mut self.blockhash.inner as &mut dyn AnyStoredVec, &mut self.coinbase_tag, &mut self.difficulty, - &mut self.timestamp, + &mut self.timestamp.inner, &mut self.total, &mut self.weight, &mut self.position, diff --git a/crates/brk_query/src/impl/block/timestamp.rs b/crates/brk_query/src/impl/block/timestamp.rs index dd77f4595..b22f2be59 100644 --- a/crates/brk_query/src/impl/block/timestamp.rs +++ b/crates/brk_query/src/impl/block/timestamp.rs @@ -60,7 +60,7 @@ impl Query { let blockhash = indexer .vecs .blocks - .cached_blockhash + .blockhash .collect_one(height) .data()?; diff --git a/crates/brk_query/src/impl/tx.rs b/crates/brk_query/src/impl/tx.rs index 6fe03f6bf..c1b6a0dd8 100644 --- a/crates/brk_query/src/impl/tx.rs +++ b/crates/brk_query/src/impl/tx.rs @@ -65,8 +65,8 @@ impl Query { #[inline] pub(crate) fn block_hash_and_time(&self, height: Height) -> Result<(BlockHash, Timestamp)> { let indexer = self.indexer(); - let hash = indexer.vecs.blocks.cached_blockhash.collect_one(height).data()?; - let time = indexer.vecs.blocks.cached_timestamp.collect_one(height).data()?; + let hash = indexer.vecs.blocks.blockhash.collect_one(height).data()?; + let time = indexer.vecs.blocks.timestamp.collect_one(height).data()?; Ok((hash, time)) } diff --git a/crates/brk_traversable/src/lib.rs b/crates/brk_traversable/src/lib.rs index 355e78746..2ddd41501 100644 --- a/crates/brk_traversable/src/lib.rs +++ b/crates/brk_traversable/src/lib.rs @@ -8,9 +8,10 @@ pub use brk_traversable_derive::Traversable; use schemars::JsonSchema; use serde::Serialize; use vecdb::{ - AggFold, AnyExportableVec, AnyVec, BytesVec, BytesVecValue, CompressionStrategy, DeltaOp, - EagerVec, Formattable, LazyAggVec, LazyDeltaVec, LazyVecFrom1, LazyVecFrom2, LazyVecFrom3, - RawStrategy, ReadOnlyCompressedVec, ReadOnlyRawVec, StoredVec, VecIndex, VecValue, + AggFold, AnyExportableVec, AnyVec, BytesVec, BytesVecValue, CachedVec, CompressionStrategy, + DeltaOp, EagerVec, Formattable, LazyAggVec, LazyDeltaVec, LazyVecFrom1, LazyVecFrom2, + LazyVecFrom3, RawStrategy, ReadOnlyCompressedVec, ReadOnlyRawVec, StoredVec, TypedVec, + VecIndex, VecValue, }; pub trait Traversable { @@ -256,6 +257,20 @@ where } } +impl Traversable for CachedVec { + fn to_tree_node(&self) -> TreeNode { + self.inner.to_tree_node() + } + + fn iter_any_exportable(&self) -> impl Iterator { + self.inner.iter_any_exportable() + } + + fn iter_any_visible(&self) -> impl Iterator { + self.inner.iter_any_visible() + } +} + impl Traversable for Box { fn to_tree_node(&self) -> TreeNode { (**self).to_tree_node()