Extract some parts of miner from ethcore. (#7353)
* Move miner away from ethcore. * Fix ethcore to use miner/transaction. * Fix tests and warnings. * fixed incorrect merge of the test in the documentation
This commit is contained in:
committed by
Marek Kotewicz
parent
9a12945304
commit
f044b61f42
@@ -10,6 +10,7 @@ authors = ["Parity Technologies <admin@parity.io>"]
|
||||
log = "0.3"
|
||||
ethcore = { path = ".."}
|
||||
ethcore-bytes = { path = "../../util/bytes" }
|
||||
ethcore-transaction = { path = "../transaction" }
|
||||
ethereum-types = "0.1"
|
||||
memorydb = { path = "../../util/memorydb" }
|
||||
patricia-trie = { path = "../../util/patricia_trie" }
|
||||
|
||||
@@ -57,6 +57,7 @@ extern crate bincode;
|
||||
extern crate ethcore_io as io;
|
||||
extern crate ethcore_network as network;
|
||||
extern crate ethcore_bytes as bytes;
|
||||
extern crate ethcore_transaction as transaction;
|
||||
extern crate ethereum_types;
|
||||
extern crate ethcore;
|
||||
extern crate evm;
|
||||
|
||||
@@ -18,7 +18,7 @@
|
||||
//!
|
||||
//! This uses a "Provider" to answer requests.
|
||||
|
||||
use ethcore::transaction::UnverifiedTransaction;
|
||||
use transaction::UnverifiedTransaction;
|
||||
|
||||
use io::TimerToken;
|
||||
use network::{HostInfo, NetworkProtocolHandler, NetworkContext, PeerId};
|
||||
|
||||
@@ -20,9 +20,9 @@
|
||||
use ethcore::blockchain_info::BlockChainInfo;
|
||||
use ethcore::client::{EachBlockWith, TestBlockChainClient};
|
||||
use ethcore::ids::BlockId;
|
||||
use ethcore::transaction::{Action, PendingTransaction};
|
||||
use ethcore::encoded;
|
||||
use network::{PeerId, NodeId};
|
||||
use transaction::{Action, PendingTransaction};
|
||||
|
||||
use net::context::IoContext;
|
||||
use net::status::{Capabilities, Status};
|
||||
|
||||
@@ -24,7 +24,7 @@ use ethcore::engines::{EthEngine, StateDependentProof};
|
||||
use ethcore::machine::EthereumMachine;
|
||||
use ethcore::receipt::Receipt;
|
||||
use ethcore::state::{self, ProvedExecution};
|
||||
use ethcore::transaction::SignedTransaction;
|
||||
use transaction::SignedTransaction;
|
||||
use vm::EnvInfo;
|
||||
use hash::{KECCAK_NULL_RLP, KECCAK_EMPTY, KECCAK_EMPTY_LIST_RLP, keccak};
|
||||
|
||||
|
||||
@@ -21,11 +21,11 @@ use std::sync::Arc;
|
||||
|
||||
use ethcore::blockchain_info::BlockChainInfo;
|
||||
use ethcore::client::{BlockChainClient, ProvingBlockChainClient};
|
||||
use ethcore::transaction::PendingTransaction;
|
||||
use ethcore::ids::BlockId;
|
||||
use ethcore::encoded;
|
||||
use ethcore::ids::BlockId;
|
||||
use ethereum_types::H256;
|
||||
use parking_lot::RwLock;
|
||||
use transaction::PendingTransaction;
|
||||
|
||||
use cht::{self, BlockInfo};
|
||||
use client::{LightChainClient, AsLightClient};
|
||||
@@ -260,7 +260,7 @@ impl<T: ProvingBlockChainClient + ?Sized> Provider for T {
|
||||
}
|
||||
|
||||
fn transaction_proof(&self, req: request::CompleteExecutionRequest) -> Option<request::ExecutionResponse> {
|
||||
use ethcore::transaction::Transaction;
|
||||
use transaction::Transaction;
|
||||
|
||||
let id = BlockId::Hash(req.block_hash);
|
||||
let nonce = match self.nonce(&req.from, id.clone()) {
|
||||
|
||||
@@ -26,8 +26,7 @@
|
||||
use std::collections::{BTreeMap, HashMap};
|
||||
use std::collections::hash_map::Entry;
|
||||
|
||||
use ethcore::error::{TransactionError, TransactionImportResult};
|
||||
use ethcore::transaction::{Condition, PendingTransaction, SignedTransaction};
|
||||
use transaction::{self, Condition, PendingTransaction, SignedTransaction};
|
||||
use ethereum_types::{H256, U256, Address};
|
||||
use plain_hasher::H256FastMap;
|
||||
|
||||
@@ -123,13 +122,13 @@ pub struct TransactionQueue {
|
||||
|
||||
impl TransactionQueue {
|
||||
/// Import a pending transaction to be queued.
|
||||
pub fn import(&mut self, tx: PendingTransaction) -> Result<TransactionImportResult, TransactionError> {
|
||||
pub fn import(&mut self, tx: PendingTransaction) -> Result<transaction::ImportResult, transaction::Error> {
|
||||
let sender = tx.sender();
|
||||
let hash = tx.hash();
|
||||
let nonce = tx.nonce;
|
||||
let tx_info = TransactionInfo::from(&tx);
|
||||
|
||||
if self.by_hash.contains_key(&hash) { return Err(TransactionError::AlreadyImported) }
|
||||
if self.by_hash.contains_key(&hash) { return Err(transaction::Error::AlreadyImported) }
|
||||
|
||||
let res = match self.by_account.entry(sender) {
|
||||
Entry::Vacant(entry) => {
|
||||
@@ -139,14 +138,14 @@ impl TransactionQueue {
|
||||
future: BTreeMap::new(),
|
||||
});
|
||||
|
||||
TransactionImportResult::Current
|
||||
transaction::ImportResult::Current
|
||||
}
|
||||
Entry::Occupied(mut entry) => {
|
||||
let acct_txs = entry.get_mut();
|
||||
if &nonce < acct_txs.cur_nonce.value() {
|
||||
// don't accept txs from before known current nonce.
|
||||
if acct_txs.cur_nonce.is_known() {
|
||||
return Err(TransactionError::Old)
|
||||
return Err(transaction::Error::Old)
|
||||
}
|
||||
|
||||
// lower our assumption until corrected later.
|
||||
@@ -161,7 +160,7 @@ impl TransactionQueue {
|
||||
let old = ::std::mem::replace(&mut acct_txs.current[idx], tx_info);
|
||||
self.by_hash.remove(&old.hash);
|
||||
|
||||
TransactionImportResult::Current
|
||||
transaction::ImportResult::Current
|
||||
}
|
||||
Err(idx) => {
|
||||
let cur_len = acct_txs.current.len();
|
||||
@@ -183,13 +182,13 @@ impl TransactionQueue {
|
||||
acct_txs.future.insert(future_nonce, future);
|
||||
}
|
||||
|
||||
TransactionImportResult::Current
|
||||
transaction::ImportResult::Current
|
||||
} else if idx == cur_len && acct_txs.current.last().map_or(false, |f| f.nonce + 1.into() != nonce) {
|
||||
trace!(target: "txqueue", "Queued future transaction for {}, nonce={}", sender, nonce);
|
||||
let future_nonce = nonce;
|
||||
acct_txs.future.insert(future_nonce, tx_info);
|
||||
|
||||
TransactionImportResult::Future
|
||||
transaction::ImportResult::Future
|
||||
} else {
|
||||
trace!(target: "txqueue", "Queued current transaction for {}, nonce={}", sender, nonce);
|
||||
|
||||
@@ -197,7 +196,7 @@ impl TransactionQueue {
|
||||
acct_txs.current.insert(idx, tx_info);
|
||||
acct_txs.adjust_future();
|
||||
|
||||
TransactionImportResult::Current
|
||||
transaction::ImportResult::Current
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -331,7 +330,7 @@ impl TransactionQueue {
|
||||
mod tests {
|
||||
use super::TransactionQueue;
|
||||
use ethereum_types::Address;
|
||||
use ethcore::transaction::{Transaction, PendingTransaction, Condition};
|
||||
use transaction::{Transaction, PendingTransaction, Condition};
|
||||
|
||||
#[test]
|
||||
fn queued_senders() {
|
||||
|
||||
@@ -1094,7 +1094,7 @@ pub mod block_body {
|
||||
impl Decodable for Response {
|
||||
fn decode(rlp: &UntrustedRlp) -> Result<Self, DecoderError> {
|
||||
use ethcore::header::Header as FullHeader;
|
||||
use ethcore::transaction::UnverifiedTransaction;
|
||||
use transaction::UnverifiedTransaction;
|
||||
|
||||
// check body validity.
|
||||
let _: Vec<UnverifiedTransaction> = rlp.list_at(0)?;
|
||||
@@ -1410,7 +1410,7 @@ pub mod contract_code {
|
||||
/// A request for proof of execution.
|
||||
pub mod execution {
|
||||
use super::{Field, NoSuchOutput, OutputKind, Output};
|
||||
use ethcore::transaction::Action;
|
||||
use transaction::Action;
|
||||
use rlp::{Encodable, Decodable, DecoderError, RlpStream, UntrustedRlp};
|
||||
use ethereum_types::{H256, U256, Address};
|
||||
use kvdb::DBValue;
|
||||
@@ -1755,7 +1755,7 @@ mod tests {
|
||||
|
||||
#[test]
|
||||
fn body_roundtrip() {
|
||||
use ethcore::transaction::{Transaction, UnverifiedTransaction};
|
||||
use transaction::{Transaction, UnverifiedTransaction};
|
||||
let req = IncompleteBodyRequest {
|
||||
hash: Field::Scalar(Default::default()),
|
||||
};
|
||||
@@ -1850,7 +1850,7 @@ mod tests {
|
||||
let req = IncompleteExecutionRequest {
|
||||
block_hash: Field::Scalar(Default::default()),
|
||||
from: Default::default(),
|
||||
action: ::ethcore::transaction::Action::Create,
|
||||
action: ::transaction::Action::Create,
|
||||
gas: 100_000.into(),
|
||||
gas_price: 0.into(),
|
||||
value: 100_000_001.into(),
|
||||
@@ -1880,7 +1880,7 @@ mod tests {
|
||||
let reqs: Vec<_> = (0..10).map(|_| IncompleteExecutionRequest {
|
||||
block_hash: Field::Scalar(Default::default()),
|
||||
from: Default::default(),
|
||||
action: ::ethcore::transaction::Action::Create,
|
||||
action: ::transaction::Action::Create,
|
||||
gas: 100_000.into(),
|
||||
gas_price: 0.into(),
|
||||
value: 100_000_001.into(),
|
||||
|
||||
Reference in New Issue
Block a user