server: openapi fixes

This commit is contained in:
nym21
2025-12-16 20:23:01 +01:00
parent f7f065c6e0
commit 2ccf0ef856
23 changed files with 350 additions and 188 deletions

View File

@@ -1,3 +1,12 @@
// TODO: INCOMPLETE - indexes_to_fee_rate.dateindex doesn't have percentile fields
// because from_txindex.rs calls remove_percentiles() before creating dateindex.
// Need to either:
// 1. Use .height instead and convert height to dateindex for iteration
// 2. Fix from_txindex.rs to preserve percentiles for dateindex
// 3. Create a separate dateindex computation path with percentiles
#![allow(dead_code)]
use brk_error::Result;
use brk_types::{BlockFeeRatesEntry, FeeRatePercentiles, TimePeriod};
use vecdb::{IterableVec, VecIndex};
@@ -6,38 +15,42 @@ use super::dateindex_iter::DateIndexIter;
use crate::Query;
impl Query {
pub fn block_fee_rates(&self, time_period: TimePeriod) -> Result<Vec<BlockFeeRatesEntry>> {
let computer = self.computer();
let current_height = self.height();
let start = current_height
.to_usize()
.saturating_sub(time_period.block_count());
pub fn block_fee_rates(&self, _time_period: TimePeriod) -> Result<Vec<BlockFeeRatesEntry>> {
// Disabled until percentile data is available at dateindex level
Ok(Vec::new())
let iter = DateIndexIter::new(computer, start, current_height.to_usize());
let vecs = &computer.chain.indexes_to_fee_rate.dateindex;
let mut min = vecs.unwrap_min().iter();
let mut pct10 = vecs.unwrap_pct10().iter();
let mut pct25 = vecs.unwrap_pct25().iter();
let mut median = vecs.unwrap_median().iter();
let mut pct75 = vecs.unwrap_pct75().iter();
let mut pct90 = vecs.unwrap_pct90().iter();
let mut max = vecs.unwrap_max().iter();
Ok(iter.collect(|di, ts, h| {
Some(BlockFeeRatesEntry {
avg_height: h,
timestamp: ts,
percentiles: FeeRatePercentiles::new(
min.get(di).unwrap_or_default(),
pct10.get(di).unwrap_or_default(),
pct25.get(di).unwrap_or_default(),
median.get(di).unwrap_or_default(),
pct75.get(di).unwrap_or_default(),
pct90.get(di).unwrap_or_default(),
max.get(di).unwrap_or_default(),
),
})
}))
// Original implementation:
// let computer = self.computer();
// let current_height = self.height();
// let start = current_height
// .to_usize()
// .saturating_sub(time_period.block_count());
//
// let iter = DateIndexIter::new(computer, start, current_height.to_usize());
//
// let vecs = &computer.chain.indexes_to_fee_rate.dateindex;
// let mut min = vecs.unwrap_min().iter();
// let mut pct10 = vecs.unwrap_pct10().iter();
// let mut pct25 = vecs.unwrap_pct25().iter();
// let mut median = vecs.unwrap_median().iter();
// let mut pct75 = vecs.unwrap_pct75().iter();
// let mut pct90 = vecs.unwrap_pct90().iter();
// let mut max = vecs.unwrap_max().iter();
//
// Ok(iter.collect(|di, ts, h| {
// Some(BlockFeeRatesEntry {
// avg_height: h,
// timestamp: ts,
// percentiles: FeeRatePercentiles::new(
// min.get(di).unwrap_or_default(),
// pct10.get(di).unwrap_or_default(),
// pct25.get(di).unwrap_or_default(),
// median.get(di).unwrap_or_default(),
// pct75.get(di).unwrap_or_default(),
// pct90.get(di).unwrap_or_default(),
// max.get(di).unwrap_or_default(),
// ),
// })
// }))
}
}

View File

@@ -48,8 +48,9 @@ impl<'a> DateIndexIter<'a> {
.computer
.chain
.timeindexes_to_timestamp
.dateindex_extra
.unwrap_first()
.dateindex
.as_ref()
.expect("timeindexes_to_timestamp.dateindex should exist")
.iter();
let mut heights = self.computer.indexes.dateindex_to_first_height.iter();

View File

@@ -23,6 +23,7 @@ impl Query {
.indexes
.height_to_dateindex
.read_once(current_height)?;
let current_hashrate = *computer
.chain
.indexes_to_hash_rate
@@ -58,11 +59,13 @@ impl Query {
.dateindex
.unwrap_last()
.iter();
let mut timestamp_iter = computer
.chain
.timeindexes_to_timestamp
.dateindex_extra
.unwrap_first()
.dateindex
.as_ref()
.expect("timeindexes_to_timestamp.dateindex should exist")
.iter();
let mut hashrates = Vec::with_capacity(total_days / step + 1);