global: snapshot

This commit is contained in:
nym21
2026-01-10 18:43:18 +01:00
parent 3bc0615000
commit 6f45ec13f3
311 changed files with 6916 additions and 7664 deletions
@@ -3,7 +3,7 @@ use brk_types::{Height, Sats};
use vecdb::{AnyStoredVec, AnyVec, Exit, GenericStoredVec, TypedVecIterator, VecIndex};
use super::Vecs;
use crate::{ComputeIndexes, blocks, indexes, price, scripts};
use crate::{ComputeIndexes, blocks, indexes, scripts};
impl Vecs {
pub fn compute(
@@ -12,12 +12,11 @@ impl Vecs {
scripts: &scripts::Vecs,
blocks: &blocks::Vecs,
starting_indexes: &ComputeIndexes,
price: Option<&price::Vecs>,
exit: &Exit,
) -> Result<()> {
// 1. Compute opreturn supply - copy per-block opreturn values from scripts
self.opreturn
.compute_all(indexes, price, starting_indexes, exit, |height_vec| {
.compute_all(indexes, starting_indexes, exit, |height_vec| {
// Validate computed versions against dependencies
let opreturn_dep_version = scripts.value.opreturn.sats.height.version();
@@ -53,7 +52,7 @@ impl Vecs {
let unclaimed_height = &blocks.rewards.unclaimed_rewards.sats.height;
self.unspendable
.compute_all(indexes, price, starting_indexes, exit, |height_vec| {
.compute_all(indexes, starting_indexes, exit, |height_vec| {
let unspendable_dep_version =
opreturn_height.version() + unclaimed_height.version();
height_vec.validate_computed_version_or_reset(unspendable_dep_version)?;
@@ -3,29 +3,29 @@ use brk_types::Version;
use vecdb::Database;
use super::Vecs;
use crate::{indexes, internal::ValueBlockSumCum};
use crate::{indexes, internal::ValueFromHeightSumCum, price};
impl Vecs {
pub fn forced_import(
db: &Database,
version: Version,
indexes: &indexes::Vecs,
compute_dollars: bool,
price: Option<&price::Vecs>,
) -> Result<Self> {
Ok(Self {
opreturn: ValueBlockSumCum::forced_import(
opreturn: ValueFromHeightSumCum::forced_import(
db,
"opreturn_supply",
version,
indexes,
compute_dollars,
price,
)?,
unspendable: ValueBlockSumCum::forced_import(
unspendable: ValueFromHeightSumCum::forced_import(
db,
"unspendable_supply",
version,
indexes,
compute_dollars,
price,
)?,
})
}
@@ -1,10 +1,10 @@
use brk_traversable::Traversable;
use crate::internal::ValueBlockSumCum;
use crate::internal::ValueFromHeightSumCum;
/// Burned/unspendable supply metrics
#[derive(Clone, Traversable)]
pub struct Vecs {
pub opreturn: ValueBlockSumCum,
pub unspendable: ValueBlockSumCum,
pub opreturn: ValueFromHeightSumCum,
pub unspendable: ValueFromHeightSumCum,
}
@@ -3,14 +3,14 @@ use brk_types::Version;
use super::Vecs;
use crate::{
distribution,
internal::{DollarsIdentity, LazyValueBlockLast, SatsIdentity},
internal::{DollarsIdentity, LazyValueFromHeightLast, SatsIdentity},
};
impl Vecs {
pub fn import(version: Version, distribution: &distribution::Vecs) -> Self {
let supply_metrics = &distribution.utxo_cohorts.all.metrics.supply;
Self(LazyValueBlockLast::from_block_source::<
Self(LazyValueFromHeightLast::from_block_source::<
SatsIdentity,
DollarsIdentity,
>(
@@ -1,8 +1,8 @@
use brk_traversable::Traversable;
use derive_more::{Deref, DerefMut};
use crate::internal::LazyValueBlockLast;
use crate::internal::LazyValueFromHeightLast;
/// Circulating supply - lazy references to distribution's actual supply (KISS)
#[derive(Clone, Deref, DerefMut, Traversable)]
pub struct Vecs(pub LazyValueBlockLast);
pub struct Vecs(pub LazyValueFromHeightLast);
+2 -3
View File
@@ -2,7 +2,7 @@ use brk_error::Result;
use vecdb::Exit;
use super::Vecs;
use crate::{blocks, distribution, indexes, price, scripts, transactions, ComputeIndexes};
use crate::{blocks, distribution, indexes, scripts, transactions, ComputeIndexes};
impl Vecs {
#[allow(clippy::too_many_arguments)]
@@ -14,12 +14,11 @@ impl Vecs {
transactions: &transactions::Vecs,
distribution: &distribution::Vecs,
starting_indexes: &ComputeIndexes,
price: Option<&price::Vecs>,
exit: &Exit,
) -> Result<()> {
// 1. Compute burned/unspendable supply
self.burned
.compute(indexes, scripts, blocks, starting_indexes, price, exit)?;
.compute(indexes, scripts, blocks, starting_indexes, exit)?;
// 2. Compute inflation rate
self.inflation
+1 -1
View File
@@ -28,7 +28,7 @@ impl Vecs {
let circulating = super::circulating::Vecs::import(version, distribution);
// Burned/unspendable supply - computed from scripts
let burned = super::burned::Vecs::forced_import(&db, version, indexes, compute_dollars)?;
let burned = super::burned::Vecs::forced_import(&db, version, indexes, price)?;
// Inflation rate
let inflation = super::inflation::Vecs::forced_import(&db, version, indexes)?;
@@ -3,11 +3,11 @@ use brk_types::Version;
use vecdb::Database;
use super::Vecs;
use crate::{indexes, internal::ComputedDateAverage};
use crate::{indexes, internal::ComputedFromDateAverage};
impl Vecs {
pub fn forced_import(db: &Database, version: Version, indexes: &indexes::Vecs) -> Result<Self> {
Ok(Self(ComputedDateAverage::forced_import(
Ok(Self(ComputedFromDateAverage::forced_import(
db,
"inflation_rate",
version,
@@ -2,9 +2,9 @@ use brk_traversable::Traversable;
use brk_types::StoredF32;
use derive_more::{Deref, DerefMut};
use crate::internal::ComputedDateAverage;
use crate::internal::ComputedFromDateAverage;
/// Inflation rate metrics
#[derive(Clone, Deref, DerefMut, Traversable)]
#[traversable(transparent)]
pub struct Vecs(pub ComputedDateAverage<StoredF32>);
pub struct Vecs(pub ComputedFromDateAverage<StoredF32>);
@@ -4,7 +4,7 @@ use vecdb::IterableCloneableVec;
use super::Vecs;
use crate::{
distribution,
internal::{DollarsIdentity, LazyBlockLast},
internal::{DollarsIdentity, LazyFromHeightLast},
};
impl Vecs {
@@ -12,7 +12,7 @@ impl Vecs {
let supply_metrics = &distribution.utxo_cohorts.all.metrics.supply;
supply_metrics.total.dollars.as_ref().map(|d| {
Self(LazyBlockLast::from_computed::<DollarsIdentity>(
Self(LazyFromHeightLast::from_lazy_binary_computed::<DollarsIdentity, _, _>(
"market_cap",
version,
d.height.boxed_clone(),
@@ -2,7 +2,7 @@ use brk_traversable::Traversable;
use brk_types::Dollars;
use derive_more::{Deref, DerefMut};
use crate::internal::LazyBlockLast;
use crate::internal::LazyFromHeightLast;
#[derive(Clone, Deref, DerefMut, Traversable)]
pub struct Vecs(pub LazyBlockLast<Dollars>);
pub struct Vecs(pub LazyFromHeightLast<Dollars>);
@@ -3,7 +3,7 @@ use brk_types::Version;
use vecdb::Database;
use super::Vecs;
use crate::{indexes, internal::ComputedDateAverage};
use crate::{indexes, internal::ComputedFromDateAverage};
impl Vecs {
pub fn forced_import(
@@ -13,9 +13,9 @@ impl Vecs {
compute_dollars: bool,
) -> Result<Self> {
Ok(Self {
btc: ComputedDateAverage::forced_import(db, "btc_velocity", version, indexes)?,
btc: ComputedFromDateAverage::forced_import(db, "btc_velocity", version, indexes)?,
usd: compute_dollars.then(|| {
ComputedDateAverage::forced_import(db, "usd_velocity", version, indexes)
ComputedFromDateAverage::forced_import(db, "usd_velocity", version, indexes)
.unwrap()
}),
})
@@ -1,11 +1,11 @@
use brk_traversable::Traversable;
use brk_types::StoredF64;
use crate::internal::ComputedDateAverage;
use crate::internal::ComputedFromDateAverage;
/// Velocity metrics (annualized volume / circulating supply)
#[derive(Clone, Traversable)]
pub struct Vecs {
pub btc: ComputedDateAverage<StoredF64>,
pub usd: Option<ComputedDateAverage<StoredF64>>,
pub btc: ComputedFromDateAverage<StoredF64>,
pub usd: Option<ComputedFromDateAverage<StoredF64>>,
}