mirror of
https://github.com/bitcoinresearchkit/brk.git
synced 2026-05-01 01:50:00 -07:00
global: snapshot
This commit is contained in:
@@ -16,11 +16,8 @@ impl Vecs {
|
||||
exit: &Exit,
|
||||
) -> Result<()> {
|
||||
let window_starts = blocks.count.window_starts();
|
||||
self.0.compute(
|
||||
starting_indexes.height,
|
||||
&window_starts,
|
||||
exit,
|
||||
|full| {
|
||||
self.0
|
||||
.compute(starting_indexes.height, &window_starts, exit, |full| {
|
||||
full.compute_with_skip(
|
||||
starting_indexes.height,
|
||||
&indexes.txindex.input_count,
|
||||
@@ -29,8 +26,7 @@ impl Vecs {
|
||||
exit,
|
||||
0,
|
||||
)
|
||||
},
|
||||
)?;
|
||||
})?;
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
||||
@@ -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 * 50_000_000)?;
|
||||
|
||||
let db = open_db(parent_path, super::DB_NAME, 50_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,7 +2,7 @@ use brk_error::Result;
|
||||
use brk_indexer::Indexer;
|
||||
use brk_types::{Indexes, Sats, TxInIndex, TxIndex, TxOutIndex, Vout};
|
||||
use tracing::info;
|
||||
use vecdb::{AnyStoredVec, AnyVec, Database, Exit, WritableVec, ReadableVec, VecIndex};
|
||||
use vecdb::{AnyStoredVec, AnyVec, Database, Exit, ReadableVec, VecIndex, WritableVec};
|
||||
|
||||
use super::Vecs;
|
||||
|
||||
@@ -41,7 +41,7 @@ impl Vecs {
|
||||
let first_txoutindex_reader = indexer.vecs.transactions.first_txoutindex.reader();
|
||||
let value_reader = indexer.vecs.outputs.value.reader();
|
||||
let actual_total = target - min;
|
||||
let mut entries: Vec<Entry> = Vec::with_capacity(actual_total.min(BATCH_SIZE));
|
||||
let mut entries: Vec<Entry> = Vec::with_capacity(actual_total.min(BATCH_SIZE));
|
||||
|
||||
let mut batch_start = min;
|
||||
while batch_start < target {
|
||||
@@ -49,16 +49,20 @@ impl Vecs {
|
||||
|
||||
entries.clear();
|
||||
let mut j = 0usize;
|
||||
indexer.vecs.inputs.outpoint.for_each_range_at(batch_start, batch_end, |outpoint| {
|
||||
entries.push(Entry {
|
||||
txinindex: TxInIndex::from(batch_start + j),
|
||||
txindex: outpoint.txindex(),
|
||||
vout: outpoint.vout(),
|
||||
txoutindex: TxOutIndex::COINBASE,
|
||||
value: Sats::MAX,
|
||||
indexer
|
||||
.vecs
|
||||
.inputs
|
||||
.outpoint
|
||||
.for_each_range_at(batch_start, batch_end, |outpoint| {
|
||||
entries.push(Entry {
|
||||
txinindex: TxInIndex::from(batch_start + j),
|
||||
txindex: outpoint.txindex(),
|
||||
vout: outpoint.vout(),
|
||||
txoutindex: TxOutIndex::COINBASE,
|
||||
value: Sats::MAX,
|
||||
});
|
||||
j += 1;
|
||||
});
|
||||
j += 1;
|
||||
});
|
||||
|
||||
// Coinbase entries (txindex MAX) sorted to end
|
||||
entries.sort_unstable_by_key(|e| e.txindex);
|
||||
@@ -66,7 +70,8 @@ impl Vecs {
|
||||
if entry.txindex.is_coinbase() {
|
||||
break;
|
||||
}
|
||||
entry.txoutindex = first_txoutindex_reader.get(entry.txindex.to_usize()) + entry.vout;
|
||||
entry.txoutindex =
|
||||
first_txoutindex_reader.get(entry.txindex.to_usize()) + entry.vout;
|
||||
}
|
||||
|
||||
entries.sort_unstable_by_key(|e| e.txoutindex);
|
||||
|
||||
Reference in New Issue
Block a user