global: snapshot

This commit is contained in:
nym21
2026-03-03 00:23:19 +01:00
parent 0628f08e6b
commit 35df8d99dc
14 changed files with 224 additions and 754 deletions

View File

@@ -3,7 +3,7 @@ use brk_indexer::Indexer;
use brk_types::{Height, StoredU32, Timestamp};
use vecdb::{AnyVec, Cursor, EagerVec, Exit, PcoVec, ReadableVec, VecIndex};
use crate::ComputeIndexes;
use crate::{internal::WindowStarts, ComputeIndexes};
use super::{super::time, Vecs};
@@ -160,7 +160,7 @@ impl Vecs {
})?;
// Compute rolling window block counts (both block_count's own rolling + separate block_count_sum)
let ws = crate::internal::WindowStarts {
let ws = WindowStarts {
_24h: &self.height_24h_ago,
_7d: &self.height_1w_ago,
_30d: &self.height_1m_ago,

View File

@@ -5,7 +5,7 @@ use vecdb::{Exit, Ident, ReadableCloneableVec, ReadableVec, Rw, StorageMode};
use crate::{
ComputeIndexes, blocks,
internal::{ComputedFromHeight, LazyFromHeight, RatioCents64},
internal::{ComputedFromHeight, LazyFromHeight, RatioCents64, RollingWindows},
};
use crate::distribution::metrics::ImportConfig;
@@ -18,21 +18,11 @@ pub struct RealizedAdjusted<M: StorageMode = Rw> {
pub adjusted_value_destroyed: ComputedFromHeight<Cents, M>,
// === Adjusted Value Created/Destroyed Rolling Sums ===
pub adjusted_value_created_24h: ComputedFromHeight<Cents, M>,
pub adjusted_value_created_7d: ComputedFromHeight<Cents, M>,
pub adjusted_value_created_30d: ComputedFromHeight<Cents, M>,
pub adjusted_value_created_1y: ComputedFromHeight<Cents, M>,
pub adjusted_value_destroyed_24h: ComputedFromHeight<Cents, M>,
pub adjusted_value_destroyed_7d: ComputedFromHeight<Cents, M>,
pub adjusted_value_destroyed_30d: ComputedFromHeight<Cents, M>,
pub adjusted_value_destroyed_1y: ComputedFromHeight<Cents, M>,
pub adjusted_value_created_sum: RollingWindows<Cents, M>,
pub adjusted_value_destroyed_sum: RollingWindows<Cents, M>,
// === Adjusted SOPR (rolling window ratios) ===
pub adjusted_sopr: LazyFromHeight<StoredF64>,
pub adjusted_sopr_24h: ComputedFromHeight<StoredF64, M>,
pub adjusted_sopr_7d: ComputedFromHeight<StoredF64, M>,
pub adjusted_sopr_30d: ComputedFromHeight<StoredF64, M>,
pub adjusted_sopr_1y: ComputedFromHeight<StoredF64, M>,
pub adjusted_sopr: RollingWindows<StoredF64, M>,
pub adjusted_sopr_24h_7d_ema: ComputedFromHeight<StoredF64, M>,
pub adjusted_sopr_7d_ema: LazyFromHeight<StoredF64>,
pub adjusted_sopr_24h_30d_ema: ComputedFromHeight<StoredF64, M>,
@@ -43,17 +33,6 @@ impl RealizedAdjusted {
pub(crate) fn forced_import(cfg: &ImportConfig) -> Result<Self> {
let v1 = Version::ONE;
macro_rules! import_rolling {
($name:expr) => {
ComputedFromHeight::forced_import(
cfg.db,
&cfg.name($name),
cfg.version + v1,
cfg.indexes,
)?
};
}
let adjusted_value_created = ComputedFromHeight::forced_import(
cfg.db,
&cfg.name("adjusted_value_created"),
@@ -67,54 +46,35 @@ impl RealizedAdjusted {
cfg.indexes,
)?;
let adjusted_value_created_24h = import_rolling!("adjusted_value_created_24h");
let adjusted_value_created_7d = import_rolling!("adjusted_value_created_7d");
let adjusted_value_created_30d = import_rolling!("adjusted_value_created_30d");
let adjusted_value_created_1y = import_rolling!("adjusted_value_created_1y");
let adjusted_value_destroyed_24h = import_rolling!("adjusted_value_destroyed_24h");
let adjusted_value_destroyed_7d = import_rolling!("adjusted_value_destroyed_7d");
let adjusted_value_destroyed_30d = import_rolling!("adjusted_value_destroyed_30d");
let adjusted_value_destroyed_1y = import_rolling!("adjusted_value_destroyed_1y");
let adjusted_value_created_sum = RollingWindows::forced_import(
cfg.db, &cfg.name("adjusted_value_created"), cfg.version + v1, cfg.indexes,
)?;
let adjusted_value_destroyed_sum = RollingWindows::forced_import(
cfg.db, &cfg.name("adjusted_value_destroyed"), cfg.version + v1, cfg.indexes,
)?;
let adjusted_sopr = RollingWindows::forced_import(
cfg.db, &cfg.name("adjusted_sopr"), cfg.version + v1, cfg.indexes,
)?;
let adjusted_sopr_24h = ComputedFromHeight::forced_import(
cfg.db,
&cfg.name("adjusted_sopr_24h"),
cfg.version + v1,
cfg.indexes,
)?;
let adjusted_sopr_7d = ComputedFromHeight::forced_import(
cfg.db,
&cfg.name("adjusted_sopr_7d"),
cfg.version + v1,
cfg.indexes,
)?;
let adjusted_sopr_30d = ComputedFromHeight::forced_import(
cfg.db,
&cfg.name("adjusted_sopr_30d"),
cfg.version + v1,
cfg.indexes,
)?;
let adjusted_sopr_1y = ComputedFromHeight::forced_import(
cfg.db,
&cfg.name("adjusted_sopr_1y"),
cfg.version + v1,
cfg.indexes,
)?;
let adjusted_sopr = LazyFromHeight::from_computed::<Ident>(
&cfg.name("adjusted_sopr"),
cfg.version + v1,
adjusted_sopr_24h.height.read_only_boxed_clone(),
&adjusted_sopr_24h,
);
macro_rules! import_computed {
($name:expr) => {
ComputedFromHeight::forced_import(
cfg.db,
&cfg.name($name),
cfg.version + v1,
cfg.indexes,
)?
};
}
let adjusted_sopr_24h_7d_ema = import_rolling!("adjusted_sopr_24h_7d_ema");
let adjusted_sopr_24h_7d_ema = import_computed!("adjusted_sopr_24h_7d_ema");
let adjusted_sopr_7d_ema = LazyFromHeight::from_computed::<Ident>(
&cfg.name("adjusted_sopr_7d_ema"),
cfg.version + v1,
adjusted_sopr_24h_7d_ema.height.read_only_boxed_clone(),
&adjusted_sopr_24h_7d_ema,
);
let adjusted_sopr_24h_30d_ema = import_rolling!("adjusted_sopr_24h_30d_ema");
let adjusted_sopr_24h_30d_ema = import_computed!("adjusted_sopr_24h_30d_ema");
let adjusted_sopr_30d_ema = LazyFromHeight::from_computed::<Ident>(
&cfg.name("adjusted_sopr_30d_ema"),
cfg.version + v1,
@@ -125,19 +85,9 @@ impl RealizedAdjusted {
Ok(RealizedAdjusted {
adjusted_value_created,
adjusted_value_destroyed,
adjusted_value_created_24h,
adjusted_value_created_7d,
adjusted_value_created_30d,
adjusted_value_created_1y,
adjusted_value_destroyed_24h,
adjusted_value_destroyed_7d,
adjusted_value_destroyed_30d,
adjusted_value_destroyed_1y,
adjusted_value_created_sum,
adjusted_value_destroyed_sum,
adjusted_sopr,
adjusted_sopr_24h,
adjusted_sopr_7d,
adjusted_sopr_30d,
adjusted_sopr_1y,
adjusted_sopr_24h_7d_ema,
adjusted_sopr_7d_ema,
adjusted_sopr_24h_30d_ema,
@@ -171,101 +121,31 @@ impl RealizedAdjusted {
)?;
// Adjusted value created/destroyed rolling sums
self.adjusted_value_created_24h.height.compute_rolling_sum(
starting_indexes.height,
&blocks.count.height_24h_ago,
&self.adjusted_value_created.height,
exit,
let window_starts = blocks.count.window_starts();
self.adjusted_value_created_sum.compute_rolling_sum(
starting_indexes.height, &window_starts, &self.adjusted_value_created.height, exit,
)?;
self.adjusted_value_created_7d.height.compute_rolling_sum(
starting_indexes.height,
&blocks.count.height_1w_ago,
&self.adjusted_value_created.height,
exit,
self.adjusted_value_destroyed_sum.compute_rolling_sum(
starting_indexes.height, &window_starts, &self.adjusted_value_destroyed.height, exit,
)?;
self.adjusted_value_created_30d.height.compute_rolling_sum(
starting_indexes.height,
&blocks.count.height_1m_ago,
&self.adjusted_value_created.height,
exit,
)?;
self.adjusted_value_created_1y.height.compute_rolling_sum(
starting_indexes.height,
&blocks.count.height_1y_ago,
&self.adjusted_value_created.height,
exit,
)?;
self.adjusted_value_destroyed_24h
.height
.compute_rolling_sum(
starting_indexes.height,
&blocks.count.height_24h_ago,
&self.adjusted_value_destroyed.height,
exit,
)?;
self.adjusted_value_destroyed_7d
.height
.compute_rolling_sum(
starting_indexes.height,
&blocks.count.height_1w_ago,
&self.adjusted_value_destroyed.height,
exit,
)?;
self.adjusted_value_destroyed_30d
.height
.compute_rolling_sum(
starting_indexes.height,
&blocks.count.height_1m_ago,
&self.adjusted_value_destroyed.height,
exit,
)?;
self.adjusted_value_destroyed_1y
.height
.compute_rolling_sum(
starting_indexes.height,
&blocks.count.height_1y_ago,
&self.adjusted_value_destroyed.height,
exit,
)?;
// SOPR ratios from rolling sums
self.adjusted_sopr_24h
.compute_binary::<Cents, Cents, RatioCents64>(
starting_indexes.height,
&self.adjusted_value_created_24h.height,
&self.adjusted_value_destroyed_24h.height,
exit,
)?;
self.adjusted_sopr_7d
.compute_binary::<Cents, Cents, RatioCents64>(
starting_indexes.height,
&self.adjusted_value_created_7d.height,
&self.adjusted_value_destroyed_7d.height,
exit,
)?;
self.adjusted_sopr_30d
.compute_binary::<Cents, Cents, RatioCents64>(
starting_indexes.height,
&self.adjusted_value_created_30d.height,
&self.adjusted_value_destroyed_30d.height,
exit,
)?;
self.adjusted_sopr_1y
.compute_binary::<Cents, Cents, RatioCents64>(
starting_indexes.height,
&self.adjusted_value_created_1y.height,
&self.adjusted_value_destroyed_1y.height,
exit,
for ((sopr, vc), vd) in self.adjusted_sopr.as_mut_array().into_iter()
.zip(self.adjusted_value_created_sum.as_array())
.zip(self.adjusted_value_destroyed_sum.as_array())
{
sopr.compute_binary::<Cents, Cents, RatioCents64>(
starting_indexes.height, &vc.height, &vd.height, exit,
)?;
}
// Adjusted SOPR EMAs
// Adjusted SOPR EMAs (based on 24h window)
self.adjusted_sopr_24h_7d_ema
.height
.compute_rolling_ema(
starting_indexes.height,
&blocks.count.height_1w_ago,
&self.adjusted_sopr.height,
&self.adjusted_sopr._24h.height,
exit,
)?;
self.adjusted_sopr_24h_30d_ema
@@ -273,7 +153,7 @@ impl RealizedAdjusted {
.compute_rolling_ema(
starting_indexes.height,
&blocks.count.height_1m_ago,
&self.adjusted_sopr.height,
&self.adjusted_sopr._24h.height,
exit,
)?;

View File

@@ -15,7 +15,7 @@ use crate::{
CentsPlus, CentsUnsignedToDollars, ComputedFromHeightCumulative, ComputedFromHeight,
ComputedFromHeightRatio, NegCentsUnsignedToDollars, ValueFromHeightCumulative, LazyFromHeight,
PercentageCentsF32, PercentageCentsSignedCentsF32, PercentageCentsSignedDollarsF32, Price, RatioCents64,
Identity, ValueFromHeight,
RollingWindows, Identity, ValueFromHeight,
},
prices,
};
@@ -80,38 +80,19 @@ pub struct RealizedBase<M: StorageMode = Rw> {
pub profit_flow: LazyFromHeight<Dollars, Cents>,
// === Value Created/Destroyed Rolling Sums ===
pub value_created_24h: ComputedFromHeight<Cents, M>,
pub value_created_7d: ComputedFromHeight<Cents, M>,
pub value_created_30d: ComputedFromHeight<Cents, M>,
pub value_created_1y: ComputedFromHeight<Cents, M>,
pub value_destroyed_24h: ComputedFromHeight<Cents, M>,
pub value_destroyed_7d: ComputedFromHeight<Cents, M>,
pub value_destroyed_30d: ComputedFromHeight<Cents, M>,
pub value_destroyed_1y: ComputedFromHeight<Cents, M>,
pub value_created_sum: RollingWindows<Cents, M>,
pub value_destroyed_sum: RollingWindows<Cents, M>,
// === SOPR (rolling window ratios) ===
pub sopr: LazyFromHeight<StoredF64>,
pub sopr_24h: ComputedFromHeight<StoredF64, M>,
pub sopr_7d: ComputedFromHeight<StoredF64, M>,
pub sopr_30d: ComputedFromHeight<StoredF64, M>,
pub sopr_1y: ComputedFromHeight<StoredF64, M>,
pub sopr: RollingWindows<StoredF64, M>,
pub sopr_24h_7d_ema: ComputedFromHeight<StoredF64, M>,
pub sopr_7d_ema: LazyFromHeight<StoredF64>,
pub sopr_24h_30d_ema: ComputedFromHeight<StoredF64, M>,
pub sopr_30d_ema: LazyFromHeight<StoredF64>,
// === Sell Side Risk Rolling Sum Intermediates ===
pub realized_value_24h: ComputedFromHeight<Cents, M>,
pub realized_value_7d: ComputedFromHeight<Cents, M>,
pub realized_value_30d: ComputedFromHeight<Cents, M>,
pub realized_value_1y: ComputedFromHeight<Cents, M>,
// === Sell Side Risk (rolling window ratios) ===
pub sell_side_risk_ratio: LazyFromHeight<StoredF32>,
pub sell_side_risk_ratio_24h: ComputedFromHeight<StoredF32, M>,
pub sell_side_risk_ratio_7d: ComputedFromHeight<StoredF32, M>,
pub sell_side_risk_ratio_30d: ComputedFromHeight<StoredF32, M>,
pub sell_side_risk_ratio_1y: ComputedFromHeight<StoredF32, M>,
// === Sell Side Risk ===
pub realized_value_sum: RollingWindows<Cents, M>,
pub sell_side_risk_ratio: RollingWindows<StoredF32, M>,
pub sell_side_risk_ratio_24h_7d_ema: ComputedFromHeight<StoredF32, M>,
pub sell_side_risk_ratio_7d_ema: LazyFromHeight<StoredF32>,
pub sell_side_risk_ratio_24h_30d_ema: ComputedFromHeight<StoredF32, M>,
@@ -351,8 +332,25 @@ impl RealizedBase {
&realized_price_extra.ratio,
);
// === Rolling sum intermediates ===
macro_rules! import_rolling {
// === Rolling windows ===
let value_created_sum = RollingWindows::forced_import(
cfg.db, &cfg.name("value_created"), cfg.version + v1, cfg.indexes,
)?;
let value_destroyed_sum = RollingWindows::forced_import(
cfg.db, &cfg.name("value_destroyed"), cfg.version + v1, cfg.indexes,
)?;
let realized_value_sum = RollingWindows::forced_import(
cfg.db, &cfg.name("realized_value"), cfg.version + v1, cfg.indexes,
)?;
let sopr = RollingWindows::forced_import(
cfg.db, &cfg.name("sopr"), cfg.version + v1, cfg.indexes,
)?;
let sell_side_risk_ratio = RollingWindows::forced_import(
cfg.db, &cfg.name("sell_side_risk_ratio"), cfg.version + v1, cfg.indexes,
)?;
// === EMA imports + identity aliases ===
macro_rules! import_computed {
($name:expr) => {
ComputedFromHeight::forced_import(
cfg.db,
@@ -363,52 +361,14 @@ impl RealizedBase {
};
}
let value_created_24h = import_rolling!("value_created_24h");
let value_created_7d = import_rolling!("value_created_7d");
let value_created_30d = import_rolling!("value_created_30d");
let value_created_1y = import_rolling!("value_created_1y");
let value_destroyed_24h = import_rolling!("value_destroyed_24h");
let value_destroyed_7d = import_rolling!("value_destroyed_7d");
let value_destroyed_30d = import_rolling!("value_destroyed_30d");
let value_destroyed_1y = import_rolling!("value_destroyed_1y");
let realized_value_24h = import_rolling!("realized_value_24h");
let realized_value_7d = import_rolling!("realized_value_7d");
let realized_value_30d = import_rolling!("realized_value_30d");
let realized_value_1y = import_rolling!("realized_value_1y");
// === Rolling window stored ratios ===
let sopr_24h = import_rolling!("sopr_24h");
let sopr_7d = import_rolling!("sopr_7d");
let sopr_30d = import_rolling!("sopr_30d");
let sopr_1y = import_rolling!("sopr_1y");
let sopr = LazyFromHeight::from_computed::<Ident>(
&cfg.name("sopr"),
cfg.version + v1,
sopr_24h.height.read_only_boxed_clone(),
&sopr_24h,
);
let sell_side_risk_ratio_24h = import_rolling!("sell_side_risk_ratio_24h");
let sell_side_risk_ratio_7d = import_rolling!("sell_side_risk_ratio_7d");
let sell_side_risk_ratio_30d = import_rolling!("sell_side_risk_ratio_30d");
let sell_side_risk_ratio_1y = import_rolling!("sell_side_risk_ratio_1y");
let sell_side_risk_ratio = LazyFromHeight::from_computed::<Ident>(
&cfg.name("sell_side_risk_ratio"),
cfg.version + v1,
sell_side_risk_ratio_24h.height.read_only_boxed_clone(),
&sell_side_risk_ratio_24h,
);
// === EMA imports + identity aliases ===
let sopr_24h_7d_ema = import_rolling!("sopr_24h_7d_ema");
let sopr_24h_7d_ema = import_computed!("sopr_24h_7d_ema");
let sopr_7d_ema = LazyFromHeight::from_computed::<Ident>(
&cfg.name("sopr_7d_ema"),
cfg.version + v1,
sopr_24h_7d_ema.height.read_only_boxed_clone(),
&sopr_24h_7d_ema,
);
let sopr_24h_30d_ema = import_rolling!("sopr_24h_30d_ema");
let sopr_24h_30d_ema = import_computed!("sopr_24h_30d_ema");
let sopr_30d_ema = LazyFromHeight::from_computed::<Ident>(
&cfg.name("sopr_30d_ema"),
cfg.version + v1,
@@ -416,7 +376,7 @@ impl RealizedBase {
&sopr_24h_30d_ema,
);
let sell_side_risk_ratio_24h_7d_ema = import_rolling!("sell_side_risk_ratio_24h_7d_ema");
let sell_side_risk_ratio_24h_7d_ema = import_computed!("sell_side_risk_ratio_24h_7d_ema");
let sell_side_risk_ratio_7d_ema = LazyFromHeight::from_computed::<Ident>(
&cfg.name("sell_side_risk_ratio_7d_ema"),
cfg.version + v1,
@@ -425,7 +385,7 @@ impl RealizedBase {
.read_only_boxed_clone(),
&sell_side_risk_ratio_24h_7d_ema,
);
let sell_side_risk_ratio_24h_30d_ema = import_rolling!("sell_side_risk_ratio_24h_30d_ema");
let sell_side_risk_ratio_24h_30d_ema = import_computed!("sell_side_risk_ratio_24h_30d_ema");
let sell_side_risk_ratio_30d_ema = LazyFromHeight::from_computed::<Ident>(
&cfg.name("sell_side_risk_ratio_30d_ema"),
cfg.version + v1,
@@ -480,32 +440,15 @@ impl RealizedBase {
value_destroyed,
capitulation_flow,
profit_flow,
value_created_24h,
value_created_7d,
value_created_30d,
value_created_1y,
value_destroyed_24h,
value_destroyed_7d,
value_destroyed_30d,
value_destroyed_1y,
value_created_sum,
value_destroyed_sum,
sopr,
sopr_24h,
sopr_7d,
sopr_30d,
sopr_1y,
sopr_24h_7d_ema,
sopr_7d_ema,
sopr_24h_30d_ema,
sopr_30d_ema,
realized_value_24h,
realized_value_7d,
realized_value_30d,
realized_value_1y,
realized_value_sum,
sell_side_risk_ratio,
sell_side_risk_ratio_24h,
sell_side_risk_ratio_7d,
sell_side_risk_ratio_30d,
sell_side_risk_ratio_1y,
sell_side_risk_ratio_24h_7d_ema,
sell_side_risk_ratio_7d_ema,
sell_side_risk_ratio_24h_30d_ema,
@@ -927,135 +870,35 @@ impl RealizedBase {
)?;
// === Rolling sum intermediates ===
macro_rules! rolling_sum {
($target:expr, $window:expr, $source:expr) => {
$target.height.compute_rolling_sum(
starting_indexes.height,
$window,
$source,
exit,
)?
};
}
rolling_sum!(
self.value_created_24h,
&blocks.count.height_24h_ago,
&self.value_created.height
);
rolling_sum!(
self.value_created_7d,
&blocks.count.height_1w_ago,
&self.value_created.height
);
rolling_sum!(
self.value_created_30d,
&blocks.count.height_1m_ago,
&self.value_created.height
);
rolling_sum!(
self.value_created_1y,
&blocks.count.height_1y_ago,
&self.value_created.height
);
rolling_sum!(
self.value_destroyed_24h,
&blocks.count.height_24h_ago,
&self.value_destroyed.height
);
rolling_sum!(
self.value_destroyed_7d,
&blocks.count.height_1w_ago,
&self.value_destroyed.height
);
rolling_sum!(
self.value_destroyed_30d,
&blocks.count.height_1m_ago,
&self.value_destroyed.height
);
rolling_sum!(
self.value_destroyed_1y,
&blocks.count.height_1y_ago,
&self.value_destroyed.height
);
// Realized value rolling sums
rolling_sum!(
self.realized_value_24h,
&blocks.count.height_24h_ago,
&self.realized_value.height
);
rolling_sum!(
self.realized_value_7d,
&blocks.count.height_1w_ago,
&self.realized_value.height
);
rolling_sum!(
self.realized_value_30d,
&blocks.count.height_1m_ago,
&self.realized_value.height
);
rolling_sum!(
self.realized_value_1y,
&blocks.count.height_1y_ago,
&self.realized_value.height
);
let window_starts = blocks.count.window_starts();
self.value_created_sum.compute_rolling_sum(
starting_indexes.height, &window_starts, &self.value_created.height, exit,
)?;
self.value_destroyed_sum.compute_rolling_sum(
starting_indexes.height, &window_starts, &self.value_destroyed.height, exit,
)?;
self.realized_value_sum.compute_rolling_sum(
starting_indexes.height, &window_starts, &self.realized_value.height, exit,
)?;
// Compute SOPR from rolling sums
self.sopr_24h.compute_binary::<Cents, Cents, RatioCents64>(
starting_indexes.height,
&self.value_created_24h.height,
&self.value_destroyed_24h.height,
exit,
)?;
self.sopr_7d.compute_binary::<Cents, Cents, RatioCents64>(
starting_indexes.height,
&self.value_created_7d.height,
&self.value_destroyed_7d.height,
exit,
)?;
self.sopr_30d.compute_binary::<Cents, Cents, RatioCents64>(
starting_indexes.height,
&self.value_created_30d.height,
&self.value_destroyed_30d.height,
exit,
)?;
self.sopr_1y.compute_binary::<Cents, Cents, RatioCents64>(
starting_indexes.height,
&self.value_created_1y.height,
&self.value_destroyed_1y.height,
exit,
)?;
for ((sopr, vc), vd) in self.sopr.as_mut_array().into_iter()
.zip(self.value_created_sum.as_array())
.zip(self.value_destroyed_sum.as_array())
{
sopr.compute_binary::<Cents, Cents, RatioCents64>(
starting_indexes.height, &vc.height, &vd.height, exit,
)?;
}
// Compute sell-side risk ratios
self.sell_side_risk_ratio_24h
.compute_binary::<Cents, Cents, PercentageCentsF32>(
starting_indexes.height,
&self.realized_value_24h.height,
&self.realized_cap_cents.height,
exit,
)?;
self.sell_side_risk_ratio_7d
.compute_binary::<Cents, Cents, PercentageCentsF32>(
starting_indexes.height,
&self.realized_value_7d.height,
&self.realized_cap_cents.height,
exit,
)?;
self.sell_side_risk_ratio_30d
.compute_binary::<Cents, Cents, PercentageCentsF32>(
starting_indexes.height,
&self.realized_value_30d.height,
&self.realized_cap_cents.height,
exit,
)?;
self.sell_side_risk_ratio_1y
.compute_binary::<Cents, Cents, PercentageCentsF32>(
starting_indexes.height,
&self.realized_value_1y.height,
&self.realized_cap_cents.height,
exit,
for (ssrr, rv) in self.sell_side_risk_ratio.as_mut_array().into_iter()
.zip(self.realized_value_sum.as_array())
{
ssrr.compute_binary::<Cents, Cents, PercentageCentsF32>(
starting_indexes.height, &rv.height, &self.realized_cap_cents.height, exit,
)?;
}
// 7d EMAs
self.realized_profit_7d_ema.height.compute_rolling_ema(
@@ -1095,27 +938,27 @@ impl RealizedBase {
exit,
)?;
// SOPR EMAs
// SOPR EMAs (based on 24h window)
self.sopr_24h_7d_ema.height.compute_rolling_ema(
starting_indexes.height,
&blocks.count.height_1w_ago,
&self.sopr.height,
&self.sopr._24h.height,
exit,
)?;
self.sopr_24h_30d_ema.height.compute_rolling_ema(
starting_indexes.height,
&blocks.count.height_1m_ago,
&self.sopr.height,
&self.sopr._24h.height,
exit,
)?;
// Sell side risk EMAs
// Sell side risk EMAs (based on 24h window)
self.sell_side_risk_ratio_24h_7d_ema
.height
.compute_rolling_ema(
starting_indexes.height,
&blocks.count.height_1w_ago,
&self.sell_side_risk_ratio.height,
&self.sell_side_risk_ratio._24h.height,
exit,
)?;
self.sell_side_risk_ratio_24h_30d_ema
@@ -1123,7 +966,7 @@ impl RealizedBase {
.compute_rolling_ema(
starting_indexes.height,
&blocks.count.height_1m_ago,
&self.sell_side_risk_ratio.height,
&self.sell_side_risk_ratio._24h.height,
exit,
)?;

View File

@@ -5,7 +5,7 @@ use vecdb::{Exit, ReadableVec, Rw, StorageMode};
use crate::{
ComputeIndexes, blocks,
internal::{ComputedFromHeight, ComputedFromHeightRatioExtension, RatioCents64},
internal::{ComputedFromHeight, ComputedFromHeightRatioExtension, RatioCents64, RollingWindows},
};
use crate::distribution::metrics::ImportConfig;
@@ -18,20 +18,11 @@ pub struct RealizedExtended<M: StorageMode = Rw> {
pub realized_cap_rel_to_own_market_cap: ComputedFromHeight<StoredF32, M>,
// === Realized Profit/Loss Rolling Sums ===
pub realized_profit_24h: ComputedFromHeight<Cents, M>,
pub realized_profit_7d: ComputedFromHeight<Cents, M>,
pub realized_profit_30d: ComputedFromHeight<Cents, M>,
pub realized_profit_1y: ComputedFromHeight<Cents, M>,
pub realized_loss_24h: ComputedFromHeight<Cents, M>,
pub realized_loss_7d: ComputedFromHeight<Cents, M>,
pub realized_loss_30d: ComputedFromHeight<Cents, M>,
pub realized_loss_1y: ComputedFromHeight<Cents, M>,
pub realized_profit_sum: RollingWindows<Cents, M>,
pub realized_loss_sum: RollingWindows<Cents, M>,
// === Realized Profit to Loss Ratio (from rolling sums) ===
pub realized_profit_to_loss_ratio_24h: ComputedFromHeight<StoredF64, M>,
pub realized_profit_to_loss_ratio_7d: ComputedFromHeight<StoredF64, M>,
pub realized_profit_to_loss_ratio_30d: ComputedFromHeight<StoredF64, M>,
pub realized_profit_to_loss_ratio_1y: ComputedFromHeight<StoredF64, M>,
pub realized_profit_to_loss_ratio: RollingWindows<StoredF64, M>,
// === Extended ratio metrics for realized/investor price ===
pub realized_price_ratio_ext: ComputedFromHeightRatioExtension<M>,
@@ -42,17 +33,6 @@ impl RealizedExtended {
pub(crate) fn forced_import(cfg: &ImportConfig) -> Result<Self> {
let v1 = Version::ONE;
macro_rules! import_rolling {
($name:expr) => {
ComputedFromHeight::forced_import(
cfg.db,
&cfg.name($name),
cfg.version + v1,
cfg.indexes,
)?
};
}
Ok(RealizedExtended {
realized_cap_rel_to_own_market_cap: ComputedFromHeight::forced_import(
cfg.db,
@@ -60,18 +40,15 @@ impl RealizedExtended {
cfg.version,
cfg.indexes,
)?,
realized_profit_24h: import_rolling!("realized_profit_24h"),
realized_profit_7d: import_rolling!("realized_profit_7d"),
realized_profit_30d: import_rolling!("realized_profit_30d"),
realized_profit_1y: import_rolling!("realized_profit_1y"),
realized_loss_24h: import_rolling!("realized_loss_24h"),
realized_loss_7d: import_rolling!("realized_loss_7d"),
realized_loss_30d: import_rolling!("realized_loss_30d"),
realized_loss_1y: import_rolling!("realized_loss_1y"),
realized_profit_to_loss_ratio_24h: import_rolling!("realized_profit_to_loss_ratio_24h"),
realized_profit_to_loss_ratio_7d: import_rolling!("realized_profit_to_loss_ratio_7d"),
realized_profit_to_loss_ratio_30d: import_rolling!("realized_profit_to_loss_ratio_30d"),
realized_profit_to_loss_ratio_1y: import_rolling!("realized_profit_to_loss_ratio_1y"),
realized_profit_sum: RollingWindows::forced_import(
cfg.db, &cfg.name("realized_profit"), cfg.version + v1, cfg.indexes,
)?,
realized_loss_sum: RollingWindows::forced_import(
cfg.db, &cfg.name("realized_loss"), cfg.version + v1, cfg.indexes,
)?,
realized_profit_to_loss_ratio: RollingWindows::forced_import(
cfg.db, &cfg.name("realized_profit_to_loss_ratio"), cfg.version + v1, cfg.indexes,
)?,
realized_price_ratio_ext: ComputedFromHeightRatioExtension::forced_import(
cfg.db,
&cfg.name("realized_price"),
@@ -97,53 +74,12 @@ impl RealizedExtended {
exit: &Exit,
) -> Result<()> {
// Realized profit/loss rolling sums
self.realized_profit_24h.height.compute_rolling_sum(
starting_indexes.height,
&blocks.count.height_24h_ago,
&base.realized_profit.height,
exit,
let window_starts = blocks.count.window_starts();
self.realized_profit_sum.compute_rolling_sum(
starting_indexes.height, &window_starts, &base.realized_profit.height, exit,
)?;
self.realized_profit_7d.height.compute_rolling_sum(
starting_indexes.height,
&blocks.count.height_1w_ago,
&base.realized_profit.height,
exit,
)?;
self.realized_profit_30d.height.compute_rolling_sum(
starting_indexes.height,
&blocks.count.height_1m_ago,
&base.realized_profit.height,
exit,
)?;
self.realized_profit_1y.height.compute_rolling_sum(
starting_indexes.height,
&blocks.count.height_1y_ago,
&base.realized_profit.height,
exit,
)?;
self.realized_loss_24h.height.compute_rolling_sum(
starting_indexes.height,
&blocks.count.height_24h_ago,
&base.realized_loss.height,
exit,
)?;
self.realized_loss_7d.height.compute_rolling_sum(
starting_indexes.height,
&blocks.count.height_1w_ago,
&base.realized_loss.height,
exit,
)?;
self.realized_loss_30d.height.compute_rolling_sum(
starting_indexes.height,
&blocks.count.height_1m_ago,
&base.realized_loss.height,
exit,
)?;
self.realized_loss_1y.height.compute_rolling_sum(
starting_indexes.height,
&blocks.count.height_1y_ago,
&base.realized_loss.height,
exit,
self.realized_loss_sum.compute_rolling_sum(
starting_indexes.height, &window_starts, &base.realized_loss.height, exit,
)?;
// Realized cap relative to own market cap
@@ -157,34 +93,14 @@ impl RealizedExtended {
)?;
// Realized profit to loss ratios
self.realized_profit_to_loss_ratio_24h
.compute_binary::<Cents, Cents, RatioCents64>(
starting_indexes.height,
&self.realized_profit_24h.height,
&self.realized_loss_24h.height,
exit,
)?;
self.realized_profit_to_loss_ratio_7d
.compute_binary::<Cents, Cents, RatioCents64>(
starting_indexes.height,
&self.realized_profit_7d.height,
&self.realized_loss_7d.height,
exit,
)?;
self.realized_profit_to_loss_ratio_30d
.compute_binary::<Cents, Cents, RatioCents64>(
starting_indexes.height,
&self.realized_profit_30d.height,
&self.realized_loss_30d.height,
exit,
)?;
self.realized_profit_to_loss_ratio_1y
.compute_binary::<Cents, Cents, RatioCents64>(
starting_indexes.height,
&self.realized_profit_1y.height,
&self.realized_loss_1y.height,
exit,
for ((ratio, profit), loss) in self.realized_profit_to_loss_ratio.as_mut_array().into_iter()
.zip(self.realized_profit_sum.as_array())
.zip(self.realized_loss_sum.as_array())
{
ratio.compute_binary::<Cents, Cents, RatioCents64>(
starting_indexes.height, &profit.height, &loss.height, exit,
)?;
}
// Extended ratio metrics
self.realized_price_ratio_ext.compute_rest(

View File

@@ -92,12 +92,9 @@ impl RollingFullByUnit {
indexes: &indexes::Vecs,
) -> Result<Self> {
let v = version + VERSION;
Ok(Self(Windows {
_24h: RollingFullSlot::forced_import(db, &format!("{name}_24h"), v, indexes)?,
_7d: RollingFullSlot::forced_import(db, &format!("{name}_7d"), v, indexes)?,
_30d: RollingFullSlot::forced_import(db, &format!("{name}_30d"), v, indexes)?,
_1y: RollingFullSlot::forced_import(db, &format!("{name}_1y"), v, indexes)?,
}))
Ok(Self(Windows::try_from_fn(|suffix| {
RollingFullSlot::forced_import(db, &format!("{name}_{suffix}"), v, indexes)
})?))
}
pub(crate) fn compute(
@@ -109,7 +106,7 @@ impl RollingFullByUnit {
exit: &Exit,
) -> Result<()> {
for (slot, starts) in self.0.as_mut_array().into_iter().zip(windows.as_array()) {
slot.compute(max_from, starts, sats_source, cents_source, exit)?;
slot.compute(max_from, *starts, sats_source, cents_source, exit)?;
}
Ok(())
}

View File

@@ -38,8 +38,8 @@ impl RollingSumByUnit {
exit: &Exit,
) -> Result<()> {
for (w, starts) in self.0.as_mut_array().into_iter().zip(windows.as_array()) {
w.sats.height.compute_rolling_sum(max_from, starts, sats_source, exit)?;
w.cents.height.compute_rolling_sum(max_from, starts, cents_source, exit)?;
w.sats.height.compute_rolling_sum(max_from, *starts, sats_source, exit)?;
w.cents.height.compute_rolling_sum(max_from, *starts, cents_source, exit)?;
}
Ok(())
}

View File

@@ -14,11 +14,8 @@ impl Windows<ByUnit> {
version: Version,
indexes: &indexes::Vecs,
) -> Result<Self> {
Ok(Self {
_24h: ByUnit::forced_import(db, &format!("{name}_24h"), version, indexes)?,
_7d: ByUnit::forced_import(db, &format!("{name}_7d"), version, indexes)?,
_30d: ByUnit::forced_import(db, &format!("{name}_30d"), version, indexes)?,
_1y: ByUnit::forced_import(db, &format!("{name}_1y"), version, indexes)?,
Windows::try_from_fn(|suffix| {
ByUnit::forced_import(db, &format!("{name}_{suffix}"), version, indexes)
})
}
}

View File

@@ -36,32 +36,9 @@ impl ValueFromHeightWindows {
indexes: &indexes::Vecs,
) -> Result<Self> {
let v = version + VERSION;
Ok(Self(Windows {
_24h: ValueFromHeight::forced_import(
db,
&format!("{name}_24h"),
v,
indexes,
)?,
_7d: ValueFromHeight::forced_import(
db,
&format!("{name}_7d"),
v,
indexes,
)?,
_30d: ValueFromHeight::forced_import(
db,
&format!("{name}_30d"),
v,
indexes,
)?,
_1y: ValueFromHeight::forced_import(
db,
&format!("{name}_1y"),
v,
indexes,
)?,
}))
Ok(Self(Windows::try_from_fn(|suffix| {
ValueFromHeight::forced_import(db, &format!("{name}_{suffix}"), v, indexes)
})?))
}
pub(crate) fn compute_rolling_sum(
@@ -73,7 +50,7 @@ impl ValueFromHeightWindows {
exit: &Exit,
) -> Result<()> {
for (w, starts) in self.0.as_mut_array().into_iter().zip(windows.as_array()) {
w.compute_rolling_sum(max_from, starts, sats_source, cents_source, exit)?;
w.compute_rolling_sum(max_from, *starts, sats_source, cents_source, exit)?;
}
Ok(())
}

View File

@@ -18,19 +18,8 @@ use crate::{
internal::{ComputedFromHeight, ComputedVecValue, NumericValue, Windows},
};
/// Rolling window start heights — references to the 4 height-ago vecs.
pub struct WindowStarts<'a> {
pub _24h: &'a EagerVec<PcoVec<Height, Height>>,
pub _7d: &'a EagerVec<PcoVec<Height, Height>>,
pub _30d: &'a EagerVec<PcoVec<Height, Height>>,
pub _1y: &'a EagerVec<PcoVec<Height, Height>>,
}
impl<'a> WindowStarts<'a> {
pub fn as_array(&self) -> [&'a EagerVec<PcoVec<Height, Height>>; 4] {
[self._24h, self._7d, self._30d, self._1y]
}
}
/// Rolling window start heights — the 4 height-ago vecs (24h, 7d, 30d, 1y).
pub type WindowStarts<'a> = Windows<&'a EagerVec<PcoVec<Height, Height>>>;
/// 4 rolling window vecs (24h, 7d, 30d, 1y), each with height data + all 17 index views.
#[derive(Deref, DerefMut, Traversable)]
@@ -52,12 +41,9 @@ where
indexes: &indexes::Vecs,
) -> Result<Self> {
let v = version + VERSION;
Ok(Self(Windows {
_24h: ComputedFromHeight::forced_import(db, &format!("{name}_24h"), v, indexes)?,
_7d: ComputedFromHeight::forced_import(db, &format!("{name}_7d"), v, indexes)?,
_30d: ComputedFromHeight::forced_import(db, &format!("{name}_30d"), v, indexes)?,
_1y: ComputedFromHeight::forced_import(db, &format!("{name}_1y"), v, indexes)?,
}))
Ok(Self(Windows::try_from_fn(|suffix| {
ComputedFromHeight::forced_import(db, &format!("{name}_{suffix}"), v, indexes)
})?))
}
pub(crate) fn compute_rolling_sum(
@@ -71,7 +57,7 @@ where
T: Default + SubAssign,
{
for (w, starts) in self.0.as_mut_array().into_iter().zip(windows.as_array()) {
w.height.compute_rolling_sum(max_from, starts, source, exit)?;
w.height.compute_rolling_sum(max_from, *starts, source, exit)?;
}
Ok(())
}

View File

@@ -17,6 +17,23 @@ pub struct Windows<A, B = A, C = A, D = A> {
}
impl<A> Windows<A> {
pub const SUFFIXES: [&'static str; 4] = ["24h", "7d", "30d", "1y"];
pub fn try_from_fn<E>(
mut f: impl FnMut(&str) -> std::result::Result<A, E>,
) -> std::result::Result<Self, E> {
Ok(Self {
_24h: f(Self::SUFFIXES[0])?,
_7d: f(Self::SUFFIXES[1])?,
_30d: f(Self::SUFFIXES[2])?,
_1y: f(Self::SUFFIXES[3])?,
})
}
pub fn as_array(&self) -> [&A; 4] {
[&self._24h, &self._7d, &self._30d, &self._1y]
}
pub fn as_mut_array(&mut self) -> [&mut A; 4] {
[&mut self._24h, &mut self._7d, &mut self._30d, &mut self._1y]
}

View File

@@ -130,30 +130,20 @@ impl Vecs {
)?;
// Rolling fee dominance = sum(fees) / sum(coinbase) * 100
self.fee_dominance_24h.height.compute_percentage(
starting_indexes.height,
&self.fees.rolling._24h.sum.sats.height,
&self.coinbase.rolling._24h.sum.sats.height,
exit,
)?;
self.fee_dominance_7d.height.compute_percentage(
starting_indexes.height,
&self.fees.rolling._7d.sum.sats.height,
&self.coinbase.rolling._7d.sum.sats.height,
exit,
)?;
self.fee_dominance_30d.height.compute_percentage(
starting_indexes.height,
&self.fees.rolling._30d.sum.sats.height,
&self.coinbase.rolling._30d.sum.sats.height,
exit,
)?;
self.fee_dominance_1y.height.compute_percentage(
starting_indexes.height,
&self.fees.rolling._1y.sum.sats.height,
&self.coinbase.rolling._1y.sum.sats.height,
exit,
)?;
for ((fee_dom, fees_w), coinbase_w) in self
.fee_dominance_rolling
.as_mut_array()
.into_iter()
.zip(self.fees.rolling.as_array())
.zip(self.coinbase.rolling.as_array())
{
fee_dom.height.compute_percentage(
starting_indexes.height,
&fees_w.sum.sats.height,
&coinbase_w.sum.sats.height,
exit,
)?;
}
// All-time cumulative subsidy dominance
self.subsidy_dominance.height.compute_percentage(
@@ -165,30 +155,19 @@ impl Vecs {
// Rolling subsidy dominance = 100 - fee_dominance
let hundred = StoredF32::from(100u8);
self.subsidy_dominance_24h.height.compute_transform(
starting_indexes.height,
&self.fee_dominance_24h.height,
|(height, fee_dom, _)| (height, hundred - fee_dom),
exit,
)?;
self.subsidy_dominance_7d.height.compute_transform(
starting_indexes.height,
&self.fee_dominance_7d.height,
|(height, fee_dom, _)| (height, hundred - fee_dom),
exit,
)?;
self.subsidy_dominance_30d.height.compute_transform(
starting_indexes.height,
&self.fee_dominance_30d.height,
|(height, fee_dom, _)| (height, hundred - fee_dom),
exit,
)?;
self.subsidy_dominance_1y.height.compute_transform(
starting_indexes.height,
&self.fee_dominance_1y.height,
|(height, fee_dom, _)| (height, hundred - fee_dom),
exit,
)?;
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(
starting_indexes.height,
&fee_dom.height,
|(height, fee_dom, _)| (height, hundred - fee_dom),
exit,
)?;
}
self.subsidy_usd_1y_sma.cents.height.compute_rolling_average(
starting_indexes.height,

View File

@@ -6,7 +6,7 @@ use super::Vecs;
use crate::{
indexes,
internal::{
ComputedFromHeight, FiatFromHeight, ValueFromHeightFull,
ComputedFromHeight, FiatFromHeight, RollingWindows, ValueFromHeightFull,
ValueFromHeightCumulativeSum,
},
};
@@ -33,27 +33,9 @@ impl Vecs {
version,
indexes,
)?,
fee_dominance_24h: ComputedFromHeight::forced_import(
fee_dominance_rolling: RollingWindows::forced_import(
db,
"fee_dominance_24h",
version,
indexes,
)?,
fee_dominance_7d: ComputedFromHeight::forced_import(
db,
"fee_dominance_7d",
version,
indexes,
)?,
fee_dominance_30d: ComputedFromHeight::forced_import(
db,
"fee_dominance_30d",
version,
indexes,
)?,
fee_dominance_1y: ComputedFromHeight::forced_import(
db,
"fee_dominance_1y",
"fee_dominance",
version,
indexes,
)?,
@@ -63,27 +45,9 @@ impl Vecs {
version,
indexes,
)?,
subsidy_dominance_24h: ComputedFromHeight::forced_import(
subsidy_dominance_rolling: RollingWindows::forced_import(
db,
"subsidy_dominance_24h",
version,
indexes,
)?,
subsidy_dominance_7d: ComputedFromHeight::forced_import(
db,
"subsidy_dominance_7d",
version,
indexes,
)?,
subsidy_dominance_30d: ComputedFromHeight::forced_import(
db,
"subsidy_dominance_30d",
version,
indexes,
)?,
subsidy_dominance_1y: ComputedFromHeight::forced_import(
db,
"subsidy_dominance_1y",
"subsidy_dominance",
version,
indexes,
)?,

View File

@@ -3,7 +3,7 @@ use brk_types::{Cents, StoredF32};
use vecdb::{Rw, StorageMode};
use crate::internal::{
ComputedFromHeight, FiatFromHeight, ValueFromHeightFull,
ComputedFromHeight, FiatFromHeight, RollingWindows, ValueFromHeightFull,
ValueFromHeightCumulativeSum,
};
@@ -15,14 +15,8 @@ pub struct Vecs<M: StorageMode = Rw> {
pub fees: ValueFromHeightFull<M>,
pub unclaimed_rewards: ValueFromHeightCumulativeSum<M>,
pub fee_dominance: ComputedFromHeight<StoredF32, M>,
pub fee_dominance_24h: ComputedFromHeight<StoredF32, M>,
pub fee_dominance_7d: ComputedFromHeight<StoredF32, M>,
pub fee_dominance_30d: ComputedFromHeight<StoredF32, M>,
pub fee_dominance_1y: ComputedFromHeight<StoredF32, M>,
pub fee_dominance_rolling: RollingWindows<StoredF32, M>,
pub subsidy_dominance: ComputedFromHeight<StoredF32, M>,
pub subsidy_dominance_24h: ComputedFromHeight<StoredF32, M>,
pub subsidy_dominance_7d: ComputedFromHeight<StoredF32, M>,
pub subsidy_dominance_30d: ComputedFromHeight<StoredF32, M>,
pub subsidy_dominance_1y: ComputedFromHeight<StoredF32, M>,
pub subsidy_dominance_rolling: RollingWindows<StoredF32, M>,
pub subsidy_usd_1y_sma: FiatFromHeight<Cents, M>,
}

View File

@@ -8,7 +8,7 @@ use crate::{
indexes::{self, ComputeIndexes},
internal::{
ComputedFromHeightCumulativeSum, ComputedFromHeight, MaskSats, PercentageU32F32,
ValueFromHeightCumulativeSum,
RollingWindows, ValueFromHeightCumulativeSum,
},
mining, prices,
};
@@ -18,19 +18,12 @@ pub struct Vecs<M: StorageMode = Rw> {
slug: PoolSlug,
pub blocks_mined: ComputedFromHeightCumulativeSum<StoredU32, M>,
pub blocks_mined_24h_sum: ComputedFromHeight<StoredU32, M>,
pub blocks_mined_1w_sum: ComputedFromHeight<StoredU32, M>,
pub blocks_mined_1m_sum: ComputedFromHeight<StoredU32, M>,
pub blocks_mined_1y_sum: ComputedFromHeight<StoredU32, M>,
pub blocks_mined_sum: RollingWindows<StoredU32, M>,
pub subsidy: ValueFromHeightCumulativeSum<M>,
pub fee: ValueFromHeightCumulativeSum<M>,
pub coinbase: ValueFromHeightCumulativeSum<M>,
pub dominance: ComputedFromHeight<StoredF32, M>,
pub dominance_24h: ComputedFromHeight<StoredF32, M>,
pub dominance_1w: ComputedFromHeight<StoredF32, M>,
pub dominance_1m: ComputedFromHeight<StoredF32, M>,
pub dominance_1y: ComputedFromHeight<StoredF32, M>,
pub dominance_rolling: RollingWindows<StoredF32, M>,
pub blocks_since_block: ComputedFromHeight<StoredU32, M>,
pub days_since_block: ComputedFromHeight<StoredU16, M>,
}
@@ -52,30 +45,8 @@ impl Vecs {
indexes,
)?;
let blocks_mined_24h_sum = ComputedFromHeight::forced_import(
db,
&suffix("blocks_mined_24h_sum"),
version,
indexes,
)?;
let blocks_mined_1w_sum = ComputedFromHeight::forced_import(
db,
&suffix("blocks_mined_1w_sum"),
version,
indexes,
)?;
let blocks_mined_1m_sum = ComputedFromHeight::forced_import(
db,
&suffix("blocks_mined_1m_sum"),
version,
indexes,
)?;
let blocks_mined_1y_sum = ComputedFromHeight::forced_import(
db,
&suffix("blocks_mined_1y_sum"),
version,
indexes,
)?;
let blocks_mined_sum =
RollingWindows::forced_import(db, &suffix("blocks_mined_sum"), version, indexes)?;
let subsidy =
ValueFromHeightCumulativeSum::forced_import(db, &suffix("subsidy"), version, indexes)?;
@@ -88,27 +59,15 @@ impl Vecs {
let dominance =
ComputedFromHeight::forced_import(db, &suffix("dominance"), version, indexes)?;
let dominance_24h =
ComputedFromHeight::forced_import(db, &suffix("dominance_24h"), version, indexes)?;
let dominance_1w =
ComputedFromHeight::forced_import(db, &suffix("dominance_1w"), version, indexes)?;
let dominance_1m =
ComputedFromHeight::forced_import(db, &suffix("dominance_1m"), version, indexes)?;
let dominance_1y =
ComputedFromHeight::forced_import(db, &suffix("dominance_1y"), version, indexes)?;
let dominance_rolling =
RollingWindows::forced_import(db, &suffix("dominance"), version, indexes)?;
Ok(Self {
dominance,
dominance_24h,
dominance_1w,
dominance_1m,
dominance_1y,
dominance_rolling,
slug,
blocks_mined,
blocks_mined_24h_sum,
blocks_mined_1w_sum,
blocks_mined_1m_sum,
blocks_mined_1y_sum,
blocks_mined_sum,
coinbase,
subsidy,
fee,
@@ -159,31 +118,9 @@ impl Vecs {
Ok(())
})?;
// Compute rolling window blocks mined using the start heights from blocks.count
self.blocks_mined_24h_sum.height.compute_rolling_sum(
self.blocks_mined_sum.compute_rolling_sum(
starting_indexes.height,
&blocks.count.height_24h_ago,
&self.blocks_mined.height,
exit,
)?;
self.blocks_mined_1w_sum.height.compute_rolling_sum(
starting_indexes.height,
&blocks.count.height_1w_ago,
&self.blocks_mined.height,
exit,
)?;
self.blocks_mined_1m_sum.height.compute_rolling_sum(
starting_indexes.height,
&blocks.count.height_1m_ago,
&self.blocks_mined.height,
exit,
)?;
self.blocks_mined_1y_sum.height.compute_rolling_sum(
starting_indexes.height,
&blocks.count.height_1y_ago,
&window_starts,
&self.blocks_mined.height,
exit,
)?;
@@ -196,37 +133,20 @@ impl Vecs {
exit,
)?;
self.dominance_24h
.compute_binary::<StoredU32, StoredU32, PercentageU32F32>(
for ((dom, mined), total) in self
.dominance_rolling
.as_mut_array()
.into_iter()
.zip(self.blocks_mined_sum.as_array())
.zip(blocks.count.block_count_sum.as_array())
{
dom.compute_binary::<StoredU32, StoredU32, PercentageU32F32>(
starting_indexes.height,
&self.blocks_mined_24h_sum.height,
&blocks.count.block_count_sum._24h.height,
exit,
)?;
self.dominance_1w
.compute_binary::<StoredU32, StoredU32, PercentageU32F32>(
starting_indexes.height,
&self.blocks_mined_1w_sum.height,
&blocks.count.block_count_sum._7d.height,
exit,
)?;
self.dominance_1m
.compute_binary::<StoredU32, StoredU32, PercentageU32F32>(
starting_indexes.height,
&self.blocks_mined_1m_sum.height,
&blocks.count.block_count_sum._30d.height,
exit,
)?;
self.dominance_1y
.compute_binary::<StoredU32, StoredU32, PercentageU32F32>(
starting_indexes.height,
&self.blocks_mined_1y_sum.height,
&blocks.count.block_count_sum._1y.height,
&mined.height,
&total.height,
exit,
)?;
}
self.subsidy.compute(
starting_indexes.height,