Extract Machine from ethcore (#10949)
* 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
This commit is contained in:
@@ -46,13 +46,18 @@ use client::{
|
||||
BlockChainReset
|
||||
};
|
||||
use client::{
|
||||
BlockId, TransactionId, UncleId, TraceId, ClientConfig, BlockChainClient,
|
||||
ClientConfig, BlockChainClient,
|
||||
TraceFilter, CallAnalytics, Mode,
|
||||
ChainNotify, NewBlocks, ChainRoute, PruningInfo, ProvingBlockChainClient, EngineInfo, ChainMessageType,
|
||||
IoClient, BadBlocks, bad_blocks, BlockInfo, ClientIoMessage,
|
||||
IoClient, BadBlocks, bad_blocks, ClientIoMessage,
|
||||
};
|
||||
use client_traits::BlockInfo;
|
||||
use engines::{Engine, EpochTransition, ForkChoice};
|
||||
use executive::{Executive, Executed, TransactOptions, contract_address};
|
||||
use machine::{
|
||||
executed::Executed,
|
||||
executive::{Executive, TransactOptions, contract_address},
|
||||
transaction_ext::Transaction,
|
||||
};
|
||||
use trie_vm_factories::{Factories, VmFactory};
|
||||
use miner::{Miner, MinerService};
|
||||
use snapshot::{self, io as snapshot_io, SnapshotClient};
|
||||
@@ -61,7 +66,6 @@ use account_state::State;
|
||||
use executive_state;
|
||||
use state_db::StateDB;
|
||||
use trace::{self, TraceDB, ImportRequest as TraceImportRequest, LocalizedTrace, Database as TraceDatabase};
|
||||
use transaction_ext::Transaction;
|
||||
use types::{
|
||||
ancestry_action::AncestryAction,
|
||||
BlockNumber,
|
||||
@@ -74,6 +78,7 @@ use types::{
|
||||
machine::{AuxiliaryData, Call as MachineCall},
|
||||
},
|
||||
errors::{EngineError, ExecutionError, BlockError, EthcoreError, SnapshotError, ImportError, EthcoreResult},
|
||||
ids::{BlockId, TransactionId, UncleId, TraceId},
|
||||
transaction::{self, LocalizedTransaction, UnverifiedTransaction, SignedTransaction, Action, CallError},
|
||||
filter::Filter,
|
||||
log_entry::LocalizedLogEntry,
|
||||
@@ -1759,7 +1764,7 @@ impl BlockChainClient for Client {
|
||||
self.config.spec_name.clone()
|
||||
}
|
||||
|
||||
fn chain(&self) -> Arc<BlockProvider> {
|
||||
fn chain(&self) -> Arc<dyn BlockProvider> {
|
||||
self.chain.read().clone()
|
||||
}
|
||||
|
||||
@@ -2652,20 +2657,27 @@ impl IoChannelQueue {
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use ethereum_types::{H256, Address};
|
||||
use client::{BlockChainClient, ChainInfo};
|
||||
use types::{
|
||||
encoded,
|
||||
ids::{BlockId, TransactionId},
|
||||
log_entry::{LogEntry, LocalizedLogEntry},
|
||||
receipt::{Receipt, LocalizedReceipt, TransactionOutcome},
|
||||
transaction::{Transaction, LocalizedTransaction, Action},
|
||||
};
|
||||
use test_helpers::{generate_dummy_client, get_good_dummy_block_hash, generate_dummy_client_with_data};
|
||||
use std::thread;
|
||||
use std::time::Duration;
|
||||
use std::sync::Arc;
|
||||
use std::sync::atomic::{AtomicBool, Ordering};
|
||||
use kvdb::DBTransaction;
|
||||
use blockchain::ExtrasInsert;
|
||||
use hash::keccak;
|
||||
use super::transaction_receipt;
|
||||
use ethkey::KeyPair;
|
||||
|
||||
#[test]
|
||||
fn should_not_cache_details_before_commit() {
|
||||
use client::{BlockChainClient, ChainInfo};
|
||||
use test_helpers::{generate_dummy_client, get_good_dummy_block_hash};
|
||||
|
||||
use std::thread;
|
||||
use std::time::Duration;
|
||||
use std::sync::Arc;
|
||||
use std::sync::atomic::{AtomicBool, Ordering};
|
||||
use kvdb::DBTransaction;
|
||||
use blockchain::ExtrasInsert;
|
||||
use types::encoded;
|
||||
|
||||
let client = generate_dummy_client(0);
|
||||
let genesis = client.chain_info().best_block_hash;
|
||||
let (new_hash, new_block) = get_good_dummy_block_hash();
|
||||
@@ -2693,9 +2705,6 @@ mod tests {
|
||||
|
||||
#[test]
|
||||
fn should_return_block_receipts() {
|
||||
use client::{BlockChainClient, BlockId, TransactionId};
|
||||
use test_helpers::{generate_dummy_client_with_data};
|
||||
|
||||
let client = generate_dummy_client_with_data(2, 2, &[1.into(), 1.into()]);
|
||||
let receipts = client.localized_block_receipts(BlockId::Latest).unwrap();
|
||||
|
||||
@@ -2719,13 +2728,6 @@ mod tests {
|
||||
|
||||
#[test]
|
||||
fn should_return_correct_log_index() {
|
||||
use hash::keccak;
|
||||
use super::transaction_receipt;
|
||||
use ethkey::KeyPair;
|
||||
use types::log_entry::{LogEntry, LocalizedLogEntry};
|
||||
use types::receipt::{Receipt, LocalizedReceipt, TransactionOutcome};
|
||||
use types::transaction::{Transaction, LocalizedTransaction, Action};
|
||||
|
||||
// given
|
||||
let key = KeyPair::from_secret_slice(keccak("test").as_bytes()).unwrap();
|
||||
let secret = key.secret();
|
||||
|
||||
@@ -21,7 +21,7 @@ use std::sync::Arc;
|
||||
use ethereum_types::{H256, U256, H160};
|
||||
use {trie_vm_factories, journaldb, trie, kvdb_memorydb};
|
||||
use kvdb::{self, KeyValueDB};
|
||||
use {state_db, client, executive, trace, db, spec};
|
||||
use {state_db, client, trace, db, spec};
|
||||
use pod::PodState;
|
||||
use types::{
|
||||
errors::EthcoreError,
|
||||
@@ -35,7 +35,11 @@ use evm::{VMType, FinalizationResult};
|
||||
use vm::{self, ActionParams, CreateContractAddress};
|
||||
use ethtrie;
|
||||
use account_state::{CleanupMode, State};
|
||||
use substate::Substate;
|
||||
use machine::{
|
||||
executive,
|
||||
substate::Substate,
|
||||
};
|
||||
|
||||
use executive_state::ExecutiveState;
|
||||
|
||||
/// EVM test Error.
|
||||
|
||||
@@ -35,19 +35,18 @@ pub use self::io_message::ClientIoMessage;
|
||||
pub use self::test_client::{TestBlockChainClient, EachBlockWith, TestState};
|
||||
pub use self::chain_notify::{ChainNotify, NewBlocks, ChainRoute, ChainRouteType, ChainMessageType};
|
||||
pub use self::traits::{
|
||||
Nonce, Balance, ChainInfo, BlockInfo, ReopenBlock, PrepareOpenBlock, TransactionInfo, ScheduleInfo, ImportSealedBlock, BroadcastProposalBlock, ImportBlock,
|
||||
Nonce, Balance, ChainInfo, ReopenBlock, PrepareOpenBlock, TransactionInfo, ScheduleInfo, ImportSealedBlock, BroadcastProposalBlock, ImportBlock,
|
||||
StateOrBlock, StateClient, Call, EngineInfo, AccountData, BlockChain, BlockProducer, SealedBlockImporter, BadBlocks,
|
||||
BlockChainReset
|
||||
BlockChainReset, BlockChainClient, EngineClient, ProvingBlockChainClient, IoClient
|
||||
};
|
||||
pub use account_state::state::StateInfo;
|
||||
pub use self::traits::{BlockChainClient, EngineClient, ProvingBlockChainClient, IoClient};
|
||||
|
||||
pub use types::ids::*;
|
||||
pub use types::trace_filter::Filter as TraceFilter;
|
||||
pub use types::pruning_info::PruningInfo;
|
||||
pub use types::call_analytics::CallAnalytics;
|
||||
use types::{
|
||||
trace_filter::Filter as TraceFilter,
|
||||
pruning_info::PruningInfo,
|
||||
call_analytics::CallAnalytics,
|
||||
};
|
||||
|
||||
pub use executive::{Executed, Executive, TransactOptions};
|
||||
pub use vm::{LastHashes, EnvInfo};
|
||||
|
||||
pub use verification::VerifierType;
|
||||
|
||||
@@ -37,33 +37,37 @@ use kvdb_memorydb;
|
||||
use parking_lot::RwLock;
|
||||
use rlp::{Rlp, RlpStream};
|
||||
use rustc_hex::FromHex;
|
||||
use types::transaction::{self, Transaction, LocalizedTransaction, SignedTransaction, Action, CallError};
|
||||
use types::BlockNumber;
|
||||
use types::basic_account::BasicAccount;
|
||||
use types::encoded;
|
||||
use types::errors::{EthcoreError as Error, EthcoreResult};
|
||||
use types::filter::Filter;
|
||||
use types::header::Header;
|
||||
use types::log_entry::LocalizedLogEntry;
|
||||
use types::pruning_info::PruningInfo;
|
||||
use types::receipt::{Receipt, LocalizedReceipt, TransactionOutcome};
|
||||
use types::view;
|
||||
use types::views::BlockView;
|
||||
use types::{
|
||||
BlockNumber,
|
||||
encoded,
|
||||
ids::{BlockId, TransactionId, UncleId, TraceId},
|
||||
basic_account::BasicAccount,
|
||||
errors::{EthcoreError as Error, EthcoreResult},
|
||||
transaction::{self, Transaction, LocalizedTransaction, SignedTransaction, Action, CallError},
|
||||
filter::Filter,
|
||||
trace_filter::Filter as TraceFilter,
|
||||
call_analytics::CallAnalytics,
|
||||
header::Header,
|
||||
log_entry::LocalizedLogEntry,
|
||||
pruning_info::PruningInfo,
|
||||
receipt::{Receipt, LocalizedReceipt, TransactionOutcome},
|
||||
view,
|
||||
views::BlockView,
|
||||
};
|
||||
use vm::Schedule;
|
||||
|
||||
use block::{OpenBlock, SealedBlock, ClosedBlock};
|
||||
use call_contract::{CallContract, RegistryInfo};
|
||||
use client::{
|
||||
Nonce, Balance, ChainInfo, ReopenBlock, TransactionInfo,
|
||||
PrepareOpenBlock, BlockChainClient, BlockChainInfo, BlockStatus, BlockId, Mode,
|
||||
TransactionId, UncleId, TraceId, TraceFilter, LastHashes, CallAnalytics,
|
||||
ProvingBlockChainClient, ScheduleInfo, ImportSealedBlock, BroadcastProposalBlock, ImportBlock, StateOrBlock,
|
||||
Call, StateClient, EngineInfo, AccountData, BlockChain, BlockProducer, SealedBlockImporter, IoClient,
|
||||
BadBlocks
|
||||
PrepareOpenBlock, BlockChainClient, BlockChainInfo, BlockStatus, Mode,
|
||||
LastHashes, ProvingBlockChainClient, ScheduleInfo, ImportSealedBlock, BroadcastProposalBlock,
|
||||
ImportBlock, StateOrBlock, Call, StateClient, EngineInfo, AccountData, BlockChain, BlockProducer,
|
||||
SealedBlockImporter, IoClient, BadBlocks
|
||||
};
|
||||
use client::BlockInfo;
|
||||
use client_traits::BlockInfo;
|
||||
use engines::Engine;
|
||||
use executive::Executed;
|
||||
use machine::executed::Executed;
|
||||
use journaldb;
|
||||
use miner::{self, Miner, MinerService};
|
||||
use spec::{Spec, self};
|
||||
@@ -704,7 +708,7 @@ impl BlockChainClient for TestBlockChainClient {
|
||||
}
|
||||
}
|
||||
|
||||
fn chain(&self) -> Arc<BlockProvider> {
|
||||
fn chain(&self) -> Arc<dyn BlockProvider> {
|
||||
unimplemented!()
|
||||
}
|
||||
|
||||
|
||||
@@ -20,6 +20,7 @@ use std::sync::Arc;
|
||||
use blockchain::{BlockReceipts, TreeRoute, BlockProvider};
|
||||
use bytes::Bytes;
|
||||
use call_contract::{CallContract, RegistryInfo};
|
||||
use client_traits::BlockInfo;
|
||||
use ethcore_miner::pool::VerifiedTransaction;
|
||||
use ethereum_types::{H256, U256, Address};
|
||||
use evm::Schedule;
|
||||
@@ -49,7 +50,7 @@ use vm::LastHashes;
|
||||
use block::{OpenBlock, SealedBlock, ClosedBlock};
|
||||
use client::Mode;
|
||||
use engines::Engine;
|
||||
use executive::Executed;
|
||||
use machine::executed::Executed;
|
||||
use account_state::state::StateInfo;
|
||||
use trace::LocalizedTrace;
|
||||
use verification::queue::kind::blocks::Unverified; // todo this is reexported from common_types
|
||||
@@ -114,21 +115,6 @@ pub trait ChainInfo {
|
||||
fn chain_info(&self) -> BlockChainInfo;
|
||||
}
|
||||
|
||||
/// Provides various information on a block by it's ID
|
||||
pub trait BlockInfo {
|
||||
/// Get raw block header data by block id.
|
||||
fn block_header(&self, id: BlockId) -> Option<encoded::Header>;
|
||||
|
||||
/// Get the best block header.
|
||||
fn best_block_header(&self) -> Header;
|
||||
|
||||
/// Get raw block data by block header hash.
|
||||
fn block(&self, id: BlockId) -> Option<encoded::Block>;
|
||||
|
||||
/// Get address code hash at given block's state.
|
||||
fn code_hash(&self, address: &Address, id: BlockId) -> Option<H256>;
|
||||
}
|
||||
|
||||
/// Provides various information on a transaction by it's ID
|
||||
pub trait TransactionInfo {
|
||||
/// Get the hash of block that contains the transaction, if any.
|
||||
@@ -233,7 +219,8 @@ pub trait BlockChainClient : Sync + Send + AccountData + BlockChain + CallContra
|
||||
.expect("code will return Some if given BlockId::Latest; qed")
|
||||
}
|
||||
|
||||
fn chain(&self) -> Arc<BlockProvider>;
|
||||
/// Get a reference to the `BlockProvider`.
|
||||
fn chain(&self) -> Arc<dyn BlockProvider>;
|
||||
|
||||
/// Get block queue information.
|
||||
fn queue_info(&self) -> BlockQueueInfo;
|
||||
|
||||
Reference in New Issue
Block a user