clients: snapshot

This commit is contained in:
nym21
2026-01-14 00:39:28 +01:00
parent 524ab3de05
commit 3a836ab0f4
15 changed files with 869 additions and 896 deletions

View File

@@ -7,5 +7,6 @@ use crate::internal::ComputedFromDateLast;
/// Price lookback metrics
#[derive(Clone, Traversable)]
pub struct Vecs {
#[traversable(flatten)]
pub price_ago: ByLookbackPeriod<ComputedFromDateLast<Dollars>>,
}

View File

@@ -20,6 +20,9 @@ use super::{
};
use crate::{ComputeIndexes, indexes};
/// Flush interval for periodic writes during oracle computation.
const FLUSH_INTERVAL: usize = 10_000;
impl Vecs {
/// Compute oracle prices from on-chain data
pub fn compute(
@@ -275,9 +278,15 @@ impl Vecs {
self.price_cents
.truncate_push_at(height.to_usize(), price_cents)?;
// Periodic flush to avoid data loss on long computations
if height.to_usize() % FLUSH_INTERVAL == 0 {
let _lock = exit.lock();
self.price_cents.write()?;
}
}
// Write height prices
// Final write
{
let _lock = exit.lock();
self.price_cents.write()?;

View File

@@ -1,6 +1,6 @@
use brk_error::Result;
use brk_types::Version;
use vecdb::{BytesVec, Database, ImportableVec, PcoVec};
use brk_types::{DateIndex, OHLCCents, OHLCDollars, Version};
use vecdb::{BytesVec, Database, ImportableVec, IterableCloneableVec, LazyVecFrom1, PcoVec};
use super::Vecs;
@@ -10,9 +10,17 @@ impl Vecs {
let ohlc_cents = BytesVec::forced_import(db, "oracle_ohlc_cents", version)?;
let tx_count = PcoVec::forced_import(db, "oracle_tx_count", version)?;
let ohlc_dollars = LazyVecFrom1::init(
"oracle_ohlc",
version,
ohlc_cents.boxed_clone(),
|di: DateIndex, iter| iter.get(di).map(|o: OHLCCents| OHLCDollars::from(o)),
);
Ok(Self {
price_cents,
ohlc_cents,
ohlc_dollars,
tx_count,
})
}

View File

@@ -1,6 +1,6 @@
use brk_traversable::Traversable;
use brk_types::{Cents, DateIndex, Height, OHLCCents, StoredU32};
use vecdb::{BytesVec, PcoVec};
use brk_types::{Cents, DateIndex, Height, OHLCCents, OHLCDollars, StoredU32};
use vecdb::{BytesVec, LazyVecFrom1, PcoVec};
/// Vectors storing UTXOracle-derived price data
#[derive(Clone, Traversable)]
@@ -13,6 +13,9 @@ pub struct Vecs {
/// Uses BytesVec because OHLCCents is a complex type
pub ohlc_cents: BytesVec<DateIndex, OHLCCents>,
/// Daily OHLC in dollars (lazy conversion from cents)
pub ohlc_dollars: LazyVecFrom1<DateIndex, OHLCDollars, DateIndex, OHLCCents>,
/// Number of qualifying transactions per day (for confidence)
pub tx_count: PcoVec<DateIndex, StoredU32>,
}