global: snapshot part 16

This commit is contained in:
nym21
2026-03-21 17:15:53 +01:00
parent b45c6ec05f
commit 2991562234
31 changed files with 355 additions and 423 deletions

View File

@@ -1134,38 +1134,6 @@ pub struct AverageBaseCumulativeMaxMedianMinPct10Pct25Pct75Pct90SumPattern<T> {
pub sum: _1m1w1y24hPattern<T>,
}
/// Pattern struct for repeated tree structure.
pub struct AverageGainsLossesRsiStochPattern {
pub average_gain: SeriesPattern1<StoredF32>,
pub average_loss: SeriesPattern1<StoredF32>,
pub gains: SeriesPattern1<StoredF32>,
pub losses: SeriesPattern1<StoredF32>,
pub rsi: BpsPercentRatioPattern3,
pub rsi_max: BpsPercentRatioPattern3,
pub rsi_min: BpsPercentRatioPattern3,
pub stoch_rsi: BpsPercentRatioPattern3,
pub stoch_rsi_d: BpsPercentRatioPattern3,
pub stoch_rsi_k: BpsPercentRatioPattern3,
}
impl AverageGainsLossesRsiStochPattern {
/// Create a new pattern node with accumulated series name.
pub fn new(client: Arc<BrkClientBase>, acc: String, disc: String) -> Self {
Self {
average_gain: SeriesPattern1::new(client.clone(), _m(&acc, &format!("average_gain_{disc}", disc=disc))),
average_loss: SeriesPattern1::new(client.clone(), _m(&acc, &format!("average_loss_{disc}", disc=disc))),
gains: SeriesPattern1::new(client.clone(), _m(&acc, &format!("gains_{disc}", disc=disc))),
losses: SeriesPattern1::new(client.clone(), _m(&acc, &format!("losses_{disc}", disc=disc))),
rsi: BpsPercentRatioPattern3::new(client.clone(), _m(&acc, &disc)),
rsi_max: BpsPercentRatioPattern3::new(client.clone(), _m(&acc, &format!("max_{disc}", disc=disc))),
rsi_min: BpsPercentRatioPattern3::new(client.clone(), _m(&acc, &format!("min_{disc}", disc=disc))),
stoch_rsi: BpsPercentRatioPattern3::new(client.clone(), _m(&acc, &format!("stoch_{disc}", disc=disc))),
stoch_rsi_d: BpsPercentRatioPattern3::new(client.clone(), _m(&acc, &format!("stoch_d_{disc}", disc=disc))),
stoch_rsi_k: BpsPercentRatioPattern3::new(client.clone(), _m(&acc, &format!("stoch_k_{disc}", disc=disc))),
}
}
}
/// Pattern struct for repeated tree structure.
pub struct AllP2aP2pk33P2pk65P2pkhP2shP2trP2wpkhP2wshPattern3 {
pub all: SeriesPattern1<StoredU64>,
@@ -2528,7 +2496,7 @@ impl CentsSatsUsdPattern {
pub struct CumulativeRollingSumPattern {
pub cumulative: SeriesPattern1<StoredU64>,
pub rolling: AverageMaxMedianMinPct10Pct25Pct75Pct90SumPattern,
pub sum: SeriesPattern1<StoredU64>,
pub sum: SeriesPattern18<StoredU64>,
}
impl CumulativeRollingSumPattern {
@@ -2537,7 +2505,7 @@ impl CumulativeRollingSumPattern {
Self {
cumulative: SeriesPattern1::new(client.clone(), _m(&acc, "cumulative")),
rolling: AverageMaxMedianMinPct10Pct25Pct75Pct90SumPattern::new(client.clone(), acc.clone()),
sum: SeriesPattern1::new(client.clone(), _m(&acc, "sum")),
sum: SeriesPattern18::new(client.clone(), _m(&acc, "sum")),
}
}
}
@@ -2592,6 +2560,24 @@ pub struct RatioTransferValuePattern {
pub value_destroyed: AverageBlockCumulativeSumPattern<Cents>,
}
/// Pattern struct for repeated tree structure.
pub struct RsiStochPattern {
pub rsi: BpsPercentRatioPattern3,
pub stoch_rsi_d: BpsPercentRatioPattern3,
pub stoch_rsi_k: BpsPercentRatioPattern3,
}
impl RsiStochPattern {
/// Create a new pattern node with accumulated series name.
pub fn new(client: Arc<BrkClientBase>, acc: String, disc: String) -> Self {
Self {
rsi: BpsPercentRatioPattern3::new(client.clone(), _m(&acc, &disc)),
stoch_rsi_d: BpsPercentRatioPattern3::new(client.clone(), _m(&acc, &format!("stoch_d_{disc}", disc=disc))),
stoch_rsi_k: BpsPercentRatioPattern3::new(client.clone(), _m(&acc, &format!("stoch_k_{disc}", disc=disc))),
}
}
}
/// Pattern struct for repeated tree structure.
pub struct _6bBlockTxPattern<T> {
pub _6b: MaxMedianMinPct10Pct25Pct75Pct90Pattern<T>,
@@ -2676,7 +2662,7 @@ impl AllSthPattern {
/// Pattern struct for repeated tree structure.
pub struct BaseSumPattern {
pub base: SeriesPattern1<Dollars>,
pub base: SeriesPattern18<Dollars>,
pub sum: _1m1w1y24hPattern<Dollars>,
}
@@ -2684,7 +2670,7 @@ impl BaseSumPattern {
/// Create a new pattern node with accumulated series name.
pub fn new(client: Arc<BrkClientBase>, acc: String) -> Self {
Self {
base: SeriesPattern1::new(client.clone(), acc.clone()),
base: SeriesPattern18::new(client.clone(), acc.clone()),
sum: _1m1w1y24hPattern::new(client.clone(), _m(&acc, "sum")),
}
}
@@ -2706,6 +2692,22 @@ impl BaseDeltaPattern {
}
}
/// Pattern struct for repeated tree structure.
pub struct BlockCumulativePattern {
pub block: BtcCentsSatsUsdPattern2,
pub cumulative: BtcCentsSatsUsdPattern3,
}
impl BlockCumulativePattern {
/// Create a new pattern node with accumulated series name.
pub fn new(client: Arc<BrkClientBase>, acc: String) -> Self {
Self {
block: BtcCentsSatsUsdPattern2::new(client.clone(), acc.clone()),
cumulative: BtcCentsSatsUsdPattern3::new(client.clone(), _m(&acc, "cumulative")),
}
}
}
/// Pattern struct for repeated tree structure.
pub struct BlocksDominancePattern {
pub blocks_mined: AverageBlockCumulativeSumPattern2,
@@ -4076,13 +4078,13 @@ impl SeriesTree_Scripts_Count {
/// Series tree node.
pub struct SeriesTree_Scripts_Value {
pub op_return: AverageBlockCumulativeSumPattern3,
pub op_return: BlockCumulativePattern,
}
impl SeriesTree_Scripts_Value {
pub fn new(client: Arc<BrkClientBase>, base_path: String) -> Self {
Self {
op_return: AverageBlockCumulativeSumPattern3::new(client.clone(), "op_return_value".to_string()),
op_return: BlockCumulativePattern::new(client.clone(), "op_return_value".to_string()),
}
}
}
@@ -4107,7 +4109,7 @@ pub struct SeriesTree_Mining_Rewards {
pub coinbase: AverageBlockCumulativeSumPattern3,
pub subsidy: SeriesTree_Mining_Rewards_Subsidy,
pub fees: SeriesTree_Mining_Rewards_Fees,
pub unclaimed: SeriesTree_Mining_Rewards_Unclaimed,
pub unclaimed: BlockCumulativePattern,
}
impl SeriesTree_Mining_Rewards {
@@ -4116,7 +4118,7 @@ impl SeriesTree_Mining_Rewards {
coinbase: AverageBlockCumulativeSumPattern3::new(client.clone(), "coinbase".to_string()),
subsidy: SeriesTree_Mining_Rewards_Subsidy::new(client.clone(), format!("{base_path}_subsidy")),
fees: SeriesTree_Mining_Rewards_Fees::new(client.clone(), format!("{base_path}_fees")),
unclaimed: SeriesTree_Mining_Rewards_Unclaimed::new(client.clone(), format!("{base_path}_unclaimed")),
unclaimed: BlockCumulativePattern::new(client.clone(), "unclaimed_rewards".to_string()),
}
}
}
@@ -4128,7 +4130,6 @@ pub struct SeriesTree_Mining_Rewards_Subsidy {
pub sum: _1m1w1y24hPattern4,
pub average: _1m1w1y24hPattern3,
pub dominance: _1m1w1y24hBpsPercentRatioPattern,
pub sma_1y: CentsUsdPattern3,
}
impl SeriesTree_Mining_Rewards_Subsidy {
@@ -4139,7 +4140,6 @@ impl SeriesTree_Mining_Rewards_Subsidy {
sum: _1m1w1y24hPattern4::new(client.clone(), "subsidy_sum".to_string()),
average: _1m1w1y24hPattern3::new(client.clone(), "subsidy_average".to_string()),
dominance: _1m1w1y24hBpsPercentRatioPattern::new(client.clone(), "subsidy_dominance".to_string()),
sma_1y: CentsUsdPattern3::new(client.clone(), "subsidy_sma_1y".to_string()),
}
}
}
@@ -4200,21 +4200,6 @@ impl SeriesTree_Mining_Rewards_Fees_ToSubsidyRatio {
}
}
/// Series tree node.
pub struct SeriesTree_Mining_Rewards_Unclaimed {
pub block: BtcCentsSatsUsdPattern2,
pub cumulative: BtcCentsSatsUsdPattern3,
}
impl SeriesTree_Mining_Rewards_Unclaimed {
pub fn new(client: Arc<BrkClientBase>, base_path: String) -> Self {
Self {
block: BtcCentsSatsUsdPattern2::new(client.clone(), "unclaimed_rewards".to_string()),
cumulative: BtcCentsSatsUsdPattern3::new(client.clone(), "unclaimed_rewards_cumulative".to_string()),
}
}
}
/// Series tree node.
pub struct SeriesTree_Mining_Hashrate {
pub rate: SeriesTree_Mining_Hashrate_Rate,
@@ -5715,8 +5700,6 @@ impl SeriesTree_Market_Dca_Class_Return {
/// Series tree node.
pub struct SeriesTree_Market_Technical {
pub rsi: SeriesTree_Market_Technical_Rsi,
pub stoch_k: BpsPercentRatioPattern3,
pub stoch_d: BpsPercentRatioPattern3,
pub pi_cycle: BpsRatioPattern2,
pub macd: SeriesTree_Market_Technical_Macd,
}
@@ -5725,8 +5708,6 @@ impl SeriesTree_Market_Technical {
pub fn new(client: Arc<BrkClientBase>, base_path: String) -> Self {
Self {
rsi: SeriesTree_Market_Technical_Rsi::new(client.clone(), format!("{base_path}_rsi")),
stoch_k: BpsPercentRatioPattern3::new(client.clone(), "stoch_k".to_string()),
stoch_d: BpsPercentRatioPattern3::new(client.clone(), "stoch_d".to_string()),
pi_cycle: BpsRatioPattern2::new(client.clone(), "pi_cycle".to_string()),
macd: SeriesTree_Market_Technical_Macd::new(client.clone(), format!("{base_path}_macd")),
}
@@ -5735,17 +5716,17 @@ impl SeriesTree_Market_Technical {
/// Series tree node.
pub struct SeriesTree_Market_Technical_Rsi {
pub _24h: AverageGainsLossesRsiStochPattern,
pub _1w: AverageGainsLossesRsiStochPattern,
pub _1m: AverageGainsLossesRsiStochPattern,
pub _24h: RsiStochPattern,
pub _1w: RsiStochPattern,
pub _1m: RsiStochPattern,
}
impl SeriesTree_Market_Technical_Rsi {
pub fn new(client: Arc<BrkClientBase>, base_path: String) -> Self {
Self {
_24h: AverageGainsLossesRsiStochPattern::new(client.clone(), "rsi".to_string(), "24h".to_string()),
_1w: AverageGainsLossesRsiStochPattern::new(client.clone(), "rsi".to_string(), "1w".to_string()),
_1m: AverageGainsLossesRsiStochPattern::new(client.clone(), "rsi".to_string(), "1m".to_string()),
_24h: RsiStochPattern::new(client.clone(), "rsi".to_string(), "24h".to_string()),
_1w: RsiStochPattern::new(client.clone(), "rsi".to_string(), "1w".to_string()),
_1m: RsiStochPattern::new(client.clone(), "rsi".to_string(), "1m".to_string()),
}
}
}
@@ -6267,7 +6248,7 @@ impl SeriesTree_Prices_Spot {
pub struct SeriesTree_Supply {
pub state: SeriesPattern18<SupplyState>,
pub circulating: BtcCentsSatsUsdPattern3,
pub burned: AverageBlockCumulativeSumPattern3,
pub burned: BlockCumulativePattern,
pub inflation_rate: BpsPercentRatioPattern,
pub velocity: SeriesTree_Supply_Velocity,
pub market_cap: CentsDeltaUsdPattern,
@@ -6280,7 +6261,7 @@ impl SeriesTree_Supply {
Self {
state: SeriesPattern18::new(client.clone(), "supply_state".to_string()),
circulating: BtcCentsSatsUsdPattern3::new(client.clone(), "circulating_supply".to_string()),
burned: AverageBlockCumulativeSumPattern3::new(client.clone(), "unspendable_supply".to_string()),
burned: BlockCumulativePattern::new(client.clone(), "unspendable_supply".to_string()),
inflation_rate: BpsPercentRatioPattern::new(client.clone(), "inflation_rate".to_string()),
velocity: SeriesTree_Supply_Velocity::new(client.clone(), format!("{base_path}_velocity")),
market_cap: CentsDeltaUsdPattern::new(client.clone(), "market_cap".to_string()),

View File

@@ -67,8 +67,8 @@ pub(crate) fn process_blocks(
let height_to_first_txout_index = &indexer.vecs.outputs.first_txout_index;
let height_to_first_txin_index = &indexer.vecs.inputs.first_txin_index;
let height_to_tx_count = &transactions.count.total.block;
let height_to_output_count = &outputs.count.total.sum.height;
let height_to_input_count = &inputs.count.sum.height;
let height_to_output_count = &outputs.count.total.sum;
let height_to_input_count = &inputs.count.sum;
let tx_index_to_output_count = &indexes.tx_index.output_count;
let tx_index_to_input_count = &indexes.tx_index.input_count;

View File

@@ -3,7 +3,8 @@ use brk_traversable::Traversable;
use brk_types::{BasisPointsSigned32, Bitcoin, Cents, CentsSigned, Dollars, Height, Indexes, StoredF64, Version};
use derive_more::{Deref, DerefMut};
use vecdb::{
AnyStoredVec, Exit, ReadableCloneableVec, ReadableVec, Rw, StorageMode, WritableVec,
AnyStoredVec, Exit, LazyVecFrom1, ReadableCloneableVec, ReadableVec, Rw, StorageMode,
WritableVec,
};
use crate::{
@@ -22,7 +23,7 @@ use super::RealizedMinimal;
#[derive(Clone, Traversable)]
pub struct NegRealizedLoss {
#[traversable(flatten)]
pub base: LazyPerBlock<Dollars, Cents>,
pub base: LazyVecFrom1<Height, Dollars, Height, Cents>,
pub sum: Windows<LazyPerBlock<Dollars, Cents>>,
}
@@ -51,11 +52,10 @@ impl RealizedCore {
let minimal = RealizedMinimal::forced_import(cfg)?;
let neg_loss_base = LazyPerBlock::from_height_source::<NegCentsUnsignedToDollars>(
let neg_loss_base = LazyVecFrom1::transformed::<NegCentsUnsignedToDollars>(
&cfg.name("realized_loss_neg"),
cfg.version + Version::ONE,
minimal.loss.block.cents.read_only_boxed_clone(),
cfg.indexes,
);
let neg_loss_sum = minimal.loss.sum.0.map_with_suffix(|suffix, slot| {

View File

@@ -22,7 +22,7 @@ impl Vecs {
.compute_binary::<Dollars, Dollars, RatioDollarsBp32>(
starting_indexes.height,
&mining.rewards.subsidy.block.usd,
&mining.rewards.subsidy_sma_1y.usd.height,
&mining.rewards.subsidy.average._1y.usd.height,
exit,
)?;

View File

@@ -1,7 +1,7 @@
use brk_error::Result;
use brk_traversable::Traversable;
use brk_types::{Height, Version};
use vecdb::{Database, Exit, Rw, StorageMode};
use brk_types::{Height, Sats, Version};
use vecdb::{Database, EagerVec, Exit, PcoVec, Rw, StorageMode};
use crate::{
indexes,
@@ -57,4 +57,15 @@ impl AmountPerBlockCumulative {
Ok(())
}
pub(crate) fn compute_with(
&mut self,
max_from: Height,
prices: &prices::Vecs,
exit: &Exit,
compute_sats: impl FnOnce(&mut EagerVec<PcoVec<Height, Sats>>) -> Result<()>,
) -> Result<()> {
compute_sats(&mut self.block.sats)?;
self.compute(prices, max_from, exit)
}
}

View File

@@ -3,8 +3,8 @@ use brk_traversable::Traversable;
use brk_types::Height;
use schemars::JsonSchema;
use vecdb::{
AnyStoredVec, AnyVec, Database, Exit, ReadableVec, Rw, StorageMode, VecIndex, VecValue,
Version, WritableVec,
AnyStoredVec, AnyVec, Database, EagerVec, Exit, ImportableVec, PcoVec, ReadableVec, Rw,
StorageMode, VecIndex, VecValue, Version, WritableVec,
};
use crate::{
@@ -17,7 +17,7 @@ pub struct PerBlockAggregated<T, M: StorageMode = Rw>
where
T: NumericValue + JsonSchema,
{
pub sum: PerBlock<T, M>,
pub sum: M::Stored<EagerVec<PcoVec<Height, T>>>,
pub cumulative: PerBlock<T, M>,
pub rolling: RollingComplete<T, M>,
}
@@ -33,7 +33,7 @@ where
indexes: &indexes::Vecs,
cached_starts: &CachedWindowStarts,
) -> Result<Self> {
let sum = PerBlock::forced_import(db, &format!("{name}_sum"), version, indexes)?;
let sum = EagerVec::forced_import(db, &format!("{name}_sum"), version)?;
let cumulative =
PerBlock::forced_import(db, &format!("{name}_cumulative"), version, indexes)?;
let rolling = RollingComplete::forced_import(
@@ -73,9 +73,8 @@ where
let mut index = max_from;
index = {
self.sum
.height
.validate_computed_version_or_reset(combined_version)?;
index.min(Height::from(self.sum.height.len()))
index.min(Height::from(self.sum.len()))
};
index = {
self.cumulative
@@ -86,7 +85,7 @@ where
let start = index.to_usize();
self.sum.height.truncate_if_needed_at(start)?;
self.sum.truncate_if_needed_at(start)?;
self.cumulative.height.truncate_if_needed_at(start)?;
let mut cumulative_val = index.decremented().map_or(T::from(0_usize), |idx| {
@@ -117,7 +116,7 @@ where
|acc, val| acc + val,
);
self.sum.height.push(sum_val);
self.sum.push(sum_val);
cumulative_val += sum_val;
self.cumulative.height.push(cumulative_val);
@@ -125,12 +124,11 @@ where
})?;
let _lock = exit.lock();
self.sum.height.write()?;
self.sum.write()?;
self.cumulative.height.write()?;
drop(_lock);
self.rolling
.compute(max_from, windows, &self.sum.height, exit)?;
self.rolling.compute(max_from, windows, &self.sum, exit)?;
Ok(())
}
}

View File

@@ -58,10 +58,9 @@ impl Vecs {
r3?;
r4?;
// Phase 3: Depends on returns, range, moving_average
// Phase 3: Depends on returns, moving_average
self.technical.compute(
&self.returns,
&self.range,
prices,
blocks,
&self.moving_average,

View File

@@ -1,9 +1,9 @@
use brk_error::Result;
use brk_types::{BasisPoints16, Dollars, Indexes};
use brk_types::{Dollars, Indexes};
use vecdb::Exit;
use super::{
super::{moving_average, range, returns},
super::{moving_average, returns},
Vecs, macd, rsi,
};
use crate::{blocks, internal::{RatioDollarsBp32, WindowsTo1m}, prices};
@@ -13,37 +13,12 @@ impl Vecs {
pub(crate) fn compute(
&mut self,
returns: &returns::Vecs,
range: &range::Vecs,
prices: &prices::Vecs,
blocks: &blocks::Vecs,
moving_average: &moving_average::Vecs,
starting_indexes: &Indexes,
exit: &Exit,
) -> Result<()> {
self.stoch_k.bps.height.compute_transform3(
starting_indexes.height,
&prices.spot.usd.height,
&range.min._2w.usd.height,
&range.max._2w.usd.height,
|(h, close, low, high, ..)| {
let range = *high - *low;
let stoch = if range == 0.0 {
BasisPoints16::ZERO
} else {
BasisPoints16::from((*close - *low) / range)
};
(h, stoch)
},
exit,
)?;
self.stoch_d.bps.height.compute_rolling_average(
starting_indexes.height,
&blocks.lookback._3d,
&self.stoch_k.bps.height,
exit,
)?;
let daily_returns = &returns.periods._24h.ratio.height;
for (rsi_chain, &m) in self.rsi.as_mut_array().into_iter().zip(&WindowsTo1m::<()>::DAYS) {
rsi::compute(

View File

@@ -110,15 +110,10 @@ impl Vecs {
WindowsTo1m::try_from_fn(|tf| RsiChain::forced_import(db, tf, v + Version::TWO, indexes))?;
let macd = WindowsTo1m::try_from_fn(|tf| MacdChain::forced_import(db, tf, v, indexes))?;
let stoch_k = PercentPerBlock::forced_import(db, "stoch_k", v, indexes)?;
let stoch_d = PercentPerBlock::forced_import(db, "stoch_d", v, indexes)?;
let pi_cycle = RatioPerBlock::forced_import_raw(db, "pi_cycle", v, indexes)?;
Ok(Self {
rsi,
stoch_k,
stoch_d,
pi_cycle,
macd,
})

View File

@@ -6,13 +6,20 @@ use crate::internal::{PerBlock, PercentPerBlock, RatioPerBlock, WindowsTo1m};
#[derive(Traversable)]
pub struct RsiChain<M: StorageMode = Rw> {
#[traversable(hidden)]
pub gains: PerBlock<StoredF32, M>,
#[traversable(hidden)]
pub losses: PerBlock<StoredF32, M>,
#[traversable(hidden)]
pub average_gain: PerBlock<StoredF32, M>,
#[traversable(hidden)]
pub average_loss: PerBlock<StoredF32, M>,
pub rsi: PercentPerBlock<BasisPoints16, M>,
#[traversable(hidden)]
pub rsi_min: PercentPerBlock<BasisPoints16, M>,
#[traversable(hidden)]
pub rsi_max: PercentPerBlock<BasisPoints16, M>,
#[traversable(hidden)]
pub stoch_rsi: PercentPerBlock<BasisPoints16, M>,
pub stoch_rsi_k: PercentPerBlock<BasisPoints16, M>,
pub stoch_rsi_d: PercentPerBlock<BasisPoints16, M>,
@@ -31,9 +38,6 @@ pub struct MacdChain<M: StorageMode = Rw> {
pub struct Vecs<M: StorageMode = Rw> {
pub rsi: WindowsTo1m<RsiChain<M>>,
pub stoch_k: PercentPerBlock<BasisPoints16, M>,
pub stoch_d: PercentPerBlock<BasisPoints16, M>,
pub pi_cycle: RatioPerBlock<BasisPoints32, M>,
pub macd: WindowsTo1m<MacdChain<M>>,

View File

@@ -133,13 +133,6 @@ impl Vecs {
exit,
)?;
self.subsidy_sma_1y.cents.height.compute_rolling_average(
starting_indexes.height,
&lookback._1y,
&self.subsidy.block.cents,
exit,
)?;
self.fee_to_subsidy_ratio
.compute_binary::<Dollars, Dollars, RatioDollarsBp32, _, _>(
starting_indexes.height,

View File

@@ -7,7 +7,7 @@ use crate::{
indexes,
internal::{
AmountPerBlockCumulative, AmountPerBlockCumulativeRolling, AmountPerBlockFull,
CachedWindowStarts, FiatPerBlock, LazyPercentRollingWindows, OneMinusBp16,
CachedWindowStarts, LazyPercentRollingWindows, OneMinusBp16,
PercentPerBlock, PercentRollingWindows, RatioRollingWindows,
},
};
@@ -55,7 +55,6 @@ impl Vecs {
indexes,
)?,
subsidy_dominance_rolling,
subsidy_sma_1y: FiatPerBlock::forced_import(db, "subsidy_sma_1y", version, indexes)?,
fee_to_subsidy_ratio: RatioRollingWindows::forced_import(
db,
"fee_to_subsidy_ratio",

View File

@@ -1,11 +1,10 @@
use brk_traversable::Traversable;
use brk_types::{BasisPoints16, BasisPoints32, Cents};
use brk_types::{BasisPoints16, BasisPoints32};
use vecdb::{Rw, StorageMode};
use crate::internal::{
AmountPerBlockCumulative, AmountPerBlockCumulativeRolling, AmountPerBlockFull,
FiatPerBlock, LazyPercentRollingWindows, PercentPerBlock, PercentRollingWindows,
RatioRollingWindows,
LazyPercentRollingWindows, PercentPerBlock, PercentRollingWindows, RatioRollingWindows,
};
#[derive(Traversable)]
@@ -22,8 +21,6 @@ pub struct Vecs<M: StorageMode = Rw> {
pub subsidy_dominance: PercentPerBlock<BasisPoints16, M>,
#[traversable(wrap = "subsidy", rename = "dominance")]
pub subsidy_dominance_rolling: LazyPercentRollingWindows<BasisPoints16>,
#[traversable(wrap = "subsidy", rename = "sma_1y")]
pub subsidy_sma_1y: FiatPerBlock<Cents, M>,
#[traversable(wrap = "fees", rename = "to_subsidy_ratio")]
pub fee_to_subsidy_ratio: RatioRollingWindows<BasisPoints32, M>,
}

View File

@@ -22,7 +22,7 @@ impl Vecs {
let version = parent_version;
let count = CountVecs::forced_import(&db, version, indexes, cached_starts)?;
let value = ValueVecs::forced_import(&db, version, indexes, cached_starts)?;
let value = ValueVecs::forced_import(&db, version, indexes)?;
let this = Self { db, count, value };
finalize_db(&this.db, &this)?;

View File

@@ -14,7 +14,7 @@ impl Vecs {
starting_indexes: &Indexes,
exit: &Exit,
) -> Result<()> {
self.op_return.compute(
self.op_return.compute_with(
starting_indexes.height,
prices,
exit,

View File

@@ -3,22 +3,20 @@ use brk_types::Version;
use vecdb::Database;
use super::Vecs;
use crate::{indexes, internal::{AmountPerBlockCumulativeRolling, CachedWindowStarts}};
use crate::{indexes, internal::AmountPerBlockCumulative};
impl Vecs {
pub(crate) fn forced_import(
db: &Database,
version: Version,
indexes: &indexes::Vecs,
cached_starts: &CachedWindowStarts,
) -> Result<Self> {
Ok(Self {
op_return: AmountPerBlockCumulativeRolling::forced_import(
op_return: AmountPerBlockCumulative::forced_import(
db,
"op_return_value",
version,
indexes,
cached_starts,
)?,
})
}

View File

@@ -1,9 +1,9 @@
use brk_traversable::Traversable;
use vecdb::{Rw, StorageMode};
use crate::internal::AmountPerBlockCumulativeRolling;
use crate::internal::AmountPerBlockCumulative;
#[derive(Traversable)]
pub struct Vecs<M: StorageMode = Rw> {
pub op_return: AmountPerBlockCumulativeRolling<M>,
pub op_return: AmountPerBlockCumulative<M>,
}

View File

@@ -1,6 +1,6 @@
use brk_error::Result;
use brk_types::{Height, Indexes, Sats};
use vecdb::{AnyStoredVec, AnyVec, Exit, ReadableVec, VecIndex, WritableVec};
use brk_types::{Indexes, Sats};
use vecdb::{Exit, VecIndex};
use super::Vecs;
use crate::{mining, prices, scripts};
@@ -14,46 +14,21 @@ impl Vecs {
starting_indexes: &Indexes,
exit: &Exit,
) -> Result<()> {
let op_return_height = &scripts.value.op_return.block.sats;
let unclaimed_height = &mining.rewards.unclaimed.block.sats;
self.total.compute(
self.total.compute_with(
starting_indexes.height,
prices,
exit,
|height_vec| {
let unspendable_dep_version =
op_return_height.version() + unclaimed_height.version();
height_vec.validate_computed_version_or_reset(unspendable_dep_version)?;
let op_return_target = op_return_height.len();
if op_return_target > 0 {
let target_height = Height::from(op_return_target - 1);
let current_len = height_vec.len();
let starting_height =
Height::from(current_len.min(starting_indexes.height.to_usize()));
if starting_height <= target_height {
let start = starting_height.to_usize();
let end = target_height.to_usize() + 1;
let unclaimed_data = unclaimed_height.collect_range_at(start, end);
height_vec.truncate_if_needed(starting_height)?;
op_return_height.fold_range_at(start, end, start, |idx, op_return| {
let unclaimed = unclaimed_data[idx - start];
let genesis = if idx == 0 {
Sats::FIFTY_BTC
} else {
Sats::ZERO
};
let unspendable = genesis + op_return + unclaimed;
height_vec.push(unspendable);
idx + 1
});
}
}
height_vec.write()?;
Ok(())
|sats| {
Ok(sats.compute_transform2(
starting_indexes.height,
&scripts.value.op_return.block.sats,
&mining.rewards.unclaimed.block.sats,
|(h, op_return, unclaimed, ..)| {
let genesis = if h.to_usize() == 0 { Sats::FIFTY_BTC } else { Sats::ZERO };
(h, genesis + op_return + unclaimed)
},
exit,
)?)
},
)?;

View File

@@ -3,22 +3,20 @@ use brk_types::Version;
use vecdb::Database;
use super::Vecs;
use crate::{indexes, internal::{AmountPerBlockCumulativeRolling, CachedWindowStarts}};
use crate::{indexes, internal::AmountPerBlockCumulative};
impl Vecs {
pub(crate) fn forced_import(
db: &Database,
version: Version,
indexes: &indexes::Vecs,
cached_starts: &CachedWindowStarts,
) -> Result<Self> {
Ok(Self {
total: AmountPerBlockCumulativeRolling::forced_import(
total: AmountPerBlockCumulative::forced_import(
db,
"unspendable_supply",
version,
indexes,
cached_starts,
)?,
})
}

View File

@@ -1,10 +1,10 @@
use brk_traversable::Traversable;
use vecdb::{Rw, StorageMode};
use crate::internal::AmountPerBlockCumulativeRolling;
use crate::internal::AmountPerBlockCumulative;
#[derive(Traversable)]
#[traversable(transparent)]
pub struct Vecs<M: StorageMode = Rw> {
pub total: AmountPerBlockCumulativeRolling<M>,
pub total: AmountPerBlockCumulative<M>,
}

View File

@@ -34,7 +34,7 @@ impl Vecs {
let circulating =
LazyAmountPerBlock::identity("circulating_supply", &supply_metrics.total, version);
let burned = burned::Vecs::forced_import(&db, version, indexes, cached_starts)?;
let burned = burned::Vecs::forced_import(&db, version, indexes)?;
// Inflation rate
let inflation_rate = PercentPerBlock::forced_import(