verify chunk hashes in cli restore (#3241)
This commit is contained in:
parent
6ab6c0709d
commit
d18bb9d152
@ -66,6 +66,8 @@ pub struct SnapshotCommand {
|
|||||||
// helper for reading chunks from arbitrary reader and feeding them into the
|
// helper for reading chunks from arbitrary reader and feeding them into the
|
||||||
// service.
|
// service.
|
||||||
fn restore_using<R: SnapshotReader>(snapshot: Arc<SnapshotService>, reader: &R, recover: bool) -> Result<(), String> {
|
fn restore_using<R: SnapshotReader>(snapshot: Arc<SnapshotService>, reader: &R, recover: bool) -> Result<(), String> {
|
||||||
|
use util::sha3::Hashable;
|
||||||
|
|
||||||
let manifest = reader.manifest();
|
let manifest = reader.manifest();
|
||||||
|
|
||||||
info!("Restoring to block #{} (0x{:?})", manifest.block_number, manifest.block_hash);
|
info!("Restoring to block #{} (0x{:?})", manifest.block_number, manifest.block_hash);
|
||||||
@ -93,6 +95,12 @@ fn restore_using<R: SnapshotReader>(snapshot: Arc<SnapshotService>, reader: &R,
|
|||||||
|
|
||||||
let chunk = try!(reader.chunk(state_hash)
|
let chunk = try!(reader.chunk(state_hash)
|
||||||
.map_err(|e| format!("Encountered error while reading chunk {:?}: {}", state_hash, e)));
|
.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);
|
snapshot.feed_state_chunk(state_hash, &chunk);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -104,6 +112,11 @@ fn restore_using<R: SnapshotReader>(snapshot: Arc<SnapshotService>, reader: &R,
|
|||||||
|
|
||||||
let chunk = try!(reader.chunk(block_hash)
|
let chunk = try!(reader.chunk(block_hash)
|
||||||
.map_err(|e| format!("Encountered error while reading chunk {:?}: {}", block_hash, e)));
|
.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);
|
snapshot.feed_block_chunk(block_hash, &chunk);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user