mirror of
https://github.com/bitcoinresearchkit/brk.git
synced 2026-04-29 00:59:58 -07:00
global: big snapshot
This commit is contained in:
@@ -13,21 +13,11 @@ impl Vecs {
|
||||
starting_indexes: &ComputeIndexes,
|
||||
exit: &Exit,
|
||||
) -> Result<()> {
|
||||
self.indexes_to_tx_weight.derive_from(
|
||||
indexer,
|
||||
indexes,
|
||||
starting_indexes,
|
||||
&self.txindex_to_weight,
|
||||
exit,
|
||||
)?;
|
||||
self.weight
|
||||
.derive_from(indexer, indexes, starting_indexes, exit)?;
|
||||
|
||||
self.indexes_to_tx_vsize.derive_from(
|
||||
indexer,
|
||||
indexes,
|
||||
starting_indexes,
|
||||
&self.txindex_to_vsize,
|
||||
exit,
|
||||
)?;
|
||||
self.vsize
|
||||
.derive_from(indexer, indexes, starting_indexes, exit)?;
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
||||
@@ -4,7 +4,7 @@ use brk_types::{TxIndex, VSize, Version, Weight};
|
||||
use vecdb::{Database, IterableCloneableVec, LazyVecFrom2, VecIndex};
|
||||
|
||||
use super::Vecs;
|
||||
use crate::{indexes, internal::ComputedTxDistribution};
|
||||
use crate::{indexes, internal::LazyTxDistribution};
|
||||
|
||||
impl Vecs {
|
||||
pub fn forced_import(
|
||||
@@ -16,43 +16,46 @@ impl Vecs {
|
||||
let txindex_to_weight = LazyVecFrom2::init(
|
||||
"weight",
|
||||
version,
|
||||
indexer.vecs.tx.txindex_to_base_size.boxed_clone(),
|
||||
indexer.vecs.tx.txindex_to_total_size.boxed_clone(),
|
||||
|index: TxIndex, txindex_to_base_size_iter, txindex_to_total_size_iter| {
|
||||
indexer.vecs.transactions.base_size.boxed_clone(),
|
||||
indexer.vecs.transactions.total_size.boxed_clone(),
|
||||
|index: TxIndex, base_size_iter, total_size_iter| {
|
||||
let index = index.to_usize();
|
||||
txindex_to_base_size_iter.get_at(index).map(|base_size| {
|
||||
let total_size = txindex_to_total_size_iter.get_at_unwrap(index);
|
||||
base_size_iter.get_at(index).map(|base_size| {
|
||||
let total_size = total_size_iter.get_at_unwrap(index);
|
||||
Weight::from_sizes(*base_size, *total_size)
|
||||
})
|
||||
},
|
||||
);
|
||||
|
||||
// Derive directly from eager sources to avoid Lazy <- Lazy
|
||||
let txindex_to_vsize = LazyVecFrom2::init(
|
||||
"vsize",
|
||||
version,
|
||||
indexer.vecs.tx.txindex_to_base_size.boxed_clone(),
|
||||
indexer.vecs.tx.txindex_to_total_size.boxed_clone(),
|
||||
|index: TxIndex, txindex_to_base_size_iter, txindex_to_total_size_iter| {
|
||||
indexer.vecs.transactions.base_size.boxed_clone(),
|
||||
indexer.vecs.transactions.total_size.boxed_clone(),
|
||||
|index: TxIndex, base_size_iter, total_size_iter| {
|
||||
let index = index.to_usize();
|
||||
txindex_to_base_size_iter.get_at(index).map(|base_size| {
|
||||
let total_size = txindex_to_total_size_iter.get_at_unwrap(index);
|
||||
base_size_iter.get_at(index).map(|base_size| {
|
||||
let total_size = total_size_iter.get_at_unwrap(index);
|
||||
VSize::from(Weight::from_sizes(*base_size, *total_size))
|
||||
})
|
||||
},
|
||||
);
|
||||
|
||||
let indexes_to_tx_vsize =
|
||||
ComputedTxDistribution::forced_import(db, "tx_vsize", version, indexes)?;
|
||||
|
||||
let indexes_to_tx_weight =
|
||||
ComputedTxDistribution::forced_import(db, "tx_weight", version, indexes)?;
|
||||
|
||||
Ok(Self {
|
||||
indexes_to_tx_vsize,
|
||||
indexes_to_tx_weight,
|
||||
txindex_to_vsize,
|
||||
txindex_to_weight,
|
||||
vsize: LazyTxDistribution::forced_import(
|
||||
db,
|
||||
"tx_vsize",
|
||||
version,
|
||||
txindex_to_vsize,
|
||||
indexes,
|
||||
)?,
|
||||
weight: LazyTxDistribution::forced_import(
|
||||
db,
|
||||
"tx_weight",
|
||||
version,
|
||||
txindex_to_weight,
|
||||
indexes,
|
||||
)?,
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,14 +1,10 @@
|
||||
use brk_traversable::Traversable;
|
||||
use brk_types::{StoredU32, TxIndex, VSize, Weight};
|
||||
use vecdb::LazyVecFrom2;
|
||||
use brk_types::{StoredU32, VSize, Weight};
|
||||
|
||||
use crate::internal::ComputedTxDistribution;
|
||||
use crate::internal::LazyTxDistribution;
|
||||
|
||||
#[derive(Clone, Traversable)]
|
||||
pub struct Vecs {
|
||||
pub indexes_to_tx_vsize: ComputedTxDistribution<VSize>,
|
||||
pub indexes_to_tx_weight: ComputedTxDistribution<Weight>,
|
||||
// Both derive directly from eager sources (base_size, total_size) to avoid Lazy <- Lazy
|
||||
pub txindex_to_vsize: LazyVecFrom2<TxIndex, VSize, TxIndex, StoredU32, TxIndex, StoredU32>,
|
||||
pub txindex_to_weight: LazyVecFrom2<TxIndex, Weight, TxIndex, StoredU32, TxIndex, StoredU32>,
|
||||
pub vsize: LazyTxDistribution<VSize, StoredU32, StoredU32>,
|
||||
pub weight: LazyTxDistribution<Weight, StoredU32, StoredU32>,
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user