global: snapshot

This commit is contained in:
nym21
2026-01-10 18:43:18 +01:00
parent 3bc0615000
commit 6f45ec13f3
311 changed files with 6916 additions and 7664 deletions

View File

@@ -2,7 +2,7 @@ use brk_error::Result;
use brk_indexer::Indexer;
use vecdb::Exit;
use crate::{indexes, price, ComputeIndexes};
use crate::{indexes, ComputeIndexes};
use super::Vecs;
@@ -11,7 +11,6 @@ impl Vecs {
&mut self,
indexer: &Indexer,
indexes: &indexes::Vecs,
price: Option<&price::Vecs>,
starting_indexes: &ComputeIndexes,
exit: &Exit,
) -> Result<()> {
@@ -19,7 +18,7 @@ impl Vecs {
.compute(indexer, indexes, starting_indexes, exit)?;
self.value
.compute(indexer, indexes, price, starting_indexes, exit)?;
.compute(indexer, indexes, starting_indexes, exit)?;
let _lock = exit.lock();
self.db.compact()?;

View File

@@ -5,7 +5,7 @@ use vecdb::{Database, IterableCloneableVec};
use super::Vecs;
use crate::{
indexes,
internal::{ComputedBlockFull, LazyBinaryBlockFull, PercentageU64F32},
internal::{ComputedFromHeightFull, LazyBinaryFromHeightFull, PercentageU64F32},
outputs,
};
@@ -16,23 +16,23 @@ impl Vecs {
indexes: &indexes::Vecs,
outputs: &outputs::Vecs,
) -> Result<Self> {
let p2a = ComputedBlockFull::forced_import(db, "p2a_count", version, indexes)?;
let p2ms = ComputedBlockFull::forced_import(db, "p2ms_count", version, indexes)?;
let p2pk33 = ComputedBlockFull::forced_import(db, "p2pk33_count", version, indexes)?;
let p2pk65 = ComputedBlockFull::forced_import(db, "p2pk65_count", version, indexes)?;
let p2pkh = ComputedBlockFull::forced_import(db, "p2pkh_count", version, indexes)?;
let p2sh = ComputedBlockFull::forced_import(db, "p2sh_count", version, indexes)?;
let p2tr = ComputedBlockFull::forced_import(db, "p2tr_count", version, indexes)?;
let p2wpkh = ComputedBlockFull::forced_import(db, "p2wpkh_count", version, indexes)?;
let p2wsh = ComputedBlockFull::forced_import(db, "p2wsh_count", version, indexes)?;
let p2a = ComputedFromHeightFull::forced_import(db, "p2a_count", version, indexes)?;
let p2ms = ComputedFromHeightFull::forced_import(db, "p2ms_count", version, indexes)?;
let p2pk33 = ComputedFromHeightFull::forced_import(db, "p2pk33_count", version, indexes)?;
let p2pk65 = ComputedFromHeightFull::forced_import(db, "p2pk65_count", version, indexes)?;
let p2pkh = ComputedFromHeightFull::forced_import(db, "p2pkh_count", version, indexes)?;
let p2sh = ComputedFromHeightFull::forced_import(db, "p2sh_count", version, indexes)?;
let p2tr = ComputedFromHeightFull::forced_import(db, "p2tr_count", version, indexes)?;
let p2wpkh = ComputedFromHeightFull::forced_import(db, "p2wpkh_count", version, indexes)?;
let p2wsh = ComputedFromHeightFull::forced_import(db, "p2wsh_count", version, indexes)?;
// Aggregate counts (computed from per-type counts)
let segwit = ComputedBlockFull::forced_import(db, "segwit_count", version, indexes)?;
let segwit = ComputedFromHeightFull::forced_import(db, "segwit_count", version, indexes)?;
// Adoption ratios (lazy)
// Uses outputs.count.count as denominator (total output count)
// At height level: per-block ratio; at dateindex level: sum-based ratio (% of new outputs)
let taproot_adoption = LazyBinaryBlockFull::from_height_and_txindex::<PercentageU64F32>(
let taproot_adoption = LazyBinaryFromHeightFull::from_height_and_txindex::<PercentageU64F32>(
"taproot_adoption",
version,
p2tr.height.boxed_clone(),
@@ -40,7 +40,7 @@ impl Vecs {
&p2tr,
&outputs.count.total_count,
);
let segwit_adoption = LazyBinaryBlockFull::from_height_and_txindex::<PercentageU64F32>(
let segwit_adoption = LazyBinaryFromHeightFull::from_height_and_txindex::<PercentageU64F32>(
"segwit_adoption",
version,
segwit.height.boxed_clone(),
@@ -59,14 +59,14 @@ impl Vecs {
p2tr,
p2wpkh,
p2wsh,
opreturn: ComputedBlockFull::forced_import(db, "opreturn_count", version, indexes)?,
emptyoutput: ComputedBlockFull::forced_import(
opreturn: ComputedFromHeightFull::forced_import(db, "opreturn_count", version, indexes)?,
emptyoutput: ComputedFromHeightFull::forced_import(
db,
"emptyoutput_count",
version,
indexes,
)?,
unknownoutput: ComputedBlockFull::forced_import(
unknownoutput: ComputedFromHeightFull::forced_import(
db,
"unknownoutput_count",
version,

View File

@@ -1,29 +1,29 @@
use brk_traversable::Traversable;
use brk_types::{StoredF32, StoredU64};
use crate::internal::{ComputedBlockFull, LazyBinaryBlockFull};
use crate::internal::{ComputedFromHeightFull, LazyBinaryFromHeightFull};
#[derive(Clone, Traversable)]
pub struct Vecs {
// Per-type output counts
pub p2a: ComputedBlockFull<StoredU64>,
pub p2ms: ComputedBlockFull<StoredU64>,
pub p2pk33: ComputedBlockFull<StoredU64>,
pub p2pk65: ComputedBlockFull<StoredU64>,
pub p2pkh: ComputedBlockFull<StoredU64>,
pub p2sh: ComputedBlockFull<StoredU64>,
pub p2tr: ComputedBlockFull<StoredU64>,
pub p2wpkh: ComputedBlockFull<StoredU64>,
pub p2wsh: ComputedBlockFull<StoredU64>,
pub opreturn: ComputedBlockFull<StoredU64>,
pub emptyoutput: ComputedBlockFull<StoredU64>,
pub unknownoutput: ComputedBlockFull<StoredU64>,
pub p2a: ComputedFromHeightFull<StoredU64>,
pub p2ms: ComputedFromHeightFull<StoredU64>,
pub p2pk33: ComputedFromHeightFull<StoredU64>,
pub p2pk65: ComputedFromHeightFull<StoredU64>,
pub p2pkh: ComputedFromHeightFull<StoredU64>,
pub p2sh: ComputedFromHeightFull<StoredU64>,
pub p2tr: ComputedFromHeightFull<StoredU64>,
pub p2wpkh: ComputedFromHeightFull<StoredU64>,
pub p2wsh: ComputedFromHeightFull<StoredU64>,
pub opreturn: ComputedFromHeightFull<StoredU64>,
pub emptyoutput: ComputedFromHeightFull<StoredU64>,
pub unknownoutput: ComputedFromHeightFull<StoredU64>,
// Aggregate counts
/// SegWit output count (p2wpkh + p2wsh + p2tr)
pub segwit: ComputedBlockFull<StoredU64>,
pub segwit: ComputedFromHeightFull<StoredU64>,
// Adoption ratios
pub taproot_adoption: LazyBinaryBlockFull<StoredF32, StoredU64, StoredU64>,
pub segwit_adoption: LazyBinaryBlockFull<StoredF32, StoredU64, StoredU64>,
pub taproot_adoption: LazyBinaryFromHeightFull<StoredF32, StoredU64, StoredU64>,
pub segwit_adoption: LazyBinaryFromHeightFull<StoredF32, StoredU64, StoredU64>,
}

View File

@@ -21,10 +21,9 @@ impl Vecs {
db.set_min_len(PAGE_SIZE * 50_000_000)?;
let version = parent_version;
let compute_dollars = price.is_some();
let count = CountVecs::forced_import(&db, version, indexes, outputs)?;
let value = ValueVecs::forced_import(&db, version, indexes, compute_dollars)?;
let value = ValueVecs::forced_import(&db, version, indexes, price)?;
let this = Self { db, count, value };

View File

@@ -4,19 +4,18 @@ use brk_types::{Height, OutputType, Sats, TxOutIndex};
use vecdb::{AnyStoredVec, AnyVec, Exit, GenericStoredVec, TypedVecIterator, VecIndex};
use super::Vecs;
use crate::{ComputeIndexes, indexes, price};
use crate::{ComputeIndexes, indexes};
impl Vecs {
pub fn compute(
&mut self,
indexer: &Indexer,
indexes: &indexes::Vecs,
price: Option<&price::Vecs>,
starting_indexes: &ComputeIndexes,
exit: &Exit,
) -> Result<()> {
self.opreturn
.compute_all(indexes, price, starting_indexes, exit, |height_vec| {
.compute_all(indexes, starting_indexes, exit, |height_vec| {
// Validate computed versions against dependencies
let dep_version = indexer.vecs.outputs.first_txoutindex.version()
+ indexer.vecs.outputs.outputtype.version()

View File

@@ -3,22 +3,22 @@ use brk_types::Version;
use vecdb::Database;
use super::Vecs;
use crate::{indexes, internal::ValueBlockFull};
use crate::{indexes, internal::ValueFromHeightFull, price};
impl Vecs {
pub fn forced_import(
db: &Database,
version: Version,
indexes: &indexes::Vecs,
compute_dollars: bool,
price: Option<&price::Vecs>,
) -> Result<Self> {
Ok(Self {
opreturn: ValueBlockFull::forced_import(
opreturn: ValueFromHeightFull::forced_import(
db,
"opreturn_value",
version,
indexes,
compute_dollars,
price,
)?,
})
}

View File

@@ -1,8 +1,8 @@
use brk_traversable::Traversable;
use crate::internal::ValueBlockFull;
use crate::internal::ValueFromHeightFull;
#[derive(Clone, Traversable)]
pub struct Vecs {
pub opreturn: ValueBlockFull,
pub opreturn: ValueFromHeightFull,
}