diff --git a/crates/brk_client/src/lib.rs b/crates/brk_client/src/lib.rs index 8f594dc96..fa8fcd972 100644 --- a/crates/brk_client/src/lib.rs +++ b/crates/brk_client/src/lib.rs @@ -2951,26 +2951,6 @@ impl _1y24h30d7dPattern2 { } } -/// Pattern struct for repeated tree structure. -pub struct _1h24hBlockTxindexPattern { - pub _1h: AverageMaxMedianMinPct10Pct25Pct75Pct90Pattern, - pub _24h: AverageMaxMedianMinPct10Pct25Pct75Pct90Pattern, - pub block: AverageMaxMedianMinPct10Pct25Pct75Pct90Pattern, - pub txindex: MetricPattern21, -} - -impl _1h24hBlockTxindexPattern { - /// Create a new pattern node with accumulated metric name. - pub fn new(client: Arc, acc: String) -> Self { - Self { - _1h: AverageMaxMedianMinPct10Pct25Pct75Pct90Pattern::new(client.clone(), _m(&acc, "1h")), - _24h: AverageMaxMedianMinPct10Pct25Pct75Pct90Pattern::new(client.clone(), _m(&acc, "24h")), - block: AverageMaxMedianMinPct10Pct25Pct75Pct90Pattern::new(client.clone(), acc.clone()), - txindex: MetricPattern21::new(client.clone(), acc.clone()), - } - } -} - /// Pattern struct for repeated tree structure. pub struct _1y24h30d7dPattern { pub _1y: MetricPattern1, @@ -3081,6 +3061,24 @@ impl HistogramLineSignalPattern { } } +/// Pattern struct for repeated tree structure. +pub struct _6bBlockTxindexPattern { + pub _6b: AverageMaxMedianMinPct10Pct25Pct75Pct90Pattern, + pub block: AverageMaxMedianMinPct10Pct25Pct75Pct90Pattern, + pub txindex: MetricPattern21, +} + +impl _6bBlockTxindexPattern { + /// Create a new pattern node with accumulated metric name. + pub fn new(client: Arc, acc: String) -> Self { + Self { + _6b: AverageMaxMedianMinPct10Pct25Pct75Pct90Pattern::new(client.clone(), _m(&acc, "6b")), + block: AverageMaxMedianMinPct10Pct25Pct75Pct90Pattern::new(client.clone(), acc.clone()), + txindex: MetricPattern21::new(client.clone(), acc.clone()), + } + } +} + /// Pattern struct for repeated tree structure. pub struct CumulativeHeightSumPattern { pub cumulative: MetricPattern1, @@ -3546,15 +3544,15 @@ impl MetricsTree_Transactions_Count { /// Metrics tree node. pub struct MetricsTree_Transactions_Size { - pub vsize: _1h24hBlockTxindexPattern, - pub weight: _1h24hBlockTxindexPattern, + pub vsize: _6bBlockTxindexPattern, + pub weight: _6bBlockTxindexPattern, } impl MetricsTree_Transactions_Size { pub fn new(client: Arc, base_path: String) -> Self { Self { - vsize: _1h24hBlockTxindexPattern::new(client.clone(), "tx_vsize".to_string()), - weight: _1h24hBlockTxindexPattern::new(client.clone(), "tx_weight".to_string()), + vsize: _6bBlockTxindexPattern::new(client.clone(), "tx_vsize".to_string()), + weight: _6bBlockTxindexPattern::new(client.clone(), "tx_weight".to_string()), } } } @@ -3563,8 +3561,8 @@ impl MetricsTree_Transactions_Size { pub struct MetricsTree_Transactions_Fees { pub input_value: MetricPattern21, pub output_value: MetricPattern21, - pub fee: _1h24hBlockTxindexPattern, - pub fee_rate: _1h24hBlockTxindexPattern, + pub fee: _6bBlockTxindexPattern, + pub fee_rate: _6bBlockTxindexPattern, } impl MetricsTree_Transactions_Fees { @@ -3572,8 +3570,8 @@ impl MetricsTree_Transactions_Fees { Self { input_value: MetricPattern21::new(client.clone(), "input_value".to_string()), output_value: MetricPattern21::new(client.clone(), "output_value".to_string()), - fee: _1h24hBlockTxindexPattern::new(client.clone(), "fee".to_string()), - fee_rate: _1h24hBlockTxindexPattern::new(client.clone(), "fee_rate".to_string()), + fee: _6bBlockTxindexPattern::new(client.clone(), "fee".to_string()), + fee_rate: _6bBlockTxindexPattern::new(client.clone(), "fee_rate".to_string()), } } } diff --git a/crates/brk_computer/src/blocks/count/vecs.rs b/crates/brk_computer/src/blocks/count/vecs.rs index 8e09c830a..99a4bc160 100644 --- a/crates/brk_computer/src/blocks/count/vecs.rs +++ b/crates/brk_computer/src/blocks/count/vecs.rs @@ -3,7 +3,7 @@ use brk_types::{Height, StoredU32, StoredU64}; use vecdb::{EagerVec, PcoVec, Rw, StorageMode}; use crate::internal::{ - BlockWindowStarts, ComputedFromHeightCumulativeSum, ConstantVecs, RollingWindows, WindowStarts, + ComputedFromHeightCumulativeSum, ConstantVecs, RollingWindows, WindowStarts, }; #[derive(Traversable)] @@ -56,14 +56,6 @@ impl Vecs { } } - /// Get the 2 block-count rolling window start heights (1h, 24h) for tx-derived metrics. - pub fn block_window_starts(&self) -> BlockWindowStarts<'_> { - BlockWindowStarts { - _1h: &self.height_1h_ago, - _24h: &self.height_24h_ago, - } - } - pub fn start_vec(&self, days: usize) -> &EagerVec> { match days { 1 => &self.height_24h_ago, diff --git a/crates/brk_computer/src/internal/block_windows.rs b/crates/brk_computer/src/internal/block_windows.rs deleted file mode 100644 index 38721be97..000000000 --- a/crates/brk_computer/src/internal/block_windows.rs +++ /dev/null @@ -1,13 +0,0 @@ -//! Base generic struct with 2 type parameters — one per rolling window duration. -//! -//! Foundation for tx-derived rolling window types (1h, 24h — actual time-based). - -use brk_traversable::Traversable; - -#[derive(Clone, Traversable)] -pub struct BlockWindows { - #[traversable(rename = "1h")] - pub _1h: A, - #[traversable(rename = "24h")] - pub _24h: B, -} diff --git a/crates/brk_computer/src/internal/compute.rs b/crates/brk_computer/src/internal/compute.rs index 5308e61a0..8fbe324ad 100644 --- a/crates/brk_computer/src/internal/compute.rs +++ b/crates/brk_computer/src/internal/compute.rs @@ -315,17 +315,17 @@ where Ok(()) } -/// Compute distribution stats from windowed ranges of a source vec. +/// Compute distribution stats from a fixed n-block rolling window. /// -/// For each index `i`, reads all source items from groups `window_starts[i]..=i` +/// For each height `h`, aggregates all source items from blocks `max(0, h - n_blocks + 1)..=h` /// and computes average, min, max, median, and percentiles across the full window. #[allow(clippy::too_many_arguments)] -pub(crate) fn compute_aggregations_windowed( +pub(crate) fn compute_aggregations_nblock_window( max_from: I, source: &impl ReadableVec, first_indexes: &impl ReadableVec, count_indexes: &impl ReadableVec, - window_starts: &impl ReadableVec, + n_blocks: usize, exit: &Exit, min: &mut EagerVec>, max: &mut EagerVec>, @@ -342,7 +342,7 @@ where A: VecIndex + VecValue + CheckedSub, { let combined_version = - source.version() + first_indexes.version() + count_indexes.version() + window_starts.version(); + source.version() + first_indexes.version() + count_indexes.version(); let mut idx = max_from; for vec in [&mut *min, &mut *max, &mut *average, &mut *median, &mut *pct10, &mut *pct25, &mut *pct75, &mut *pct90] { @@ -353,35 +353,30 @@ where let start = index.to_usize(); let fi_len = first_indexes.len(); - let first_indexes_batch: Vec = first_indexes.collect_range_at(start, fi_len); + // Only fetch first_indexes from the earliest possible window start + let batch_start = start.saturating_sub(n_blocks - 1); + let first_indexes_batch: Vec = first_indexes.collect_range_at(batch_start, fi_len); let count_indexes_batch: Vec = count_indexes.collect_range_at(start, fi_len); - let window_starts_batch: Vec = window_starts.collect_range_at(start, fi_len); let zero = T::from(0_usize); let mut values: Vec = Vec::new(); - first_indexes_batch + count_indexes_batch .iter() - .zip(count_indexes_batch.iter()) - .zip(window_starts_batch.iter()) .enumerate() - .try_for_each(|(j, ((fi, ci), ws))| -> Result<()> { + .try_for_each(|(j, ci)| -> Result<()> { let idx = start + j; - let window_start_offset = ws.to_usize(); + + // Window start: max(0, idx - n_blocks + 1) + let window_start = idx.saturating_sub(n_blocks - 1); // Last tx index (exclusive) of current block let count = u64::from(*ci) as usize; + let fi = first_indexes_batch[idx - batch_start]; let range_end_usize = fi.to_usize() + count; // First tx index of the window start block - let range_start_usize = if window_start_offset >= start { - first_indexes_batch[window_start_offset - start].to_usize() - } else { - first_indexes - .collect_one_at(window_start_offset) - .unwrap() - .to_usize() - }; + let range_start_usize = first_indexes_batch[window_start - batch_start].to_usize(); let effective_count = range_end_usize.saturating_sub(range_start_usize); diff --git a/crates/brk_computer/src/internal/mod.rs b/crates/brk_computer/src/internal/mod.rs index 0dbafa29b..8363a82e4 100644 --- a/crates/brk_computer/src/internal/mod.rs +++ b/crates/brk_computer/src/internal/mod.rs @@ -1,4 +1,3 @@ -mod block_windows; mod compute; mod distribution_stats; mod eager_indexes; @@ -8,9 +7,9 @@ mod multi; mod single; pub(crate) mod sliding_window; mod traits; +mod transform; mod windows; -pub(crate) use block_windows::*; pub(crate) use compute::*; pub(crate) use distribution_stats::*; pub(crate) use eager_indexes::*; @@ -19,4 +18,5 @@ pub(crate) use lazy_eager_indexes::*; pub(crate) use multi::*; pub(crate) use single::*; pub(crate) use traits::*; +pub use transform::*; pub(crate) use windows::*; diff --git a/crates/brk_computer/src/internal/multi/from_tx/distribution.rs b/crates/brk_computer/src/internal/multi/from_tx/distribution.rs index 40f4ddffa..ff9436db5 100644 --- a/crates/brk_computer/src/internal/multi/from_tx/distribution.rs +++ b/crates/brk_computer/src/internal/multi/from_tx/distribution.rs @@ -12,7 +12,7 @@ use vecdb::{Database, EagerVec, Exit, ImportableVec, PcoVec, Rw, StorageMode, Ve use crate::{ ComputeIndexes, indexes, - internal::{BlockWindowStarts, ComputedVecValue, NumericValue, TxDerivedDistribution}, + internal::{ComputedVecValue, NumericValue, TxDerivedDistribution}, }; #[derive(Traversable)] @@ -44,7 +44,6 @@ where indexer: &Indexer, indexes: &indexes::Vecs, starting_indexes: &ComputeIndexes, - block_windows: &BlockWindowStarts<'_>, exit: &Exit, skip_count: usize, ) -> Result<()> @@ -56,7 +55,6 @@ where indexer, indexes, starting_indexes, - block_windows, &self.txindex, exit, skip_count, diff --git a/crates/brk_computer/src/internal/multi/from_tx/lazy_distribution.rs b/crates/brk_computer/src/internal/multi/from_tx/lazy_distribution.rs index 4f6c5d0d7..fe61b2aa2 100644 --- a/crates/brk_computer/src/internal/multi/from_tx/lazy_distribution.rs +++ b/crates/brk_computer/src/internal/multi/from_tx/lazy_distribution.rs @@ -9,7 +9,7 @@ use vecdb::{Database, Exit, LazyVecFrom2, ReadableVec, Rw, StorageMode, Version} use crate::{ ComputeIndexes, indexes, - internal::{BlockWindowStarts, ComputedVecValue, NumericValue, TxDerivedDistribution}, + internal::{ComputedVecValue, NumericValue, TxDerivedDistribution}, }; #[derive(Traversable)] @@ -48,7 +48,6 @@ where indexer: &Indexer, indexes: &indexes::Vecs, starting_indexes: &ComputeIndexes, - block_windows: &BlockWindowStarts<'_>, exit: &Exit, ) -> Result<()> where @@ -60,7 +59,6 @@ where indexer, indexes, starting_indexes, - block_windows, &self.txindex, exit, ) diff --git a/crates/brk_computer/src/internal/multi/tx_derived/distribution.rs b/crates/brk_computer/src/internal/multi/tx_derived/distribution.rs index e370da88d..907d7f6bf 100644 --- a/crates/brk_computer/src/internal/multi/tx_derived/distribution.rs +++ b/crates/brk_computer/src/internal/multi/tx_derived/distribution.rs @@ -1,7 +1,7 @@ //! TxDerivedDistribution - per-block + rolling window distribution stats from tx-level data. //! //! Computes true distribution stats (average, min, max, median, percentiles) by reading -//! actual tx values for each scope: current block, last 1h, last 24h. +//! actual tx values for each scope: current block, last 6 blocks. use brk_error::Result; use brk_indexer::Indexer; @@ -14,7 +14,7 @@ use vecdb::{Database, Exit, ReadableVec, Rw, StorageMode, Version}; use crate::{ ComputeIndexes, indexes, internal::{ - BlockRollingDistribution, BlockWindowStarts, ComputedVecValue, Distribution, NumericValue, + BlockRollingDistribution, ComputedVecValue, Distribution, NumericValue, }, }; @@ -44,7 +44,6 @@ where indexer: &Indexer, indexes: &indexes::Vecs, starting_indexes: &ComputeIndexes, - block_windows: &BlockWindowStarts<'_>, txindex_source: &impl ReadableVec, exit: &Exit, ) -> Result<()> @@ -56,7 +55,6 @@ where indexer, indexes, starting_indexes, - block_windows, txindex_source, exit, 0, @@ -73,7 +71,6 @@ where indexer: &Indexer, indexes: &indexes::Vecs, starting_indexes: &ComputeIndexes, - block_windows: &BlockWindowStarts<'_>, txindex_source: &impl ReadableVec, exit: &Exit, skip_count: usize, @@ -92,23 +89,13 @@ where skip_count, )?; - // 1h rolling: true distribution from all txs in last hour - self.rolling._1h.compute_from_window( + // 6-block rolling: true distribution from all txs in last 6 blocks + self.rolling._6b.compute_from_nblocks( starting_indexes.height, txindex_source, &indexer.vecs.transactions.first_txindex, &indexes.height.txindex_count, - block_windows._1h, - exit, - )?; - - // 24h rolling: true distribution from all txs in last 24 hours - self.rolling._24h.compute_from_window( - starting_indexes.height, - txindex_source, - &indexer.vecs.transactions.first_txindex, - &indexes.height.txindex_count, - block_windows._24h, + 6, exit, )?; diff --git a/crates/brk_computer/src/internal/single/group/distribution.rs b/crates/brk_computer/src/internal/single/group/distribution.rs index 002014202..e16232637 100644 --- a/crates/brk_computer/src/internal/single/group/distribution.rs +++ b/crates/brk_computer/src/internal/single/group/distribution.rs @@ -72,28 +72,27 @@ impl Distribution { ) } - /// Compute distribution stats from all items in a rolling window of groups. + /// Compute distribution stats from a fixed n-block rolling window. /// - /// For each index `i`, reads all source items from groups `window_starts[i]..=i` - /// and computes distribution stats across the entire window. - pub(crate) fn compute_from_window( + /// For each index `i`, aggregates all source items from blocks `max(0, i - n_blocks + 1)..=i`. + pub(crate) fn compute_from_nblocks( &mut self, max_from: I, source: &impl ReadableVec, first_indexes: &impl ReadableVec, count_indexes: &impl ReadableVec, - window_starts: &impl ReadableVec, + n_blocks: usize, exit: &Exit, ) -> Result<()> where A: VecIndex + VecValue + brk_types::CheckedSub, { - crate::internal::compute_aggregations_windowed( + crate::internal::compute_aggregations_nblock_window( max_from, source, first_indexes, count_indexes, - window_starts, + n_blocks, exit, &mut self.min.0, &mut self.max.0, diff --git a/crates/brk_computer/src/internal/single/mod.rs b/crates/brk_computer/src/internal/single/mod.rs index 079ee2493..fff829c2c 100644 --- a/crates/brk_computer/src/internal/single/mod.rs +++ b/crates/brk_computer/src/internal/single/mod.rs @@ -3,11 +3,9 @@ mod group; mod height; mod rolling; -mod transform; mod vec; pub use group::*; pub use height::*; pub use rolling::*; -pub use transform::*; pub use vec::*; diff --git a/crates/brk_computer/src/internal/single/rolling/block_windows.rs b/crates/brk_computer/src/internal/single/rolling/block_windows.rs index d356db470..aceee90ed 100644 --- a/crates/brk_computer/src/internal/single/rolling/block_windows.rs +++ b/crates/brk_computer/src/internal/single/rolling/block_windows.rs @@ -1,31 +1,22 @@ -//! Block-count-based rolling window starts and distribution — 1h and 24h (actual time-based). -//! -//! Uses stored height-ago vecs (`height_1h_ago`, `height_24h_ago`) for accurate -//! time-based window starts. +//! Block-count-based rolling distribution — 6-block window. use brk_error::Result; use brk_traversable::Traversable; use brk_types::Height; -use derive_more::{Deref, DerefMut}; use schemars::JsonSchema; -use vecdb::{Database, EagerVec, PcoVec, Rw, StorageMode, Version}; +use vecdb::{Database, Rw, StorageMode, Version}; -use crate::internal::{BlockWindows, ComputedVecValue, Distribution, NumericValue}; +use crate::internal::{ComputedVecValue, Distribution, NumericValue}; -/// Rolling window start heights for tx-derived metrics (1h, 24h). -pub struct BlockWindowStarts<'a> { - pub _1h: &'a EagerVec>, - pub _24h: &'a EagerVec>, -} - -/// 2 rolling window distributions (1h, 24h), each with 8 distribution stat vecs. -#[derive(Deref, DerefMut, Traversable)] -#[traversable(transparent)] -pub struct BlockRollingDistribution( - pub BlockWindows>, -) +/// Single 6-block rolling window distribution with 8 distribution stat vecs. +#[derive(Traversable)] +pub struct BlockRollingDistribution where - T: ComputedVecValue + PartialOrd + JsonSchema; + T: ComputedVecValue + PartialOrd + JsonSchema, +{ + #[traversable(rename = "6b")] + pub _6b: Distribution, +} impl BlockRollingDistribution where @@ -36,9 +27,8 @@ where name: &str, version: Version, ) -> Result { - Ok(Self(BlockWindows { - _1h: Distribution::forced_import(db, &format!("{name}_1h"), version)?, - _24h: Distribution::forced_import(db, &format!("{name}_24h"), version)?, - })) + Ok(Self { + _6b: Distribution::forced_import(db, &format!("{name}_6b"), version)?, + }) } } diff --git a/crates/brk_computer/src/internal/single/transform/block_count_target.rs b/crates/brk_computer/src/internal/transform/block_count_target.rs similarity index 100% rename from crates/brk_computer/src/internal/single/transform/block_count_target.rs rename to crates/brk_computer/src/internal/transform/block_count_target.rs diff --git a/crates/brk_computer/src/internal/single/transform/cents_to_dollars.rs b/crates/brk_computer/src/internal/transform/cents_to_dollars.rs similarity index 100% rename from crates/brk_computer/src/internal/single/transform/cents_to_dollars.rs rename to crates/brk_computer/src/internal/transform/cents_to_dollars.rs diff --git a/crates/brk_computer/src/internal/single/transform/cents_to_sats.rs b/crates/brk_computer/src/internal/transform/cents_to_sats.rs similarity index 100% rename from crates/brk_computer/src/internal/single/transform/cents_to_sats.rs rename to crates/brk_computer/src/internal/transform/cents_to_sats.rs diff --git a/crates/brk_computer/src/internal/single/transform/dollar_halve.rs b/crates/brk_computer/src/internal/transform/dollar_halve.rs similarity index 100% rename from crates/brk_computer/src/internal/single/transform/dollar_halve.rs rename to crates/brk_computer/src/internal/transform/dollar_halve.rs diff --git a/crates/brk_computer/src/internal/single/transform/dollar_identity.rs b/crates/brk_computer/src/internal/transform/dollar_identity.rs similarity index 100% rename from crates/brk_computer/src/internal/single/transform/dollar_identity.rs rename to crates/brk_computer/src/internal/transform/dollar_identity.rs diff --git a/crates/brk_computer/src/internal/single/transform/dollar_plus.rs b/crates/brk_computer/src/internal/transform/dollar_plus.rs similarity index 100% rename from crates/brk_computer/src/internal/single/transform/dollar_plus.rs rename to crates/brk_computer/src/internal/transform/dollar_plus.rs diff --git a/crates/brk_computer/src/internal/single/transform/dollar_times_tenths.rs b/crates/brk_computer/src/internal/transform/dollar_times_tenths.rs similarity index 100% rename from crates/brk_computer/src/internal/single/transform/dollar_times_tenths.rs rename to crates/brk_computer/src/internal/transform/dollar_times_tenths.rs diff --git a/crates/brk_computer/src/internal/single/transform/dollars_to_sats_fract.rs b/crates/brk_computer/src/internal/transform/dollars_to_sats_fract.rs similarity index 100% rename from crates/brk_computer/src/internal/single/transform/dollars_to_sats_fract.rs rename to crates/brk_computer/src/internal/transform/dollars_to_sats_fract.rs diff --git a/crates/brk_computer/src/internal/single/transform/f32_identity.rs b/crates/brk_computer/src/internal/transform/f32_identity.rs similarity index 100% rename from crates/brk_computer/src/internal/single/transform/f32_identity.rs rename to crates/brk_computer/src/internal/transform/f32_identity.rs diff --git a/crates/brk_computer/src/internal/single/transform/mod.rs b/crates/brk_computer/src/internal/transform/mod.rs similarity index 100% rename from crates/brk_computer/src/internal/single/transform/mod.rs rename to crates/brk_computer/src/internal/transform/mod.rs diff --git a/crates/brk_computer/src/internal/single/transform/ohlc_cents_to_dollars.rs b/crates/brk_computer/src/internal/transform/ohlc_cents_to_dollars.rs similarity index 100% rename from crates/brk_computer/src/internal/single/transform/ohlc_cents_to_dollars.rs rename to crates/brk_computer/src/internal/transform/ohlc_cents_to_dollars.rs diff --git a/crates/brk_computer/src/internal/single/transform/ohlc_cents_to_sats.rs b/crates/brk_computer/src/internal/transform/ohlc_cents_to_sats.rs similarity index 100% rename from crates/brk_computer/src/internal/single/transform/ohlc_cents_to_sats.rs rename to crates/brk_computer/src/internal/transform/ohlc_cents_to_sats.rs diff --git a/crates/brk_computer/src/internal/single/transform/percentage_diff_close_dollars.rs b/crates/brk_computer/src/internal/transform/percentage_diff_close_dollars.rs similarity index 100% rename from crates/brk_computer/src/internal/single/transform/percentage_diff_close_dollars.rs rename to crates/brk_computer/src/internal/transform/percentage_diff_close_dollars.rs diff --git a/crates/brk_computer/src/internal/single/transform/percentage_dollars_f32.rs b/crates/brk_computer/src/internal/transform/percentage_dollars_f32.rs similarity index 100% rename from crates/brk_computer/src/internal/single/transform/percentage_dollars_f32.rs rename to crates/brk_computer/src/internal/transform/percentage_dollars_f32.rs diff --git a/crates/brk_computer/src/internal/single/transform/percentage_dollars_f32_neg.rs b/crates/brk_computer/src/internal/transform/percentage_dollars_f32_neg.rs similarity index 100% rename from crates/brk_computer/src/internal/single/transform/percentage_dollars_f32_neg.rs rename to crates/brk_computer/src/internal/transform/percentage_dollars_f32_neg.rs diff --git a/crates/brk_computer/src/internal/single/transform/percentage_sats_f64.rs b/crates/brk_computer/src/internal/transform/percentage_sats_f64.rs similarity index 100% rename from crates/brk_computer/src/internal/single/transform/percentage_sats_f64.rs rename to crates/brk_computer/src/internal/transform/percentage_sats_f64.rs diff --git a/crates/brk_computer/src/internal/single/transform/percentage_u32_f32.rs b/crates/brk_computer/src/internal/transform/percentage_u32_f32.rs similarity index 100% rename from crates/brk_computer/src/internal/single/transform/percentage_u32_f32.rs rename to crates/brk_computer/src/internal/transform/percentage_u32_f32.rs diff --git a/crates/brk_computer/src/internal/single/transform/price_times_ratio.rs b/crates/brk_computer/src/internal/transform/price_times_ratio.rs similarity index 100% rename from crates/brk_computer/src/internal/single/transform/price_times_ratio.rs rename to crates/brk_computer/src/internal/transform/price_times_ratio.rs diff --git a/crates/brk_computer/src/internal/single/transform/ratio32.rs b/crates/brk_computer/src/internal/transform/ratio32.rs similarity index 100% rename from crates/brk_computer/src/internal/single/transform/ratio32.rs rename to crates/brk_computer/src/internal/transform/ratio32.rs diff --git a/crates/brk_computer/src/internal/single/transform/ratio64.rs b/crates/brk_computer/src/internal/transform/ratio64.rs similarity index 100% rename from crates/brk_computer/src/internal/single/transform/ratio64.rs rename to crates/brk_computer/src/internal/transform/ratio64.rs diff --git a/crates/brk_computer/src/internal/single/transform/ratio_u64_f32.rs b/crates/brk_computer/src/internal/transform/ratio_u64_f32.rs similarity index 100% rename from crates/brk_computer/src/internal/single/transform/ratio_u64_f32.rs rename to crates/brk_computer/src/internal/transform/ratio_u64_f32.rs diff --git a/crates/brk_computer/src/internal/single/transform/return_f32_tenths.rs b/crates/brk_computer/src/internal/transform/return_f32_tenths.rs similarity index 100% rename from crates/brk_computer/src/internal/single/transform/return_f32_tenths.rs rename to crates/brk_computer/src/internal/transform/return_f32_tenths.rs diff --git a/crates/brk_computer/src/internal/single/transform/return_i8.rs b/crates/brk_computer/src/internal/transform/return_i8.rs similarity index 100% rename from crates/brk_computer/src/internal/single/transform/return_i8.rs rename to crates/brk_computer/src/internal/transform/return_i8.rs diff --git a/crates/brk_computer/src/internal/single/transform/return_u16.rs b/crates/brk_computer/src/internal/transform/return_u16.rs similarity index 100% rename from crates/brk_computer/src/internal/single/transform/return_u16.rs rename to crates/brk_computer/src/internal/transform/return_u16.rs diff --git a/crates/brk_computer/src/internal/single/transform/sat_halve.rs b/crates/brk_computer/src/internal/transform/sat_halve.rs similarity index 100% rename from crates/brk_computer/src/internal/single/transform/sat_halve.rs rename to crates/brk_computer/src/internal/transform/sat_halve.rs diff --git a/crates/brk_computer/src/internal/single/transform/sat_halve_to_bitcoin.rs b/crates/brk_computer/src/internal/transform/sat_halve_to_bitcoin.rs similarity index 100% rename from crates/brk_computer/src/internal/single/transform/sat_halve_to_bitcoin.rs rename to crates/brk_computer/src/internal/transform/sat_halve_to_bitcoin.rs diff --git a/crates/brk_computer/src/internal/single/transform/sat_identity.rs b/crates/brk_computer/src/internal/transform/sat_identity.rs similarity index 100% rename from crates/brk_computer/src/internal/single/transform/sat_identity.rs rename to crates/brk_computer/src/internal/transform/sat_identity.rs diff --git a/crates/brk_computer/src/internal/single/transform/sat_mask.rs b/crates/brk_computer/src/internal/transform/sat_mask.rs similarity index 100% rename from crates/brk_computer/src/internal/single/transform/sat_mask.rs rename to crates/brk_computer/src/internal/transform/sat_mask.rs diff --git a/crates/brk_computer/src/internal/single/transform/sat_to_bitcoin.rs b/crates/brk_computer/src/internal/transform/sat_to_bitcoin.rs similarity index 100% rename from crates/brk_computer/src/internal/single/transform/sat_to_bitcoin.rs rename to crates/brk_computer/src/internal/transform/sat_to_bitcoin.rs diff --git a/crates/brk_computer/src/internal/single/transform/sats_to_dollars.rs b/crates/brk_computer/src/internal/transform/sats_to_dollars.rs similarity index 100% rename from crates/brk_computer/src/internal/single/transform/sats_to_dollars.rs rename to crates/brk_computer/src/internal/transform/sats_to_dollars.rs diff --git a/crates/brk_computer/src/internal/single/transform/u16_to_years.rs b/crates/brk_computer/src/internal/transform/u16_to_years.rs similarity index 100% rename from crates/brk_computer/src/internal/single/transform/u16_to_years.rs rename to crates/brk_computer/src/internal/transform/u16_to_years.rs diff --git a/crates/brk_computer/src/internal/single/transform/volatility_sqrt30.rs b/crates/brk_computer/src/internal/transform/volatility_sqrt30.rs similarity index 100% rename from crates/brk_computer/src/internal/single/transform/volatility_sqrt30.rs rename to crates/brk_computer/src/internal/transform/volatility_sqrt30.rs diff --git a/crates/brk_computer/src/internal/single/transform/volatility_sqrt365.rs b/crates/brk_computer/src/internal/transform/volatility_sqrt365.rs similarity index 100% rename from crates/brk_computer/src/internal/single/transform/volatility_sqrt365.rs rename to crates/brk_computer/src/internal/transform/volatility_sqrt365.rs diff --git a/crates/brk_computer/src/internal/single/transform/volatility_sqrt7.rs b/crates/brk_computer/src/internal/transform/volatility_sqrt7.rs similarity index 100% rename from crates/brk_computer/src/internal/single/transform/volatility_sqrt7.rs rename to crates/brk_computer/src/internal/transform/volatility_sqrt7.rs diff --git a/crates/brk_computer/src/transactions/compute.rs b/crates/brk_computer/src/transactions/compute.rs index 4286b2457..7573f1af1 100644 --- a/crates/brk_computer/src/transactions/compute.rs +++ b/crates/brk_computer/src/transactions/compute.rs @@ -27,17 +27,16 @@ impl Vecs { self.versions .compute(indexer, &blocks.count, starting_indexes, exit)?; - // Size computes next (uses BlockWindowStarts for 1h/24h rolling) + // Size computes next (uses 6-block rolling window) self.size - .compute(indexer, indexes, &blocks.count, starting_indexes, exit)?; + .compute(indexer, indexes, starting_indexes, exit)?; - // Fees depends on size, blocks (window starts) + // Fees depends on size self.fees.compute( indexer, indexes, inputs, &self.size, - blocks, starting_indexes, exit, )?; diff --git a/crates/brk_computer/src/transactions/fees/compute.rs b/crates/brk_computer/src/transactions/fees/compute.rs index 37515c9e7..845c3ff9f 100644 --- a/crates/brk_computer/src/transactions/fees/compute.rs +++ b/crates/brk_computer/src/transactions/fees/compute.rs @@ -5,7 +5,7 @@ use vecdb::{Exit, unlikely}; use super::super::size; use super::Vecs; -use crate::{ComputeIndexes, blocks, indexes, inputs}; +use crate::{ComputeIndexes, indexes, inputs}; impl Vecs { #[allow(clippy::too_many_arguments)] @@ -15,7 +15,6 @@ impl Vecs { indexes: &indexes::Vecs, txins: &inputs::Vecs, size_vecs: &size::Vecs, - blocks: &blocks::Vecs, starting_indexes: &ComputeIndexes, exit: &Exit, ) -> Result<()> { @@ -58,14 +57,11 @@ impl Vecs { exit, )?; - let block_windows = blocks.count.block_window_starts(); - // Skip coinbase (first tx per block) since it has fee=0 self.fee.derive_from_with_skip( indexer, indexes, starting_indexes, - &block_windows, exit, 1, )?; @@ -75,7 +71,6 @@ impl Vecs { indexer, indexes, starting_indexes, - &block_windows, exit, 1, )?; diff --git a/crates/brk_computer/src/transactions/size/compute.rs b/crates/brk_computer/src/transactions/size/compute.rs index a04e7b568..dafd1f190 100644 --- a/crates/brk_computer/src/transactions/size/compute.rs +++ b/crates/brk_computer/src/transactions/size/compute.rs @@ -3,24 +3,21 @@ use brk_indexer::Indexer; use vecdb::Exit; use super::Vecs; -use crate::{blocks, indexes, ComputeIndexes}; +use crate::{indexes, ComputeIndexes}; impl Vecs { pub(crate) fn compute( &mut self, indexer: &Indexer, indexes: &indexes::Vecs, - count_vecs: &blocks::CountVecs, starting_indexes: &ComputeIndexes, exit: &Exit, ) -> Result<()> { - let block_windows = count_vecs.block_window_starts(); - self.weight - .derive_from(indexer, indexes, starting_indexes, &block_windows, exit)?; + .derive_from(indexer, indexes, starting_indexes, exit)?; self.vsize - .derive_from(indexer, indexes, starting_indexes, &block_windows, exit)?; + .derive_from(indexer, indexes, starting_indexes, exit)?; Ok(()) } diff --git a/modules/brk-client/index.js b/modules/brk-client/index.js index f739d2983..aa1660512 100644 --- a/modules/brk-client/index.js +++ b/modules/brk-client/index.js @@ -3652,31 +3652,6 @@ function create_1y24h30d7dPattern2(client, acc) { }; } -/** - * @template T - * @typedef {Object} _1h24hBlockTxindexPattern - * @property {AverageMaxMedianMinPct10Pct25Pct75Pct90Pattern} _1h - * @property {AverageMaxMedianMinPct10Pct25Pct75Pct90Pattern} _24h - * @property {AverageMaxMedianMinPct10Pct25Pct75Pct90Pattern} block - * @property {MetricPattern21} txindex - */ - -/** - * Create a _1h24hBlockTxindexPattern pattern node - * @template T - * @param {BrkClientBase} client - * @param {string} acc - Accumulated metric name - * @returns {_1h24hBlockTxindexPattern} - */ -function create_1h24hBlockTxindexPattern(client, acc) { - return { - _1h: createAverageMaxMedianMinPct10Pct25Pct75Pct90Pattern(client, _m(acc, '1h')), - _24h: createAverageMaxMedianMinPct10Pct25Pct75Pct90Pattern(client, _m(acc, '24h')), - block: createAverageMaxMedianMinPct10Pct25Pct75Pct90Pattern(client, acc), - txindex: createMetricPattern21(client, acc), - }; -} - /** * @template T * @typedef {Object} _1y24h30d7dPattern @@ -3807,6 +3782,29 @@ function createHistogramLineSignalPattern(client, acc) { }; } +/** + * @template T + * @typedef {Object} _6bBlockTxindexPattern + * @property {AverageMaxMedianMinPct10Pct25Pct75Pct90Pattern} _6b + * @property {AverageMaxMedianMinPct10Pct25Pct75Pct90Pattern} block + * @property {MetricPattern21} txindex + */ + +/** + * Create a _6bBlockTxindexPattern pattern node + * @template T + * @param {BrkClientBase} client + * @param {string} acc - Accumulated metric name + * @returns {_6bBlockTxindexPattern} + */ +function create_6bBlockTxindexPattern(client, acc) { + return { + _6b: createAverageMaxMedianMinPct10Pct25Pct75Pct90Pattern(client, _m(acc, '6b')), + block: createAverageMaxMedianMinPct10Pct25Pct75Pct90Pattern(client, acc), + txindex: createMetricPattern21(client, acc), + }; +} + /** * @template T * @typedef {Object} CumulativeHeightSumPattern @@ -4140,16 +4138,16 @@ function createRatioPattern2(client, acc) { /** * @typedef {Object} MetricsTree_Transactions_Size - * @property {_1h24hBlockTxindexPattern} vsize - * @property {_1h24hBlockTxindexPattern} weight + * @property {_6bBlockTxindexPattern} vsize + * @property {_6bBlockTxindexPattern} weight */ /** * @typedef {Object} MetricsTree_Transactions_Fees * @property {MetricPattern21} inputValue * @property {MetricPattern21} outputValue - * @property {_1h24hBlockTxindexPattern} fee - * @property {_1h24hBlockTxindexPattern} feeRate + * @property {_6bBlockTxindexPattern} fee + * @property {_6bBlockTxindexPattern} feeRate */ /** @@ -6674,14 +6672,14 @@ class BrkClient extends BrkClientBase { isCoinbase: createMetricPattern21(this, 'is_coinbase'), }, size: { - vsize: create_1h24hBlockTxindexPattern(this, 'tx_vsize'), - weight: create_1h24hBlockTxindexPattern(this, 'tx_weight'), + vsize: create_6bBlockTxindexPattern(this, 'tx_vsize'), + weight: create_6bBlockTxindexPattern(this, 'tx_weight'), }, fees: { inputValue: createMetricPattern21(this, 'input_value'), outputValue: createMetricPattern21(this, 'output_value'), - fee: create_1h24hBlockTxindexPattern(this, 'fee'), - feeRate: create_1h24hBlockTxindexPattern(this, 'fee_rate'), + fee: create_6bBlockTxindexPattern(this, 'fee'), + feeRate: create_6bBlockTxindexPattern(this, 'fee_rate'), }, versions: { v1: createCumulativeHeightSumPattern(this, 'tx_v1'), diff --git a/packages/brk_client/brk_client/__init__.py b/packages/brk_client/brk_client/__init__.py index e3710cde9..63bc5de6c 100644 --- a/packages/brk_client/brk_client/__init__.py +++ b/packages/brk_client/brk_client/__init__.py @@ -3070,16 +3070,6 @@ class _1y24h30d7dPattern2: self._30d: BtcSatsUsdPattern = BtcSatsUsdPattern(client, _m(acc, '30d')) self._7d: BtcSatsUsdPattern = BtcSatsUsdPattern(client, _m(acc, '7d')) -class _1h24hBlockTxindexPattern(Generic[T]): - """Pattern struct for repeated tree structure.""" - - def __init__(self, client: BrkClientBase, acc: str): - """Create pattern node with accumulated metric name.""" - self._1h: AverageMaxMedianMinPct10Pct25Pct75Pct90Pattern[T] = AverageMaxMedianMinPct10Pct25Pct75Pct90Pattern(client, _m(acc, '1h')) - self._24h: AverageMaxMedianMinPct10Pct25Pct75Pct90Pattern[T] = AverageMaxMedianMinPct10Pct25Pct75Pct90Pattern(client, _m(acc, '24h')) - self.block: AverageMaxMedianMinPct10Pct25Pct75Pct90Pattern[T] = AverageMaxMedianMinPct10Pct25Pct75Pct90Pattern(client, acc) - self.txindex: MetricPattern21[T] = MetricPattern21(client, acc) - class _1y24h30d7dPattern(Generic[T]): """Pattern struct for repeated tree structure.""" @@ -3135,6 +3125,15 @@ class HistogramLineSignalPattern: self.line: MetricPattern1[StoredF32] = MetricPattern1(client, _m(acc, 'line_1y')) self.signal: MetricPattern1[StoredF32] = MetricPattern1(client, _m(acc, 'signal_1y')) +class _6bBlockTxindexPattern(Generic[T]): + """Pattern struct for repeated tree structure.""" + + def __init__(self, client: BrkClientBase, acc: str): + """Create pattern node with accumulated metric name.""" + self._6b: AverageMaxMedianMinPct10Pct25Pct75Pct90Pattern[T] = AverageMaxMedianMinPct10Pct25Pct75Pct90Pattern(client, _m(acc, '6b')) + self.block: AverageMaxMedianMinPct10Pct25Pct75Pct90Pattern[T] = AverageMaxMedianMinPct10Pct25Pct75Pct90Pattern(client, acc) + self.txindex: MetricPattern21[T] = MetricPattern21(client, acc) + class CumulativeHeightSumPattern(Generic[T]): """Pattern struct for repeated tree structure.""" @@ -3326,8 +3325,8 @@ class MetricsTree_Transactions_Size: """Metrics tree node.""" def __init__(self, client: BrkClientBase, base_path: str = ''): - self.vsize: _1h24hBlockTxindexPattern[VSize] = _1h24hBlockTxindexPattern(client, 'tx_vsize') - self.weight: _1h24hBlockTxindexPattern[Weight] = _1h24hBlockTxindexPattern(client, 'tx_weight') + self.vsize: _6bBlockTxindexPattern[VSize] = _6bBlockTxindexPattern(client, 'tx_vsize') + self.weight: _6bBlockTxindexPattern[Weight] = _6bBlockTxindexPattern(client, 'tx_weight') class MetricsTree_Transactions_Fees: """Metrics tree node.""" @@ -3335,8 +3334,8 @@ class MetricsTree_Transactions_Fees: def __init__(self, client: BrkClientBase, base_path: str = ''): self.input_value: MetricPattern21[Sats] = MetricPattern21(client, 'input_value') self.output_value: MetricPattern21[Sats] = MetricPattern21(client, 'output_value') - self.fee: _1h24hBlockTxindexPattern[Sats] = _1h24hBlockTxindexPattern(client, 'fee') - self.fee_rate: _1h24hBlockTxindexPattern[FeeRate] = _1h24hBlockTxindexPattern(client, 'fee_rate') + self.fee: _6bBlockTxindexPattern[Sats] = _6bBlockTxindexPattern(client, 'fee') + self.fee_rate: _6bBlockTxindexPattern[FeeRate] = _6bBlockTxindexPattern(client, 'fee_rate') class MetricsTree_Transactions_Versions: """Metrics tree node."""