diff --git a/parity/snapshot.rs b/parity/snapshot.rs index 09a180a6743..872e4ba5e0e 100644 --- a/parity/snapshot.rs +++ b/parity/snapshot.rs @@ -66,6 +66,8 @@ pub struct SnapshotCommand { // helper for reading chunks from arbitrary reader and feeding them into the // service. fn restore_using(snapshot: Arc, 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); @@ -93,6 +95,12 @@ fn restore_using(snapshot: Arc, 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); } @@ -104,6 +112,11 @@ fn restore_using(snapshot: Arc, 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); }