global: snapshot

This commit is contained in:
nym21
2026-03-13 16:27:10 +01:00
parent b2a1251774
commit 3709ceff8e
168 changed files with 2007 additions and 2008 deletions

View File

@@ -20,7 +20,7 @@ impl Vecs {
starting_indexes: &Indexes,
exit: &Exit,
) -> Result<()> {
self.rate.raw.height.compute_transform2(
self.rate.base.height.compute_transform2(
starting_indexes.height,
&count_vecs.total.sum._24h.height,
&difficulty_vecs.as_hash.height,
@@ -36,7 +36,7 @@ impl Vecs {
exit,
)?;
let hash_rate = &self.rate.raw.height;
let hash_rate = &self.rate.base.height;
for (sma, window) in [
(&mut self.rate.sma._1w.height, &lookback._1w),
(&mut self.rate.sma._1m.height, &lookback._1m),
@@ -48,13 +48,13 @@ impl Vecs {
self.rate.ath.height.compute_all_time_high(
starting_indexes.height,
&self.rate.raw.height,
&self.rate.base.height,
exit,
)?;
self.rate.drawdown.compute_drawdown(
starting_indexes.height,
&self.rate.raw.height,
&self.rate.base.height,
&self.rate.ath.height,
exit,
)?;
@@ -62,7 +62,7 @@ impl Vecs {
self.price.ths.height.compute_transform2(
starting_indexes.height,
coinbase_usd_24h_sum,
&self.rate.raw.height,
&self.rate.base.height,
|(i, coinbase_sum, hashrate, ..)| {
let hashrate_ths = *hashrate / ONE_TERA_HASH;
let price = if hashrate_ths == 0.0 {
@@ -75,17 +75,10 @@ impl Vecs {
exit,
)?;
self.price.phs.height.compute_transform(
starting_indexes.height,
&self.price.ths.height,
|(i, price, ..)| (i, (*price * 1000.0).into()),
exit,
)?;
self.value.ths.height.compute_transform2(
starting_indexes.height,
coinbase_sats_24h_sum,
&self.rate.raw.height,
&self.rate.base.height,
|(i, coinbase_sum, hashrate, ..)| {
let hashrate_ths = *hashrate / ONE_TERA_HASH;
let value = if hashrate_ths == 0.0 {
@@ -98,30 +91,9 @@ impl Vecs {
exit,
)?;
self.value.phs.height.compute_transform(
starting_indexes.height,
&self.value.ths.height,
|(i, value, ..)| (i, (*value * 1000.0).into()),
exit,
)?;
for (min_vec, src_vec) in [
(
&mut self.price.ths_min.height,
&self.price.ths.height,
),
(
&mut self.price.phs_min.height,
&self.price.phs.height,
),
(
&mut self.value.ths_min.height,
&self.value.ths.height,
),
(
&mut self.value.phs_min.height,
&self.value.phs.height,
),
(&mut self.price.ths_min.height, &self.price.ths.height),
(&mut self.value.ths_min.height, &self.value.ths.height),
] {
min_vec.compute_all_time_low_(starting_indexes.height, src_vec, exit, true)?;
}

View File

@@ -1,6 +1,6 @@
use brk_error::Result;
use brk_types::Version;
use vecdb::Database;
use vecdb::{Database, ReadableCloneableVec};
use super::{
vecs::{HashPriceValueVecs, HashRateSmaVecs, RateVecs},
@@ -8,7 +8,7 @@ use super::{
};
use crate::{
indexes,
internal::{ComputedPerBlock, PercentPerBlock},
internal::{LazyPerBlock, PerBlock, PercentPerBlock, ThsToPhsF32},
};
impl Vecs {
@@ -20,111 +20,49 @@ impl Vecs {
let v4 = Version::new(4);
let v5 = Version::new(5);
let price_ths = PerBlock::forced_import(db, "hash_price_ths", version + v4, indexes)?;
let price_ths_min = PerBlock::forced_import(db, "hash_price_ths_min", version + v4, indexes)?;
let price_phs = LazyPerBlock::from_computed::<ThsToPhsF32>(
"hash_price_phs", version + v4, price_ths.height.read_only_boxed_clone(), &price_ths,
);
let price_phs_min = LazyPerBlock::from_computed::<ThsToPhsF32>(
"hash_price_phs_min", version + v4, price_ths_min.height.read_only_boxed_clone(), &price_ths_min,
);
let value_ths = PerBlock::forced_import(db, "hash_value_ths", version + v4, indexes)?;
let value_ths_min = PerBlock::forced_import(db, "hash_value_ths_min", version + v4, indexes)?;
let value_phs = LazyPerBlock::from_computed::<ThsToPhsF32>(
"hash_value_phs", version + v4, value_ths.height.read_only_boxed_clone(), &value_ths,
);
let value_phs_min = LazyPerBlock::from_computed::<ThsToPhsF32>(
"hash_value_phs_min", version + v4, value_ths_min.height.read_only_boxed_clone(), &value_ths_min,
);
Ok(Self {
rate: RateVecs {
raw: ComputedPerBlock::forced_import(db, "hash_rate", version + v5, indexes)?,
base: PerBlock::forced_import(db, "hash_rate", version + v5, indexes)?,
sma: HashRateSmaVecs {
_1w: ComputedPerBlock::forced_import(
db,
"hash_rate_sma_1w",
version,
indexes,
)?,
_1m: ComputedPerBlock::forced_import(
db,
"hash_rate_sma_1m",
version,
indexes,
)?,
_2m: ComputedPerBlock::forced_import(
db,
"hash_rate_sma_2m",
version,
indexes,
)?,
_1y: ComputedPerBlock::forced_import(
db,
"hash_rate_sma_1y",
version,
indexes,
)?,
_1w: PerBlock::forced_import(db, "hash_rate_sma_1w", version, indexes)?,
_1m: PerBlock::forced_import(db, "hash_rate_sma_1m", version, indexes)?,
_2m: PerBlock::forced_import(db, "hash_rate_sma_2m", version, indexes)?,
_1y: PerBlock::forced_import(db, "hash_rate_sma_1y", version, indexes)?,
},
ath: ComputedPerBlock::forced_import(
db,
"hash_rate_ath",
version,
indexes,
)?,
drawdown: PercentPerBlock::forced_import(
db,
"hash_rate_drawdown",
version,
indexes,
)?,
ath: PerBlock::forced_import(db, "hash_rate_ath", version, indexes)?,
drawdown: PercentPerBlock::forced_import(db, "hash_rate_drawdown", version, indexes)?,
},
price: HashPriceValueVecs {
ths: ComputedPerBlock::forced_import(
db,
"hash_price_ths",
version + v4,
indexes,
)?,
ths_min: ComputedPerBlock::forced_import(
db,
"hash_price_ths_min",
version + v4,
indexes,
)?,
phs: ComputedPerBlock::forced_import(
db,
"hash_price_phs",
version + v4,
indexes,
)?,
phs_min: ComputedPerBlock::forced_import(
db,
"hash_price_phs_min",
version + v4,
indexes,
)?,
rebound: PercentPerBlock::forced_import(
db,
"hash_price_rebound",
version + v4,
indexes,
)?,
ths: price_ths,
ths_min: price_ths_min,
phs: price_phs,
phs_min: price_phs_min,
rebound: PercentPerBlock::forced_import(db, "hash_price_rebound", version + v4, indexes)?,
},
value: HashPriceValueVecs {
ths: ComputedPerBlock::forced_import(
db,
"hash_value_ths",
version + v4,
indexes,
)?,
ths_min: ComputedPerBlock::forced_import(
db,
"hash_value_ths_min",
version + v4,
indexes,
)?,
phs: ComputedPerBlock::forced_import(
db,
"hash_value_phs",
version + v4,
indexes,
)?,
phs_min: ComputedPerBlock::forced_import(
db,
"hash_value_phs_min",
version + v4,
indexes,
)?,
rebound: PercentPerBlock::forced_import(
db,
"hash_value_rebound",
version + v4,
indexes,
)?,
ths: value_ths,
ths_min: value_ths_min,
phs: value_phs,
phs_min: value_phs_min,
rebound: PercentPerBlock::forced_import(db, "hash_value_rebound", version + v4, indexes)?,
},
})
}

View File

@@ -2,30 +2,30 @@ use brk_traversable::Traversable;
use brk_types::{BasisPointsSigned16, BasisPointsSigned32, StoredF32, StoredF64};
use vecdb::{Rw, StorageMode};
use crate::internal::{ComputedPerBlock, PercentPerBlock};
use crate::internal::{LazyPerBlock, PerBlock, PercentPerBlock};
#[derive(Traversable)]
pub struct HashRateSmaVecs<M: StorageMode = Rw> {
pub _1w: ComputedPerBlock<StoredF64, M>,
pub _1m: ComputedPerBlock<StoredF64, M>,
pub _2m: ComputedPerBlock<StoredF64, M>,
pub _1y: ComputedPerBlock<StoredF64, M>,
pub _1w: PerBlock<StoredF64, M>,
pub _1m: PerBlock<StoredF64, M>,
pub _2m: PerBlock<StoredF64, M>,
pub _1y: PerBlock<StoredF64, M>,
}
#[derive(Traversable)]
pub struct HashPriceValueVecs<M: StorageMode = Rw> {
pub ths: ComputedPerBlock<StoredF32, M>,
pub ths_min: ComputedPerBlock<StoredF32, M>,
pub phs: ComputedPerBlock<StoredF32, M>,
pub phs_min: ComputedPerBlock<StoredF32, M>,
pub ths: PerBlock<StoredF32, M>,
pub ths_min: PerBlock<StoredF32, M>,
pub phs: LazyPerBlock<StoredF32>,
pub phs_min: LazyPerBlock<StoredF32>,
pub rebound: PercentPerBlock<BasisPointsSigned32, M>,
}
#[derive(Traversable)]
pub struct RateVecs<M: StorageMode = Rw> {
pub raw: ComputedPerBlock<StoredF64, M>,
pub base: PerBlock<StoredF64, M>,
pub sma: HashRateSmaVecs<M>,
pub ath: ComputedPerBlock<StoredF64, M>,
pub ath: PerBlock<StoredF64, M>,
pub drawdown: PercentPerBlock<BasisPointsSigned16, M>,
}

View File

@@ -5,7 +5,7 @@ use brk_types::Version;
use crate::{
indexes,
internal::{finalize_db, open_db, CachedWindowStarts},
internal::{CachedWindowStarts, db_utils::{finalize_db, open_db}},
};
use super::{HashrateVecs, RewardsVecs, Vecs};

View File

@@ -1,6 +1,6 @@
use brk_error::Result;
use brk_indexer::Indexer;
use brk_types::{BasisPoints16, CheckedSub, Dollars, Halving, Indexes, Sats};
use brk_types::{CheckedSub, Dollars, Halving, Indexes, Sats};
use vecdb::{Exit, ReadableVec, VecIndex};
use super::Vecs;
@@ -77,7 +77,7 @@ impl Vecs {
self.subsidy.base.sats.height.compute_transform2(
starting_indexes.height,
&self.coinbase.raw.sats.height,
&self.coinbase.base.sats.height,
&self.fees.base.sats.height,
|(height, coinbase, fees, ..)| {
(
@@ -137,21 +137,6 @@ impl Vecs {
exit,
)?;
// 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.bps.height.compute_transform(
starting_indexes.height,
&fee_dom.bps.height,
|(height, fee, _)| (height, BasisPoints16::ONE - fee),
exit,
)?;
}
self.subsidy_sma_1y.cents.height.compute_rolling_average(
starting_indexes.height,
&lookback._1y,

View File

@@ -7,8 +7,8 @@ use crate::{
indexes,
internal::{
AmountPerBlockCumulative, AmountPerBlockCumulativeWithSums, AmountPerBlockFull,
CachedWindowStarts, FiatPerBlock, PercentPerBlock, PercentRollingWindows,
RatioRollingWindows,
CachedWindowStarts, FiatPerBlock, LazyPercentRollingWindows, OneMinusBp16,
PercentPerBlock, PercentRollingWindows, RatioRollingWindows,
},
};
@@ -19,6 +19,19 @@ impl Vecs {
indexes: &indexes::Vecs,
cached_starts: &CachedWindowStarts,
) -> Result<Self> {
let fee_dominance_rolling = PercentRollingWindows::forced_import(
db,
"fee_dominance",
version,
indexes,
)?;
let subsidy_dominance_rolling = LazyPercentRollingWindows::from_rolling::<OneMinusBp16>(
"subsidy_dominance",
version,
&fee_dominance_rolling,
);
Ok(Self {
coinbase: AmountPerBlockCumulativeWithSums::forced_import(
db, "coinbase", version, indexes, cached_starts,
@@ -33,24 +46,14 @@ impl Vecs {
cached_starts,
)?,
fee_dominance: PercentPerBlock::forced_import(db, "fee_dominance", version, indexes)?,
fee_dominance_rolling: PercentRollingWindows::forced_import(
db,
"fee_dominance",
version,
indexes,
)?,
fee_dominance_rolling,
subsidy_dominance: PercentPerBlock::forced_import(
db,
"subsidy_dominance",
version,
indexes,
)?,
subsidy_dominance_rolling: PercentRollingWindows::forced_import(
db,
"subsidy_dominance",
version,
indexes,
)?,
subsidy_dominance_rolling,
subsidy_sma_1y: FiatPerBlock::forced_import(db, "subsidy_sma_1y", version, indexes)?,
fee_ratio_multiple: RatioRollingWindows::forced_import(
db,

View File

@@ -4,7 +4,8 @@ use vecdb::{Rw, StorageMode};
use crate::internal::{
AmountPerBlockCumulative, AmountPerBlockCumulativeWithSums, AmountPerBlockFull,
FiatPerBlock, PercentPerBlock, PercentRollingWindows, RatioRollingWindows,
FiatPerBlock, LazyPercentRollingWindows, PercentPerBlock, PercentRollingWindows,
RatioRollingWindows,
};
#[derive(Traversable)]
@@ -20,7 +21,7 @@ pub struct Vecs<M: StorageMode = Rw> {
#[traversable(wrap = "subsidy", rename = "dominance")]
pub subsidy_dominance: PercentPerBlock<BasisPoints16, M>,
#[traversable(wrap = "subsidy", rename = "dominance")]
pub subsidy_dominance_rolling: PercentRollingWindows<BasisPoints16, M>,
pub subsidy_dominance_rolling: LazyPercentRollingWindows<BasisPoints16>,
#[traversable(wrap = "subsidy", rename = "sma_1y")]
pub subsidy_sma_1y: FiatPerBlock<Cents, M>,
#[traversable(wrap = "fees", rename = "ratio_multiple")]