mirror of
https://github.com/bitcoinresearchkit/brk.git
synced 2026-04-24 06:39:58 -07:00
clients: snapshot
This commit is contained in:
@@ -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>>,
|
||||
}
|
||||
|
||||
@@ -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()?;
|
||||
|
||||
@@ -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,
|
||||
})
|
||||
}
|
||||
|
||||
@@ -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>,
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user