mirror of
https://github.com/bitcoinresearchkit/brk.git
synced 2026-07-30 20:28:11 -07:00
crates: snapshot
This commit is contained in:
@@ -6,7 +6,7 @@ use std::path::PathBuf;
|
||||
use std::time::Instant;
|
||||
|
||||
use brk_indexer::Indexer;
|
||||
use brk_oracle::{Config, NUM_BINS, Oracle, PRICES, START_HEIGHT, cents_to_bin, sats_to_bin};
|
||||
use brk_oracle::{Config, Histogram, NUM_BINS, Oracle, PRICES, cents_to_bin, sats_to_bin};
|
||||
use brk_types::{OutputType, Sats, TxIndex, TxOutIndex};
|
||||
use vecdb::{AnyVec, ReadableVec, VecIndex};
|
||||
|
||||
@@ -159,7 +159,7 @@ fn main() {
|
||||
let ref_config = Config::default();
|
||||
let earliest_start = *start_heights.iter().min().unwrap();
|
||||
|
||||
for h in START_HEIGHT..total_heights {
|
||||
for h in earliest_start..total_heights {
|
||||
let ft = first_tx_index[h];
|
||||
let next_ft = first_tx_index
|
||||
.get(h + 1)
|
||||
@@ -187,10 +187,6 @@ fn main() {
|
||||
.unwrap_or(TxOutIndex::from(total_outputs))
|
||||
.to_usize();
|
||||
|
||||
if h < earliest_start {
|
||||
continue;
|
||||
}
|
||||
|
||||
let values: Vec<Sats> = indexer
|
||||
.vecs
|
||||
.outputs
|
||||
@@ -203,8 +199,8 @@ fn main() {
|
||||
.collect_range_at(out_start, out_end);
|
||||
|
||||
// Build full histogram and per-digit histograms.
|
||||
let mut full_hist = [0u32; NUM_BINS];
|
||||
let mut digit_hist = [[0u32; NUM_BINS]; 9];
|
||||
let mut full_hist = Histogram::zeros();
|
||||
let mut digit_hist: [Histogram; 9] = std::array::from_fn(|_| Histogram::zeros());
|
||||
|
||||
for (sats, output_type) in values.into_iter().zip(output_types) {
|
||||
if ref_config.excluded_output_types.contains(&output_type) {
|
||||
@@ -214,11 +210,11 @@ fn main() {
|
||||
continue;
|
||||
}
|
||||
if let Some(bin) = sats_to_bin(sats) {
|
||||
full_hist[bin] += 1;
|
||||
full_hist.increment(bin);
|
||||
if is_round(*sats) {
|
||||
let d = leading_digit(*sats);
|
||||
if (1..=9).contains(&d) {
|
||||
digit_hist[(d - 1) as usize][bin] += 1;
|
||||
digit_hist[(d - 1) as usize].increment(bin);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -227,7 +223,7 @@ fn main() {
|
||||
// Feed each (mask, start_height) combo.
|
||||
for (mi, &(mask, _)) in masks.iter().enumerate() {
|
||||
// Build filtered histogram for this mask.
|
||||
let mut hist = full_hist;
|
||||
let mut hist = full_hist.clone();
|
||||
(0..9usize).for_each(|d| {
|
||||
if mask & (1 << d) != 0 {
|
||||
for bin in 0..NUM_BINS {
|
||||
|
||||
@@ -11,7 +11,9 @@
|
||||
use std::path::PathBuf;
|
||||
|
||||
use brk_indexer::Indexer;
|
||||
use brk_oracle::{Config, NUM_BINS, Oracle, PRICES, START_HEIGHT, cents_to_bin, sats_to_bin};
|
||||
use brk_oracle::{
|
||||
Config, Histogram, Oracle, PRICES, START_HEIGHT, cents_to_bin, default_eligible_bin,
|
||||
};
|
||||
use brk_types::{OutputType, Sats, TxIndex, TxOutIndex};
|
||||
use vecdb::{AnyVec, ReadableVec, VecIndex};
|
||||
|
||||
@@ -52,8 +54,6 @@ fn main() {
|
||||
let first_tx_index: Vec<TxIndex> = indexer.vecs.transactions.first_tx_index.collect();
|
||||
let out_first: Vec<TxOutIndex> = indexer.vecs.outputs.first_txout_index.collect();
|
||||
|
||||
let ref_config = Config::default();
|
||||
|
||||
// Reference oracle at 575k.
|
||||
let ref_start = START_HEIGHT;
|
||||
let mut ref_oracle = Oracle::new(seed_bin(ref_start), Config::default());
|
||||
@@ -112,18 +112,10 @@ fn main() {
|
||||
.output_type
|
||||
.collect_range_at(out_start, out_end);
|
||||
|
||||
let mut hist = [0u32; NUM_BINS];
|
||||
let mut hist = Histogram::zeros();
|
||||
for (sats, output_type) in values.into_iter().zip(output_types) {
|
||||
if ref_config.excluded_output_types.contains(&output_type) {
|
||||
continue;
|
||||
}
|
||||
if *sats < ref_config.min_sats
|
||||
|| (ref_config.exclude_common_round_values && sats.is_common_round_value())
|
||||
{
|
||||
continue;
|
||||
}
|
||||
if let Some(bin) = sats_to_bin(sats) {
|
||||
hist[bin] += 1;
|
||||
if let Some(bin) = default_eligible_bin(sats, output_type) {
|
||||
hist.increment(bin as usize);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -6,7 +6,7 @@ use std::path::PathBuf;
|
||||
use std::time::Instant;
|
||||
|
||||
use brk_indexer::Indexer;
|
||||
use brk_oracle::{Config, NUM_BINS, Oracle, PRICES, cents_to_bin, sats_to_bin};
|
||||
use brk_oracle::{Config, Histogram, Oracle, PRICES, cents_to_bin, default_eligible_bin};
|
||||
use brk_types::{Sats, TxIndex, TxOutIndex};
|
||||
use vecdb::{AnyVec, ReadableVec, VecIndex};
|
||||
|
||||
@@ -19,7 +19,7 @@ fn bins_to_pct(bins: f64) -> f64 {
|
||||
(10.0_f64.powf(bins / BPD) - 1.0) * 100.0
|
||||
}
|
||||
|
||||
fn price_seed_bin(start_height: usize) -> f64 {
|
||||
fn seed_bin(start_height: usize) -> f64 {
|
||||
let price: f64 = PRICES
|
||||
.lines()
|
||||
.nth(start_height - 1)
|
||||
@@ -30,9 +30,7 @@ fn price_seed_bin(start_height: usize) -> f64 {
|
||||
}
|
||||
|
||||
/// Clamp the top N bins in `src` down to the (N+1)th highest value, writing into `dst`.
|
||||
fn clamp_top_n(src: &[u32; NUM_BINS], dst: &mut [u32; NUM_BINS], n: usize) {
|
||||
// Find the (n+1)th largest value.
|
||||
// Collect non-zero counts, sort descending, take the (n+1)th.
|
||||
fn clamp_top_n(src: &Histogram, dst: &mut Histogram, n: usize) {
|
||||
let mut top: Vec<u32> = src.iter().copied().filter(|&v| v > 0).collect();
|
||||
top.sort_unstable_by(|a, b| b.cmp(a));
|
||||
let clamp_to = if top.len() > n { top[n] } else { 0 };
|
||||
@@ -102,7 +100,7 @@ fn main() {
|
||||
let total_blocks = total_heights - lowest;
|
||||
|
||||
struct BlockData {
|
||||
hist: Box<[u32; NUM_BINS]>,
|
||||
hist: Histogram,
|
||||
high_bin: f64,
|
||||
low_bin: f64,
|
||||
}
|
||||
@@ -144,21 +142,12 @@ fn main() {
|
||||
.unwrap_or(TxOutIndex::from(total_outputs))
|
||||
.to_usize();
|
||||
|
||||
let mut hist = Box::new([0u32; NUM_BINS]);
|
||||
let mut hist = Histogram::zeros();
|
||||
for i in out_start..out_end {
|
||||
let sats: Sats = value_reader.get(i);
|
||||
let output_type = output_type_reader.get(i);
|
||||
if config.excluded_output_types.contains(&output_type) {
|
||||
continue;
|
||||
}
|
||||
if *sats < config.min_sats {
|
||||
continue;
|
||||
}
|
||||
if config.exclude_common_round_values && sats.is_common_round_value() {
|
||||
continue;
|
||||
}
|
||||
if let Some(bin) = sats_to_bin(sats) {
|
||||
hist[bin] += 1;
|
||||
if let Some(bin) = default_eligible_bin(sats, output_type) {
|
||||
hist.increment(bin as usize);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -206,7 +195,7 @@ fn main() {
|
||||
println!("{}", "-".repeat(72));
|
||||
|
||||
for &start_height in &start_heights {
|
||||
let mut oracle = Oracle::new(price_seed_bin(start_height), config.clone());
|
||||
let mut oracle = Oracle::new(seed_bin(start_height), config.clone());
|
||||
let block_offset = start_height - lowest;
|
||||
|
||||
let mut worst_err: f64 = 0.0;
|
||||
@@ -217,7 +206,7 @@ fn main() {
|
||||
let mut total_sq_err: f64 = 0.0;
|
||||
let mut total_measured: u64 = 0;
|
||||
|
||||
let mut clamped_hist = [0u32; NUM_BINS];
|
||||
let mut clamped_hist = Histogram::zeros();
|
||||
for (i, bd) in blocks[block_offset..].iter().enumerate() {
|
||||
if clamp_n > 0 {
|
||||
clamp_top_n(&bd.hist, &mut clamped_hist, clamp_n);
|
||||
|
||||
@@ -6,7 +6,8 @@ use std::path::PathBuf;
|
||||
|
||||
use brk_indexer::Indexer;
|
||||
use brk_oracle::{
|
||||
Config, NUM_BINS, Oracle, PRICES, START_HEIGHT, bin_to_cents, cents_to_bin, sats_to_bin,
|
||||
Config, Histogram, Oracle, PRICES, START_HEIGHT, bin_to_cents, cents_to_bin,
|
||||
default_eligible_bin,
|
||||
};
|
||||
use brk_types::{OutputType, Sats, TxIndex, TxOutIndex};
|
||||
use vecdb::{AnyVec, ReadableVec, VecIndex};
|
||||
@@ -188,8 +189,6 @@ fn main() {
|
||||
let first_tx_index: Vec<TxIndex> = indexer.vecs.transactions.first_tx_index.collect();
|
||||
let out_first: Vec<TxOutIndex> = indexer.vecs.outputs.first_txout_index.collect();
|
||||
|
||||
let ref_config = Config::default();
|
||||
|
||||
let mut year_stats: Vec<YearStats> = Vec::new();
|
||||
let mut overall = YearStats::new(0);
|
||||
let mut worst_blocks: Vec<BlockError> = Vec::new();
|
||||
@@ -238,18 +237,10 @@ fn main() {
|
||||
.output_type
|
||||
.collect_range_at(out_start, out_end);
|
||||
|
||||
let mut hist = [0u32; NUM_BINS];
|
||||
let mut hist = Histogram::zeros();
|
||||
for (sats, output_type) in values.into_iter().zip(output_types) {
|
||||
if ref_config.excluded_output_types.contains(&output_type) {
|
||||
continue;
|
||||
}
|
||||
if *sats < ref_config.min_sats
|
||||
|| (ref_config.exclude_common_round_values && sats.is_common_round_value())
|
||||
{
|
||||
continue;
|
||||
}
|
||||
if let Some(bin) = sats_to_bin(sats) {
|
||||
hist[bin] += 1;
|
||||
if let Some(bin) = default_eligible_bin(sats, output_type) {
|
||||
hist.increment(bin as usize);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -12,7 +12,7 @@ use std::path::PathBuf;
|
||||
use std::time::Instant;
|
||||
|
||||
use brk_indexer::Indexer;
|
||||
use brk_oracle::{Config, NUM_BINS, Oracle, PRICES, START_HEIGHT, cents_to_bin, sats_to_bin};
|
||||
use brk_oracle::{Config, Histogram, Oracle, PRICES, cents_to_bin, sats_to_bin};
|
||||
use brk_types::{OutputType, Sats, TxIndex, TxOutIndex};
|
||||
use vecdb::{AnyVec, ReadableVec, VecIndex};
|
||||
|
||||
@@ -117,7 +117,7 @@ impl Stats {
|
||||
}
|
||||
|
||||
struct BlockData {
|
||||
full_hist: Box<[u32; NUM_BINS]>,
|
||||
full_hist: Histogram,
|
||||
/// (bin_index, leading_digit) for outputs that are round values.
|
||||
round_outputs: Vec<(u16, u8)>,
|
||||
high_bin: f64,
|
||||
@@ -173,7 +173,7 @@ fn main() {
|
||||
let total_blocks = total_heights - sweep_start;
|
||||
let mut blocks: Vec<BlockData> = Vec::with_capacity(total_blocks);
|
||||
|
||||
for h in START_HEIGHT..total_heights {
|
||||
for h in sweep_start..total_heights {
|
||||
let ft = first_tx_index[h];
|
||||
let next_ft = first_tx_index
|
||||
.get(h + 1)
|
||||
@@ -201,10 +201,6 @@ fn main() {
|
||||
.unwrap_or(TxOutIndex::from(total_outputs))
|
||||
.to_usize();
|
||||
|
||||
if h < sweep_start {
|
||||
continue;
|
||||
}
|
||||
|
||||
let values: Vec<Sats> = indexer
|
||||
.vecs
|
||||
.outputs
|
||||
@@ -216,7 +212,7 @@ fn main() {
|
||||
.output_type
|
||||
.collect_range_at(out_start, out_end);
|
||||
|
||||
let mut full_hist = Box::new([0u32; NUM_BINS]);
|
||||
let mut full_hist = Histogram::zeros();
|
||||
let mut round_outputs = Vec::new();
|
||||
|
||||
for (sats, output_type) in values.into_iter().zip(output_types) {
|
||||
@@ -227,7 +223,7 @@ fn main() {
|
||||
continue;
|
||||
}
|
||||
if let Some(bin) = sats_to_bin(sats) {
|
||||
full_hist[bin] += 1;
|
||||
full_hist.increment(bin);
|
||||
if is_round(*sats) {
|
||||
let d = leading_digit(*sats);
|
||||
if (1..=9).contains(&d) {
|
||||
@@ -260,7 +256,7 @@ fn main() {
|
||||
}
|
||||
}
|
||||
|
||||
let mem_hists = blocks.len() * std::mem::size_of::<[u32; NUM_BINS]>();
|
||||
let mem_hists = blocks.len() * std::mem::size_of::<Histogram>();
|
||||
let mem_rounds: usize = blocks.iter().map(|b| b.round_outputs.len() * 3).sum();
|
||||
eprintln!(
|
||||
"\r {} blocks precomputed ({:.1} GB hists + {:.0} MB rounds) in {:.1}s",
|
||||
@@ -308,7 +304,7 @@ fn main() {
|
||||
let mut stats = Stats::new();
|
||||
|
||||
for bd in blocks.iter() {
|
||||
let mut hist = *bd.full_hist;
|
||||
let mut hist = bd.full_hist.clone();
|
||||
for &(bin, digit) in &bd.round_outputs {
|
||||
if mask & (1 << (digit - 1)) != 0 {
|
||||
hist[bin as usize] -= 1;
|
||||
|
||||
@@ -12,7 +12,7 @@ use std::path::PathBuf;
|
||||
use std::time::Instant;
|
||||
|
||||
use brk_indexer::Indexer;
|
||||
use brk_oracle::{Config, NUM_BINS, Oracle, PRICES, START_HEIGHT, cents_to_bin, sats_to_bin};
|
||||
use brk_oracle::{Config, Histogram, Oracle, PRICES, cents_to_bin, sats_to_bin};
|
||||
use brk_types::{OutputType, Sats, TxIndex, TxOutIndex};
|
||||
use vecdb::{AnyVec, ReadableVec, VecIndex};
|
||||
|
||||
@@ -114,7 +114,7 @@ struct RoundOutput {
|
||||
}
|
||||
|
||||
struct BlockData {
|
||||
full_hist: Box<[u32; NUM_BINS]>,
|
||||
full_hist: Histogram,
|
||||
round_outputs: Vec<RoundOutput>,
|
||||
high_bin: f64,
|
||||
low_bin: f64,
|
||||
@@ -175,7 +175,7 @@ fn main() {
|
||||
// Outputs beyond 5% relative error will never be filtered at any tolerance.
|
||||
let max_tolerance: f64 = 0.05;
|
||||
|
||||
for h in START_HEIGHT..total_heights {
|
||||
for h in sweep_start..total_heights {
|
||||
let ft = first_tx_index[h];
|
||||
let next_ft = first_tx_index
|
||||
.get(h + 1)
|
||||
@@ -203,10 +203,6 @@ fn main() {
|
||||
.unwrap_or(TxOutIndex::from(total_outputs))
|
||||
.to_usize();
|
||||
|
||||
if h < sweep_start {
|
||||
continue;
|
||||
}
|
||||
|
||||
let values: Vec<Sats> = indexer
|
||||
.vecs
|
||||
.outputs
|
||||
@@ -218,7 +214,7 @@ fn main() {
|
||||
.output_type
|
||||
.collect_range_at(out_start, out_end);
|
||||
|
||||
let mut full_hist = Box::new([0u32; NUM_BINS]);
|
||||
let mut full_hist = Histogram::zeros();
|
||||
let mut round_outputs = Vec::new();
|
||||
|
||||
for (sats, output_type) in values.into_iter().zip(output_types) {
|
||||
@@ -229,7 +225,7 @@ fn main() {
|
||||
continue;
|
||||
}
|
||||
if let Some(bin) = sats_to_bin(sats) {
|
||||
full_hist[bin] += 1;
|
||||
full_hist.increment(bin);
|
||||
let d = leading_digit(*sats);
|
||||
if (1..=9).contains(&d) {
|
||||
let rel_err = relative_roundness(*sats);
|
||||
@@ -267,7 +263,7 @@ fn main() {
|
||||
}
|
||||
}
|
||||
|
||||
let mem_hists = blocks.len() * std::mem::size_of::<[u32; NUM_BINS]>();
|
||||
let mem_hists = blocks.len() * std::mem::size_of::<Histogram>();
|
||||
let mem_rounds: usize = blocks
|
||||
.iter()
|
||||
.map(|b| b.round_outputs.len() * std::mem::size_of::<RoundOutput>())
|
||||
@@ -350,7 +346,7 @@ fn main() {
|
||||
let mut stats = Stats::new();
|
||||
|
||||
for bd in blocks.iter() {
|
||||
let mut hist = *bd.full_hist;
|
||||
let mut hist = bd.full_hist.clone();
|
||||
|
||||
// Remove outputs matching this tolerance + mask.
|
||||
let tol_f32 = tolerance as f32;
|
||||
|
||||
@@ -9,7 +9,9 @@
|
||||
use std::path::PathBuf;
|
||||
|
||||
use brk_indexer::Indexer;
|
||||
use brk_oracle::{Config, NUM_BINS, Oracle, PRICES, START_HEIGHT, cents_to_bin, sats_to_bin};
|
||||
use brk_oracle::{
|
||||
Config, Histogram, Oracle, PRICES, START_HEIGHT, cents_to_bin, default_eligible_bin,
|
||||
};
|
||||
use brk_types::{OutputType, Sats, TxIndex, TxOutIndex};
|
||||
use vecdb::{AnyVec, ReadableVec, VecIndex};
|
||||
|
||||
@@ -155,8 +157,6 @@ fn main() {
|
||||
let first_tx_index: Vec<TxIndex> = indexer.vecs.transactions.first_tx_index.collect();
|
||||
let out_first: Vec<TxOutIndex> = indexer.vecs.outputs.first_txout_index.collect();
|
||||
|
||||
let ref_config = Config::default();
|
||||
|
||||
for h in START_HEIGHT..total_heights {
|
||||
let ft = first_tx_index[h];
|
||||
let next_ft = first_tx_index
|
||||
@@ -197,18 +197,10 @@ fn main() {
|
||||
.output_type
|
||||
.collect_range_at(out_start, out_end);
|
||||
|
||||
let mut hist = [0u32; NUM_BINS];
|
||||
let mut hist = Histogram::zeros();
|
||||
for (sats, output_type) in values.into_iter().zip(output_types) {
|
||||
if ref_config.excluded_output_types.contains(&output_type) {
|
||||
continue;
|
||||
}
|
||||
if *sats < ref_config.min_sats
|
||||
|| (ref_config.exclude_common_round_values && sats.is_common_round_value())
|
||||
{
|
||||
continue;
|
||||
}
|
||||
if let Some(bin) = sats_to_bin(sats) {
|
||||
hist[bin] += 1;
|
||||
if let Some(bin) = default_eligible_bin(sats, output_type) {
|
||||
hist.increment(bin as usize);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user