global: snapshot pre cached change

This commit is contained in:
nym21
2026-04-10 10:27:07 +02:00
parent 95e5168244
commit 12aae503c9
8 changed files with 34 additions and 32 deletions

6
Cargo.lock generated
View File

@@ -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",

View File

@@ -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

View File

@@ -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,

View File

@@ -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(())

View File

@@ -14,17 +14,13 @@ use crate::parallel_import;
#[derive(Traversable)]
pub struct BlocksVecs<M: StorageMode = Rw> {
pub blockhash: M::Stored<BytesVec<Height, BlockHash>>,
#[traversable(skip)]
pub cached_blockhash: CachedVec<Height, BlockHash>,
pub blockhash: CachedVec<M::Stored<BytesVec<Height, BlockHash>>>,
pub coinbase_tag: M::Stored<BytesVec<Height, CoinbaseTag>>,
#[traversable(wrap = "difficulty", rename = "value")]
pub difficulty: M::Stored<PcoVec<Height, StoredF64>>,
/// Doesn't guarantee continuity due to possible reorgs and more generally the nature of mining
#[traversable(wrap = "time")]
pub timestamp: M::Stored<PcoVec<Height, Timestamp>>,
#[traversable(skip)]
pub cached_timestamp: CachedVec<Height, Timestamp>,
pub timestamp: CachedVec<M::Stored<PcoVec<Height, Timestamp>>>,
#[traversable(wrap = "size", rename = "base")]
pub total: M::Stored<PcoVec<Height, StoredU64>>,
#[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(&timestamp);
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<Item = &mut dyn AnyStoredVec> {
[
&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,

View File

@@ -60,7 +60,7 @@ impl Query {
let blockhash = indexer
.vecs
.blocks
.cached_blockhash
.blockhash
.collect_one(height)
.data()?;

View File

@@ -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))
}

View File

@@ -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<V: TypedVec + Traversable> Traversable for CachedVec<V> {
fn to_tree_node(&self) -> TreeNode {
self.inner.to_tree_node()
}
fn iter_any_exportable(&self) -> impl Iterator<Item = &dyn AnyExportableVec> {
self.inner.iter_any_exportable()
}
fn iter_any_visible(&self) -> impl Iterator<Item = &dyn AnyExportableVec> {
self.inner.iter_any_visible()
}
}
impl<T: Traversable + ?Sized> Traversable for Box<T> {
fn to_tree_node(&self) -> TreeNode {
(**self).to_tree_node()