Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion hintfile/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ version = "0.1.0"
edition = "2021"

[dependencies]
bitcoin = { workspace = true }
kernel = { workspace = true }

[[bin]]
Expand Down
14 changes: 6 additions & 8 deletions hintfile/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@ use std::{
io::{self, Read, Write},
};

use bitcoin::{consensus, BlockHash, BlockHeight, BlockHeightInterval};
type BlockHash = [u8; 32];
type BlockHeight = u32;

pub fn write_compact_size<W: Write>(value: u64, writer: &mut W) -> Result<(), io::Error> {
match value {
Expand Down Expand Up @@ -54,20 +55,17 @@ impl Hints {
// Panics when expected data is not present, or the hintfile overflows the maximum blockheight
pub fn from_file<R: Read>(reader: &mut R) -> Self {
let mut map = BTreeMap::new();
let mut height = BlockHeight::from_u32(1);
let mut buf = [0; 32];
reader.read_exact(&mut buf).expect("empty file");
let assume_valid = consensus::deserialize::<BlockHash>(&buf).expect("empty file.");
let mut height = 1;
let mut assume_valid = [0; 32];
reader.read_exact(&mut assume_valid).expect("empty file");
while let Ok(count) = read_compact_size(reader) {
// panics on 32 bit machines
let mut offsets = Vec::with_capacity(count as usize);
for _ in 0..count {
offsets.push(read_compact_size(reader).expect("unexpected end of hintfile"));
}
map.insert(height, offsets);
height = height
.checked_add(BlockHeightInterval::from_u32(1))
.expect("hintfile absurdly large.")
height += 1;
}
Self { map, assume_valid }
}
Expand Down
5 changes: 3 additions & 2 deletions node/src/bin/ibd.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ use std::{
time::Instant,
};

use bitcoin::Network;
use bitcoin::{consensus, BlockHash, Network};
use hintfile::Hints;
use kernel::{ChainType, ChainstateManager, ChainstateManagerOptions, ContextBuilder};

Expand Down Expand Up @@ -33,7 +33,8 @@ fn main() {
elapsed_time(hintfile_start_time);
let block_file_path = Path::new(BLOCK_FILE_PATH);
std::fs::create_dir(block_file_path).expect("could not create block file directory");
let stop_hash = hints.stop_hash();
let stop_hash =
consensus::deserialize::<BlockHash>(&hints.stop_hash()).expect("stop hash is not valid");
tracing::info!("Assume valid hash: {stop_hash}");
tracing::info!("Finding peers with DNS");
let dns_start_time = Instant::now();
Expand Down
6 changes: 3 additions & 3 deletions node/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ use bitcoin::{
key::rand::{seq::SliceRandom, thread_rng},
script::ScriptExt,
transaction::TransactionExt,
BlockHash, BlockHeight, Network, OutPoint,
BlockHash, Network, OutPoint,
};
use hintfile::Hints;
use kernel::ChainstateManager;
Expand Down Expand Up @@ -202,10 +202,10 @@ pub fn get_blocks_for_range(
let kernal_hash: kernel::BlockHash = kernel::BlockHash {
hash: hash.to_byte_array(),
};
let height = chain
let block_index = chain
.block_index_by_hash(kernal_hash)
.expect("header is in best chain.");
let block_height = BlockHeight::from_u32(height.height().unsigned_abs());
let block_height = block_index.height().unsigned_abs();
let unspent_indexes: HashSet<u64> =
hints.get_block_offsets(block_height).into_iter().collect();
// tracing::info!("{task_id} -> {block_height}:{hash}");
Expand Down