global: snapshot

This commit is contained in:
nym21
2026-03-03 22:10:05 +01:00
parent 28f6b0f18b
commit 269c1d5fdf
99 changed files with 1565 additions and 1146 deletions

View File

@@ -35,28 +35,28 @@ impl Vecs {
exit,
)?;
self.hash_rate_1w_sma.height.compute_rolling_average(
self.hash_rate_sma_1w.height.compute_rolling_average(
starting_indexes.height,
&count_vecs.height_1w_ago,
&self.hash_rate.height,
exit,
)?;
self.hash_rate_1m_sma.height.compute_rolling_average(
self.hash_rate_sma_1m.height.compute_rolling_average(
starting_indexes.height,
&count_vecs.height_1m_ago,
&self.hash_rate.height,
exit,
)?;
self.hash_rate_2m_sma.height.compute_rolling_average(
self.hash_rate_sma_2m.height.compute_rolling_average(
starting_indexes.height,
&count_vecs.height_2m_ago,
&self.hash_rate.height,
exit,
)?;
self.hash_rate_1y_sma.height.compute_rolling_average(
self.hash_rate_sma_1y.height.compute_rolling_average(
starting_indexes.height,
&count_vecs.height_1y_ago,
&self.hash_rate.height,
@@ -69,7 +69,7 @@ impl Vecs {
exit,
)?;
self.hash_rate_drawdown.height.compute_drawdown(
self.hash_rate_drawdown.compute_drawdown(
starting_indexes.height,
&self.hash_rate.height,
&self.hash_rate_ath.height,

View File

@@ -5,7 +5,7 @@ use vecdb::Database;
use super::Vecs;
use crate::{
indexes,
internal::ComputedFromHeight,
internal::{Bps16ToFloat, Bps16ToPercent, ComputedFromHeight, PercentFromHeight},
};
impl Vecs {
@@ -19,27 +19,27 @@ impl Vecs {
Ok(Self {
hash_rate: ComputedFromHeight::forced_import(db, "hash_rate", version + v5, indexes)?,
hash_rate_1w_sma: ComputedFromHeight::forced_import(
hash_rate_sma_1w: ComputedFromHeight::forced_import(
db,
"hash_rate_1w_sma",
"hash_rate_sma_1w",
version,
indexes,
)?,
hash_rate_1m_sma: ComputedFromHeight::forced_import(
hash_rate_sma_1m: ComputedFromHeight::forced_import(
db,
"hash_rate_1m_sma",
"hash_rate_sma_1m",
version,
indexes,
)?,
hash_rate_2m_sma: ComputedFromHeight::forced_import(
hash_rate_sma_2m: ComputedFromHeight::forced_import(
db,
"hash_rate_2m_sma",
"hash_rate_sma_2m",
version,
indexes,
)?,
hash_rate_1y_sma: ComputedFromHeight::forced_import(
hash_rate_sma_1y: ComputedFromHeight::forced_import(
db,
"hash_rate_1y_sma",
"hash_rate_sma_1y",
version,
indexes,
)?,
@@ -49,7 +49,7 @@ impl Vecs {
version,
indexes,
)?,
hash_rate_drawdown: ComputedFromHeight::forced_import(
hash_rate_drawdown: PercentFromHeight::forced_import::<Bps16ToFloat, Bps16ToPercent>(
db,
"hash_rate_drawdown",
version,

View File

@@ -1,19 +1,19 @@
use brk_traversable::Traversable;
use brk_types::{StoredF32, StoredF64};
use brk_types::{BasisPointsSigned16, StoredF32, StoredF64};
use vecdb::{Rw, StorageMode};
use crate::internal::ComputedFromHeight;
use crate::internal::{ComputedFromHeight, PercentFromHeight};
/// Mining-related metrics: hash rate, hash price, hash value
#[derive(Traversable)]
pub struct Vecs<M: StorageMode = Rw> {
pub hash_rate: ComputedFromHeight<StoredF64, M>,
pub hash_rate_1w_sma: ComputedFromHeight<StoredF64, M>,
pub hash_rate_1m_sma: ComputedFromHeight<StoredF64, M>,
pub hash_rate_2m_sma: ComputedFromHeight<StoredF64, M>,
pub hash_rate_1y_sma: ComputedFromHeight<StoredF64, M>,
pub hash_rate_sma_1w: ComputedFromHeight<StoredF64, M>,
pub hash_rate_sma_1m: ComputedFromHeight<StoredF64, M>,
pub hash_rate_sma_2m: ComputedFromHeight<StoredF64, M>,
pub hash_rate_sma_1y: ComputedFromHeight<StoredF64, M>,
pub hash_rate_ath: ComputedFromHeight<StoredF64, M>,
pub hash_rate_drawdown: ComputedFromHeight<StoredF32, M>,
pub hash_rate_drawdown: PercentFromHeight<BasisPointsSigned16, M>,
pub hash_price_ths: ComputedFromHeight<StoredF32, M>,
pub hash_price_ths_min: ComputedFromHeight<StoredF32, M>,
pub hash_price_phs: ComputedFromHeight<StoredF32, M>,

View File

@@ -1,10 +1,10 @@
use brk_error::Result;
use brk_indexer::Indexer;
use brk_types::{CheckedSub, HalvingEpoch, Sats, StoredF32};
use brk_types::{BasisPoints16, CheckedSub, HalvingEpoch, Sats};
use vecdb::{Exit, ReadableVec, VecIndex};
use super::Vecs;
use crate::{ComputeIndexes, blocks, indexes, prices, transactions};
use crate::{ComputeIndexes, blocks, indexes, internal::RatioSatsBp16, prices, transactions};
impl Vecs {
#[allow(clippy::too_many_arguments)]
@@ -122,14 +122,14 @@ impl Vecs {
)?;
// All-time cumulative fee dominance
self.fee_dominance.height.compute_percentage(
self.fee_dominance.compute_binary::<Sats, Sats, RatioSatsBp16>(
starting_indexes.height,
&self.fees.cumulative.sats.height,
&self.coinbase.cumulative.sats.height,
exit,
)?;
// Rolling fee dominance = sum(fees) / sum(coinbase) * 100
// Rolling fee dominance = sum(fees) / sum(coinbase)
for ((fee_dom, fees_w), coinbase_w) in self
.fee_dominance_rolling
.as_mut_array()
@@ -137,7 +137,7 @@ impl Vecs {
.zip(self.fees.rolling.as_array())
.zip(self.coinbase.rolling.as_array())
{
fee_dom.height.compute_percentage(
fee_dom.compute_binary::<Sats, Sats, RatioSatsBp16>(
starting_indexes.height,
&fees_w.sum.sats.height,
&coinbase_w.sum.sats.height,
@@ -146,30 +146,29 @@ impl Vecs {
}
// All-time cumulative subsidy dominance
self.subsidy_dominance.height.compute_percentage(
self.subsidy_dominance.compute_binary::<Sats, Sats, RatioSatsBp16>(
starting_indexes.height,
&self.subsidy.cumulative.sats.height,
&self.coinbase.cumulative.sats.height,
exit,
)?;
// Rolling subsidy dominance = 100 - fee_dominance
let hundred = StoredF32::from(100u8);
// Rolling subsidy dominance = 1 - fee_dominance
for (sub_dom, fee_dom) in self
.subsidy_dominance_rolling
.as_mut_array()
.into_iter()
.zip(self.fee_dominance_rolling.as_array())
{
sub_dom.height.compute_transform(
sub_dom.bps.height.compute_transform(
starting_indexes.height,
&fee_dom.height,
|(height, fee_dom, _)| (height, hundred - fee_dom),
&fee_dom.bps.height,
|(height, fee, _)| (height, BasisPoints16::ONE - fee),
exit,
)?;
}
self.subsidy_usd_1y_sma.cents.height.compute_rolling_average(
self.subsidy_sma_1y.cents.height.compute_rolling_average(
starting_indexes.height,
&count_vecs.height_1y_ago,
&self.subsidy.base.cents.height,

View File

@@ -6,8 +6,8 @@ use super::Vecs;
use crate::{
indexes,
internal::{
ComputedFromHeight, FiatFromHeight, RollingWindows, ValueFromHeightFull,
ValueFromHeightCumulativeSum,
Bp16ToFloat, Bp16ToPercent, FiatFromHeight, PercentFromHeight, PercentRollingWindows,
ValueFromHeightFull, ValueFromHeightCumulativeSum,
},
};
@@ -27,33 +27,33 @@ impl Vecs {
version,
indexes,
)?,
fee_dominance: ComputedFromHeight::forced_import(
fee_dominance: PercentFromHeight::forced_import::<Bp16ToFloat, Bp16ToPercent>(
db,
"fee_dominance",
version,
indexes,
)?,
fee_dominance_rolling: RollingWindows::forced_import(
fee_dominance_rolling: PercentRollingWindows::forced_import::<Bp16ToFloat, Bp16ToPercent>(
db,
"fee_dominance",
version,
indexes,
)?,
subsidy_dominance: ComputedFromHeight::forced_import(
subsidy_dominance: PercentFromHeight::forced_import::<Bp16ToFloat, Bp16ToPercent>(
db,
"subsidy_dominance",
version,
indexes,
)?,
subsidy_dominance_rolling: RollingWindows::forced_import(
subsidy_dominance_rolling: PercentRollingWindows::forced_import::<Bp16ToFloat, Bp16ToPercent>(
db,
"subsidy_dominance",
version,
indexes,
)?,
subsidy_usd_1y_sma: FiatFromHeight::forced_import(
subsidy_sma_1y: FiatFromHeight::forced_import(
db,
"subsidy_usd_1y_sma",
"subsidy_sma_1y",
version,
indexes,
)?,

View File

@@ -1,10 +1,10 @@
use brk_traversable::Traversable;
use brk_types::{Cents, StoredF32};
use brk_types::{BasisPoints16, Cents};
use vecdb::{Rw, StorageMode};
use crate::internal::{
ComputedFromHeight, FiatFromHeight, RollingWindows, ValueFromHeightFull,
ValueFromHeightCumulativeSum,
FiatFromHeight, PercentFromHeight, PercentRollingWindows, RollingWindows,
ValueFromHeightFull, ValueFromHeightCumulativeSum,
};
/// Coinbase/subsidy/rewards metrics
@@ -14,9 +14,9 @@ pub struct Vecs<M: StorageMode = Rw> {
pub subsidy: ValueFromHeightFull<M>,
pub fees: ValueFromHeightFull<M>,
pub unclaimed_rewards: ValueFromHeightCumulativeSum<M>,
pub fee_dominance: ComputedFromHeight<StoredF32, M>,
pub fee_dominance_rolling: RollingWindows<StoredF32, M>,
pub subsidy_dominance: ComputedFromHeight<StoredF32, M>,
pub subsidy_dominance_rolling: RollingWindows<StoredF32, M>,
pub subsidy_usd_1y_sma: FiatFromHeight<Cents, M>,
pub fee_dominance: PercentFromHeight<BasisPoints16, M>,
pub fee_dominance_rolling: PercentRollingWindows<BasisPoints16, M>,
pub subsidy_dominance: PercentFromHeight<BasisPoints16, M>,
pub subsidy_dominance_rolling: PercentRollingWindows<BasisPoints16, M>,
pub subsidy_sma_1y: FiatFromHeight<Cents, M>,
}