mempool: fixes

This commit is contained in:
nym21
2026-04-21 12:43:50 +02:00
parent 327873d010
commit 6afce0bbdc
20 changed files with 272 additions and 300 deletions
+25 -2
View File
@@ -14,13 +14,14 @@ use axum::{
};
use brk_query::AsyncQuery;
use brk_types::{
Addr, BlockHash, BlockHashPrefix, Height, ONE_HOUR_IN_SEC, Timestamp as BrkTimestamp, Txid,
Version,
Addr, BlockHash, BlockHashPrefix, Date, Height, ONE_HOUR_IN_SEC, Timestamp as BrkTimestamp,
Txid, Version,
};
use derive_more::Deref;
use jiff::Timestamp;
use quick_cache::sync::{Cache, GuardResult};
use serde::Serialize;
use vecdb::ReadableVec;
use crate::{
CacheParams, CacheStrategy, Error, Website,
@@ -59,6 +60,28 @@ impl AppState {
}
}
/// `Immutable` if `date` is strictly before the indexed tip's date, `Tip` otherwise.
/// For per-date files that keep being rewritten while the tip is still within the
/// date's day, then settle once the tip crosses the day boundary.
pub fn date_cache(&self, version: Version, date: Date) -> CacheStrategy {
self.sync(|q| {
let height = q.indexed_height();
q.indexer()
.vecs
.blocks
.timestamp
.collect_one(height)
.map(|ts| {
if date < Date::from(ts) {
CacheStrategy::Immutable(version)
} else {
CacheStrategy::Tip
}
})
.unwrap_or(CacheStrategy::Tip)
})
}
/// Smart address caching: checks mempool activity first (unless `chain_only`), then on-chain.
/// - Address has mempool txs → `MempoolHash(addr_specific_hash)`
/// - No mempool, has on-chain activity → `BlockBound(last_activity_block)`