mirror of
https://github.com/bitcoinresearchkit/brk.git
synced 2026-04-25 07:09:59 -07:00
global: snapshot
This commit is contained in:
@@ -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(())
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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,
|
||||
)?,
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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>,
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user