global: MASSIVE snapshot

This commit is contained in:
nym21
2026-01-07 01:16:37 +01:00
parent e832ffbe23
commit cb0abc324e
487 changed files with 21155 additions and 13627 deletions

View File

@@ -4,7 +4,7 @@ use brk_types::StoredU64;
use vecdb::{Exit, TypedVecIterator};
use super::Vecs;
use crate::{indexes, utils::OptionExt, ComputeIndexes};
use crate::{indexes, ComputeIndexes};
impl Vecs {
pub fn compute(
@@ -147,14 +147,14 @@ impl Vecs {
})?;
// Compute segwit_count = p2wpkh + p2wsh + p2tr
let mut p2wsh_iter = self.indexes_to_p2wsh_count.height.u().into_iter();
let mut p2tr_iter = self.indexes_to_p2tr_count.height.u().into_iter();
let mut p2wsh_iter = self.indexes_to_p2wsh_count.height.into_iter();
let mut p2tr_iter = self.indexes_to_p2tr_count.height.into_iter();
self.indexes_to_segwit_count
.compute_all(indexes, starting_indexes, exit, |v| {
v.compute_transform(
starting_indexes.height,
self.indexes_to_p2wpkh_count.height.u(),
&self.indexes_to_p2wpkh_count.height,
|(h, p2wpkh, ..)| {
let sum = *p2wpkh + *p2wsh_iter.get_unwrap(h) + *p2tr_iter.get_unwrap(h);
(h, StoredU64::from(sum))

View File

@@ -6,11 +6,9 @@ use super::Vecs;
use crate::{
indexes,
internal::{
ComputedVecsFromHeight, LazyVecsFrom2FromHeight, PercentageU64F32, Source,
VecBuilderOptions,
ComputedBlockFull, BinaryBlockFull, PercentageU64F32,
},
outputs,
utils::OptionExt,
};
impl Vecs {
@@ -20,116 +18,87 @@ impl Vecs {
indexes: &indexes::Vecs,
outputs: &outputs::Vecs,
) -> Result<Self> {
let full_stats = || {
VecBuilderOptions::default()
.add_average()
.add_minmax()
.add_percentiles()
.add_sum()
.add_cumulative()
};
let indexes_to_p2a_count = ComputedVecsFromHeight::forced_import(
let indexes_to_p2a_count = ComputedBlockFull::forced_import(
db,
"p2a_count",
Source::Compute,
version,
indexes,
full_stats(),
)?;
let indexes_to_p2ms_count = ComputedVecsFromHeight::forced_import(
let indexes_to_p2ms_count = ComputedBlockFull::forced_import(
db,
"p2ms_count",
Source::Compute,
version,
indexes,
full_stats(),
)?;
let indexes_to_p2pk33_count = ComputedVecsFromHeight::forced_import(
let indexes_to_p2pk33_count = ComputedBlockFull::forced_import(
db,
"p2pk33_count",
Source::Compute,
version,
indexes,
full_stats(),
)?;
let indexes_to_p2pk65_count = ComputedVecsFromHeight::forced_import(
let indexes_to_p2pk65_count = ComputedBlockFull::forced_import(
db,
"p2pk65_count",
Source::Compute,
version,
indexes,
full_stats(),
)?;
let indexes_to_p2pkh_count = ComputedVecsFromHeight::forced_import(
let indexes_to_p2pkh_count = ComputedBlockFull::forced_import(
db,
"p2pkh_count",
Source::Compute,
version,
indexes,
full_stats(),
)?;
let indexes_to_p2sh_count = ComputedVecsFromHeight::forced_import(
let indexes_to_p2sh_count = ComputedBlockFull::forced_import(
db,
"p2sh_count",
Source::Compute,
version,
indexes,
full_stats(),
)?;
let indexes_to_p2tr_count = ComputedVecsFromHeight::forced_import(
let indexes_to_p2tr_count = ComputedBlockFull::forced_import(
db,
"p2tr_count",
Source::Compute,
version,
indexes,
full_stats(),
)?;
let indexes_to_p2wpkh_count = ComputedVecsFromHeight::forced_import(
let indexes_to_p2wpkh_count = ComputedBlockFull::forced_import(
db,
"p2wpkh_count",
Source::Compute,
version,
indexes,
full_stats(),
)?;
let indexes_to_p2wsh_count = ComputedVecsFromHeight::forced_import(
let indexes_to_p2wsh_count = ComputedBlockFull::forced_import(
db,
"p2wsh_count",
Source::Compute,
version,
indexes,
full_stats(),
)?;
// Aggregate counts (computed from per-type counts)
let indexes_to_segwit_count = ComputedVecsFromHeight::forced_import(
let indexes_to_segwit_count = ComputedBlockFull::forced_import(
db,
"segwit_count",
Source::Compute,
version,
indexes,
full_stats(),
)?;
// Adoption ratios (lazy)
// Uses outputs.count.indexes_to_count as denominator (total output count)
// At height level: per-block ratio; at dateindex level: sum-based ratio (% of new outputs)
let indexes_to_taproot_adoption =
LazyVecsFrom2FromHeight::from_height_and_txindex::<PercentageU64F32>(
BinaryBlockFull::from_height_and_txindex::<PercentageU64F32>(
"taproot_adoption",
version,
indexes_to_p2tr_count.height.u().boxed_clone(),
outputs.count.indexes_to_count.height.sum.u().boxed_clone(),
indexes_to_p2tr_count.height.boxed_clone(),
outputs.count.indexes_to_count.height.sum_cum.sum.0.boxed_clone(),
&indexes_to_p2tr_count,
&outputs.count.indexes_to_count,
);
let indexes_to_segwit_adoption =
LazyVecsFrom2FromHeight::from_height_and_txindex::<PercentageU64F32>(
BinaryBlockFull::from_height_and_txindex::<PercentageU64F32>(
"segwit_adoption",
version,
indexes_to_segwit_count.height.u().boxed_clone(),
outputs.count.indexes_to_count.height.sum.u().boxed_clone(),
indexes_to_segwit_count.height.boxed_clone(),
outputs.count.indexes_to_count.height.sum_cum.sum.0.boxed_clone(),
&indexes_to_segwit_count,
&outputs.count.indexes_to_count,
);
@@ -144,29 +113,23 @@ impl Vecs {
indexes_to_p2tr_count,
indexes_to_p2wpkh_count,
indexes_to_p2wsh_count,
indexes_to_opreturn_count: ComputedVecsFromHeight::forced_import(
indexes_to_opreturn_count: ComputedBlockFull::forced_import(
db,
"opreturn_count",
Source::Compute,
version,
indexes,
full_stats(),
)?,
indexes_to_emptyoutput_count: ComputedVecsFromHeight::forced_import(
indexes_to_emptyoutput_count: ComputedBlockFull::forced_import(
db,
"emptyoutput_count",
Source::Compute,
version,
indexes,
full_stats(),
)?,
indexes_to_unknownoutput_count: ComputedVecsFromHeight::forced_import(
indexes_to_unknownoutput_count: ComputedBlockFull::forced_import(
db,
"unknownoutput_count",
Source::Compute,
version,
indexes,
full_stats(),
)?,
indexes_to_segwit_count,
indexes_to_taproot_adoption,

View File

@@ -1,32 +1,32 @@
use brk_traversable::Traversable;
use brk_types::{StoredF32, StoredU64};
use crate::internal::{ComputedVecsFromHeight, LazyVecsFrom2FromHeight};
use crate::internal::{ComputedBlockFull, BinaryBlockFull};
#[derive(Clone, Traversable)]
pub struct Vecs {
// Per-type output counts
pub indexes_to_p2a_count: ComputedVecsFromHeight<StoredU64>,
pub indexes_to_p2ms_count: ComputedVecsFromHeight<StoredU64>,
pub indexes_to_p2pk33_count: ComputedVecsFromHeight<StoredU64>,
pub indexes_to_p2pk65_count: ComputedVecsFromHeight<StoredU64>,
pub indexes_to_p2pkh_count: ComputedVecsFromHeight<StoredU64>,
pub indexes_to_p2sh_count: ComputedVecsFromHeight<StoredU64>,
pub indexes_to_p2tr_count: ComputedVecsFromHeight<StoredU64>,
pub indexes_to_p2wpkh_count: ComputedVecsFromHeight<StoredU64>,
pub indexes_to_p2wsh_count: ComputedVecsFromHeight<StoredU64>,
pub indexes_to_opreturn_count: ComputedVecsFromHeight<StoredU64>,
pub indexes_to_emptyoutput_count: ComputedVecsFromHeight<StoredU64>,
pub indexes_to_unknownoutput_count: ComputedVecsFromHeight<StoredU64>,
pub indexes_to_p2a_count: ComputedBlockFull<StoredU64>,
pub indexes_to_p2ms_count: ComputedBlockFull<StoredU64>,
pub indexes_to_p2pk33_count: ComputedBlockFull<StoredU64>,
pub indexes_to_p2pk65_count: ComputedBlockFull<StoredU64>,
pub indexes_to_p2pkh_count: ComputedBlockFull<StoredU64>,
pub indexes_to_p2sh_count: ComputedBlockFull<StoredU64>,
pub indexes_to_p2tr_count: ComputedBlockFull<StoredU64>,
pub indexes_to_p2wpkh_count: ComputedBlockFull<StoredU64>,
pub indexes_to_p2wsh_count: ComputedBlockFull<StoredU64>,
pub indexes_to_opreturn_count: ComputedBlockFull<StoredU64>,
pub indexes_to_emptyoutput_count: ComputedBlockFull<StoredU64>,
pub indexes_to_unknownoutput_count: ComputedBlockFull<StoredU64>,
// Aggregate counts
/// SegWit output count (p2wpkh + p2wsh + p2tr)
pub indexes_to_segwit_count: ComputedVecsFromHeight<StoredU64>,
pub indexes_to_segwit_count: ComputedBlockFull<StoredU64>,
// Adoption ratios (lazy)
// Denominator is outputs.count.indexes_to_count (total output count)
/// Taproot adoption: p2tr / total_outputs * 100
pub indexes_to_taproot_adoption: LazyVecsFrom2FromHeight<StoredF32, StoredU64, StoredU64>,
pub indexes_to_taproot_adoption: BinaryBlockFull<StoredF32, StoredU64, StoredU64>,
/// SegWit adoption: segwit / total_outputs * 100
pub indexes_to_segwit_adoption: LazyVecsFrom2FromHeight<StoredF32, StoredU64, StoredU64>,
pub indexes_to_segwit_adoption: BinaryBlockFull<StoredF32, StoredU64, StoredU64>,
}

View File

@@ -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(())

View File

@@ -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,
})
}

View File

@@ -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,
}