global: snapshot

This commit is contained in:
nym21
2026-03-04 17:10:15 +01:00
parent 891f0dad9e
commit 9e23de4ba1
313 changed files with 9087 additions and 4918 deletions
@@ -5,7 +5,7 @@ use vecdb::Database;
use super::Vecs;
use crate::{
indexes,
internal::{ComputedFromHeightAggregated, ComputedFromHeight},
internal::{ComputedFromHeight, ComputedFromHeightAggregated},
};
impl Vecs {
@@ -2,7 +2,7 @@ use brk_traversable::Traversable;
use brk_types::StoredU64;
use vecdb::{Rw, StorageMode};
use crate::internal::{ComputedFromHeightAggregated, ComputedFromHeight};
use crate::internal::{ComputedFromHeight, ComputedFromHeightAggregated};
#[derive(Traversable)]
pub struct Vecs<M: StorageMode = Rw> {
+7 -14
View File
@@ -1,12 +1,14 @@
use std::path::Path;
use brk_error::Result;
use brk_traversable::Traversable;
use brk_types::Version;
use vecdb::{Database, PAGE_SIZE};
use crate::{
indexes,
internal::{finalize_db, open_db},
};
use super::{CountVecs, SpentVecs, Vecs};
use crate::indexes;
impl Vecs {
pub(crate) fn forced_import(
@@ -14,23 +16,14 @@ impl Vecs {
parent_version: Version,
indexes: &indexes::Vecs,
) -> Result<Self> {
let db = Database::open(&parent_path.join(super::DB_NAME))?;
db.set_min_len(PAGE_SIZE * 10_000_000)?;
let db = open_db(parent_path, super::DB_NAME, 10_000_000)?;
let version = parent_version;
let spent = SpentVecs::forced_import(&db, version)?;
let count = CountVecs::forced_import(&db, version, indexes)?;
let this = Self { db, spent, count };
this.db.retain_regions(
this.iter_any_exportable()
.flat_map(|v| v.region_names())
.collect(),
)?;
this.db.compact()?;
finalize_db(&this.db, &this)?;
Ok(this)
}
}
@@ -2,9 +2,7 @@ use brk_error::Result;
use brk_indexer::Indexer;
use brk_types::{Height, Indexes, TxInIndex, TxOutIndex};
use tracing::info;
use vecdb::{
AnyStoredVec, AnyVec, Database, Exit, WritableVec, ReadableVec, Stamp, VecIndex,
};
use vecdb::{AnyStoredVec, AnyVec, Database, Exit, ReadableVec, Stamp, VecIndex, WritableVec};
use super::Vecs;
use crate::inputs;
@@ -59,8 +57,8 @@ impl Vecs {
// Only collect from min_height onward (not from 0)
let offset = min_height.to_usize();
let first_txoutindex_data = first_txoutindex_vec
.collect_range_at(offset, target_height.to_usize() + 1);
let first_txoutindex_data =
first_txoutindex_vec.collect_range_at(offset, target_height.to_usize() + 1);
let first_txinindex_data = indexer
.vecs
.inputs
@@ -91,7 +89,8 @@ impl Vecs {
.fill_to(batch_txoutindex, TxInIndex::UNSPENT)?;
// Get txin range for this height batch
let txin_start = first_txinindex_data[batch_start_height.to_usize() - offset].to_usize();
let txin_start =
first_txinindex_data[batch_start_height.to_usize() - offset].to_usize();
let txin_end = if batch_end_height >= target_height {
inputs.spent.txoutindex.len()
} else {
@@ -101,12 +100,16 @@ impl Vecs {
// Stream txins directly into pairs — avoids intermediate Vec allocation
pairs.clear();
let mut j = txin_start;
txinindex_to_txoutindex.for_each_range_at(txin_start, txin_end, |txoutindex: TxOutIndex| {
if !txoutindex.is_coinbase() {
pairs.push((txoutindex, TxInIndex::from(j)));
}
j += 1;
});
txinindex_to_txoutindex.for_each_range_at(
txin_start,
txin_end,
|txoutindex: TxOutIndex| {
if !txoutindex.is_coinbase() {
pairs.push((txoutindex, TxInIndex::from(j)));
}
j += 1;
},
);
pairs.sort_unstable_by_key(|(txoutindex, _)| *txoutindex);