Skip to content
This repository has been archived by the owner on Oct 9, 2022. It is now read-only.

Commit

Permalink
add check for to param
Browse files Browse the repository at this point in the history
  • Loading branch information
hackfisher committed Nov 2, 2020
1 parent d8be6ad commit 0b803d0
Showing 1 changed file with 9 additions and 6 deletions.
15 changes: 9 additions & 6 deletions src/cmd/import.rs
Original file line number Diff line number Diff line change
Expand Up @@ -49,30 +49,33 @@ fn geth(path: String, to: i32) -> Result<(), Error> {
last_leaf + 1
};

if from as i32 >= to {
error!(
"The to position of mmr is {}, can not import mmr from {}, from must be less than to",
to, from
);
}

// Get hashes
info!("Importing ethereum headers from {}...", &path);
let hashes = ethereum::import(&path, from as i32, to);
let hashes_vec = hashes.split(',').collect::<Vec<&str>>();

// Check empty
info!("Imported {} hashes", hashes_vec.len());
info!("Imported {} hashes from ethereum node", hashes_vec.len());
if hashes_vec[0].is_empty() {
error!("Importing hashes from {} failed", path);
return Ok(());
}

// Generate mmr store
info!("Got {} header hashes", hashes_vec.len());


// Build mmr
info!("mmr_size: {}, from: {}", mmr_size, from);
let mut mmr = MMR::<_, MergeHash, _>::new(mmr_size, &shared.store);

let mut ptr = from;
for hash in &hashes_vec {
if ptr % 1000 == 0 {
trace!("Calculating {:?}/{}", ptr as usize, to);
trace!("Start to push hash into mmr for block {:?}/{}", ptr as usize, to);
}

ptr += 1;
Expand Down

0 comments on commit 0b803d0

Please sign in to comment.