global: snapshot

This commit is contained in:
nym21
2025-10-22 12:36:35 +02:00
parent 8072c4670c
commit 6cd60a064b
20 changed files with 385 additions and 214 deletions
+1 -1
View File
@@ -32,7 +32,7 @@ impl AnyBlock {
let header = Header::consensus_decode(&mut cursor)?;
let hash = header.block_hash().into();
let hash = header.block_hash();
let tx_count = VarInt::consensus_decode(&mut cursor)?.0;
+27 -7
View File
@@ -19,6 +19,7 @@ use brk_rpc::Client;
use brk_structs::{BlkMetadata, BlkPosition, BlockHash, Height, ReadBlock};
pub use crossbeam::channel::Receiver;
use crossbeam::channel::bounded;
use derive_deref::Deref;
use log::error;
use parking_lot::{RwLock, RwLockReadGuard};
use rayon::prelude::*;
@@ -35,15 +36,30 @@ pub use xor_index::*;
const MAGIC_BYTES: [u8; 4] = [249, 190, 180, 217];
const BOUND_CAP: usize = 50;
#[derive(Debug, Clone)]
pub struct Reader {
///
/// Bitcoin BLK file reader
///
/// Thread safe and free to clone
///
///
#[derive(Debug, Clone, Deref)]
pub struct Reader(Arc<ReaderInner>);
impl Reader {
pub fn new(blocks_dir: PathBuf, client: Client) -> Self {
Self(Arc::new(ReaderInner::new(blocks_dir, client)))
}
}
#[derive(Debug)]
pub struct ReaderInner {
blk_index_to_blk_path: Arc<RwLock<BlkIndexToBlkPath>>,
xor_bytes: XORBytes,
blocks_dir: PathBuf,
client: Client,
}
impl Reader {
impl ReaderInner {
pub fn new(blocks_dir: PathBuf, client: Client) -> Self {
Self {
xor_bytes: XORBytes::from(blocks_dir.as_path()),
@@ -55,6 +71,10 @@ impl Reader {
}
}
pub fn client(&self) -> &Client {
&self.client
}
pub fn blk_index_to_blk_path(&self) -> RwLockReadGuard<'_, BlkIndexToBlkPath> {
self.blk_index_to_blk_path.read()
}
@@ -227,6 +247,10 @@ impl Reader {
}
current_height.increment();
if end.is_some_and(|end| end == current_height) {
return ControlFlow::Break(());
}
}
ControlFlow::Continue(())
@@ -343,8 +367,4 @@ impl Reader {
Ok(Height::new(height))
}
pub fn static_clone(&self) -> &'static Self {
Box::leak(Box::new(self.clone()))
}
}