address grumbles

This commit is contained in:
Robert Habermeier 2017-04-24 13:14:50 +02:00
parent 7ab92f0807
commit 6a5702f27c
6 changed files with 27 additions and 19 deletions

View File

@ -414,7 +414,7 @@ impl Client {
// Final Verification // Final Verification
if let Err(e) = self.verifier.verify_block_final(header, locked_block.block().header()) { if let Err(e) = self.verifier.verify_block_final(header, locked_block.block().header()) {
warn!(target: "client", "Stage 4 block verification failed for #{} ({})\nError: {:?}", header.number(), header.hash(), e); warn!(target: "client", "Stage 5 block verification failed for #{} ({})\nError: {:?}", header.number(), header.hash(), e);
return Err(()); return Err(());
} }

View File

@ -19,7 +19,7 @@
use error::Error; use error::Error;
use header::Header; use header::Header;
/// Verifier for all blocks within an epoch without accessing /// Verifier for all blocks within an epoch with self-contained state.
/// ///
/// See docs on `Engine` relating to proving functions for more details. /// See docs on `Engine` relating to proving functions for more details.
pub trait EpochVerifier: Sync { pub trait EpochVerifier: Sync {

View File

@ -62,6 +62,6 @@ impl Engine for NullEngine {
} }
fn snapshot_components(&self) -> Option<Box<::snapshot::SnapshotComponents>> { fn snapshot_components(&self) -> Option<Box<::snapshot::SnapshotComponents>> {
Some(Box::new(::snapshot::PowSnapshot)) Some(Box::new(::snapshot::PowSnapshot(10000)))
} }
} }

View File

@ -32,6 +32,10 @@ use rlp::{self, UntrustedRlp};
/// Parity tries to round block.gas_limit to multiple of this constant /// Parity tries to round block.gas_limit to multiple of this constant
pub const PARITY_GAS_LIMIT_DETERMINANT: U256 = U256([37, 0, 0, 0]); pub const PARITY_GAS_LIMIT_DETERMINANT: U256 = U256([37, 0, 0, 0]);
/// Number of blocks in an ethash snapshot.
// make dependent on difficulty incrment divisor?
const SNAPSHOT_BLOCKS: u64 = 30000;
/// Ethash params. /// Ethash params.
#[derive(Debug, PartialEq)] #[derive(Debug, PartialEq)]
pub struct EthashParams { pub struct EthashParams {
@ -401,7 +405,7 @@ impl Engine for Arc<Ethash> {
} }
fn snapshot_components(&self) -> Option<Box<::snapshot::SnapshotComponents>> { fn snapshot_components(&self) -> Option<Box<::snapshot::SnapshotComponents>> {
Some(Box::new(::snapshot::PowSnapshot)) Some(Box::new(::snapshot::PowSnapshot(SNAPSHOT_BLOCKS)))
} }
} }

View File

@ -36,9 +36,6 @@ use rlp::{RlpStream, UntrustedRlp};
/// A sink for produced chunks. /// A sink for produced chunks.
pub type ChunkSink<'a> = FnMut(&[u8]) -> io::Result<()> + 'a; pub type ChunkSink<'a> = FnMut(&[u8]) -> io::Result<()> + 'a;
// How many blocks to include in a snapshot, starting from the head of the chain.
const SNAPSHOT_BLOCKS: u64 = 30000;
/// Components necessary for snapshot creation and restoration. /// Components necessary for snapshot creation and restoration.
pub trait SnapshotComponents: Send { pub trait SnapshotComponents: Send {
/// Create secondary snapshot chunks; these corroborate the state data /// Create secondary snapshot chunks; these corroborate the state data
@ -92,7 +89,11 @@ pub trait Rebuilder: Send {
/// Snapshot creation and restoration for PoW chains. /// Snapshot creation and restoration for PoW chains.
/// This includes blocks from the head of the chain as a /// This includes blocks from the head of the chain as a
/// loose assurance that the chain is valid. /// loose assurance that the chain is valid.
pub struct PowSnapshot; ///
/// The field is the number of blocks from the head of the chain
/// to include in the snapshot.
#[derive(Clone, Copy, PartialEq)]
pub struct PowSnapshot(pub u64);
impl SnapshotComponents for PowSnapshot { impl SnapshotComponents for PowSnapshot {
fn chunk_all( fn chunk_all(
@ -108,7 +109,7 @@ impl SnapshotComponents for PowSnapshot {
current_hash: block_at, current_hash: block_at,
writer: chunk_sink, writer: chunk_sink,
preferred_size: preferred_size, preferred_size: preferred_size,
}.chunk_all() }.chunk_all(self.0)
} }
fn rebuilder( fn rebuilder(
@ -117,7 +118,7 @@ impl SnapshotComponents for PowSnapshot {
db: Arc<KeyValueDB>, db: Arc<KeyValueDB>,
manifest: &ManifestData, manifest: &ManifestData,
) -> Result<Box<Rebuilder>, ::error::Error> { ) -> Result<Box<Rebuilder>, ::error::Error> {
PowRebuilder::new(chain, db, manifest).map(|r| Box::new(r) as Box<_>) PowRebuilder::new(chain, db, manifest, self.0).map(|r| Box::new(r) as Box<_>)
} }
} }
@ -134,13 +135,13 @@ struct PowWorker<'a> {
impl<'a> PowWorker<'a> { impl<'a> PowWorker<'a> {
// Repeatedly fill the buffers and writes out chunks, moving backwards from starting block hash. // Repeatedly fill the buffers and writes out chunks, moving backwards from starting block hash.
// Loops until we reach the first desired block, and writes out the remainder. // Loops until we reach the first desired block, and writes out the remainder.
fn chunk_all(&mut self) -> Result<(), Error> { fn chunk_all(&mut self, snapshot_blocks: u64) -> Result<(), Error> {
let mut loaded_size = 0; let mut loaded_size = 0;
let mut last = self.current_hash; let mut last = self.current_hash;
let genesis_hash = self.chain.genesis_hash(); let genesis_hash = self.chain.genesis_hash();
for _ in 0..SNAPSHOT_BLOCKS { for _ in 0..snapshot_blocks {
if self.current_hash == genesis_hash { break } if self.current_hash == genesis_hash { break }
let (block, receipts) = self.chain.block(&self.current_hash) let (block, receipts) = self.chain.block(&self.current_hash)
@ -229,11 +230,12 @@ pub struct PowRebuilder {
best_hash: H256, best_hash: H256,
best_root: H256, best_root: H256,
fed_blocks: u64, fed_blocks: u64,
snapshot_blocks: u64,
} }
impl PowRebuilder { impl PowRebuilder {
/// Create a new PowRebuilder. /// Create a new PowRebuilder.
fn new(chain: BlockChain, db: Arc<KeyValueDB>, manifest: &ManifestData) -> Result<Self, ::error::Error> { fn new(chain: BlockChain, db: Arc<KeyValueDB>, manifest: &ManifestData, snapshot_blocks: u64) -> Result<Self, ::error::Error> {
Ok(PowRebuilder { Ok(PowRebuilder {
chain: chain, chain: chain,
db: db, db: db,
@ -243,6 +245,7 @@ impl PowRebuilder {
best_hash: manifest.block_hash, best_hash: manifest.block_hash,
best_root: manifest.state_root, best_root: manifest.state_root,
fed_blocks: 0, fed_blocks: 0,
snapshot_blocks: snapshot_blocks,
}) })
} }
} }
@ -263,8 +266,8 @@ impl Rebuilder for PowRebuilder {
trace!(target: "snapshot", "restoring block chunk with {} blocks.", item_count - 3); trace!(target: "snapshot", "restoring block chunk with {} blocks.", item_count - 3);
if self.fed_blocks + num_blocks > SNAPSHOT_BLOCKS { if self.fed_blocks + num_blocks > self.snapshot_blocks {
return Err(Error::TooManyBlocks(SNAPSHOT_BLOCKS, self.fed_blocks).into()) return Err(Error::TooManyBlocks(self.snapshot_blocks, self.fed_blocks).into())
} }
// todo: assert here that these values are consistent with chunks being in order. // todo: assert here that these values are consistent with chunks being in order.

View File

@ -30,11 +30,12 @@ use util::kvdb::{self, KeyValueDB, DBTransaction};
use std::sync::Arc; use std::sync::Arc;
use std::sync::atomic::AtomicBool; use std::sync::atomic::AtomicBool;
const SNAPSHOT_MODE: ::snapshot::PowSnapshot = ::snapshot::PowSnapshot(30000);
fn chunk_and_restore(amount: u64) { fn chunk_and_restore(amount: u64) {
let mut canon_chain = ChainGenerator::default(); let mut canon_chain = ChainGenerator::default();
let mut finalizer = BlockFinalizer::default(); let mut finalizer = BlockFinalizer::default();
let genesis = canon_chain.generate(&mut finalizer).unwrap(); let genesis = canon_chain.generate(&mut finalizer).unwrap();
let components = ::snapshot::PowSnapshot;
let engine = Arc::new(::engines::NullEngine::default()); let engine = Arc::new(::engines::NullEngine::default());
let new_path = RandomTempPath::create_dir(); let new_path = RandomTempPath::create_dir();
@ -59,7 +60,7 @@ fn chunk_and_restore(amount: u64) {
// snapshot it. // snapshot it.
let writer = Mutex::new(PackedWriter::new(&snapshot_path).unwrap()); let writer = Mutex::new(PackedWriter::new(&snapshot_path).unwrap());
let block_hashes = chunk_secondary( let block_hashes = chunk_secondary(
Box::new(::snapshot::PowSnapshot), Box::new(SNAPSHOT_MODE),
&bc, &bc,
best_hash, best_hash,
&writer, &writer,
@ -80,7 +81,7 @@ fn chunk_and_restore(amount: u64) {
// restore it. // restore it.
let new_db = Arc::new(kvdb::in_memory(::db::NUM_COLUMNS.unwrap_or(0))); let new_db = Arc::new(kvdb::in_memory(::db::NUM_COLUMNS.unwrap_or(0)));
let new_chain = BlockChain::new(Default::default(), &genesis, new_db.clone()); let new_chain = BlockChain::new(Default::default(), &genesis, new_db.clone());
let mut rebuilder = components.rebuilder(new_chain, new_db.clone(), &manifest).unwrap(); let mut rebuilder = SNAPSHOT_MODE.rebuilder(new_chain, new_db.clone(), &manifest).unwrap();
let reader = PackedReader::new(&snapshot_path).unwrap().unwrap(); let reader = PackedReader::new(&snapshot_path).unwrap().unwrap();
let flag = AtomicBool::new(true); let flag = AtomicBool::new(true);
@ -138,7 +139,7 @@ fn checks_flag() {
block_hash: H256::default(), block_hash: H256::default(),
}; };
let mut rebuilder = ::snapshot::PowSnapshot.rebuilder(chain, db.clone(), &manifest).unwrap(); let mut rebuilder = SNAPSHOT_MODE.rebuilder(chain, db.clone(), &manifest).unwrap();
match rebuilder.feed(&chunk, engine.as_ref(), &AtomicBool::new(false)) { match rebuilder.feed(&chunk, engine.as_ref(), &AtomicBool::new(false)) {
Err(Error::Snapshot(SnapshotError::RestorationAborted)) => {} Err(Error::Snapshot(SnapshotError::RestorationAborted)) => {}