global: snapshot

This commit is contained in:
nym21
2026-02-27 18:48:37 +01:00
parent 6845ad409b
commit d5ec291579
62 changed files with 1960 additions and 1449 deletions

View File

@@ -1,18 +1,16 @@
use brk_error::Result;
use brk_indexer::Indexer;
use brk_types::StoredF32;
use brk_types::StoredU64;
use vecdb::Exit;
use super::Vecs;
use crate::{ComputeIndexes, blocks, outputs};
use crate::{ComputeIndexes, blocks};
impl Vecs {
pub(crate) fn compute(
&mut self,
indexer: &Indexer,
count_vecs: &blocks::CountVecs,
outputs_count: &outputs::CountVecs,
starting_indexes: &ComputeIndexes,
exit: &Exit,
) -> Result<()> {
@@ -151,37 +149,6 @@ impl Vecs {
)?)
})?;
// Adoption ratios: per-block ratio of script type / total outputs
self.taproot_adoption.height.compute_transform2(
starting_indexes.height,
&self.p2tr.height,
&outputs_count.total_count.full.sum_cumulative.sum.0,
|(h, p2tr, total, ..)| {
let ratio = if *total > 0 {
StoredF32::from(*p2tr as f64 / *total as f64)
} else {
StoredF32::from(0.0)
};
(h, ratio)
},
exit,
)?;
self.segwit_adoption.height.compute_transform2(
starting_indexes.height,
&self.segwit.height,
&outputs_count.total_count.full.sum_cumulative.sum.0,
|(h, segwit, total, ..)| {
let ratio = if *total > 0 {
StoredF32::from(*segwit as f64 / *total as f64)
} else {
StoredF32::from(0.0)
};
(h, ratio)
},
exit,
)?;
Ok(())
}
}

View File

@@ -3,10 +3,7 @@ use brk_types::Version;
use vecdb::Database;
use super::Vecs;
use crate::{
indexes,
internal::{ComputedFromHeightCumulativeSum, ComputedFromHeightLast},
};
use crate::{indexes, internal::ComputedFromHeightCumulativeSum};
impl Vecs {
pub(crate) fn forced_import(
@@ -58,18 +55,6 @@ impl Vecs {
indexes,
)?,
segwit,
taproot_adoption: ComputedFromHeightLast::forced_import(
db,
"taproot_adoption",
version,
indexes,
)?,
segwit_adoption: ComputedFromHeightLast::forced_import(
db,
"segwit_adoption",
version,
indexes,
)?,
})
}
}

View File

@@ -1,8 +1,8 @@
use brk_traversable::Traversable;
use brk_types::{StoredF32, StoredU64};
use brk_types::StoredU64;
use vecdb::{Rw, StorageMode};
use crate::internal::{ComputedFromHeightCumulativeSum, ComputedFromHeightLast};
use crate::internal::ComputedFromHeightCumulativeSum;
#[derive(Traversable)]
pub struct Vecs<M: StorageMode = Rw> {
@@ -23,8 +23,4 @@ pub struct Vecs<M: StorageMode = Rw> {
// Aggregate counts
/// SegWit output count (p2wpkh + p2wsh + p2tr)
pub segwit: ComputedFromHeightCumulativeSum<StoredU64, M>,
// Adoption ratios (stored per-block, lazy period views)
pub taproot_adoption: ComputedFromHeightLast<StoredF32, M>,
pub segwit_adoption: ComputedFromHeightLast<StoredF32, M>,
}