mirror of
https://github.com/bitcoinresearchkit/brk.git
synced 2026-04-24 22:59:58 -07:00
global: big snapshot
This commit is contained in:
@@ -3,7 +3,7 @@ use brk_indexer::Indexer;
|
||||
use vecdb::Exit;
|
||||
|
||||
use super::Vecs;
|
||||
use crate::{indexes, ComputeIndexes};
|
||||
use crate::{ComputeIndexes, indexes};
|
||||
|
||||
impl Vecs {
|
||||
pub fn compute(
|
||||
@@ -13,14 +13,13 @@ impl Vecs {
|
||||
starting_indexes: &ComputeIndexes,
|
||||
exit: &Exit,
|
||||
) -> Result<()> {
|
||||
self.indexes_to_count.derive_from(
|
||||
self.derive_from(
|
||||
indexer,
|
||||
indexes,
|
||||
starting_indexes,
|
||||
&indexes.transaction.txindex_to_input_count,
|
||||
&indexes.txindex.input_count,
|
||||
exit,
|
||||
)?;
|
||||
|
||||
Ok(())
|
||||
}
|
||||
}
|
||||
|
||||
@@ -7,9 +7,11 @@ use crate::{indexes, internal::DerivedTxFull};
|
||||
|
||||
impl Vecs {
|
||||
pub fn forced_import(db: &Database, version: Version, indexes: &indexes::Vecs) -> Result<Self> {
|
||||
let indexes_to_count =
|
||||
DerivedTxFull::forced_import(db, "input_count", version, indexes)?;
|
||||
|
||||
Ok(Self { indexes_to_count })
|
||||
Ok(Self(DerivedTxFull::forced_import(
|
||||
db,
|
||||
"input_count",
|
||||
version,
|
||||
indexes,
|
||||
)?))
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,9 +1,8 @@
|
||||
use brk_traversable::Traversable;
|
||||
use brk_types::StoredU64;
|
||||
use derive_more::{Deref, DerefMut};
|
||||
|
||||
use crate::internal::DerivedTxFull;
|
||||
|
||||
#[derive(Clone, Traversable)]
|
||||
pub struct Vecs {
|
||||
pub indexes_to_count: DerivedTxFull<StoredU64>,
|
||||
}
|
||||
#[derive(Clone, Deref, DerefMut, Traversable)]
|
||||
pub struct Vecs(pub DerivedTxFull<StoredU64>);
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
use brk_error::Result;
|
||||
use brk_indexer::Indexer;
|
||||
use brk_types::{Sats, TxInIndex, TxIndex, TxOutIndex, Vout};
|
||||
use log::info;
|
||||
use tracing::info;
|
||||
use vecdb::{AnyStoredVec, AnyVec, Database, Exit, GenericStoredVec, TypedVecIterator, VecIndex};
|
||||
|
||||
use super::Vecs;
|
||||
@@ -18,21 +18,20 @@ impl Vecs {
|
||||
exit: &Exit,
|
||||
) -> Result<()> {
|
||||
// Validate computed versions against dependencies
|
||||
let dep_version = indexer.vecs.txin.txinindex_to_outpoint.version()
|
||||
+ indexer.vecs.tx.txindex_to_first_txoutindex.version()
|
||||
+ indexer.vecs.txout.txoutindex_to_value.version();
|
||||
self.txinindex_to_txoutindex
|
||||
.validate_computed_version_or_reset(dep_version)?;
|
||||
self.txinindex_to_value
|
||||
let dep_version = indexer.vecs.inputs.outpoint.version()
|
||||
+ indexer.vecs.transactions.first_txoutindex.version()
|
||||
+ indexer.vecs.outputs.value.version();
|
||||
self.txoutindex
|
||||
.validate_computed_version_or_reset(dep_version)?;
|
||||
self.value.validate_computed_version_or_reset(dep_version)?;
|
||||
|
||||
let target = indexer.vecs.txin.txinindex_to_outpoint.len();
|
||||
let target = indexer.vecs.inputs.outpoint.len();
|
||||
if target == 0 {
|
||||
return Ok(());
|
||||
}
|
||||
|
||||
let len1 = self.txinindex_to_txoutindex.len();
|
||||
let len2 = self.txinindex_to_value.len();
|
||||
let len1 = self.txoutindex.len();
|
||||
let len2 = self.value.len();
|
||||
let starting = starting_indexes.txinindex.to_usize();
|
||||
let min = len1.min(len2).min(starting);
|
||||
|
||||
@@ -40,9 +39,9 @@ impl Vecs {
|
||||
return Ok(());
|
||||
}
|
||||
|
||||
let mut outpoint_iter = indexer.vecs.txin.txinindex_to_outpoint.iter()?;
|
||||
let mut first_txoutindex_iter = indexer.vecs.tx.txindex_to_first_txoutindex.iter()?;
|
||||
let mut value_iter = indexer.vecs.txout.txoutindex_to_value.iter()?;
|
||||
let mut outpoint_iter = indexer.vecs.inputs.outpoint.iter()?;
|
||||
let mut first_txoutindex_iter = indexer.vecs.transactions.first_txoutindex.iter()?;
|
||||
let mut value_iter = indexer.vecs.outputs.value.iter()?;
|
||||
let mut entries: Vec<Entry> = Vec::with_capacity(BATCH_SIZE);
|
||||
|
||||
let mut batch_start = min;
|
||||
@@ -81,10 +80,9 @@ impl Vecs {
|
||||
|
||||
entries.sort_unstable_by_key(|e| e.txinindex);
|
||||
for entry in &entries {
|
||||
self.txinindex_to_txoutindex
|
||||
self.txoutindex
|
||||
.truncate_push(entry.txinindex, entry.txoutindex)?;
|
||||
self.txinindex_to_value
|
||||
.truncate_push(entry.txinindex, entry.value)?;
|
||||
self.value.truncate_push(entry.txinindex, entry.value)?;
|
||||
}
|
||||
|
||||
if batch_end < target {
|
||||
@@ -92,8 +90,8 @@ impl Vecs {
|
||||
}
|
||||
|
||||
let _lock = exit.lock();
|
||||
self.txinindex_to_txoutindex.write()?;
|
||||
self.txinindex_to_value.write()?;
|
||||
self.txoutindex.write()?;
|
||||
self.value.write()?;
|
||||
db.flush()?;
|
||||
|
||||
batch_start = batch_end;
|
||||
|
||||
@@ -7,8 +7,8 @@ use super::Vecs;
|
||||
impl Vecs {
|
||||
pub fn forced_import(db: &Database, version: Version) -> Result<Self> {
|
||||
Ok(Self {
|
||||
txinindex_to_txoutindex: PcoVec::forced_import(db, "txoutindex", version)?,
|
||||
txinindex_to_value: PcoVec::forced_import(db, "value", version)?,
|
||||
txoutindex: PcoVec::forced_import(db, "txoutindex", version)?,
|
||||
value: PcoVec::forced_import(db, "value", version)?,
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
@@ -4,6 +4,6 @@ use vecdb::PcoVec;
|
||||
|
||||
#[derive(Clone, Traversable)]
|
||||
pub struct Vecs {
|
||||
pub txinindex_to_txoutindex: PcoVec<TxInIndex, TxOutIndex>,
|
||||
pub txinindex_to_value: PcoVec<TxInIndex, Sats>,
|
||||
pub txoutindex: PcoVec<TxInIndex, TxOutIndex>,
|
||||
pub value: PcoVec<TxInIndex, Sats>,
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user