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
8 changes: 6 additions & 2 deletions hintfile/src/bin/construct.rs
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,12 @@ fn main() {
let chainman = ChainstateManager::new(options).unwrap();
println!("Chain state initialized");
// Writing the chain tip allows the client to know where to stop
let tip = chainman.block_index_tip().block_hash().hash;
file.write_all(&tip).expect("file cannot be written to");
let tip = chainman.block_index_tip();
let stop_height = (tip.height() as u32).to_le_bytes();
file.write_all(&stop_height)
.expect("file cannot be written to");
file.write_all(&tip.block_hash().hash)
.expect("file cannot be written to");

let genesis = chainman.block_index_genesis();
let mut current = chainman.next_block_index(genesis).unwrap();
Expand Down
14 changes: 13 additions & 1 deletion hintfile/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ pub fn read_compact_size<R: Read>(reader: &mut R) -> Result<u64, io::Error> {
pub struct Hints {
map: BTreeMap<BlockHeight, Vec<u64>>,
assume_valid: BlockHash,
stop_height: BlockHeight,
}

impl Hints {
Expand All @@ -56,6 +57,8 @@ impl Hints {
pub fn from_file<R: Read>(reader: &mut R) -> Self {
let mut map = BTreeMap::new();
let mut height = 1;
let mut stop_height = [0; 4];
reader.read_exact(&mut stop_height).expect("empty file");
let mut assume_valid = [0; 32];
reader.read_exact(&mut assume_valid).expect("empty file");
while let Ok(count) = read_compact_size(reader) {
Expand All @@ -67,14 +70,23 @@ impl Hints {
map.insert(height, offsets);
height += 1;
}
Self { map, assume_valid }
Self {
map,
assume_valid,
stop_height: BlockHeight::from_le_bytes(stop_height),
}
}

/// Get the last hash encoded in the hintfile.
pub fn stop_hash(&self) -> BlockHash {
self.assume_valid
}

/// Get the stop height of the hint file.
pub fn stop_height(&self) -> BlockHeight {
self.stop_height
}

/// # Panics
///
/// If there are no offset present at that height, aka an overflow, or the entry has already
Expand Down
1 change: 1 addition & 0 deletions node/src/bin/ibd.rs
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ fn main() {
let mut hintfile = File::open(hint_path).expect("invalid hintfile path");
let hints = Arc::new(Hints::from_file(&mut hintfile));
elapsed_time(hintfile_start_time);
tracing::info!("Syncing to height {}", hints.stop_height());
let block_file_path = blocks_dir.map(PathBuf::from);
if let Some(block_file_path) = block_file_path.as_ref() {
std::fs::create_dir(block_file_path).expect("could not create block file directory");
Expand Down