mirror of
https://github.com/bitcoinresearchkit/brk.git
synced 2026-05-05 19:59:09 -07:00
global: big 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, ComputeIndexes};
|
||||
use crate::{ComputeIndexes, distribution, indexes};
|
||||
|
||||
impl Vecs {
|
||||
pub fn compute(
|
||||
@@ -13,9 +13,16 @@ impl Vecs {
|
||||
distribution: &distribution::Vecs,
|
||||
exit: &Exit,
|
||||
) -> Result<()> {
|
||||
let circulating_supply = &distribution.utxo_cohorts.all.metrics.supply.height_to_supply;
|
||||
let circulating_supply = &distribution
|
||||
.utxo_cohorts
|
||||
.all
|
||||
.metrics
|
||||
.supply
|
||||
.supply
|
||||
.sats
|
||||
.height;
|
||||
|
||||
self.indexes_to_coinblocks_created
|
||||
self.coinblocks_created
|
||||
.compute_all(indexes, starting_indexes, exit, |vec| {
|
||||
vec.compute_transform(
|
||||
starting_indexes.height,
|
||||
@@ -26,21 +33,19 @@ impl Vecs {
|
||||
Ok(())
|
||||
})?;
|
||||
|
||||
let indexes_to_coinblocks_destroyed = &distribution
|
||||
let coinblocks_destroyed = &distribution
|
||||
.utxo_cohorts
|
||||
.all
|
||||
.metrics
|
||||
.activity
|
||||
.indexes_to_coinblocks_destroyed;
|
||||
.coinblocks_destroyed;
|
||||
|
||||
self.indexes_to_coinblocks_stored
|
||||
self.coinblocks_stored
|
||||
.compute_all(indexes, starting_indexes, exit, |vec| {
|
||||
let mut coinblocks_destroyed_iter = indexes_to_coinblocks_destroyed
|
||||
.height
|
||||
.into_iter();
|
||||
let mut coinblocks_destroyed_iter = coinblocks_destroyed.height.into_iter();
|
||||
vec.compute_transform(
|
||||
starting_indexes.height,
|
||||
&self.indexes_to_coinblocks_created.height,
|
||||
&self.coinblocks_created.height,
|
||||
|(i, created, ..)| {
|
||||
let destroyed = coinblocks_destroyed_iter.get_unwrap(i);
|
||||
(i, created.checked_sub(destroyed).unwrap())
|
||||
@@ -50,42 +55,38 @@ impl Vecs {
|
||||
Ok(())
|
||||
})?;
|
||||
|
||||
self.indexes_to_liveliness
|
||||
self.liveliness
|
||||
.compute_all(indexes, starting_indexes, exit, |vec| {
|
||||
vec.compute_divide(
|
||||
starting_indexes.height,
|
||||
indexes_to_coinblocks_destroyed.height_cumulative.inner(),
|
||||
self.indexes_to_coinblocks_created.height_cumulative.inner(),
|
||||
coinblocks_destroyed.height_cumulative.inner(),
|
||||
self.coinblocks_created.height_cumulative.inner(),
|
||||
exit,
|
||||
)?;
|
||||
Ok(())
|
||||
})?;
|
||||
|
||||
self.indexes_to_vaultedness
|
||||
self.vaultedness
|
||||
.compute_all(indexes, starting_indexes, exit, |vec| {
|
||||
vec.compute_transform(
|
||||
starting_indexes.height,
|
||||
&self.indexes_to_liveliness.height,
|
||||
&self.liveliness.height,
|
||||
|(i, v, ..)| (i, StoredF64::from(1.0).checked_sub(v).unwrap()),
|
||||
exit,
|
||||
)?;
|
||||
Ok(())
|
||||
})?;
|
||||
|
||||
self.indexes_to_activity_to_vaultedness_ratio.compute_all(
|
||||
indexes,
|
||||
starting_indexes,
|
||||
exit,
|
||||
|vec| {
|
||||
self.activity_to_vaultedness_ratio
|
||||
.compute_all(indexes, starting_indexes, exit, |vec| {
|
||||
vec.compute_divide(
|
||||
starting_indexes.height,
|
||||
&self.indexes_to_liveliness.height,
|
||||
&self.indexes_to_vaultedness.height,
|
||||
&self.liveliness.height,
|
||||
&self.vaultedness.height,
|
||||
exit,
|
||||
)?;
|
||||
Ok(())
|
||||
},
|
||||
)?;
|
||||
})?;
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
||||
@@ -11,31 +11,21 @@ use crate::{
|
||||
impl Vecs {
|
||||
pub fn forced_import(db: &Database, version: Version, indexes: &indexes::Vecs) -> Result<Self> {
|
||||
Ok(Self {
|
||||
indexes_to_coinblocks_created: ComputedBlockSumCum::forced_import(
|
||||
coinblocks_created: ComputedBlockSumCum::forced_import(
|
||||
db,
|
||||
"coinblocks_created",
|
||||
version,
|
||||
indexes,
|
||||
)?,
|
||||
indexes_to_coinblocks_stored: ComputedBlockSumCum::forced_import(
|
||||
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(
|
||||
liveliness: ComputedBlockLast::forced_import(db, "liveliness", version, indexes)?,
|
||||
vaultedness: ComputedBlockLast::forced_import(db, "vaultedness", version, indexes)?,
|
||||
activity_to_vaultedness_ratio: ComputedBlockLast::forced_import(
|
||||
db,
|
||||
"activity_to_vaultedness_ratio",
|
||||
version,
|
||||
|
||||
@@ -5,9 +5,9 @@ use crate::internal::{ComputedBlockLast, ComputedBlockSumCum};
|
||||
|
||||
#[derive(Clone, Traversable)]
|
||||
pub struct Vecs {
|
||||
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>,
|
||||
pub coinblocks_created: ComputedBlockSumCum<StoredF64>,
|
||||
pub coinblocks_stored: ComputedBlockSumCum<StoredF64>,
|
||||
pub liveliness: ComputedBlockLast<StoredF64>,
|
||||
pub vaultedness: ComputedBlockLast<StoredF64>,
|
||||
pub activity_to_vaultedness_ratio: ComputedBlockLast<StoredF64>,
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user