mirror of
https://github.com/bitcoinresearchkit/brk.git
synced 2026-04-25 07:09:59 -07:00
global: MASSIVE snapshot
This commit is contained in:
@@ -15,71 +15,72 @@ impl Vecs {
|
||||
starting_indexes: &ComputeIndexes,
|
||||
exit: &Exit,
|
||||
) -> Result<()> {
|
||||
// Validate computed versions against dependencies
|
||||
let dep_version = indexer.vecs.txout.height_to_first_txoutindex.version()
|
||||
+ indexer.vecs.txout.txoutindex_to_outputtype.version()
|
||||
+ indexer.vecs.txout.txoutindex_to_value.version();
|
||||
self.height_to_opreturn_value
|
||||
.validate_computed_version_or_reset(dep_version)?;
|
||||
|
||||
// Get target height
|
||||
let target_len = indexer.vecs.txout.height_to_first_txoutindex.len();
|
||||
if target_len == 0 {
|
||||
return Ok(());
|
||||
}
|
||||
let target_height = Height::from(target_len - 1);
|
||||
|
||||
// Find starting height for this vec
|
||||
let current_len = self.height_to_opreturn_value.len();
|
||||
let starting_height = Height::from(current_len.min(starting_indexes.height.to_usize()));
|
||||
|
||||
if starting_height > target_height {
|
||||
return Ok(());
|
||||
}
|
||||
|
||||
// Prepare iterators
|
||||
let mut height_to_first_txoutindex =
|
||||
indexer.vecs.txout.height_to_first_txoutindex.iter()?;
|
||||
let mut txoutindex_to_outputtype = indexer.vecs.txout.txoutindex_to_outputtype.iter()?;
|
||||
let mut txoutindex_to_value = indexer.vecs.txout.txoutindex_to_value.iter()?;
|
||||
|
||||
// Iterate blocks
|
||||
for h in starting_height.to_usize()..=target_height.to_usize() {
|
||||
let height = Height::from(h);
|
||||
|
||||
// Get output range for this block
|
||||
let first_txoutindex = height_to_first_txoutindex.get_unwrap(height);
|
||||
let next_first_txoutindex = if height < target_height {
|
||||
height_to_first_txoutindex.get_unwrap(height.incremented())
|
||||
} else {
|
||||
TxOutIndex::from(indexer.vecs.txout.txoutindex_to_value.len())
|
||||
};
|
||||
|
||||
// Sum opreturn values
|
||||
let mut opreturn_value = Sats::ZERO;
|
||||
for i in first_txoutindex.to_usize()..next_first_txoutindex.to_usize() {
|
||||
let txoutindex = TxOutIndex::from(i);
|
||||
let outputtype = txoutindex_to_outputtype.get_unwrap(txoutindex);
|
||||
|
||||
if outputtype == OutputType::OpReturn {
|
||||
let value = txoutindex_to_value.get_unwrap(txoutindex);
|
||||
opreturn_value += value;
|
||||
}
|
||||
}
|
||||
|
||||
self.height_to_opreturn_value
|
||||
.truncate_push(height, opreturn_value)?;
|
||||
}
|
||||
|
||||
self.height_to_opreturn_value.write()?;
|
||||
|
||||
// Compute derived vecs (dateindex aggregations, etc.)
|
||||
self.indexes_to_opreturn_value.compute_rest(
|
||||
self.indexes_to_opreturn_value.compute_all(
|
||||
indexes,
|
||||
price,
|
||||
starting_indexes,
|
||||
exit,
|
||||
Some(&self.height_to_opreturn_value),
|
||||
|height_vec| {
|
||||
// Validate computed versions against dependencies
|
||||
let dep_version = indexer.vecs.txout.height_to_first_txoutindex.version()
|
||||
+ indexer.vecs.txout.txoutindex_to_outputtype.version()
|
||||
+ indexer.vecs.txout.txoutindex_to_value.version();
|
||||
height_vec.validate_computed_version_or_reset(dep_version)?;
|
||||
|
||||
// Get target height
|
||||
let target_len = indexer.vecs.txout.height_to_first_txoutindex.len();
|
||||
if target_len == 0 {
|
||||
return Ok(());
|
||||
}
|
||||
let target_height = Height::from(target_len - 1);
|
||||
|
||||
// Find starting height for this vec
|
||||
let current_len = height_vec.len();
|
||||
let starting_height =
|
||||
Height::from(current_len.min(starting_indexes.height.to_usize()));
|
||||
|
||||
if starting_height > target_height {
|
||||
return Ok(());
|
||||
}
|
||||
|
||||
// Prepare iterators
|
||||
let mut height_to_first_txoutindex =
|
||||
indexer.vecs.txout.height_to_first_txoutindex.iter()?;
|
||||
let mut txoutindex_to_outputtype =
|
||||
indexer.vecs.txout.txoutindex_to_outputtype.iter()?;
|
||||
let mut txoutindex_to_value = indexer.vecs.txout.txoutindex_to_value.iter()?;
|
||||
|
||||
// Iterate blocks
|
||||
for h in starting_height.to_usize()..=target_height.to_usize() {
|
||||
let height = Height::from(h);
|
||||
|
||||
// Get output range for this block
|
||||
let first_txoutindex = height_to_first_txoutindex.get_unwrap(height);
|
||||
let next_first_txoutindex = if height < target_height {
|
||||
height_to_first_txoutindex.get_unwrap(height.incremented())
|
||||
} else {
|
||||
TxOutIndex::from(indexer.vecs.txout.txoutindex_to_value.len())
|
||||
};
|
||||
|
||||
// Sum opreturn values
|
||||
let mut opreturn_value = Sats::ZERO;
|
||||
for i in first_txoutindex.to_usize()..next_first_txoutindex.to_usize() {
|
||||
let txoutindex = TxOutIndex::from(i);
|
||||
let outputtype = txoutindex_to_outputtype.get_unwrap(txoutindex);
|
||||
|
||||
if outputtype == OutputType::OpReturn {
|
||||
let value = txoutindex_to_value.get_unwrap(txoutindex);
|
||||
opreturn_value += value;
|
||||
}
|
||||
}
|
||||
|
||||
height_vec.truncate_push(height, opreturn_value)?;
|
||||
}
|
||||
|
||||
height_vec.write()?;
|
||||
|
||||
Ok(())
|
||||
},
|
||||
)?;
|
||||
|
||||
Ok(())
|
||||
|
||||
@@ -1,12 +1,9 @@
|
||||
use brk_error::Result;
|
||||
use brk_types::Version;
|
||||
use vecdb::{Database, EagerVec, ImportableVec, IterableCloneableVec};
|
||||
use vecdb::Database;
|
||||
|
||||
use super::Vecs;
|
||||
use crate::{
|
||||
indexes,
|
||||
internal::{ComputedValueVecsFromHeight, Source, VecBuilderOptions},
|
||||
};
|
||||
use crate::{indexes, internal::ValueBlockFull};
|
||||
|
||||
impl Vecs {
|
||||
pub fn forced_import(
|
||||
@@ -15,24 +12,15 @@ impl Vecs {
|
||||
indexes: &indexes::Vecs,
|
||||
compute_dollars: bool,
|
||||
) -> Result<Self> {
|
||||
let height_to_opreturn_value = EagerVec::forced_import(db, "opreturn_value", version)?;
|
||||
|
||||
let indexes_to_opreturn_value = ComputedValueVecsFromHeight::forced_import(
|
||||
let indexes_to_opreturn_value = ValueBlockFull::forced_import(
|
||||
db,
|
||||
"opreturn_value",
|
||||
Source::Vec(height_to_opreturn_value.boxed_clone()),
|
||||
version,
|
||||
VecBuilderOptions::default()
|
||||
.add_sum()
|
||||
.add_cumulative()
|
||||
.add_average()
|
||||
.add_minmax(),
|
||||
compute_dollars,
|
||||
indexes,
|
||||
compute_dollars,
|
||||
)?;
|
||||
|
||||
Ok(Self {
|
||||
height_to_opreturn_value,
|
||||
indexes_to_opreturn_value,
|
||||
})
|
||||
}
|
||||
|
||||
@@ -1,11 +1,8 @@
|
||||
use brk_traversable::Traversable;
|
||||
use brk_types::{Height, Sats};
|
||||
use vecdb::{EagerVec, PcoVec};
|
||||
|
||||
use crate::internal::ComputedValueVecsFromHeight;
|
||||
use crate::internal::ValueBlockFull;
|
||||
|
||||
#[derive(Clone, Traversable)]
|
||||
pub struct Vecs {
|
||||
pub height_to_opreturn_value: EagerVec<PcoVec<Height, Sats>>,
|
||||
pub indexes_to_opreturn_value: ComputedValueVecsFromHeight,
|
||||
pub indexes_to_opreturn_value: ValueBlockFull,
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user