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

@@ -0,0 +1,56 @@
use brk_error::Result;
use brk_traversable::Traversable;
use brk_types::{StoredF32, Version};
use vecdb::{Database, Exit, Rw, StorageMode};
use crate::{ComputeIndexes, indexes, internal::{ComputedFromHeightLast, RatioU64F32}, outputs};
use super::count::Vecs as CountVecs;
#[derive(Traversable)]
pub struct Vecs<M: StorageMode = Rw> {
pub taproot: ComputedFromHeightLast<StoredF32, M>,
pub segwit: ComputedFromHeightLast<StoredF32, M>,
}
impl Vecs {
pub(crate) fn forced_import(
db: &Database,
version: Version,
indexes: &indexes::Vecs,
) -> Result<Self> {
Ok(Self {
taproot: ComputedFromHeightLast::forced_import(
db,
"taproot_adoption",
version,
indexes,
)?,
segwit: ComputedFromHeightLast::forced_import(db, "segwit_adoption", version, indexes)?,
})
}
pub(crate) fn compute(
&mut self,
count: &CountVecs,
outputs_count: &outputs::CountVecs,
starting_indexes: &ComputeIndexes,
exit: &Exit,
) -> Result<()> {
self.taproot.compute_binary::<_, _, RatioU64F32>(
starting_indexes.height,
&count.p2tr.height,
&outputs_count.total_count.full.sum_cumulative.sum.0,
exit,
)?;
self.segwit.compute_binary::<_, _, RatioU64F32>(
starting_indexes.height,
&count.segwit.height,
&outputs_count.total_count.full.sum_cumulative.sum.0,
exit,
)?;
Ok(())
}
}

View File

@@ -17,11 +17,14 @@ impl Vecs {
exit: &Exit,
) -> Result<()> {
self.count
.compute(indexer, &blocks.count, &outputs.count, starting_indexes, exit)?;
.compute(indexer, &blocks.count, starting_indexes, exit)?;
self.value
.compute(indexer, &blocks.count, prices, starting_indexes, exit)?;
self.adoption
.compute(&self.count, &outputs.count, starting_indexes, exit)?;
let _lock = exit.lock();
self.db.compact()?;
Ok(())

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

View File

@@ -7,7 +7,7 @@ use vecdb::{Database, PAGE_SIZE};
use crate::indexes;
use super::{CountVecs, ValueVecs, Vecs};
use super::{AdoptionVecs, CountVecs, ValueVecs, Vecs};
impl Vecs {
pub(crate) fn forced_import(
@@ -22,8 +22,9 @@ impl Vecs {
let count = CountVecs::forced_import(&db, version, indexes)?;
let value = ValueVecs::forced_import(&db, version, indexes)?;
let adoption = AdoptionVecs::forced_import(&db, version, indexes)?;
let this = Self { db, count, value };
let this = Self { db, count, value, adoption };
this.db.retain_regions(
this.iter_any_exportable()

View File

@@ -1,3 +1,4 @@
pub mod adoption;
pub mod count;
pub mod value;
@@ -7,6 +8,7 @@ mod import;
use brk_traversable::Traversable;
use vecdb::{Database, Rw, StorageMode};
pub use adoption::Vecs as AdoptionVecs;
pub use count::Vecs as CountVecs;
pub use value::Vecs as ValueVecs;
@@ -19,4 +21,5 @@ pub struct Vecs<M: StorageMode = Rw> {
pub count: CountVecs<M>,
pub value: ValueVecs<M>,
pub adoption: AdoptionVecs<M>,
}