diff --git a/crates/brk_client/src/lib.rs b/crates/brk_client/src/lib.rs index 6c3c491e6..c2ffc24e2 100644 --- a/crates/brk_client/src/lib.rs +++ b/crates/brk_client/src/lib.rs @@ -1223,57 +1223,29 @@ impl RelativePattern { } } -/// Pattern struct for repeated tree structure. -pub struct BlockIntervalPattern { - pub average: Indexes3, - pub max: Indexes3, - pub median: Indexes2, - pub min: Indexes3, - pub pct10: Indexes2, - pub pct25: Indexes2, - pub pct75: Indexes2, - pub pct90: Indexes2, -} - -impl BlockIntervalPattern { - /// Create a new pattern node with accumulated metric name. - pub fn new(client: Arc, acc: &str) -> Self { - Self { - average: Indexes3::new(client.clone(), &format!("{acc}_avg")), - max: Indexes3::new(client.clone(), &format!("{acc}_max")), - median: Indexes2::new(client.clone(), &format!("{acc}_median")), - min: Indexes3::new(client.clone(), &format!("{acc}_min")), - pct10: Indexes2::new(client.clone(), &format!("{acc}_pct10")), - pct25: Indexes2::new(client.clone(), &format!("{acc}_pct25")), - pct75: Indexes2::new(client.clone(), &format!("{acc}_pct75")), - pct90: Indexes2::new(client.clone(), &format!("{acc}_pct90")), - } - } -} - /// Pattern struct for repeated tree structure. pub struct AddresstypeToHeightToAddrCountPattern { - pub p2a: Indexes2, - pub p2pk33: Indexes2, - pub p2pk65: Indexes2, - pub p2pkh: Indexes2, - pub p2sh: Indexes2, - pub p2tr: Indexes2, - pub p2wpkh: Indexes2, - pub p2wsh: Indexes2, + pub p2a: Indexes14, + pub p2pk33: Indexes15, + pub p2pk65: Indexes16, + pub p2pkh: Indexes17, + pub p2sh: Indexes18, + pub p2tr: Indexes19, + pub p2wpkh: Indexes20, + pub p2wsh: Indexes21, } impl AddresstypeToHeightToAddrCountPattern { pub fn new(client: Arc, base_path: &str) -> Self { Self { - p2a: Indexes2::new(client.clone(), &format!("{base_path}_p2a")), - p2pk33: Indexes2::new(client.clone(), &format!("{base_path}_p2pk33")), - p2pk65: Indexes2::new(client.clone(), &format!("{base_path}_p2pk65")), - p2pkh: Indexes2::new(client.clone(), &format!("{base_path}_p2pkh")), - p2sh: Indexes2::new(client.clone(), &format!("{base_path}_p2sh")), - p2tr: Indexes2::new(client.clone(), &format!("{base_path}_p2tr")), - p2wpkh: Indexes2::new(client.clone(), &format!("{base_path}_p2wpkh")), - p2wsh: Indexes2::new(client.clone(), &format!("{base_path}_p2wsh")), + p2a: Indexes14::new(client.clone(), &format!("{base_path}_p2a")), + p2pk33: Indexes15::new(client.clone(), &format!("{base_path}_p2pk33")), + p2pk65: Indexes16::new(client.clone(), &format!("{base_path}_p2pk65")), + p2pkh: Indexes17::new(client.clone(), &format!("{base_path}_p2pkh")), + p2sh: Indexes18::new(client.clone(), &format!("{base_path}_p2sh")), + p2tr: Indexes19::new(client.clone(), &format!("{base_path}_p2tr")), + p2wpkh: Indexes20::new(client.clone(), &format!("{base_path}_p2wpkh")), + p2wsh: Indexes21::new(client.clone(), &format!("{base_path}_p2wsh")), } } } @@ -1306,6 +1278,34 @@ impl Constant0Pattern { } } +/// Pattern struct for repeated tree structure. +pub struct BlockIntervalPattern { + pub average: Indexes4, + pub max: Indexes4, + pub median: Indexes5, + pub min: Indexes4, + pub pct10: Indexes5, + pub pct25: Indexes5, + pub pct75: Indexes5, + pub pct90: Indexes5, +} + +impl BlockIntervalPattern { + /// Create a new pattern node with accumulated metric name. + pub fn new(client: Arc, acc: &str) -> Self { + Self { + average: Indexes4::new(client.clone(), &format!("{acc}_avg")), + max: Indexes4::new(client.clone(), &format!("{acc}_max")), + median: Indexes5::new(client.clone(), &format!("{acc}_median")), + min: Indexes4::new(client.clone(), &format!("{acc}_min")), + pct10: Indexes5::new(client.clone(), &format!("{acc}_pct10")), + pct25: Indexes5::new(client.clone(), &format!("{acc}_pct25")), + pct75: Indexes5::new(client.clone(), &format!("{acc}_pct75")), + pct90: Indexes5::new(client.clone(), &format!("{acc}_pct90")), + } + } +} + /// Pattern struct for repeated tree structure. pub struct _0satsPattern { pub activity: ActivityPattern, @@ -1331,29 +1331,6 @@ impl _0satsPattern { } } -/// Pattern struct for repeated tree structure. -pub struct _10yTo12yPattern { - pub activity: ActivityPattern, - pub price_paid: PricePaidPattern2, - pub realized: RealizedPattern2, - pub relative: RelativePattern2, - pub supply: SupplyPattern2, - pub unrealized: UnrealizedPattern, -} - -impl _10yTo12yPattern { - pub fn new(client: Arc, base_path: &str) -> Self { - Self { - activity: ActivityPattern::new(client.clone(), &format!("{base_path}_activity")), - price_paid: PricePaidPattern2::new(client.clone(), &format!("{base_path}_price_paid")), - realized: RealizedPattern2::new(client.clone(), &format!("{base_path}_realized")), - relative: RelativePattern2::new(client.clone(), &format!("{base_path}_relative")), - supply: SupplyPattern2::new(client.clone(), &format!("{base_path}_supply")), - unrealized: UnrealizedPattern::new(client.clone(), &format!("{base_path}_unrealized")), - } - } -} - /// Pattern struct for repeated tree structure. pub struct _0satsPattern2 { pub activity: ActivityPattern, @@ -1400,6 +1377,29 @@ impl UpTo1dPattern { } } +/// Pattern struct for repeated tree structure. +pub struct _10yTo12yPattern { + pub activity: ActivityPattern, + pub price_paid: PricePaidPattern2, + pub realized: RealizedPattern2, + pub relative: RelativePattern2, + pub supply: SupplyPattern2, + pub unrealized: UnrealizedPattern, +} + +impl _10yTo12yPattern { + pub fn new(client: Arc, base_path: &str) -> Self { + Self { + activity: ActivityPattern::new(client.clone(), &format!("{base_path}_activity")), + price_paid: PricePaidPattern2::new(client.clone(), &format!("{base_path}_price_paid")), + realized: RealizedPattern2::new(client.clone(), &format!("{base_path}_realized")), + relative: RelativePattern2::new(client.clone(), &format!("{base_path}_relative")), + supply: SupplyPattern2::new(client.clone(), &format!("{base_path}_supply")), + unrealized: UnrealizedPattern::new(client.clone(), &format!("{base_path}_unrealized")), + } + } +} + /// Pattern struct for repeated tree structure. pub struct ActivityPattern { pub coinblocks_destroyed: BlockCountPattern, @@ -1442,25 +1442,6 @@ impl SupplyPattern2 { } } -/// Pattern struct for repeated tree structure. -pub struct FeePattern2 { - pub base: Indexes2, - pub bitcoin: BlockCountPattern, - pub dollars: BlockCountPattern, - pub sats: SatsPattern, -} - -impl FeePattern2 { - pub fn new(client: Arc, base_path: &str) -> Self { - Self { - base: Indexes2::new(client.clone(), &format!("{base_path}_base")), - bitcoin: BlockCountPattern::new(client.clone(), &format!("{base_path}_bitcoin")), - dollars: BlockCountPattern::new(client.clone(), &format!("{base_path}_dollars")), - sats: SatsPattern::new(client.clone(), &format!("{base_path}_sats")), - } - } -} - /// Pattern struct for repeated tree structure. pub struct SupplyPattern { pub base: Indexes2, @@ -1480,6 +1461,25 @@ impl SupplyPattern { } } +/// Pattern struct for repeated tree structure. +pub struct FeePattern2 { + pub base: Indexes2, + pub bitcoin: BlockCountPattern, + pub dollars: BlockCountPattern, + pub sats: SatsPattern, +} + +impl FeePattern2 { + pub fn new(client: Arc, base_path: &str) -> Self { + Self { + base: Indexes2::new(client.clone(), &format!("{base_path}_base")), + bitcoin: BlockCountPattern::new(client.clone(), &format!("{base_path}_bitcoin")), + dollars: BlockCountPattern::new(client.clone(), &format!("{base_path}_dollars")), + sats: SatsPattern::new(client.clone(), &format!("{base_path}_sats")), + } + } +} + /// Pattern struct for repeated tree structure. pub struct CoinbasePattern { pub bitcoin: BitcoinPattern, @@ -1497,23 +1497,6 @@ impl CoinbasePattern { } } -/// Pattern struct for repeated tree structure. -pub struct PricePaidPattern2 { - pub max_price_paid: Indexes3, - pub min_price_paid: Indexes3, - pub price_percentiles: PricePercentilesPattern, -} - -impl PricePaidPattern2 { - pub fn new(client: Arc, base_path: &str) -> Self { - Self { - max_price_paid: Indexes3::new(client.clone(), &format!("{base_path}_max_price_paid")), - min_price_paid: Indexes3::new(client.clone(), &format!("{base_path}_min_price_paid")), - price_percentiles: PricePercentilesPattern::new(client.clone(), &format!("{base_path}_price_percentiles")), - } - } -} - /// Pattern struct for repeated tree structure. pub struct ActiveSupplyPattern { pub bitcoin: Indexes3, @@ -1531,6 +1514,23 @@ impl ActiveSupplyPattern { } } +/// Pattern struct for repeated tree structure. +pub struct PricePaidPattern2 { + pub max_price_paid: Indexes3, + pub min_price_paid: Indexes3, + pub price_percentiles: PricePercentilesPattern, +} + +impl PricePaidPattern2 { + pub fn new(client: Arc, base_path: &str) -> Self { + Self { + max_price_paid: Indexes3::new(client.clone(), &format!("{base_path}_max_price_paid")), + min_price_paid: Indexes3::new(client.clone(), &format!("{base_path}_min_price_paid")), + price_percentiles: PricePercentilesPattern::new(client.clone(), &format!("{base_path}_price_percentiles")), + } + } +} + /// Pattern struct for repeated tree structure. pub struct UnclaimedRewardsPattern { pub bitcoin: BlockCountPattern, @@ -1566,17 +1566,16 @@ impl BlockCountPattern { } /// Pattern struct for repeated tree structure. -pub struct _1dReturns1mSdPattern { - pub sd: Indexes, - pub sma: Indexes, +pub struct SupplyValuePattern { + pub bitcoin: Indexes2, + pub dollars: Indexes2, } -impl _1dReturns1mSdPattern { - /// Create a new pattern node with accumulated metric name. - pub fn new(client: Arc, acc: &str) -> Self { +impl SupplyValuePattern { + pub fn new(client: Arc, base_path: &str) -> Self { Self { - sd: Indexes::new(client.clone(), &format!("{acc}_sd")), - sma: Indexes::new(client.clone(), &format!("{acc}_sma")), + bitcoin: Indexes2::new(client.clone(), &format!("{base_path}_bitcoin")), + dollars: Indexes2::new(client.clone(), &format!("{base_path}_dollars")), } } } @@ -1596,6 +1595,22 @@ impl SatsPattern { } } +/// Pattern struct for repeated tree structure. +pub struct _1dReturns1mSdPattern { + pub sd: Indexes, + pub sma: Indexes, +} + +impl _1dReturns1mSdPattern { + /// Create a new pattern node with accumulated metric name. + pub fn new(client: Arc, acc: &str) -> Self { + Self { + sd: Indexes::new(client.clone(), &format!("{acc}_sd")), + sma: Indexes::new(client.clone(), &format!("{acc}_sma")), + } + } +} + /// Pattern struct for repeated tree structure. pub struct PricePaidPattern { pub max_price_paid: Indexes3, @@ -1611,21 +1626,6 @@ impl PricePaidPattern { } } -/// Pattern struct for repeated tree structure. -pub struct SupplyValuePattern { - pub bitcoin: Indexes2, - pub dollars: Indexes2, -} - -impl SupplyValuePattern { - pub fn new(client: Arc, base_path: &str) -> Self { - Self { - bitcoin: Indexes2::new(client.clone(), &format!("{base_path}_bitcoin")), - dollars: Indexes2::new(client.clone(), &format!("{base_path}_dollars")), - } - } -} - /// Pattern struct for repeated tree structure. pub struct BitcoinPattern2 { pub base: Indexes2, @@ -1757,6 +1757,7 @@ pub struct CatalogTree_Computed_Chain_Block { pub block_vbytes: BlockSizePattern, pub block_weight: BlockSizePattern, pub interval: Indexes2, + pub timestamp: Indexes4, pub vbytes: Indexes2, } @@ -1774,6 +1775,7 @@ impl CatalogTree_Computed_Chain_Block { block_vbytes: BlockSizePattern::new(client.clone(), &format!("{base_path}_block_vbytes")), block_weight: BlockSizePattern::new(client.clone(), &format!("{base_path}_block_weight")), interval: Indexes2::new(client.clone(), &format!("{base_path}_interval")), + timestamp: Indexes4::new(client.clone(), &format!("{base_path}_timestamp")), vbytes: Indexes2::new(client.clone(), &format!("{base_path}_vbytes")), } } @@ -1812,27 +1814,29 @@ impl CatalogTree_Computed_Chain_Coinbase { /// Catalog tree node. pub struct CatalogTree_Computed_Chain_Epoch { + pub blocks_before_next_difficulty_adjustment: Indexes3, + pub blocks_before_next_halving: Indexes3, + pub days_before_next_difficulty_adjustment: Indexes3, + pub days_before_next_halving: Indexes3, pub difficultyepoch: Indexes, pub halvingepoch: Indexes, - pub timestamp: MetricNode, } impl CatalogTree_Computed_Chain_Epoch { pub fn new(client: Arc, base_path: &str) -> Self { Self { + blocks_before_next_difficulty_adjustment: Indexes3::new(client.clone(), &format!("{base_path}_blocks_before_next_difficulty_adjustment")), + blocks_before_next_halving: Indexes3::new(client.clone(), &format!("{base_path}_blocks_before_next_halving")), + days_before_next_difficulty_adjustment: Indexes3::new(client.clone(), &format!("{base_path}_days_before_next_difficulty_adjustment")), + days_before_next_halving: Indexes3::new(client.clone(), &format!("{base_path}_days_before_next_halving")), difficultyepoch: Indexes::new(client.clone(), &format!("{base_path}_difficultyepoch")), halvingepoch: Indexes::new(client.clone(), &format!("{base_path}_halvingepoch")), - timestamp: MetricNode::new(client.clone(), format!("{base_path}_timestamp")), } } } /// Catalog tree node. pub struct CatalogTree_Computed_Chain_Mining { - pub blocks_before_next_difficulty_adjustment: Indexes3, - pub blocks_before_next_halving: Indexes3, - pub days_before_next_difficulty_adjustment: Indexes3, - pub days_before_next_halving: Indexes3, pub difficulty: Indexes4, pub difficulty_adjustment: Indexes3, pub difficulty_as_hash: Indexes3, @@ -1856,10 +1860,6 @@ pub struct CatalogTree_Computed_Chain_Mining { impl CatalogTree_Computed_Chain_Mining { pub fn new(client: Arc, base_path: &str) -> Self { Self { - blocks_before_next_difficulty_adjustment: Indexes3::new(client.clone(), &format!("{base_path}_blocks_before_next_difficulty_adjustment")), - blocks_before_next_halving: Indexes3::new(client.clone(), &format!("{base_path}_blocks_before_next_halving")), - days_before_next_difficulty_adjustment: Indexes3::new(client.clone(), &format!("{base_path}_days_before_next_difficulty_adjustment")), - days_before_next_halving: Indexes3::new(client.clone(), &format!("{base_path}_days_before_next_halving")), difficulty: Indexes4::new(client.clone(), &format!("{base_path}_difficulty")), difficulty_adjustment: Indexes3::new(client.clone(), &format!("{base_path}_difficulty_adjustment")), difficulty_as_hash: Indexes3::new(client.clone(), &format!("{base_path}_difficulty_as_hash")), diff --git a/crates/brk_computer/.gitignore b/crates/brk_computer/.gitignore index d171c7d5a..88b06327a 100644 --- a/crates/brk_computer/.gitignore +++ b/crates/brk_computer/.gitignore @@ -1,2 +1,2 @@ -bottlenecks.md -BUG.md +*.md +!README.md diff --git a/crates/brk_computer/src/chain/block/compute.rs b/crates/brk_computer/src/chain/block/compute.rs index f523ddd3e..dca690c7c 100644 --- a/crates/brk_computer/src/chain/block/compute.rs +++ b/crates/brk_computer/src/chain/block/compute.rs @@ -155,13 +155,6 @@ impl Vecs { exit, )?; - self.halvingepoch_to_timestamp.compute_transform( - starting_indexes.halvingepoch, - &indexes.block.halvingepoch_to_first_height, - |(i, h, ..)| (i, height_to_timestamp_iter.get_unwrap(h)), - exit, - )?; - Ok(()) } } diff --git a/crates/brk_computer/src/chain/block/import.rs b/crates/brk_computer/src/chain/block/import.rs index fbf2f0bbd..1f7540517 100644 --- a/crates/brk_computer/src/chain/block/import.rs +++ b/crates/brk_computer/src/chain/block/import.rs @@ -167,7 +167,6 @@ impl Vecs { )?, // Timestamp metrics (moved from epoch) difficultyepoch_to_timestamp: EagerVec::forced_import(db, "timestamp", version + v0)?, - halvingepoch_to_timestamp: EagerVec::forced_import(db, "timestamp", version + v0)?, timeindexes_to_timestamp: ComputedVecsFromDateIndex::forced_import( db, "timestamp", diff --git a/crates/brk_computer/src/chain/block/vecs.rs b/crates/brk_computer/src/chain/block/vecs.rs index bc952dab2..b0e41f94b 100644 --- a/crates/brk_computer/src/chain/block/vecs.rs +++ b/crates/brk_computer/src/chain/block/vecs.rs @@ -1,7 +1,7 @@ use brk_traversable::Traversable; use brk_types::{ - DateIndex, DecadeIndex, DifficultyEpoch, HalvingEpoch, Height, MonthIndex, QuarterIndex, - SemesterIndex, StoredU32, StoredU64, Timestamp, WeekIndex, Weight, YearIndex, + DateIndex, DecadeIndex, DifficultyEpoch, Height, MonthIndex, QuarterIndex, SemesterIndex, + StoredU32, StoredU64, Timestamp, WeekIndex, Weight, YearIndex, }; use vecdb::{EagerVec, LazyVecFrom1, PcoVec}; @@ -33,6 +33,5 @@ pub struct Vecs { pub indexes_to_block_vbytes: ComputedVecsFromHeight, pub indexes_to_block_weight: ComputedVecsFromHeight, pub difficultyepoch_to_timestamp: EagerVec>, - pub halvingepoch_to_timestamp: EagerVec>, pub timeindexes_to_timestamp: ComputedVecsFromDateIndex, }