mirror of
https://github.com/bitcoinresearchkit/brk.git
synced 2026-07-19 23:18:10 -07:00
oracle: cleanup + split lib.rs
This commit is contained in:
@@ -5,7 +5,7 @@
|
||||
//! onward.
|
||||
//!
|
||||
//! Mirrors the production filter exactly (per-tx OP_RETURN drop + per-output
|
||||
//! `default_eligible_bin`), so it exercises the same code path
|
||||
//! `eligible_bin`), so it exercises the same code path
|
||||
//! `brk_computer::prices::compute::feed_blocks` uses at runtime.
|
||||
//!
|
||||
//! Run with: cargo run -p brk_oracle --example determinism --release
|
||||
@@ -14,7 +14,7 @@ use std::path::PathBuf;
|
||||
|
||||
use brk_indexer::Indexer;
|
||||
use brk_oracle::{
|
||||
Config, HistogramRaw, Oracle, PRICES, START_HEIGHT, bin_to_cents, cents_to_bin,
|
||||
Config, HistogramRaw, Oracle, PRICES, START_HEIGHT_FAST, bin_to_cents, cents_to_bin,
|
||||
for_each_round_dollar_bin,
|
||||
};
|
||||
use brk_types::{OutputType, Sats, TxIndex, TxOutIndex};
|
||||
@@ -23,8 +23,8 @@ use vecdb::{AnyVec, ReadableVec, VecIndex};
|
||||
fn seed_bin_for_start_height() -> f64 {
|
||||
let price: f64 = PRICES
|
||||
.lines()
|
||||
.nth(START_HEIGHT - 1)
|
||||
.expect("prices.txt too short for START_HEIGHT")
|
||||
.nth(START_HEIGHT_FAST - 1)
|
||||
.expect("prices.txt too short for START_HEIGHT_FAST")
|
||||
.parse()
|
||||
.expect("Failed to parse seed price");
|
||||
cents_to_bin(price * 100.0)
|
||||
@@ -73,8 +73,8 @@ fn main() {
|
||||
|
||||
let restart_offset = 1000;
|
||||
let end_offset = restart_offset + window_size * 4;
|
||||
let end_height = (START_HEIGHT + end_offset).min(total_heights);
|
||||
let restart_at = START_HEIGHT + restart_offset;
|
||||
let end_height = (START_HEIGHT_FAST + end_offset).min(total_heights);
|
||||
let restart_at = START_HEIGHT_FAST + restart_offset;
|
||||
let warmup_start = restart_at - window_size;
|
||||
|
||||
assert!(
|
||||
@@ -84,8 +84,8 @@ fn main() {
|
||||
);
|
||||
|
||||
println!(
|
||||
"Loading {} blocks ({START_HEIGHT}..{end_height})...",
|
||||
end_height - START_HEIGHT
|
||||
"Loading {} blocks ({START_HEIGHT_FAST}..{end_height})...",
|
||||
end_height - START_HEIGHT_FAST
|
||||
);
|
||||
let total_txs = indexer.vecs.transactions.txid.len();
|
||||
let total_outputs = indexer.vecs.outputs.value.len();
|
||||
@@ -93,8 +93,8 @@ fn main() {
|
||||
let out_first: Vec<TxOutIndex> = indexer.vecs.outputs.first_txout_index.collect();
|
||||
let mut txout_cursor = indexer.vecs.transactions.first_txout_index.cursor();
|
||||
|
||||
let mut blocks: Vec<Block> = Vec::with_capacity(end_height - START_HEIGHT);
|
||||
for h in START_HEIGHT..end_height {
|
||||
let mut blocks: Vec<Block> = Vec::with_capacity(end_height - START_HEIGHT_FAST);
|
||||
for h in START_HEIGHT_FAST..end_height {
|
||||
let ft = first_tx_index[h];
|
||||
let next_ft = first_tx_index
|
||||
.get(h + 1)
|
||||
@@ -146,21 +146,21 @@ fn main() {
|
||||
continuous_bins.len()
|
||||
);
|
||||
|
||||
let prev_bin = continuous_bins[restart_at - START_HEIGHT - 1];
|
||||
let prev_bin = continuous_bins[restart_at - START_HEIGHT_FAST - 1];
|
||||
let seed_bin = cents_to_bin(bin_to_cents(prev_bin) as f64);
|
||||
println!(
|
||||
"Restart at {restart_at}: prev_bin={prev_bin:.4} -> cents -> seed_bin={seed_bin:.4} (delta {:.6})",
|
||||
seed_bin - prev_bin
|
||||
);
|
||||
|
||||
let warmup_slice = &blocks[warmup_start - START_HEIGHT..restart_at - START_HEIGHT];
|
||||
let warmup_slice = &blocks[warmup_start - START_HEIGHT_FAST..restart_at - START_HEIGHT_FAST];
|
||||
let mut restored = Oracle::from_checkpoint(seed_bin, config.clone(), |o| {
|
||||
for b in warmup_slice {
|
||||
o.process_histogram(&build_histogram(b));
|
||||
}
|
||||
});
|
||||
|
||||
let restored_bins: Vec<f64> = blocks[restart_at - START_HEIGHT..]
|
||||
let restored_bins: Vec<f64> = blocks[restart_at - START_HEIGHT_FAST..]
|
||||
.iter()
|
||||
.map(|b| restored.process_histogram(&build_histogram(b)))
|
||||
.collect();
|
||||
@@ -168,7 +168,7 @@ fn main() {
|
||||
|
||||
let mut mismatches: Vec<(usize, f64, f64)> = Vec::new();
|
||||
for (i, &r) in restored_bins.iter().enumerate() {
|
||||
let c = continuous_bins[restart_at - START_HEIGHT + i];
|
||||
let c = continuous_bins[restart_at - START_HEIGHT_FAST + i];
|
||||
if r != c {
|
||||
mismatches.push((restart_at + i, c, r));
|
||||
}
|
||||
|
||||
@@ -6,8 +6,8 @@ use std::path::PathBuf;
|
||||
|
||||
use brk_indexer::Indexer;
|
||||
use brk_oracle::{
|
||||
Config, Oracle, PRICES, HistogramRaw, START_HEIGHT, bin_to_cents, cents_to_bin,
|
||||
default_eligible_bin,
|
||||
Config, Oracle, PRICES, HistogramRaw, START_HEIGHT_FAST, bin_to_cents, cents_to_bin,
|
||||
eligible_bin,
|
||||
};
|
||||
use brk_types::{OutputType, Sats, TxIndex, TxOutIndex};
|
||||
use vecdb::{AnyVec, ReadableVec, VecIndex};
|
||||
@@ -174,7 +174,7 @@ fn main() {
|
||||
|
||||
let start_price: f64 = PRICES
|
||||
.lines()
|
||||
.nth(START_HEIGHT - 1)
|
||||
.nth(START_HEIGHT_FAST - 1)
|
||||
.expect("prices.txt too short")
|
||||
.parse()
|
||||
.expect("Failed to parse seed price");
|
||||
@@ -201,7 +201,7 @@ fn main() {
|
||||
let mut oracle_candles: Vec<DayCandle> = Vec::new();
|
||||
let mut current_di: Option<usize> = None;
|
||||
|
||||
for h in START_HEIGHT..total_heights {
|
||||
for h in START_HEIGHT_FAST..total_heights {
|
||||
let ft = first_tx_index[h];
|
||||
let next_ft = first_tx_index
|
||||
.get(h + 1)
|
||||
@@ -247,7 +247,7 @@ fn main() {
|
||||
continue;
|
||||
}
|
||||
for i in lo..hi {
|
||||
if let Some(bin) = default_eligible_bin(values[i], output_types[i]) {
|
||||
if let Some(bin) = eligible_bin(values[i], output_types[i]) {
|
||||
hist.increment(bin as usize);
|
||||
}
|
||||
}
|
||||
@@ -376,7 +376,7 @@ fn main() {
|
||||
println!(" Config: w12, alpha=2/7, search -9/+11, noisy/dust/round-btc filtered");
|
||||
println!(
|
||||
" Test range: height {} .. {} ({} blocks)",
|
||||
START_HEIGHT,
|
||||
START_HEIGHT_FAST,
|
||||
total_heights - 1,
|
||||
overall.total_blocks
|
||||
);
|
||||
|
||||
@@ -6,8 +6,8 @@ use std::path::PathBuf;
|
||||
|
||||
use brk_indexer::Indexer;
|
||||
use brk_oracle::{
|
||||
Config, HistogramEma, HistogramRaw, NUM_BINS, PRICES, START_HEIGHT, bin_to_cents, cents_to_bin,
|
||||
default_eligible_bin,
|
||||
Config, HistogramEma, HistogramRaw, NUM_BINS, PRICES, START_HEIGHT_FAST, bin_to_cents,
|
||||
cents_to_bin, eligible_bin,
|
||||
};
|
||||
use brk_types::{OutputType, Sats, TxIndex, TxOutIndex};
|
||||
use vecdb::{AnyVec, ReadableVec, VecIndex};
|
||||
@@ -528,7 +528,7 @@ fn main() {
|
||||
let start = std::env::var("ORACLE_START")
|
||||
.ok()
|
||||
.and_then(|s| s.parse().ok())
|
||||
.unwrap_or(START_HEIGHT);
|
||||
.unwrap_or(START_HEIGHT_FAST);
|
||||
let end_override = std::env::var("ORACLE_END")
|
||||
.ok()
|
||||
.and_then(|s| s.parse::<usize>().ok());
|
||||
@@ -685,7 +685,7 @@ fn main() {
|
||||
},
|
||||
stencil_weight,
|
||||
);
|
||||
// Mid-run regime switch, mirrors production Oracle::reconfigure at START_HEIGHT:
|
||||
// Mid-run regime switch, mirrors production Oracle::reconfigure at START_HEIGHT_FAST:
|
||||
// at SWITCH_AT rebuild the EMA to SWITCH_WINDOW/SWITCH_ALPHA and warm-start fresh
|
||||
// (ring reset, ref_bin kept) - the same state as a fresh warm-up. Search window
|
||||
// is unchanged (both regimes share it). 0 = no switch (single-config baseline).
|
||||
@@ -903,7 +903,7 @@ fn main() {
|
||||
continue;
|
||||
}
|
||||
for i in lo..hi {
|
||||
if let Some(bin) = default_eligible_bin(values[i], output_types[i]) {
|
||||
if let Some(bin) = eligible_bin(values[i], output_types[i]) {
|
||||
hist.increment(bin as usize);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user