mirror of
https://github.com/bitcoinresearchkit/brk.git
synced 2026-05-26 17:54:44 -07:00
computer: indexes + rolling
This commit is contained in:
@@ -25,11 +25,12 @@ impl Vecs {
|
||||
exit,
|
||||
)?;
|
||||
|
||||
// Hashrate metrics (uses rewards.coinbase_24h_sum — disjoint field borrow)
|
||||
// Hashrate metrics (disjoint field borrow via coinbase_sum)
|
||||
self.hashrate.compute(
|
||||
&blocks.count,
|
||||
&blocks.difficulty,
|
||||
&self.rewards.coinbase_24h_sum,
|
||||
&self.rewards.coinbase_sum._24h.sats.height,
|
||||
&self.rewards.coinbase_sum._24h.usd.height,
|
||||
starting_indexes,
|
||||
exit,
|
||||
)?;
|
||||
|
||||
@@ -1,11 +1,10 @@
|
||||
use brk_error::Result;
|
||||
use brk_types::{StoredF32, StoredF64};
|
||||
use vecdb::Exit;
|
||||
use brk_types::{Dollars, Height, Sats, StoredF32, StoredF64};
|
||||
use vecdb::{Exit, ReadableVec};
|
||||
|
||||
use super::Vecs;
|
||||
use crate::{
|
||||
blocks::{self, ONE_TERA_HASH, TARGET_BLOCKS_PER_DAY_F64},
|
||||
internal::StoredValueFromHeightLast,
|
||||
ComputeIndexes,
|
||||
traits::ComputeDrawdown,
|
||||
};
|
||||
@@ -15,13 +14,14 @@ impl Vecs {
|
||||
&mut self,
|
||||
count_vecs: &blocks::CountVecs,
|
||||
difficulty_vecs: &blocks::DifficultyVecs,
|
||||
coinbase_sum_24h: &StoredValueFromHeightLast,
|
||||
coinbase_sats_24h_sum: &impl ReadableVec<Height, Sats>,
|
||||
coinbase_usd_24h_sum: &impl ReadableVec<Height, Dollars>,
|
||||
starting_indexes: &ComputeIndexes,
|
||||
exit: &Exit,
|
||||
) -> Result<()> {
|
||||
self.hash_rate.height.compute_transform2(
|
||||
starting_indexes.height,
|
||||
&count_vecs.block_count_24h_sum.height,
|
||||
&count_vecs.block_count_sum._24h.height,
|
||||
&difficulty_vecs.as_hash.height,
|
||||
|(i, block_count_sum, difficulty_as_hash, ..)| {
|
||||
(
|
||||
@@ -78,7 +78,7 @@ impl Vecs {
|
||||
|
||||
self.hash_price_ths.height.compute_transform2(
|
||||
starting_indexes.height,
|
||||
&coinbase_sum_24h.usd.height,
|
||||
coinbase_usd_24h_sum,
|
||||
&self.hash_rate.height,
|
||||
|(i, coinbase_sum, hashrate, ..)| {
|
||||
let hashrate_ths = *hashrate / ONE_TERA_HASH;
|
||||
@@ -101,7 +101,7 @@ impl Vecs {
|
||||
|
||||
self.hash_value_ths.height.compute_transform2(
|
||||
starting_indexes.height,
|
||||
&coinbase_sum_24h.sats.height,
|
||||
coinbase_sats_24h_sum,
|
||||
&self.hash_rate.height,
|
||||
|(i, coinbase_sum, hashrate, ..)| {
|
||||
let hashrate_ths = *hashrate / ONE_TERA_HASH;
|
||||
|
||||
@@ -48,61 +48,20 @@ impl Vecs {
|
||||
Ok(())
|
||||
})?;
|
||||
|
||||
self.coinbase_24h_sum.compute_rolling_sum(
|
||||
let window_starts = count_vecs.window_starts();
|
||||
self.coinbase_sum.compute_rolling_sum(
|
||||
starting_indexes.height,
|
||||
&count_vecs.height_24h_ago,
|
||||
&self.coinbase.sats.height,
|
||||
&self.coinbase.usd.height,
|
||||
exit,
|
||||
)?;
|
||||
self.coinbase_7d_sum.compute_rolling_sum(
|
||||
starting_indexes.height,
|
||||
&count_vecs.height_1w_ago,
|
||||
&self.coinbase.sats.height,
|
||||
&self.coinbase.usd.height,
|
||||
exit,
|
||||
)?;
|
||||
self.coinbase_30d_sum.compute_rolling_sum(
|
||||
starting_indexes.height,
|
||||
&count_vecs.height_1m_ago,
|
||||
&self.coinbase.sats.height,
|
||||
&self.coinbase.usd.height,
|
||||
exit,
|
||||
)?;
|
||||
self.coinbase_1y_sum.compute_rolling_sum(
|
||||
starting_indexes.height,
|
||||
&count_vecs.height_1y_ago,
|
||||
&window_starts,
|
||||
&self.coinbase.sats.height,
|
||||
&self.coinbase.usd.height,
|
||||
exit,
|
||||
)?;
|
||||
|
||||
let fee_sats_source = transactions_fees.fee.sats.height.sum_cum.sum.inner();
|
||||
let fee_usd_source = &transactions_fees.fee.usd.height.sum;
|
||||
self.fee_24h_sum.compute_rolling_sum(
|
||||
let fee_sats_source = transactions_fees.fee.sum_cum.sum.inner();
|
||||
let fee_usd_source = &transactions_fees.fee_usd_sum;
|
||||
self.fee_sum.compute_rolling_sum(
|
||||
starting_indexes.height,
|
||||
&count_vecs.height_24h_ago,
|
||||
fee_sats_source,
|
||||
fee_usd_source,
|
||||
exit,
|
||||
)?;
|
||||
self.fee_7d_sum.compute_rolling_sum(
|
||||
starting_indexes.height,
|
||||
&count_vecs.height_1w_ago,
|
||||
fee_sats_source,
|
||||
fee_usd_source,
|
||||
exit,
|
||||
)?;
|
||||
self.fee_30d_sum.compute_rolling_sum(
|
||||
starting_indexes.height,
|
||||
&count_vecs.height_1m_ago,
|
||||
fee_sats_source,
|
||||
fee_usd_source,
|
||||
exit,
|
||||
)?;
|
||||
self.fee_1y_sum.compute_rolling_sum(
|
||||
starting_indexes.height,
|
||||
&count_vecs.height_1y_ago,
|
||||
&window_starts,
|
||||
fee_sats_source,
|
||||
fee_usd_source,
|
||||
exit,
|
||||
@@ -112,7 +71,7 @@ impl Vecs {
|
||||
vec.compute_transform2(
|
||||
starting_indexes.height,
|
||||
&self.coinbase.sats.height,
|
||||
transactions_fees.fee.sats.height.sum_cum.sum.inner(),
|
||||
transactions_fees.fee.sum_cum.sum.inner(),
|
||||
|(height, coinbase, fees, ..)| {
|
||||
(
|
||||
height,
|
||||
@@ -145,7 +104,7 @@ impl Vecs {
|
||||
// All-time cumulative fee dominance
|
||||
self.fee_dominance.height.compute_percentage(
|
||||
starting_indexes.height,
|
||||
transactions_fees.fee.sats.height.sum_cum.cumulative.inner(),
|
||||
transactions_fees.fee.sum_cum.cumulative.inner(),
|
||||
self.coinbase.sats.rest.height_cumulative.inner(),
|
||||
exit,
|
||||
)?;
|
||||
@@ -153,26 +112,26 @@ impl Vecs {
|
||||
// Rolling fee dominance = sum(fees) / sum(coinbase) * 100
|
||||
self.fee_dominance_24h.height.compute_percentage(
|
||||
starting_indexes.height,
|
||||
&self.fee_24h_sum.sats.height,
|
||||
&self.coinbase_24h_sum.sats.height,
|
||||
&self.fee_sum._24h.sats.height,
|
||||
&self.coinbase_sum._24h.sats.height,
|
||||
exit,
|
||||
)?;
|
||||
self.fee_dominance_7d.height.compute_percentage(
|
||||
starting_indexes.height,
|
||||
&self.fee_7d_sum.sats.height,
|
||||
&self.coinbase_7d_sum.sats.height,
|
||||
&self.fee_sum._7d.sats.height,
|
||||
&self.coinbase_sum._7d.sats.height,
|
||||
exit,
|
||||
)?;
|
||||
self.fee_dominance_30d.height.compute_percentage(
|
||||
starting_indexes.height,
|
||||
&self.fee_30d_sum.sats.height,
|
||||
&self.coinbase_30d_sum.sats.height,
|
||||
&self.fee_sum._30d.sats.height,
|
||||
&self.coinbase_sum._30d.sats.height,
|
||||
exit,
|
||||
)?;
|
||||
self.fee_dominance_1y.height.compute_percentage(
|
||||
starting_indexes.height,
|
||||
&self.fee_1y_sum.sats.height,
|
||||
&self.coinbase_1y_sum.sats.height,
|
||||
&self.fee_sum._1y.sats.height,
|
||||
&self.coinbase_sum._1y.sats.height,
|
||||
exit,
|
||||
)?;
|
||||
|
||||
|
||||
@@ -5,7 +5,7 @@ use vecdb::Database;
|
||||
use super::Vecs;
|
||||
use crate::{
|
||||
indexes,
|
||||
internal::{ComputedFromHeightLast, StoredValueFromHeightLast, ValueFromHeightFull, ValueFromHeightSumCum},
|
||||
internal::{ComputedFromHeightLast, StoredValueRollingWindows, ValueFromHeightFull, ValueFromHeightSumCum},
|
||||
prices,
|
||||
};
|
||||
|
||||
@@ -17,14 +17,8 @@ impl Vecs {
|
||||
prices: &prices::Vecs,
|
||||
) -> Result<Self> {
|
||||
Ok(Self {
|
||||
coinbase_24h_sum: StoredValueFromHeightLast::forced_import(db, "coinbase_24h_sum", version, indexes)?,
|
||||
coinbase_7d_sum: StoredValueFromHeightLast::forced_import(db, "coinbase_7d_sum", version, indexes)?,
|
||||
coinbase_30d_sum: StoredValueFromHeightLast::forced_import(db, "coinbase_30d_sum", version, indexes)?,
|
||||
coinbase_1y_sum: StoredValueFromHeightLast::forced_import(db, "coinbase_1y_sum", version, indexes)?,
|
||||
fee_24h_sum: StoredValueFromHeightLast::forced_import(db, "fee_24h_sum", version, indexes)?,
|
||||
fee_7d_sum: StoredValueFromHeightLast::forced_import(db, "fee_7d_sum", version, indexes)?,
|
||||
fee_30d_sum: StoredValueFromHeightLast::forced_import(db, "fee_30d_sum", version, indexes)?,
|
||||
fee_1y_sum: StoredValueFromHeightLast::forced_import(db, "fee_1y_sum", version, indexes)?,
|
||||
coinbase_sum: StoredValueRollingWindows::forced_import(db, "coinbase_sum", version, indexes)?,
|
||||
fee_sum: StoredValueRollingWindows::forced_import(db, "fee_sum", version, indexes)?,
|
||||
coinbase: ValueFromHeightFull::forced_import(db, "coinbase", version, indexes, prices)?,
|
||||
subsidy: ValueFromHeightFull::forced_import(db, "subsidy", version, indexes, prices)?,
|
||||
unclaimed_rewards: ValueFromHeightSumCum::forced_import(
|
||||
|
||||
@@ -2,19 +2,13 @@ use brk_traversable::Traversable;
|
||||
use brk_types::{Dollars, StoredF32};
|
||||
use vecdb::{Rw, StorageMode};
|
||||
|
||||
use crate::internal::{ComputedFromHeightLast, StoredValueFromHeightLast, ValueFromHeightFull, ValueFromHeightSumCum};
|
||||
use crate::internal::{ComputedFromHeightLast, StoredValueRollingWindows, ValueFromHeightFull, ValueFromHeightSumCum};
|
||||
|
||||
/// Coinbase/subsidy/rewards metrics
|
||||
#[derive(Traversable)]
|
||||
pub struct Vecs<M: StorageMode = Rw> {
|
||||
pub coinbase_24h_sum: StoredValueFromHeightLast<M>,
|
||||
pub coinbase_7d_sum: StoredValueFromHeightLast<M>,
|
||||
pub coinbase_30d_sum: StoredValueFromHeightLast<M>,
|
||||
pub coinbase_1y_sum: StoredValueFromHeightLast<M>,
|
||||
pub fee_24h_sum: StoredValueFromHeightLast<M>,
|
||||
pub fee_7d_sum: StoredValueFromHeightLast<M>,
|
||||
pub fee_30d_sum: StoredValueFromHeightLast<M>,
|
||||
pub fee_1y_sum: StoredValueFromHeightLast<M>,
|
||||
pub coinbase_sum: StoredValueRollingWindows<M>,
|
||||
pub fee_sum: StoredValueRollingWindows<M>,
|
||||
pub coinbase: ValueFromHeightFull<M>,
|
||||
pub subsidy: ValueFromHeightFull<M>,
|
||||
pub unclaimed_rewards: ValueFromHeightSumCum<M>,
|
||||
|
||||
Reference in New Issue
Block a user