Extract the Engine trait (#10958)
* Add client-traits crate Move the BlockInfo trait to new crate * New crate `machine` Contains code extracted from ethcore that defines `Machine`, `Externalities` and other execution related code. * Use new machine and client-traits crates in ethcore * Use new crates machine and client-traits instead of ethcore where appropriate * Fix tests * Don't re-export so many types from ethcore::client * Fixing more fallout from removing re-export * fix test * More fallout from not re-exporting types * Add some docs * cleanup * import the macro edition style * Tweak docs * Add missing import * remove unused ethabi_derive imports * Use latest ethabi-contract * Move many traits from ethcore/client/traits to client-traits crate Initial version of extracted Engine trait * Move snapshot related traits to the engine crate (eew) * Move a few snapshot related types to common_types Cleanup Executed as exported from machine crate * fix warning * Gradually introduce new engine crate: snapshot * ethcore typechecks with new engine crate * Sort out types outside ethcore * Add an EpochVerifier to ethash and use that in Engine.epoch_verifier() Cleanup * Document pub members * Sort out tests Sort out default impls for EpochVerifier * Add test-helpers feature and move EngineSigner impl to the right place * Sort out tests * Sort out tests and refactor verification types * Fix missing traits * More missing traits Fix Histogram * Fix tests and cleanup * cleanup * Put back needed logger import * Don't rexport common_types from ethcore/src/client Don't export ethcore::client::* * Remove files no longer used Use types from the engine crate Explicit exports from engine::engine * Get rid of itertools * Move a few more traits from ethcore to client-traits: BlockChainReset, ScheduleInfo, StateClient * Move ProvingBlockChainClient to client-traits * Don't re-export ForkChoice and Transition from ethcore * Address grumbles: sort imports, remove commented out code * Fix merge resolution error * merge failure
This commit is contained in:
@@ -32,7 +32,8 @@ use futures::sync::mpsc as futures_mpsc;
|
||||
use futures::Stream;
|
||||
use io::{TimerToken};
|
||||
use ethkey::Secret;
|
||||
use ethcore::client::{BlockChainClient, ChainNotify, NewBlocks, ChainMessageType};
|
||||
use ethcore::client::{ChainNotify, NewBlocks, ChainMessageType};
|
||||
use client_traits::BlockChainClient;
|
||||
use ethcore::snapshot::SnapshotService;
|
||||
use types::BlockNumber;
|
||||
use sync_io::NetSyncIo;
|
||||
|
||||
@@ -22,9 +22,11 @@ use triehash_ethereum::ordered_trie_root;
|
||||
use bytes::Bytes;
|
||||
use rlp::{Rlp, RlpStream, DecoderError};
|
||||
use network;
|
||||
use ethcore::verification::queue::kind::blocks::Unverified;
|
||||
use types::transaction::UnverifiedTransaction;
|
||||
use types::header::Header as BlockHeader;
|
||||
use types::{
|
||||
transaction::UnverifiedTransaction,
|
||||
header::Header as BlockHeader,
|
||||
verification::Unverified,
|
||||
};
|
||||
|
||||
malloc_size_of_is_0!(HeaderId);
|
||||
|
||||
@@ -541,12 +543,13 @@ impl BlockCollection {
|
||||
#[cfg(test)]
|
||||
mod test {
|
||||
use super::{BlockCollection, SyncHeader};
|
||||
use ethcore::client::{TestBlockChainClient, EachBlockWith, BlockChainClient};
|
||||
use client_traits::BlockChainClient;
|
||||
use ethcore::client::{TestBlockChainClient, EachBlockWith};
|
||||
use types::{
|
||||
ids::BlockId,
|
||||
BlockNumber
|
||||
BlockNumber,
|
||||
verification::Unverified,
|
||||
};
|
||||
use ethcore::verification::queue::kind::blocks::Unverified;
|
||||
use rlp::*;
|
||||
|
||||
fn is_empty(bc: &BlockCollection) -> bool {
|
||||
|
||||
@@ -19,7 +19,6 @@ use block_sync::{BlockDownloaderImportError as DownloaderImportError, DownloadAc
|
||||
use bytes::Bytes;
|
||||
use enum_primitive::FromPrimitive;
|
||||
use ethcore::snapshot::{ManifestData, RestorationStatus};
|
||||
use ethcore::verification::queue::kind::blocks::Unverified;
|
||||
use ethereum_types::{H256, U256};
|
||||
use hash::keccak;
|
||||
use network::PeerId;
|
||||
@@ -34,6 +33,7 @@ use types::{
|
||||
block_status::BlockStatus,
|
||||
ids::BlockId,
|
||||
errors::{EthcoreError, ImportError, BlockError},
|
||||
verification::Unverified,
|
||||
};
|
||||
|
||||
use super::sync_packet::{PacketInfo, SyncPacket};
|
||||
@@ -742,9 +742,10 @@ impl SyncHandler {
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use ethcore::client::{ChainInfo, EachBlockWith, TestBlockChainClient};
|
||||
use client_traits::ChainInfo;
|
||||
use ethcore::client::{EachBlockWith, TestBlockChainClient};
|
||||
use parking_lot::RwLock;
|
||||
use rlp::{Rlp};
|
||||
use rlp::Rlp;
|
||||
use std::collections::{VecDeque};
|
||||
use tests::helpers::{TestIo};
|
||||
use tests::snapshot::TestSnapshotService;
|
||||
|
||||
@@ -108,7 +108,7 @@ use bytes::Bytes;
|
||||
use rlp::{RlpStream, DecoderError};
|
||||
use network::{self, PeerId, PacketId};
|
||||
use network::client_version::ClientVersion;
|
||||
use ethcore::client::{BlockChainClient, BlockStatus, BlockChainInfo, BlockQueueInfo};
|
||||
use client_traits::BlockChainClient;
|
||||
use ethcore::snapshot::RestorationStatus;
|
||||
use sync_io::SyncIo;
|
||||
use super::{WarpSync, SyncConfig};
|
||||
@@ -121,7 +121,10 @@ use transactions_stats::{TransactionsStats, Stats as TransactionStats};
|
||||
use types::{
|
||||
BlockNumber,
|
||||
ids::BlockId,
|
||||
transaction::UnverifiedTransaction
|
||||
transaction::UnverifiedTransaction,
|
||||
verification::VerificationQueueInfo as BlockQueueInfo,
|
||||
blockchain_info::BlockChainInfo,
|
||||
block_status::BlockStatus,
|
||||
};
|
||||
|
||||
use self::handler::SyncHandler;
|
||||
@@ -1373,8 +1376,8 @@ pub mod tests {
|
||||
use super::*;
|
||||
use ::SyncConfig;
|
||||
use super::{PeerInfo, PeerAsking};
|
||||
use ethcore::client::{BlockChainClient, EachBlockWith, TestBlockChainClient, ChainInfo};
|
||||
use client_traits::BlockInfo;
|
||||
use ethcore::client::{EachBlockWith, TestBlockChainClient};
|
||||
use client_traits::{BlockInfo, BlockChainClient, ChainInfo};
|
||||
use ethcore::miner::{MinerService, PendingOrdering};
|
||||
use types::header::Header;
|
||||
|
||||
|
||||
@@ -335,8 +335,8 @@ impl SyncPropagator {
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use ethcore::client::{ChainInfo, EachBlockWith, TestBlockChainClient};
|
||||
use client_traits::BlockInfo;
|
||||
use client_traits::{BlockInfo, ChainInfo};
|
||||
use ethcore::client::{EachBlockWith, TestBlockChainClient};
|
||||
use parking_lot::RwLock;
|
||||
use rlp::Rlp;
|
||||
use std::collections::VecDeque;
|
||||
|
||||
@@ -376,7 +376,8 @@ mod test {
|
||||
use rlp::{Rlp, RlpStream};
|
||||
use super::{*, super::tests::*};
|
||||
use blocks::SyncHeader;
|
||||
use ethcore::client::{BlockChainClient, EachBlockWith, TestBlockChainClient};
|
||||
use client_traits::BlockChainClient;
|
||||
use ethcore::client::{EachBlockWith, TestBlockChainClient};
|
||||
use std::str::FromStr;
|
||||
|
||||
#[test]
|
||||
|
||||
@@ -21,6 +21,7 @@
|
||||
//! https://github.com/ethereum/wiki/wiki/Ethereum-Wire-Protocol
|
||||
//!
|
||||
|
||||
extern crate client_traits;
|
||||
extern crate common_types as types;
|
||||
extern crate ethcore;
|
||||
extern crate ethcore_io as io;
|
||||
@@ -46,8 +47,8 @@ extern crate ethcore_light as light;
|
||||
#[cfg(test)] extern crate kvdb_memorydb;
|
||||
#[cfg(test)] extern crate rustc_hex;
|
||||
#[cfg(test)] extern crate rand_xorshift;
|
||||
#[cfg(test)] extern crate client_traits;
|
||||
#[cfg(test)] extern crate machine;
|
||||
#[cfg(test)] extern crate engine;
|
||||
|
||||
#[macro_use]
|
||||
extern crate enum_primitive;
|
||||
|
||||
@@ -19,7 +19,7 @@ use chain::sync_packet::{PacketInfo, SyncPacket};
|
||||
use network::{NetworkContext, PeerId, PacketId, Error, SessionInfo, ProtocolId};
|
||||
use network::client_version::ClientVersion;
|
||||
use bytes::Bytes;
|
||||
use ethcore::client::BlockChainClient;
|
||||
use client_traits::BlockChainClient;
|
||||
use types::BlockNumber;
|
||||
use ethcore::snapshot::SnapshotService;
|
||||
use parking_lot::RwLock;
|
||||
|
||||
@@ -16,7 +16,8 @@
|
||||
|
||||
use std::sync::Arc;
|
||||
use types::ids::BlockId;
|
||||
use ethcore::client::{TestBlockChainClient, BlockChainClient, EachBlockWith, ChainInfo};
|
||||
use client_traits::{BlockChainClient, ChainInfo};
|
||||
use ethcore::client::{TestBlockChainClient, EachBlockWith};
|
||||
use client_traits::BlockInfo;
|
||||
use chain::SyncState;
|
||||
use super::helpers::*;
|
||||
|
||||
@@ -18,8 +18,9 @@ use std::sync::Arc;
|
||||
use hash::keccak;
|
||||
use ethereum_types::{U256, Address};
|
||||
use io::{IoHandler, IoChannel};
|
||||
use ethcore::client::{ChainInfo, ClientIoMessage};
|
||||
use ethcore::engines;
|
||||
use client_traits::ChainInfo;
|
||||
use engine::signer;
|
||||
use ethcore::client::{ClientIoMessage};
|
||||
use ethcore::spec;
|
||||
use ethcore::miner::{self, MinerService};
|
||||
use ethkey::{KeyPair, Secret};
|
||||
@@ -49,8 +50,8 @@ fn authority_round() {
|
||||
let io_handler0: Arc<dyn IoHandler<ClientIoMessage>> = Arc::new(TestIoHandler::new(net.peer(0).chain.clone()));
|
||||
let io_handler1: Arc<dyn IoHandler<ClientIoMessage>> = Arc::new(TestIoHandler::new(net.peer(1).chain.clone()));
|
||||
// Push transaction to both clients. Only one of them gets lucky to produce a block.
|
||||
net.peer(0).miner.set_author(miner::Author::Sealer(engines::signer::from_keypair(s0.clone())));
|
||||
net.peer(1).miner.set_author(miner::Author::Sealer(engines::signer::from_keypair(s1.clone())));
|
||||
net.peer(0).miner.set_author(miner::Author::Sealer(signer::from_keypair(s0.clone())));
|
||||
net.peer(1).miner.set_author(miner::Author::Sealer(signer::from_keypair(s1.clone())));
|
||||
net.peer(0).chain.engine().register_client(Arc::downgrade(&net.peer(0).chain) as _);
|
||||
net.peer(1).chain.engine().register_client(Arc::downgrade(&net.peer(1).chain) as _);
|
||||
net.peer(0).chain.set_io_channel(IoChannel::to_handler(Arc::downgrade(&io_handler1)));
|
||||
|
||||
@@ -22,7 +22,8 @@ use bytes::Bytes;
|
||||
use network::{self, PeerId, ProtocolId, PacketId, SessionInfo};
|
||||
use network::client_version::ClientVersion;
|
||||
use tests::snapshot::*;
|
||||
use ethcore::client::{TestBlockChainClient, BlockChainClient, Client as EthcoreClient,
|
||||
use client_traits::BlockChainClient;
|
||||
use ethcore::client::{TestBlockChainClient, Client as EthcoreClient,
|
||||
ClientConfig, ChainNotify, NewBlocks, ChainMessageType, ClientIoMessage};
|
||||
use ethcore::snapshot::SnapshotService;
|
||||
use ethcore::spec::{self, Spec};
|
||||
|
||||
@@ -19,10 +19,11 @@ use hash::keccak;
|
||||
use io::{IoHandler, IoChannel};
|
||||
use types::transaction::{Transaction, Action};
|
||||
use types::ids::BlockId;
|
||||
use client_traits::BlockChainClient;
|
||||
use engine::signer;
|
||||
use ethcore::{
|
||||
CreateContractAddress,
|
||||
client::{ClientIoMessage, BlockChainClient},
|
||||
engines,
|
||||
client::ClientIoMessage,
|
||||
miner::{self, MinerService},
|
||||
spec::Spec,
|
||||
test_helpers::push_block_with_transactions,
|
||||
@@ -54,8 +55,8 @@ fn send_private_transaction() {
|
||||
let io_handler0: Arc<dyn IoHandler<ClientIoMessage>> = Arc::new(TestIoHandler::new(net.peer(0).chain.clone()));
|
||||
let io_handler1: Arc<dyn IoHandler<ClientIoMessage>> = Arc::new(TestIoHandler::new(net.peer(1).chain.clone()));
|
||||
|
||||
net.peer(0).miner.set_author(miner::Author::Sealer(engines::signer::from_keypair(s0.clone())));
|
||||
net.peer(1).miner.set_author(miner::Author::Sealer(engines::signer::from_keypair(s1.clone())));
|
||||
net.peer(0).miner.set_author(miner::Author::Sealer(signer::from_keypair(s0.clone())));
|
||||
net.peer(1).miner.set_author(miner::Author::Sealer(signer::from_keypair(s1.clone())));
|
||||
net.peer(0).chain.engine().register_client(Arc::downgrade(&net.peer(0).chain) as _);
|
||||
net.peer(1).chain.engine().register_client(Arc::downgrade(&net.peer(1).chain) as _);
|
||||
net.peer(0).chain.set_io_channel(IoChannel::to_handler(Arc::downgrade(&io_handler0)));
|
||||
|
||||
Reference in New Issue
Block a user