Move more types out of ethcore (#10880)

* WIP move errors, pod_account and state account to own crates

* Sort out dependencies, fix broken code and tests
Remove botched ethcore-error crate

* remove template line

* fix review feedback

* Remove test-only AccountDBMut::new

* Extract AccountDB to account-db

* Move Substate to state-account – wip

* Add lib.rs

* cleanup

* test failure

* test failure 2

* third time's the charm

* Add factories crate

* Use new factories crate

* Use factories crate

* Extract trace

* Fix tests

* Sort out parity-util-mem and parking_lot

* cleanup

* WIP port over the rest of state from ethcore

* Collect all impls for Machine

* some notes

* Rename pod-account to pod

* Move PodState to pod crate

* Use PodState from pod crate

* Fix use clause for json tests

* Sort out evmbin

* Add missing code and use PodState

* Move code that depends on Machine and Executive to own module

* Sort out cloning errors, fix ethcore to use new state crate

* Do without funky From impls

* Fix ethcore tests

* Fixes around the project to use new state crate

* Add back the more specific impls of StateOrBlock From conversions

* Move execute to freestanding function and remove it from trait
Sort out the error handling in executive_state by moving the result types from state to ethcore
Undo the verbose code added to work around the StateOrBlock From conversions

* cleanup

* Fix "error: enum variants on type aliases are experimental"

* Bring back the state tests
Fix whitespace

* remove ethcore/state/mod.rs

* cleanup

* cleanup

* Cleanup state-account errors

* Fix more todos
Add module docs

* Add error.rs

* Fixup Cargo.lock

* Smaller ethcore API is fine

* Add `to-pod-full` feature to state-account
Fix evmbin

* Fix a few more test failures

* Fix RPC test build

* Baptize the new trait

* Remove resolved TODOs

* Rename state-account to account-state

* Do not re-export the trace crate

* Don't export state_db from ethcore

* Let private-tx use StateDB. :(

* Remove ethcore/src/pod_state.rs

* Inner type does not need to be pub/pub(crate)

* optimise imports

* Revert "Inner type does not need to be pub/pub(crate)"

This reverts commit 2f839f8a0f72f71334da64620f57e6dd6039f06b.

* Move DatabaseExtras to ethcore-blockchain

* Add database_extra module to ethcore-blockchain

* Remove to-pod-full feature

* cosmetics

* New crate: state-db

* Add new crate

* Move PreverifiedBlock and BlockError to types

* Sort out the merge

* Add missing `license` meta data keys

* wip

* wip client-traits

* merge conflict

* verification crate type checks

* Move impls for CommonParams to common_types
Fix misc stuff in ethcore

* Fix tests

* Implement VerifyingEngine for all engines except Ethash
Temporarily sort out error handling
Move more types to common_types

* Split Engine in two and move code around

* cleanup

* verification: don't rexport common_types

* Use error from common_types

* Consolidate error types

* VerifyingEngine use Errors from common_types

* verification: Use error type from common_types

* SnapshotError moved to common_types

* Move more code from Engne to VerifyingEngine
Add a VerifyingClient trait: BlockInfo + CallContract
Whitespace

* Add MAX_UNCLE_AGE const

* Port over remaining code from ethcore/verification

* Use errors from common_types

* Fix the confusing "io" naming

* Move more types into common_types

* Add todos

* Experiment with Engine trait outside ethcore

* Hook up types from common_types in ethcore
Don't use verification crate
Don't use client-traits crate

* Revert to impl Engine for Arc<Ethash> and add note to explain why
Revert moving ClientIoMessage to common_types
Fix build

* Remove ClientIoMessage from common_types

* Cleanup

* More cleanup

* Sort error handling changes in the rest of parity

* Remove unused code

* Remove WIP types

* Cleanup todos not tackled here

* remove cruft

* Fix some whitespace and a merge error

* ethcore tests

* test failures

* Restore Engine impls to master to make review a bit easier

* cleanup

* whitespace

* applied review suggestions

* types does not depend on rustc-hex

* ethash engine moved to engine module

* applied review suggestion
This commit is contained in:
David
2019-07-18 12:27:08 +02:00
committed by Marek Kotewicz
parent 7f707fa524
commit 1ef9d5b52f
102 changed files with 1546 additions and 1297 deletions

View File

@@ -23,7 +23,10 @@ use engines::{Engine, EpochVerifier};
use blockchain::BlockChain;
use parking_lot::RwLock;
use rand::Rng;
use types::header::Header;
use types::{
header::Header,
errors::EthcoreError,
};
// do "heavy" verification on ~1/50 blocks, randomly sampled.
const HEAVY_VERIFY_RATE: f32 = 0.02;
@@ -51,7 +54,7 @@ impl AncientVerifier {
rng: &mut R,
header: &Header,
chain: &BlockChain,
) -> Result<(), ::error::Error> {
) -> Result<(), EthcoreError> {
// perform verification
let verified = if let Some(ref cur_verifier) = *self.cur_verifier.read() {
match rng.gen::<f32>() <= HEAVY_VERIFY_RATE {
@@ -86,7 +89,7 @@ impl AncientVerifier {
}
fn initial_verifier(&self, header: &Header, chain: &BlockChain)
-> Result<Box<dyn EpochVerifier>, ::error::Error>
-> Result<Box<dyn EpochVerifier>, EthcoreError>
{
trace!(target: "client", "Initializing ancient block restoration.");
let current_epoch_data = chain.epoch_transitions()

View File

@@ -33,38 +33,25 @@ use journaldb;
use kvdb::{DBValue, KeyValueDB, DBTransaction};
use parking_lot::{Mutex, RwLock};
use rand::rngs::OsRng;
use types::transaction::{self, LocalizedTransaction, UnverifiedTransaction, SignedTransaction, Action};
use trie::{TrieSpec, TrieFactory, Trie};
use types::ancestry_action::AncestryAction;
use types::encoded;
use types::filter::Filter;
use types::log_entry::LocalizedLogEntry;
use types::receipt::{Receipt, LocalizedReceipt};
use types::{BlockNumber, header::Header};
use vm::{EnvInfo, LastHashes, CreateContractAddress};
use hash_db::EMPTY_PREFIX;
use block::{LockedBlock, Drain, ClosedBlock, OpenBlock, enact_verified, SealedBlock};
use client::ancient_import::AncientVerifier;
use client::{
Nonce, Balance, ChainInfo, BlockInfo, TransactionInfo,
Nonce, Balance, ChainInfo, TransactionInfo,
ReopenBlock, PrepareOpenBlock, ScheduleInfo, ImportSealedBlock,
BroadcastProposalBlock, ImportBlock, StateOrBlock, StateInfo, StateClient, Call,
AccountData, BlockChain as BlockChainTrait, BlockProducer, SealedBlockImporter,
ClientIoMessage, BlockChainReset
BlockChainReset
};
use client::{
BlockId, TransactionId, UncleId, TraceId, ClientConfig, BlockChainClient,
TraceFilter, CallAnalytics, Mode,
ChainNotify, NewBlocks, ChainRoute, PruningInfo, ProvingBlockChainClient, EngineInfo, ChainMessageType,
IoClient, BadBlocks,
};
use client::bad_blocks;
use engines::{MAX_UNCLE_AGE, Engine, EpochTransition, ForkChoice, EngineError, SealingState};
use engines::epoch::PendingTransition;
use error::{
ImportError, ExecutionError, CallError, BlockError,
Error as EthcoreError, EthcoreResult,
IoClient, BadBlocks, bad_blocks, BlockInfo, ClientIoMessage,
};
use engines::{Engine, EpochTransition, ForkChoice};
use executive::{Executive, Executed, TransactOptions, contract_address};
use trie_vm_factories::{Factories, VmFactory};
use miner::{Miner, MinerService};
@@ -75,18 +62,37 @@ 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,
block::PreverifiedBlock,
encoded,
engines::{
SealingState,
MAX_UNCLE_AGE,
epoch::PendingTransition,
machine::{AuxiliaryData, Call as MachineCall},
},
errors::{EngineError, ExecutionError, BlockError, EthcoreError, SnapshotError, ImportError, EthcoreResult},
transaction::{self, LocalizedTransaction, UnverifiedTransaction, SignedTransaction, Action, CallError},
filter::Filter,
log_entry::LocalizedLogEntry,
receipt::{Receipt, LocalizedReceipt},
header::Header,
};
use verification::queue::kind::BlockLike;
use verification::queue::kind::blocks::Unverified;
use verification::{PreverifiedBlock, Verifier, BlockQueue};
use verification::{Verifier, BlockQueue};
use verification;
use ansi_term::Colour;
// re-export
pub use blockchain::CacheSize as BlockChainCacheSize;
use db::{Writable, Readable, keys::BlockDetails};
pub use types::blockchain_info::BlockChainInfo;
pub use types::block_status::BlockStatus;
pub use blockchain::CacheSize as BlockChainCacheSize;
pub use verification::QueueInfo as BlockQueueInfo;
use db::{Writable, Readable, keys::BlockDetails};
pub use types::verification_queue_info::VerificationQueueInfo as BlockQueueInfo;
use_contract!(registry, "res/contracts/registrar.json");
@@ -249,7 +255,12 @@ impl Importer {
message_channel: IoChannel<ClientIoMessage>,
miner: Arc<Miner>,
) -> Result<Importer, EthcoreError> {
let block_queue = BlockQueue::new(config.queue.clone(), engine.clone(), message_channel.clone(), config.verifier_type.verifying_seal());
let block_queue = BlockQueue::new(
config.queue.clone(),
engine.clone(),
message_channel.clone(),
config.verifier_type.verifying_seal()
);
Ok(Importer {
import_lock: Mutex::new(()),
@@ -384,7 +395,7 @@ impl Importer {
if let Err(e) = verify_family_result {
warn!(target: "client", "Stage 3 block verification failed for #{} ({})\nError: {:?}", header.number(), header.hash(), e);
return Err(e.into());
return Err(e);
};
let verify_external_result = self.verifier.verify_block_external(&header, engine);
@@ -591,7 +602,7 @@ impl Importer {
use engines::EpochChange;
let hash = header.hash();
let auxiliary = ::machine::AuxiliaryData {
let auxiliary = AuxiliaryData {
bytes: Some(block_bytes),
receipts: Some(&receipts),
};
@@ -935,7 +946,7 @@ impl Client {
// use a state-proving closure for the given block.
fn with_proving_caller<F, T>(&self, id: BlockId, with_call: F) -> T
where F: FnOnce(&::machine::Call) -> T
where F: FnOnce(&MachineCall) -> T
{
let call = |a, d| {
let tx = self.contract_call_tx(id, a, d);
@@ -1151,10 +1162,10 @@ impl Client {
) -> Result<(), EthcoreError> {
let db = self.state_db.read().journal_db().boxed_clone();
let best_block_number = self.chain_info().best_block_number;
let block_number = self.block_number(at).ok_or_else(|| snapshot::Error::InvalidStartingBlock(at))?;
let block_number = self.block_number(at).ok_or_else(|| SnapshotError::InvalidStartingBlock(at))?;
if db.is_prunable() && self.pruning_info().earliest_state > block_number {
return Err(snapshot::Error::OldBlockPrunedDB.into());
return Err(SnapshotError::OldBlockPrunedDB.into());
}
let history = cmp::min(self.history, 1000);
@@ -1168,17 +1179,17 @@ impl Client {
match self.block_hash(BlockId::Number(start_num)) {
Some(h) => h,
None => return Err(snapshot::Error::InvalidStartingBlock(at).into()),
None => return Err(SnapshotError::InvalidStartingBlock(at).into()),
}
}
_ => match self.block_hash(at) {
Some(hash) => hash,
None => return Err(snapshot::Error::InvalidStartingBlock(at).into()),
None => return Err(SnapshotError::InvalidStartingBlock(at).into()),
},
};
let processing_threads = self.config.snapshot.processing_threads;
let chunker = self.engine.snapshot_components().ok_or_else(|| snapshot::Error::SnapshotsUnsupported)?;
let chunker = self.engine.snapshot_components().ok_or_else(|| SnapshotError::SnapshotsUnsupported)?;
snapshot::take_snapshot(
chunker,
&self.chain.read(),

View File

@@ -23,7 +23,12 @@ use {trie_vm_factories, journaldb, trie, kvdb_memorydb};
use kvdb::{self, KeyValueDB};
use {state_db, client, executive, trace, db, spec};
use pod::PodState;
use types::{log_entry, receipt, transaction};
use types::{
errors::EthcoreError,
log_entry,
receipt,
transaction
};
use trie_vm_factories::Factories;
use evm::{VMType, FinalizationResult};
use vm::{self, ActionParams, CreateContractAddress};
@@ -41,12 +46,12 @@ pub enum EvmTestError {
/// EVM error.
Evm(vm::Error),
/// Initialization error.
ClientError(::error::Error),
ClientError(EthcoreError),
/// Post-condition failure,
PostCondition(String),
}
impl<E: Into<::error::Error>> From<E> for EvmTestError {
impl<E: Into<EthcoreError>> From<E> for EvmTestError {
fn from(err: E) -> Self {
EvmTestError::ClientError(err.into())
}
@@ -345,7 +350,7 @@ pub struct TransactErr {
/// State root
pub state_root: H256,
/// Execution error
pub error: ::error::Error,
pub error: EthcoreError,
/// end state if needed
pub end_state: Option<PodState>,
}

View File

@@ -36,10 +36,11 @@ use kvdb_memorydb;
use parking_lot::RwLock;
use rlp::{Rlp, RlpStream};
use rustc_hex::FromHex;
use types::transaction::{self, Transaction, LocalizedTransaction, SignedTransaction, Action};
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;
@@ -52,16 +53,15 @@ use vm::Schedule;
use block::{OpenBlock, SealedBlock, ClosedBlock};
use call_contract::{CallContract, RegistryInfo};
use client::{
Nonce, Balance, ChainInfo, BlockInfo, ReopenBlock, TransactionInfo,
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
};
use client::BlockInfo;
use engines::Engine;
use error::{Error, EthcoreResult};
use executed::CallError;
use executive::Executed;
use journaldb;
use miner::{self, Miner, MinerService};

View File

@@ -25,32 +25,34 @@ use ethereum_types::{H256, U256, Address};
use evm::Schedule;
use itertools::Itertools;
use kvdb::DBValue;
use types::transaction::{self, LocalizedTransaction, SignedTransaction};
use types::BlockNumber;
use types::basic_account::BasicAccount;
use types::block_status::BlockStatus;
use types::blockchain_info::BlockChainInfo;
use types::call_analytics::CallAnalytics;
use types::encoded;
use types::filter::Filter;
use types::header::Header;
use types::ids::*;
use types::log_entry::LocalizedLogEntry;
use types::pruning_info::PruningInfo;
use types::receipt::LocalizedReceipt;
use types::trace_filter::Filter as TraceFilter;
use types::{
transaction::{self, LocalizedTransaction, SignedTransaction, CallError},
BlockNumber,
basic_account::BasicAccount,
block_status::BlockStatus,
blockchain_info::BlockChainInfo,
call_analytics::CallAnalytics,
encoded,
errors::EthcoreError as Error,
errors::EthcoreResult,
filter::Filter,
header::Header,
ids::*,
log_entry::LocalizedLogEntry,
pruning_info::PruningInfo,
receipt::LocalizedReceipt,
trace_filter::Filter as TraceFilter,
verification_queue_info::VerificationQueueInfo as BlockQueueInfo,
};
use vm::LastHashes;
use block::{OpenBlock, SealedBlock, ClosedBlock};
use client::Mode;
use engines::Engine;
use error::{Error, EthcoreResult};
use executed::CallError;
use executive::Executed;
use account_state::state::StateInfo;
use trace::LocalizedTrace;
use verification::queue::QueueInfo as BlockQueueInfo;
use verification::queue::kind::blocks::Unverified;
use verification::queue::kind::blocks::Unverified; // todo this is reexported from common_types
/// State information to be used during client query
pub enum StateOrBlock {