global: snapshot

This commit is contained in:
nym21
2026-04-14 22:53:10 +02:00
parent 904ec93668
commit 39da441d14
57 changed files with 2886 additions and 1668 deletions
+10 -5
View File
@@ -24,7 +24,9 @@ use std::time::{Duration, Instant};
use brk_error::Result;
use brk_reader::{Reader, Receiver};
use brk_rpc::{Auth, Client};
use brk_types::{BlockHash, Height, ReadBlock};
use brk_types::{Height, ReadBlock};
type BlockStream = Receiver<Result<ReadBlock>>;
const SCENARIOS: &[usize] = &[5, 10, 100, 1_000, 10_000];
const REPEATS: usize = 3;
@@ -51,7 +53,7 @@ fn main() -> Result<()> {
for &n in SCENARIOS {
let anchor_height = Height::from(tip.saturating_sub(n as u32));
let anchor_hash = client.get_block_hash(*anchor_height as u64)?;
let anchor = Some(BlockHash::from(anchor_hash));
let anchor = Some(anchor_hash);
let mut first: Option<RunStats> = None;
for &p in PARSER_COUNTS {
@@ -113,7 +115,7 @@ struct RunStats {
fn bench<F>(repeats: usize, mut f: F) -> Result<RunStats>
where
F: FnMut() -> Result<Receiver<ReadBlock>>,
F: FnMut() -> Result<BlockStream>,
{
let mut best = Duration::MAX;
let mut total = Duration::ZERO;
@@ -124,6 +126,7 @@ where
let recv = f()?;
let mut n = 0;
for block in recv.iter() {
let block = block?;
std::hint::black_box(block.height());
n += 1;
}
@@ -175,12 +178,13 @@ struct FullRun {
fn run_once<F>(mut f: F) -> Result<FullRun>
where
F: FnMut() -> Result<Receiver<ReadBlock>>,
F: FnMut() -> Result<BlockStream>,
{
let start = Instant::now();
let recv = f()?;
let mut count = 0;
for block in recv.iter() {
let block = block?;
std::hint::black_box(block.height());
count += 1;
}
@@ -195,12 +199,13 @@ where
/// the channel, which unblocks and unwinds the reader's spawned worker.
fn run_bounded<F>(limit: usize, mut f: F) -> Result<FullRun>
where
F: FnMut() -> Result<Receiver<ReadBlock>>,
F: FnMut() -> Result<BlockStream>,
{
let start = Instant::now();
let recv = f()?;
let mut count = 0;
for block in recv.iter().take(limit) {
let block = block?;
std::hint::black_box(block.height());
count += 1;
}
+2 -2
View File
@@ -1,5 +1,5 @@
use brk_error::Result;
use brk_reader::Reader;
use brk_reader::{BlkIndexToBlkPath, Reader};
use brk_rpc::{Auth, Client};
fn main() -> Result<()> {
@@ -11,7 +11,7 @@ fn main() -> Result<()> {
let reader = Reader::new(bitcoin_dir.join("blocks"), &client);
let xor_bytes = reader.xor_bytes();
let blk_map = reader.blk_index_to_blk_path();
let blk_map = BlkIndexToBlkPath::scan(reader.blocks_dir())?;
let mut prev_height: Option<u32> = None;
let mut max_drop: u32 = 0;
+1
View File
@@ -15,6 +15,7 @@ fn main() -> Result<()> {
// Stream all blocks from genesis to the current tip.
let i = std::time::Instant::now();
for block in reader.after(None)?.iter() {
let block = block?;
println!("{}: {}", block.height(), block.hash());
}
println!("Full read: {:?}", i.elapsed());
@@ -20,6 +20,7 @@ fn main() -> Result<()> {
let i = std::time::Instant::now();
if let Some(block) = reader.range(height, height)?.iter().next() {
let block = block?;
println!(
"height={} hash={} txs={} coinbase=\"{:?}\" ({:?})",
block.height(),