Skip to content
This repository has been archived by the owner on Nov 6, 2020. It is now read-only.

Commit

Permalink
verify chunk hashes in cli restore (#3241)
Browse files Browse the repository at this point in the history
  • Loading branch information
rphmeier authored and arkpar committed Nov 7, 2016
1 parent 6ab6c07 commit d18bb9d
Showing 1 changed file with 13 additions and 0 deletions.
13 changes: 13 additions & 0 deletions parity/snapshot.rs
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,8 @@ pub struct SnapshotCommand {
// helper for reading chunks from arbitrary reader and feeding them into the
// service.
fn restore_using<R: SnapshotReader>(snapshot: Arc<SnapshotService>, reader: &R, recover: bool) -> Result<(), String> {
use util::sha3::Hashable;

let manifest = reader.manifest();

info!("Restoring to block #{} (0x{:?})", manifest.block_number, manifest.block_hash);
Expand Down Expand Up @@ -93,6 +95,12 @@ fn restore_using<R: SnapshotReader>(snapshot: Arc<SnapshotService>, reader: &R,

let chunk = try!(reader.chunk(state_hash)
.map_err(|e| format!("Encountered error while reading chunk {:?}: {}", state_hash, e)));

let hash = chunk.sha3();
if hash != state_hash {
return Err(format!("Mismatched chunk hash. Expected {:?}, got {:?}", state_hash, hash));
}

snapshot.feed_state_chunk(state_hash, &chunk);
}

Expand All @@ -104,6 +112,11 @@ fn restore_using<R: SnapshotReader>(snapshot: Arc<SnapshotService>, reader: &R,

let chunk = try!(reader.chunk(block_hash)
.map_err(|e| format!("Encountered error while reading chunk {:?}: {}", block_hash, e)));

let hash = chunk.sha3();
if hash != block_hash {
return Err(format!("Mismatched chunk hash. Expected {:?}, got {:?}", block_hash, hash));
}
snapshot.feed_block_chunk(block_hash, &chunk);
}

Expand Down

0 comments on commit d18bb9d

Please sign in to comment.