diff --git a/iterator/src/blk_metadata.rs b/iterator/src/blk_metadata.rs index a4d2b6131..4f07a98a2 100644 --- a/iterator/src/blk_metadata.rs +++ b/iterator/src/blk_metadata.rs @@ -1,4 +1,4 @@ -use std::path::PathBuf; +use std::path::Path; use crate::path_to_modified_time; @@ -9,7 +9,7 @@ pub struct BlkMetadata { } impl BlkMetadata { - pub fn new(index: usize, path: &PathBuf) -> Self { + pub fn new(index: usize, path: &Path) -> Self { Self { index, modified_time: path_to_modified_time(path), diff --git a/iterator/src/blk_recap.rs b/iterator/src/blk_recap.rs index bad813830..487ffc2ed 100644 --- a/iterator/src/blk_recap.rs +++ b/iterator/src/blk_recap.rs @@ -1,4 +1,4 @@ -use std::path::PathBuf; +use std::path::Path; use bitcoin::{hashes::Hash, BlockHash}; use serde::{Deserialize, Serialize}; @@ -29,7 +29,7 @@ impl BlkRecap { } } - pub fn has_different_modified_time(&self, blk_path: &PathBuf) -> bool { + pub fn has_different_modified_time(&self, blk_path: &Path) -> bool { if self.modified_time != path_to_modified_time(blk_path) { dbg!(self.modified_time, path_to_modified_time(blk_path)); } diff --git a/iterator/src/error.rs b/iterator/src/error.rs index 0a7562c65..41bd962f0 100644 --- a/iterator/src/error.rs +++ b/iterator/src/error.rs @@ -8,6 +8,7 @@ pub type Result = std::result::Result; #[derive(Debug)] pub enum Error { IO(io::Error), + #[cfg(feature = "zerocopy")] ZeroCopyError, } @@ -17,6 +18,7 @@ impl From for Error { } } +#[cfg(feature = "zerocopy")] impl From> for Error { fn from(_: zerocopy::error::SizeError) -> Self { Self::ZeroCopyError @@ -27,6 +29,7 @@ impl fmt::Display for Error { fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { match self { Error::IO(error) => Debug::fmt(&error, f), + #[cfg(feature = "zerocopy")] Error::ZeroCopyError => write!(f, "Zero copy convert error"), } } diff --git a/iterator/src/height.rs b/iterator/src/height.rs index 8104cb05b..b646bbc3b 100644 --- a/iterator/src/height.rs +++ b/iterator/src/height.rs @@ -1,18 +1,15 @@ use std::{ fmt::{self, Debug}, - fs, io, ops::{Add, AddAssign, Rem, Sub}, - path::Path, }; use derive_deref::{Deref, DerefMut}; use serde::{Deserialize, Serialize}; + +#[cfg(feature = "zerocopy")] use zerocopy::{FromBytes, Immutable, IntoBytes, KnownLayout}; -use crate::{ - rpc::{self, RpcApi}, - Error, -}; +use crate::rpc::{self, RpcApi}; #[derive(Debug, Clone, Copy, Deref, DerefMut, PartialEq, Eq, PartialOrd, Ord, Default, Serialize, Deserialize)] #[cfg_attr(feature = "zerocopy", derive(FromBytes, Immutable, IntoBytes, KnownLayout))] @@ -21,8 +18,9 @@ pub struct Height(u32); impl Height { const ZERO: Self = Height(0); - pub fn write(&self, path: &Path) -> Result<(), io::Error> { - fs::write(path, self.as_bytes()) + #[cfg(feature = "zerocopy")] + pub fn write(&self, path: &std::path::Path) -> Result<(), std::io::Error> { + std::fs::write(path, self.as_bytes()) } pub fn increment(&mut self) { @@ -166,16 +164,16 @@ impl From for bitcoin::locktime::absolute::Height { } #[cfg(feature = "zerocopy")] -impl TryFrom<&Path> for Height { - type Error = Error; - fn try_from(value: &Path) -> Result { - Ok(Self::read_from_bytes(fs::read(value)?.as_slice())?.to_owned()) +impl TryFrom<&std::path::Path> for Height { + type Error = crate::Error; + fn try_from(value: &std::path::Path) -> Result { + Ok(Self::read_from_bytes(std::fs::read(value)?.as_slice())?.to_owned()) } } #[cfg(feature = "fjall")] impl TryFrom for Height { - type Error = Error; + type Error = crate::Error; fn try_from(value: fjall::Slice) -> Result { Ok(Self::read_from_bytes(&value)?) } diff --git a/iterator/src/lib.rs b/iterator/src/lib.rs index 7ebcb5faf..c6811ffc4 100644 --- a/iterator/src/lib.rs +++ b/iterator/src/lib.rs @@ -38,7 +38,7 @@ use utils::*; pub const NUMBER_OF_UNSAFE_BLOCKS: usize = 1000; const MAGIC_BYTES: [u8; 4] = [249, 190, 180, 217]; -const BOUND_CAP: usize = 210; +const BOUND_CAP: usize = 100; /// /// Returns a crossbeam channel receiver that receives `(usize, Block, BlockHash)` tuples (with `usize` being the height) in sequential order. @@ -99,7 +99,7 @@ pub fn new( .iter() .filter(|(blk_index, _)| **blk_index >= starting_blk_index) .try_for_each(move |(blk_index, blk_path)| { - let blk_metadata = BlkMetadata::new(*blk_index, blk_path); + let blk_metadata = BlkMetadata::new(*blk_index, blk_path.as_path()); let blk_bytes = fs::read(blk_path).unwrap(); let blk_bytes_len = blk_bytes.len() as u64; @@ -224,8 +224,6 @@ pub fn new( tuple: BlkMetadataAndBlock| { let mut tuple = Some(tuple); - println!("{} {} {}", recent_hashes.len(), recent_chain.len(), future_blocks.len(),); - while let Some(tuple) = tuple.take().or_else(|| future_blocks.remove(prev_hash)) { let hash = tuple.block.block_hash(); diff --git a/iterator/src/main.rs b/iterator/src/main.rs index 09792ef49..4341a714d 100644 --- a/iterator/src/main.rs +++ b/iterator/src/main.rs @@ -14,7 +14,7 @@ fn main() { .unwrap(), )); - let start = Some(460_001_u32.into()); + let start = None; let end = None; biterator::new(data_dir, start, end, rpc) diff --git a/iterator/src/utils.rs b/iterator/src/utils.rs index 0894cd24d..0b73fc981 100644 --- a/iterator/src/utils.rs +++ b/iterator/src/utils.rs @@ -1,6 +1,6 @@ -use std::{fs, path::PathBuf, time::UNIX_EPOCH}; +use std::{fs, path::Path, time::UNIX_EPOCH}; -pub fn path_to_modified_time(path: &PathBuf) -> u64 { +pub fn path_to_modified_time(path: &Path) -> u64 { fs::metadata(path) .unwrap() .modified()