global: veccached change

This commit is contained in:
nym21
2026-04-10 11:30:29 +02:00
parent 12aae503c9
commit 286256ebf0
118 changed files with 579 additions and 900 deletions

View File

@@ -4,10 +4,10 @@ use bitcoin::{Network, PublicKey, ScriptBuf};
use brk_error::{Error, OptionData, Result};
use brk_types::{
Addr, AddrBytes, AddrChainStats, AddrHash, AddrIndexOutPoint, AddrIndexTxIndex, AddrStats,
AnyAddrDataIndexEnum, Dollars, Height, OutputType, Transaction, TxIndex,
TxStatus, Txid, TypeIndex, Unit, Utxo, Vout,
AnyAddrDataIndexEnum, Dollars, Height, OutputType, Transaction, TxIndex, TxStatus, Txid,
TypeIndex, Unit, Utxo, Vout,
};
use vecdb::{ReadableVec, VecIndex};
use vecdb::VecIndex;
use crate::Query;
@@ -39,15 +39,10 @@ impl Query {
let addr_type = output_type;
let hash = AddrHash::from(&bytes);
let Some(store) = stores
.addr_type_to_addr_hash_to_addr_index
.get(addr_type)
else {
let Some(store) = stores.addr_type_to_addr_hash_to_addr_index.get(addr_type) else {
return Err(Error::InvalidAddr);
};
let Ok(Some(type_index)) = store
.get(&hash)
.map(|opt| opt.map(|cow| cow.into_owned()))
let Ok(Some(type_index)) = store.get(&hash).map(|opt| opt.map(|cow| cow.into_owned()))
else {
return Err(Error::UnknownAddr);
};

View File

@@ -52,7 +52,7 @@ impl Query {
if height > max_height {
return Err(Error::OutOfRange("Block height out of range".into()));
}
Ok(self.indexer().vecs.blocks.blockhash.read_once(height)?)
self.indexer().vecs.blocks.blockhash.get(height).data()
}
pub fn blocks(&self, start_height: Option<Height>) -> Result<Vec<BlockInfo>> {
@@ -220,7 +220,7 @@ impl Query {
.block
.sats
.collect_range_at(begin, end);
let prices = computer.prices.cached_spot_usd.collect_range_at(begin, end);
let prices = computer.prices.spot.usd.height.collect_range_at(begin, end);
let output_volumes = computer
.mining
.rewards

View File

@@ -1,4 +1,4 @@
use brk_error::Result;
use brk_error::{OptionData, Result};
use brk_types::{BlockHash, BlockStatus, Height};
use vecdb::AnyVec;
@@ -25,7 +25,8 @@ impl Query {
.vecs
.blocks
.blockhash
.read_once(height.incremented())?,
.get(height.incremented())
.data()?,
)
} else {
None

View File

@@ -39,15 +39,14 @@ impl BlockWindow {
// Use pre-computed timestamp-based lookback for accurate time boundaries.
// 24h, 1w, 1m, 1y use in-memory CachedVec; others fall back to PcoVec.
let cached = &lookback.cached_window_starts.0;
let start_height = match time_period {
TimePeriod::Day => cached._24h.collect_one(current_height),
TimePeriod::Day => lookback._24h.collect_one(current_height),
TimePeriod::ThreeDays => lookback._3d.collect_one(current_height),
TimePeriod::Week => cached._1w.collect_one(current_height),
TimePeriod::Month => cached._1m.collect_one(current_height),
TimePeriod::Week => lookback._1w.collect_one(current_height),
TimePeriod::Month => lookback._1m.collect_one(current_height),
TimePeriod::ThreeMonths => lookback._3m.collect_one(current_height),
TimePeriod::SixMonths => lookback._6m.collect_one(current_height),
TimePeriod::Year => cached._1y.collect_one(current_height),
TimePeriod::Year => lookback._1y.collect_one(current_height),
TimePeriod::TwoYears => lookback._2y.collect_one(current_height),
TimePeriod::ThreeYears => lookback._3y.collect_one(current_height),
TimePeriod::All => None,
@@ -79,7 +78,7 @@ impl BlockWindow {
.collect_range_at(self.start, self.end);
let all_prices: Vec<Cents> = computer
.prices
.cached_spot_cents
.spot.cents.height
.collect_range_at(self.start, self.end);
let read_start = self.start.saturating_sub(1).max(0);
let all_cum = cumulative.collect_range_at(read_start, self.end);

View File

@@ -40,29 +40,13 @@ impl Query {
// Use timestamp-based lookback for accurate time boundaries
let lookback = &computer.blocks.lookback;
let start = match time_period {
TimePeriod::Day => lookback
.cached_window_starts
.0
._24h
.collect_one(current_height),
TimePeriod::Day => lookback._24h.collect_one(current_height),
TimePeriod::ThreeDays => lookback._3d.collect_one(current_height),
TimePeriod::Week => lookback
.cached_window_starts
.0
._1w
.collect_one(current_height),
TimePeriod::Month => lookback
.cached_window_starts
.0
._1m
.collect_one(current_height),
TimePeriod::Week => lookback._1w.collect_one(current_height),
TimePeriod::Month => lookback._1m.collect_one(current_height),
TimePeriod::ThreeMonths => lookback._3m.collect_one(current_height),
TimePeriod::SixMonths => lookback._6m.collect_one(current_height),
TimePeriod::Year => lookback
.cached_window_starts
.0
._1y
.collect_one(current_height),
TimePeriod::Year => lookback._1y.collect_one(current_height),
TimePeriod::TwoYears => lookback._2y.collect_one(current_height),
TimePeriod::ThreeYears => lookback._3y.collect_one(current_height),
TimePeriod::All => None,
@@ -191,8 +175,6 @@ impl Query {
// Use timestamp-based lookback for accurate time boundaries
let lookback = &computer.blocks.lookback;
let start_24h = lookback
.cached_window_starts
.0
._24h
.collect_one(current_height)
.unwrap_or_default()
@@ -207,8 +189,6 @@ impl Query {
let total_24h = total_all.saturating_sub(count_before_24h);
let start_1w = lookback
.cached_window_starts
.0
._1w
.collect_one(current_height)
.unwrap_or_default()
@@ -349,29 +329,13 @@ impl Query {
let lookback = &self.computer().blocks.lookback;
let current_height = self.height();
match tp {
TimePeriod::Day => lookback
.cached_window_starts
.0
._24h
.collect_one(current_height),
TimePeriod::Day => lookback._24h.collect_one(current_height),
TimePeriod::ThreeDays => lookback._3d.collect_one(current_height),
TimePeriod::Week => lookback
.cached_window_starts
.0
._1w
.collect_one(current_height),
TimePeriod::Month => lookback
.cached_window_starts
.0
._1m
.collect_one(current_height),
TimePeriod::Week => lookback._1w.collect_one(current_height),
TimePeriod::Month => lookback._1m.collect_one(current_height),
TimePeriod::ThreeMonths => lookback._3m.collect_one(current_height),
TimePeriod::SixMonths => lookback._6m.collect_one(current_height),
TimePeriod::Year => lookback
.cached_window_starts
.0
._1y
.collect_one(current_height),
TimePeriod::Year => lookback._1y.collect_one(current_height),
TimePeriod::TwoYears => lookback._2y.collect_one(current_height),
TimePeriod::ThreeYears => lookback._3y.collect_one(current_height),
TimePeriod::All => None,

View File

@@ -58,7 +58,7 @@ impl Query {
/// Current indexed height
pub fn indexed_height(&self) -> Height {
Height::from(self.indexer().vecs.blocks.blockhash.stamp())
Height::from(self.indexer().vecs.blocks.blockhash.inner.stamp())
}
/// Current computed height (series)