mirror of
https://github.com/bitcoinresearchkit/brk.git
synced 2026-05-10 22:29:09 -07:00
global: MASSIVE snapshot
This commit is contained in:
@@ -3,7 +3,7 @@ use brk_types::{Bitcoin, CheckedSub, StoredF64};
|
||||
use vecdb::{Exit, TypedVecIterator};
|
||||
|
||||
use super::Vecs;
|
||||
use crate::{distribution, indexes, utils::OptionExt, ComputeIndexes};
|
||||
use crate::{distribution, indexes, ComputeIndexes};
|
||||
|
||||
impl Vecs {
|
||||
pub fn compute(
|
||||
@@ -37,12 +37,10 @@ impl Vecs {
|
||||
.compute_all(indexes, starting_indexes, exit, |vec| {
|
||||
let mut coinblocks_destroyed_iter = indexes_to_coinblocks_destroyed
|
||||
.height
|
||||
.as_ref()
|
||||
.unwrap()
|
||||
.into_iter();
|
||||
vec.compute_transform(
|
||||
starting_indexes.height,
|
||||
self.indexes_to_coinblocks_created.height.u(),
|
||||
&self.indexes_to_coinblocks_created.height,
|
||||
|(i, created, ..)| {
|
||||
let destroyed = coinblocks_destroyed_iter.get_unwrap(i);
|
||||
(i, created.checked_sub(destroyed).unwrap())
|
||||
@@ -56,12 +54,8 @@ impl Vecs {
|
||||
.compute_all(indexes, starting_indexes, exit, |vec| {
|
||||
vec.compute_divide(
|
||||
starting_indexes.height,
|
||||
indexes_to_coinblocks_destroyed
|
||||
.height_extra
|
||||
.unwrap_cumulative(),
|
||||
self.indexes_to_coinblocks_created
|
||||
.height_extra
|
||||
.unwrap_cumulative(),
|
||||
indexes_to_coinblocks_destroyed.height_cumulative.inner(),
|
||||
self.indexes_to_coinblocks_created.height_cumulative.inner(),
|
||||
exit,
|
||||
)?;
|
||||
Ok(())
|
||||
@@ -71,7 +65,7 @@ impl Vecs {
|
||||
.compute_all(indexes, starting_indexes, exit, |vec| {
|
||||
vec.compute_transform(
|
||||
starting_indexes.height,
|
||||
self.indexes_to_liveliness.height.u(),
|
||||
&self.indexes_to_liveliness.height,
|
||||
|(i, v, ..)| (i, StoredF64::from(1.0).checked_sub(v).unwrap()),
|
||||
exit,
|
||||
)?;
|
||||
@@ -85,8 +79,8 @@ impl Vecs {
|
||||
|vec| {
|
||||
vec.compute_divide(
|
||||
starting_indexes.height,
|
||||
self.indexes_to_liveliness.height.u(),
|
||||
self.indexes_to_vaultedness.height.u(),
|
||||
&self.indexes_to_liveliness.height,
|
||||
&self.indexes_to_vaultedness.height,
|
||||
exit,
|
||||
)?;
|
||||
Ok(())
|
||||
|
||||
@@ -5,36 +5,42 @@ use vecdb::Database;
|
||||
use super::Vecs;
|
||||
use crate::{
|
||||
indexes,
|
||||
internal::{ComputedVecsFromHeight, Source, VecBuilderOptions},
|
||||
internal::{ComputedBlockLast, ComputedBlockSumCum},
|
||||
};
|
||||
|
||||
impl Vecs {
|
||||
pub fn forced_import(db: &Database, version: Version, indexes: &indexes::Vecs) -> Result<Self> {
|
||||
let last = || VecBuilderOptions::default().add_last();
|
||||
let sum_cum = || VecBuilderOptions::default().add_sum().add_cumulative();
|
||||
|
||||
macro_rules! computed_h {
|
||||
($name:expr, $opts:expr) => {
|
||||
ComputedVecsFromHeight::forced_import(
|
||||
db,
|
||||
$name,
|
||||
Source::Compute,
|
||||
version,
|
||||
indexes,
|
||||
$opts,
|
||||
)?
|
||||
};
|
||||
}
|
||||
|
||||
Ok(Self {
|
||||
indexes_to_coinblocks_created: computed_h!("coinblocks_created", sum_cum()),
|
||||
indexes_to_coinblocks_stored: computed_h!("coinblocks_stored", sum_cum()),
|
||||
indexes_to_liveliness: computed_h!("liveliness", last()),
|
||||
indexes_to_vaultedness: computed_h!("vaultedness", last()),
|
||||
indexes_to_activity_to_vaultedness_ratio: computed_h!(
|
||||
indexes_to_coinblocks_created: ComputedBlockSumCum::forced_import(
|
||||
db,
|
||||
"coinblocks_created",
|
||||
version,
|
||||
indexes,
|
||||
)?,
|
||||
indexes_to_coinblocks_stored: ComputedBlockSumCum::forced_import(
|
||||
db,
|
||||
"coinblocks_stored",
|
||||
version,
|
||||
indexes,
|
||||
)?,
|
||||
indexes_to_liveliness: ComputedBlockLast::forced_import(
|
||||
db,
|
||||
"liveliness",
|
||||
version,
|
||||
indexes,
|
||||
)?,
|
||||
indexes_to_vaultedness: ComputedBlockLast::forced_import(
|
||||
db,
|
||||
"vaultedness",
|
||||
version,
|
||||
indexes,
|
||||
)?,
|
||||
indexes_to_activity_to_vaultedness_ratio: ComputedBlockLast::forced_import(
|
||||
db,
|
||||
"activity_to_vaultedness_ratio",
|
||||
last()
|
||||
),
|
||||
version,
|
||||
indexes,
|
||||
)?,
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,13 +1,13 @@
|
||||
use brk_traversable::Traversable;
|
||||
use brk_types::StoredF64;
|
||||
|
||||
use crate::internal::ComputedVecsFromHeight;
|
||||
use crate::internal::{ComputedBlockLast, ComputedBlockSumCum};
|
||||
|
||||
#[derive(Clone, Traversable)]
|
||||
pub struct Vecs {
|
||||
pub indexes_to_coinblocks_created: ComputedVecsFromHeight<StoredF64>,
|
||||
pub indexes_to_coinblocks_stored: ComputedVecsFromHeight<StoredF64>,
|
||||
pub indexes_to_liveliness: ComputedVecsFromHeight<StoredF64>,
|
||||
pub indexes_to_vaultedness: ComputedVecsFromHeight<StoredF64>,
|
||||
pub indexes_to_activity_to_vaultedness_ratio: ComputedVecsFromHeight<StoredF64>,
|
||||
pub indexes_to_coinblocks_created: ComputedBlockSumCum<StoredF64>,
|
||||
pub indexes_to_coinblocks_stored: ComputedBlockSumCum<StoredF64>,
|
||||
pub indexes_to_liveliness: ComputedBlockLast<StoredF64>,
|
||||
pub indexes_to_vaultedness: ComputedBlockLast<StoredF64>,
|
||||
pub indexes_to_activity_to_vaultedness_ratio: ComputedBlockLast<StoredF64>,
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user