Generalize engine trait (#6591)
* move common forks and parameters to common params * port specs over to new format * fix RPC tests * parity-machine skeleton * remove block type * extract out ethereum-specific methods into EthereumMachine * beginning to integrate Machine into engines. dealing with stale transitions in Ethash * initial porting to machine * move block reward back into engine * abstract block reward logic * move last hash and DAO HF logic into machine * begin making engine function parameters generic * abstract epoch verifier and ethash block reward logic * instantiate special ethereummachine for ethash in spec * optional full verification in verify_block_family * re-instate tx_filter in a way that works for all engines * fix warnings * fix most tests, further generalize engine trait * uncomment nullengine, get ethcore tests compiling * fix warnings * update a bunch of specs * re-enable engine signer, validator set, and transition handler * migrate basic_authority engine * move last hashes into executedblock * port tendermint * make all ethcore tests pass * json-tests compilation * fix RPC tests: change in gas limit for new block changed PoW hash * fix minor grumbles * validate chainspecs * fix broken import * fix transaction verification for pre-homestead
This commit is contained in:
committed by
Gav Wood
parent
d8af9f4e7b
commit
bc167a211b
@@ -25,7 +25,8 @@ use std::sync::atomic::{AtomicBool, Ordering};
|
||||
use std::sync::Arc;
|
||||
|
||||
use blockchain::{BlockChain, BlockProvider};
|
||||
use engines::{Engine, EpochVerifier, EpochTransition};
|
||||
use engines::{EthEngine, EpochVerifier, EpochTransition};
|
||||
use machine::EthereumMachine;
|
||||
use ids::BlockId;
|
||||
use header::Header;
|
||||
use receipt::Receipt;
|
||||
@@ -168,7 +169,7 @@ struct ChunkRebuilder {
|
||||
// and epoch data from last blocks in chunks.
|
||||
// verification for these will be done at the end.
|
||||
unverified_firsts: Vec<(Header, Bytes, H256)>,
|
||||
last_epochs: Vec<(Header, Box<EpochVerifier>)>,
|
||||
last_epochs: Vec<(Header, Box<EpochVerifier<EthereumMachine>>)>,
|
||||
}
|
||||
|
||||
// verified data.
|
||||
@@ -180,9 +181,9 @@ struct Verified {
|
||||
impl ChunkRebuilder {
|
||||
fn verify_transition(
|
||||
&mut self,
|
||||
last_verifier: &mut Option<Box<EpochVerifier>>,
|
||||
last_verifier: &mut Option<Box<EpochVerifier<EthereumMachine>>>,
|
||||
transition_rlp: UntrustedRlp,
|
||||
engine: &Engine,
|
||||
engine: &EthEngine,
|
||||
) -> Result<Verified, ::error::Error> {
|
||||
use engines::ConstructedVerifier;
|
||||
|
||||
@@ -238,7 +239,7 @@ impl Rebuilder for ChunkRebuilder {
|
||||
fn feed(
|
||||
&mut self,
|
||||
chunk: &[u8],
|
||||
engine: &Engine,
|
||||
engine: &EthEngine,
|
||||
abort_flag: &AtomicBool,
|
||||
) -> Result<(), ::error::Error> {
|
||||
let rlp = UntrustedRlp::new(chunk);
|
||||
@@ -346,7 +347,7 @@ impl Rebuilder for ChunkRebuilder {
|
||||
Ok(())
|
||||
}
|
||||
|
||||
fn finalize(&mut self, _engine: &Engine) -> Result<(), ::error::Error> {
|
||||
fn finalize(&mut self, _engine: &EthEngine) -> Result<(), ::error::Error> {
|
||||
if !self.had_genesis {
|
||||
return Err(Error::WrongChunkFormat("No genesis transition included.".into()).into());
|
||||
}
|
||||
|
||||
@@ -21,7 +21,7 @@ use std::sync::atomic::AtomicBool;
|
||||
use std::sync::Arc;
|
||||
|
||||
use blockchain::BlockChain;
|
||||
use engines::Engine;
|
||||
use engines::EthEngine;
|
||||
use snapshot::{Error, ManifestData};
|
||||
|
||||
use bigint::hash::H256;
|
||||
@@ -84,7 +84,7 @@ pub trait Rebuilder: Send {
|
||||
fn feed(
|
||||
&mut self,
|
||||
chunk: &[u8],
|
||||
engine: &Engine,
|
||||
engine: &EthEngine,
|
||||
abort_flag: &AtomicBool,
|
||||
) -> Result<(), ::error::Error>;
|
||||
|
||||
@@ -93,5 +93,5 @@ pub trait Rebuilder: Send {
|
||||
///
|
||||
/// This should apply the necessary "glue" between chunks,
|
||||
/// and verify against the restored state.
|
||||
fn finalize(&mut self, engine: &Engine) -> Result<(), ::error::Error>;
|
||||
fn finalize(&mut self, engine: &EthEngine) -> Result<(), ::error::Error>;
|
||||
}
|
||||
|
||||
@@ -27,7 +27,7 @@ use std::sync::atomic::{AtomicBool, Ordering};
|
||||
use std::sync::Arc;
|
||||
|
||||
use blockchain::{BlockChain, BlockProvider};
|
||||
use engines::Engine;
|
||||
use engines::EthEngine;
|
||||
use snapshot::{Error, ManifestData};
|
||||
use snapshot::block::AbridgedBlock;
|
||||
use bigint::hash::H256;
|
||||
@@ -219,7 +219,7 @@ impl PowRebuilder {
|
||||
impl Rebuilder for PowRebuilder {
|
||||
/// Feed the rebuilder an uncompressed block chunk.
|
||||
/// Returns the number of blocks fed or any errors.
|
||||
fn feed(&mut self, chunk: &[u8], engine: &Engine, abort_flag: &AtomicBool) -> Result<(), ::error::Error> {
|
||||
fn feed(&mut self, chunk: &[u8], engine: &EthEngine, abort_flag: &AtomicBool) -> Result<(), ::error::Error> {
|
||||
use basic_types::Seal::With;
|
||||
use views::BlockView;
|
||||
use snapshot::verify_old_block;
|
||||
@@ -271,7 +271,6 @@ impl Rebuilder for PowRebuilder {
|
||||
&block.header,
|
||||
engine,
|
||||
&self.chain,
|
||||
Some(&block_bytes),
|
||||
is_best
|
||||
)?;
|
||||
|
||||
@@ -298,7 +297,7 @@ impl Rebuilder for PowRebuilder {
|
||||
}
|
||||
|
||||
/// Glue together any disconnected chunks and check that the chain is complete.
|
||||
fn finalize(&mut self, _: &Engine) -> Result<(), ::error::Error> {
|
||||
fn finalize(&mut self, _: &EthEngine) -> Result<(), ::error::Error> {
|
||||
let mut batch = self.db.transaction();
|
||||
|
||||
for (first_num, first_hash) in self.disconnected.drain(..) {
|
||||
|
||||
@@ -26,7 +26,7 @@ use hash::{keccak, KECCAK_NULL_RLP, KECCAK_EMPTY};
|
||||
|
||||
use account_db::{AccountDB, AccountDBMut};
|
||||
use blockchain::{BlockChain, BlockProvider};
|
||||
use engines::Engine;
|
||||
use engines::EthEngine;
|
||||
use header::Header;
|
||||
use ids::BlockId;
|
||||
|
||||
@@ -126,7 +126,7 @@ impl Progress {
|
||||
}
|
||||
/// Take a snapshot using the given blockchain, starting block hash, and database, writing into the given writer.
|
||||
pub fn take_snapshot<W: SnapshotWriter + Send>(
|
||||
engine: &Engine,
|
||||
engine: &EthEngine,
|
||||
chain: &BlockChain,
|
||||
block_at: H256,
|
||||
state_db: &HashDB,
|
||||
@@ -484,13 +484,13 @@ const POW_VERIFY_RATE: f32 = 0.02;
|
||||
/// Verify an old block with the given header, engine, blockchain, body. If `always` is set, it will perform
|
||||
/// the fullest verification possible. If not, it will take a random sample to determine whether it will
|
||||
/// do heavy or light verification.
|
||||
pub fn verify_old_block(rng: &mut OsRng, header: &Header, engine: &Engine, chain: &BlockChain, body: Option<&[u8]>, always: bool) -> Result<(), ::error::Error> {
|
||||
engine.verify_block_basic(header, body)?;
|
||||
pub fn verify_old_block(rng: &mut OsRng, header: &Header, engine: &EthEngine, chain: &BlockChain, always: bool) -> Result<(), ::error::Error> {
|
||||
engine.verify_block_basic(header)?;
|
||||
|
||||
if always || rng.gen::<f32>() <= POW_VERIFY_RATE {
|
||||
engine.verify_block_unordered(header, body)?;
|
||||
engine.verify_block_unordered(header)?;
|
||||
match chain.block_header(header.parent_hash()) {
|
||||
Some(parent) => engine.verify_block_family(header, &parent, body),
|
||||
Some(parent) => engine.verify_block_family(header, &parent),
|
||||
None => Ok(()),
|
||||
}
|
||||
} else {
|
||||
|
||||
@@ -28,7 +28,7 @@ use super::io::{SnapshotReader, LooseReader, SnapshotWriter, LooseWriter};
|
||||
|
||||
use blockchain::BlockChain;
|
||||
use client::{BlockChainClient, Client};
|
||||
use engines::Engine;
|
||||
use engines::EthEngine;
|
||||
use error::Error;
|
||||
use ids::BlockId;
|
||||
use service::ClientIoMessage;
|
||||
@@ -91,7 +91,7 @@ struct RestorationParams<'a> {
|
||||
writer: Option<LooseWriter>, // writer for recovered snapshot.
|
||||
genesis: &'a [u8], // genesis block of the chain.
|
||||
guard: Guard, // guard for the restoration directory.
|
||||
engine: &'a Engine,
|
||||
engine: &'a EthEngine,
|
||||
}
|
||||
|
||||
impl Restoration {
|
||||
@@ -145,7 +145,7 @@ impl Restoration {
|
||||
}
|
||||
|
||||
// feeds a block chunk
|
||||
fn feed_blocks(&mut self, hash: H256, chunk: &[u8], engine: &Engine, flag: &AtomicBool) -> Result<(), Error> {
|
||||
fn feed_blocks(&mut self, hash: H256, chunk: &[u8], engine: &EthEngine, flag: &AtomicBool) -> Result<(), Error> {
|
||||
if self.block_chunks_left.contains(&hash) {
|
||||
let len = snappy::decompress_into(chunk, &mut self.snappy_buffer)?;
|
||||
|
||||
@@ -161,7 +161,7 @@ impl Restoration {
|
||||
}
|
||||
|
||||
// finish up restoration.
|
||||
fn finalize(mut self, engine: &Engine) -> Result<(), Error> {
|
||||
fn finalize(mut self, engine: &EthEngine) -> Result<(), Error> {
|
||||
use trie::TrieError;
|
||||
|
||||
if !self.is_done() { return Ok(()) }
|
||||
@@ -199,7 +199,7 @@ pub type Channel = IoChannel<ClientIoMessage>;
|
||||
/// Snapshot service parameters.
|
||||
pub struct ServiceParams {
|
||||
/// The consensus engine this is built on.
|
||||
pub engine: Arc<Engine>,
|
||||
pub engine: Arc<EthEngine>,
|
||||
/// The chain's genesis block.
|
||||
pub genesis_block: Bytes,
|
||||
/// Database configuration options.
|
||||
@@ -225,7 +225,7 @@ pub struct Service {
|
||||
pruning: Algorithm,
|
||||
status: Mutex<RestorationStatus>,
|
||||
reader: RwLock<Option<LooseReader>>,
|
||||
engine: Arc<Engine>,
|
||||
engine: Arc<EthEngine>,
|
||||
genesis_block: Bytes,
|
||||
state_chunks: AtomicUsize,
|
||||
block_chunks: AtomicUsize,
|
||||
|
||||
@@ -24,7 +24,7 @@ use account_db::AccountDBMut;
|
||||
use basic_account::BasicAccount;
|
||||
use blockchain::BlockChain;
|
||||
use client::{BlockChainClient, Client};
|
||||
use engines::Engine;
|
||||
use engines::EthEngine;
|
||||
use snapshot::{StateRebuilder};
|
||||
use snapshot::io::{SnapshotReader, PackedWriter, PackedReader};
|
||||
|
||||
@@ -160,7 +160,7 @@ pub fn snap(client: &Client) -> GuardedTempResult<Box<SnapshotReader>> {
|
||||
/// write into the given database.
|
||||
pub fn restore(
|
||||
db: Arc<KeyValueDB>,
|
||||
engine: &Engine,
|
||||
engine: &EthEngine,
|
||||
reader: &SnapshotReader,
|
||||
genesis: &[u8],
|
||||
) -> Result<(), ::error::Error> {
|
||||
|
||||
@@ -38,7 +38,7 @@ fn chunk_and_restore(amount: u64) {
|
||||
let mut finalizer = BlockFinalizer::default();
|
||||
let genesis = canon_chain.generate(&mut finalizer).unwrap();
|
||||
|
||||
let engine = Arc::new(::engines::NullEngine::default());
|
||||
let engine = ::spec::Spec::new_test().engine;
|
||||
let new_path = RandomTempPath::create_dir();
|
||||
let mut snapshot_path = new_path.as_path().to_owned();
|
||||
snapshot_path.push("SNAP");
|
||||
@@ -128,7 +128,7 @@ fn checks_flag() {
|
||||
let chunk = stream.out();
|
||||
|
||||
let db = Arc::new(kvdb::in_memory(::db::NUM_COLUMNS.unwrap_or(0)));
|
||||
let engine = Arc::new(::engines::NullEngine::default());
|
||||
let engine = ::spec::Spec::new_test().engine;
|
||||
let chain = BlockChain::new(Default::default(), &genesis, db.clone());
|
||||
|
||||
let manifest = ::snapshot::ManifestData {
|
||||
|
||||
Reference in New Issue
Block a user