mirror of
https://github.com/bitcoinresearchkit/brk.git
synced 2026-05-19 14:24:47 -07:00
global: speed improvement part2
This commit is contained in:
@@ -43,7 +43,6 @@ impl BlockProcessor<'_> {
|
||||
already_added: &mut ByAddrType<FxHashMap<AddrHash, TypeIndex>>,
|
||||
same_block_info: &mut FxHashMap<OutPoint, SameBlockOutputInfo>,
|
||||
) -> Result<()> {
|
||||
let height = self.height;
|
||||
let indexes = &mut *self.indexes;
|
||||
|
||||
// Split transactions vecs: finalize needs first_txout_index/first_txin_index, metadata needs the rest
|
||||
@@ -85,7 +84,7 @@ impl BlockProcessor<'_> {
|
||||
same_block_info,
|
||||
)
|
||||
},
|
||||
|| tx::store_tx_metadata(height, txs, txid_prefix_store, &mut tx_metadata),
|
||||
|| tx::store_tx_metadata(txs, txid_prefix_store, &mut tx_metadata),
|
||||
);
|
||||
|
||||
finalize_result?;
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
use brk_error::{Error, Result};
|
||||
use brk_store::Store;
|
||||
use brk_types::{Height, StoredBool, TxIndex, Txid, TxidPrefix};
|
||||
use brk_types::{StoredBool, TxIndex, Txid, TxidPrefix};
|
||||
use rayon::prelude::*;
|
||||
use tracing::error;
|
||||
use vecdb::{AnyVec, WritableVec, likely};
|
||||
@@ -89,7 +89,6 @@ impl<'a> BlockProcessor<'a> {
|
||||
}
|
||||
|
||||
pub(super) fn store_tx_metadata(
|
||||
height: Height,
|
||||
txs: Vec<ComputedTx>,
|
||||
store: &mut Store<TxidPrefix, TxIndex>,
|
||||
md: &mut TxMetadataVecs<'_>,
|
||||
@@ -98,7 +97,6 @@ pub(super) fn store_tx_metadata(
|
||||
if ct.prev_tx_index_opt.is_none() {
|
||||
store.insert(ct.txid_prefix, ct.tx_index);
|
||||
}
|
||||
md.height.checked_push(ct.tx_index, height)?;
|
||||
md.tx_version
|
||||
.checked_push(ct.tx_index, ct.tx.version.into())?;
|
||||
md.txid.checked_push(ct.tx_index, ct.txid)?;
|
||||
|
||||
@@ -6,7 +6,8 @@ use brk_types::{
|
||||
};
|
||||
use rayon::prelude::*;
|
||||
use vecdb::{
|
||||
AnyStoredVec, BytesVec, Database, ImportableVec, PcoVec, Rw, Stamp, StorageMode, WritableVec,
|
||||
AnyStoredVec, BytesVec, CachedVec, Database, ImportableVec, PcoVec, Rw, Stamp, StorageMode,
|
||||
WritableVec,
|
||||
};
|
||||
|
||||
use crate::parallel_import;
|
||||
@@ -14,12 +15,16 @@ 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 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>,
|
||||
#[traversable(wrap = "size", rename = "base")]
|
||||
pub total: M::Stored<PcoVec<Height, StoredU64>>,
|
||||
#[traversable(wrap = "weight", rename = "base")]
|
||||
@@ -56,11 +61,16 @@ 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,
|
||||
coinbase_tag,
|
||||
difficulty,
|
||||
timestamp,
|
||||
cached_timestamp,
|
||||
total,
|
||||
weight,
|
||||
position,
|
||||
|
||||
@@ -14,7 +14,6 @@ use crate::parallel_import;
|
||||
#[derive(Traversable)]
|
||||
pub struct TransactionsVecs<M: StorageMode = Rw> {
|
||||
pub first_tx_index: M::Stored<PcoVec<Height, TxIndex>>,
|
||||
pub height: M::Stored<PcoVec<TxIndex, Height>>,
|
||||
pub txid: M::Stored<BytesVec<TxIndex, Txid>>,
|
||||
pub tx_version: M::Stored<PcoVec<TxIndex, TxVersion>>,
|
||||
pub raw_locktime: M::Stored<PcoVec<TxIndex, RawLockTime>>,
|
||||
@@ -28,7 +27,6 @@ pub struct TransactionsVecs<M: StorageMode = Rw> {
|
||||
}
|
||||
|
||||
pub struct TxMetadataVecs<'a> {
|
||||
pub height: &'a mut PcoVec<TxIndex, Height>,
|
||||
pub tx_version: &'a mut PcoVec<TxIndex, TxVersion>,
|
||||
pub txid: &'a mut BytesVec<TxIndex, Txid>,
|
||||
pub raw_locktime: &'a mut PcoVec<TxIndex, RawLockTime>,
|
||||
@@ -49,7 +47,6 @@ impl TransactionsVecs {
|
||||
&mut self.first_txout_index,
|
||||
&mut self.first_txin_index,
|
||||
TxMetadataVecs {
|
||||
height: &mut self.height,
|
||||
tx_version: &mut self.tx_version,
|
||||
txid: &mut self.txid,
|
||||
raw_locktime: &mut self.raw_locktime,
|
||||
@@ -63,7 +60,6 @@ impl TransactionsVecs {
|
||||
pub fn forced_import(db: &Database, version: Version) -> Result<Self> {
|
||||
let (
|
||||
first_tx_index,
|
||||
height,
|
||||
txid,
|
||||
tx_version,
|
||||
raw_locktime,
|
||||
@@ -75,7 +71,6 @@ impl TransactionsVecs {
|
||||
position,
|
||||
) = parallel_import! {
|
||||
first_tx_index = PcoVec::forced_import(db, "first_tx_index", version),
|
||||
height = PcoVec::forced_import(db, "height", version),
|
||||
txid = BytesVec::forced_import(db, "txid", version),
|
||||
tx_version = PcoVec::forced_import(db, "tx_version", version),
|
||||
raw_locktime = PcoVec::forced_import(db, "raw_locktime", version),
|
||||
@@ -88,7 +83,6 @@ impl TransactionsVecs {
|
||||
};
|
||||
Ok(Self {
|
||||
first_tx_index,
|
||||
height,
|
||||
txid,
|
||||
tx_version,
|
||||
raw_locktime,
|
||||
@@ -104,7 +98,6 @@ impl TransactionsVecs {
|
||||
pub fn truncate(&mut self, height: Height, tx_index: TxIndex, stamp: Stamp) -> Result<()> {
|
||||
self.first_tx_index
|
||||
.truncate_if_needed_with_stamp(height, stamp)?;
|
||||
self.height.truncate_if_needed_with_stamp(tx_index, stamp)?;
|
||||
self.txid.truncate_if_needed_with_stamp(tx_index, stamp)?;
|
||||
self.tx_version
|
||||
.truncate_if_needed_with_stamp(tx_index, stamp)?;
|
||||
@@ -128,7 +121,6 @@ impl TransactionsVecs {
|
||||
pub fn par_iter_mut_any(&mut self) -> impl ParallelIterator<Item = &mut dyn AnyStoredVec> {
|
||||
[
|
||||
&mut self.first_tx_index as &mut dyn AnyStoredVec,
|
||||
&mut self.height,
|
||||
&mut self.txid,
|
||||
&mut self.tx_version,
|
||||
&mut self.raw_locktime,
|
||||
|
||||
Reference in New Issue
Block a user