simplify create_address_scheme (#10890)

* simplify create_address_scheme

* fix compilation errors
This commit is contained in:
Marek Kotewicz 2019-07-16 12:43:47 +02:00 committed by Wei Tang
parent 14e7641835
commit e3665ed9e3
9 changed files with 17 additions and 27 deletions

1
Cargo.lock generated
View File

@ -1220,6 +1220,7 @@ dependencies = [
"transaction-pool 2.0.0 (registry+https://github.com/rust-lang/crates.io-index)",
"trie-db 0.12.4 (registry+https://github.com/rust-lang/crates.io-index)",
"url 1.7.1 (registry+https://github.com/rust-lang/crates.io-index)",
"vm 0.1.0",
]
[[package]]

View File

@ -42,6 +42,7 @@ tiny-keccak = "1.4"
trace = { path = "../trace" }
transaction-pool = "2.0"
url = "1"
vm = { path = "../vm" }
[dev-dependencies]
env_logger = "0.5"

View File

@ -61,6 +61,7 @@ extern crate ethabi_contract;
extern crate derive_more;
#[macro_use]
extern crate rlp_derive;
extern crate vm;
#[cfg(not(time_checked_add))]
extern crate time_utils;
@ -101,6 +102,7 @@ use trace::{Tracer, VMTracer};
use call_contract::CallContract;
use rustc_hex::FromHex;
use ethabi::FunctionOutputDecoder;
use vm::CreateContractAddress;
// Source avaiable at https://github.com/parity-contracts/private-tx/blob/master/contracts/PrivateContract.sol
const DEFAULT_STUB_CONTRACT: &'static str = include_str!("../res/private.evm");
@ -574,7 +576,7 @@ impl Provider {
let sender = transaction.sender();
let nonce = state.nonce(&sender)?;
let contract_address = contract_address.unwrap_or_else(|| {
let (new_address, _) = ethcore_contract_address(engine.create_address_scheme(env_info.number), &sender, &nonce, &transaction.data);
let (new_address, _) = ethcore_contract_address(CreateContractAddress::FromSenderAndNonce, &sender, &nonce, &transaction.data);
new_address
});
// Patch other available private contracts' states as well

View File

@ -41,7 +41,7 @@ use types::filter::Filter;
use types::log_entry::LocalizedLogEntry;
use types::receipt::{Receipt, LocalizedReceipt};
use types::{BlockNumber, header::Header};
use vm::{EnvInfo, LastHashes};
use vm::{EnvInfo, LastHashes, CreateContractAddress};
use hash_db::EMPTY_PREFIX;
use block::{LockedBlock, Drain, ClosedBlock, OpenBlock, enact_verified, SealedBlock};
use client::ancient_import::AncientVerifier;
@ -1922,7 +1922,7 @@ impl BlockChainClient for Client {
let gas_used = receipts.last().map_or_else(|| 0.into(), |r| r.gas_used);
let no_of_logs = receipts.into_iter().map(|receipt| receipt.logs.len()).sum::<usize>();
let receipt = transaction_receipt(self.engine().machine(), transaction, receipt, gas_used, no_of_logs);
let receipt = transaction_receipt(transaction, receipt, gas_used, no_of_logs);
Some(receipt)
}
@ -1933,7 +1933,6 @@ impl BlockChainClient for Client {
let receipts = chain.block_receipts(&hash)?;
let number = chain.block_number(&hash)?;
let body = chain.block_body(&hash)?;
let engine = self.engine.clone();
let mut gas_used = 0.into();
let mut no_of_logs = 0;
@ -1944,7 +1943,7 @@ impl BlockChainClient for Client {
.into_iter()
.zip(receipts.receipts)
.map(move |(transaction, receipt)| {
let result = transaction_receipt(engine.machine(), transaction, receipt, gas_used, no_of_logs);
let result = transaction_receipt(transaction, receipt, gas_used, no_of_logs);
gas_used = result.cumulative_gas_used;
no_of_logs += result.logs.len();
result
@ -2555,7 +2554,6 @@ impl SnapshotClient for Client {}
/// Returns `LocalizedReceipt` given `LocalizedTransaction`
/// and a vector of receipts from given block up to transaction index.
fn transaction_receipt(
machine: &::machine::Machine,
mut tx: LocalizedTransaction,
receipt: Receipt,
prior_gas_used: U256,
@ -2581,7 +2579,7 @@ fn transaction_receipt(
gas_used: receipt.gas_used - prior_gas_used,
contract_address: match tx.action {
Action::Call(_) => None,
Action::Create => Some(contract_address(machine.create_address_scheme(block_number), &sender, &tx.nonce, &tx.data).0)
Action::Create => Some(contract_address(CreateContractAddress::FromSenderAndNonce, &sender, &tx.nonce, &tx.data).0)
},
logs: receipt.logs.into_iter().enumerate().map(|(i, log)| LocalizedLogEntry {
entry: log,
@ -2710,7 +2708,6 @@ mod tests {
// given
let key = KeyPair::from_secret_slice(keccak("test").as_bytes()).unwrap();
let secret = key.secret();
let machine = ::ethereum::new_frontier_test_machine();
let block_number = 1;
let block_hash = H256::from_low_u64_be(5);
@ -2749,7 +2746,7 @@ mod tests {
};
// when
let receipt = transaction_receipt(&machine, transaction, receipt, 5.into(), 1);
let receipt = transaction_receipt(transaction, receipt, 5.into(), 1);
// then
assert_eq!(receipt, LocalizedReceipt {

View File

@ -26,7 +26,7 @@ use pod::PodState;
use types::{log_entry, receipt, transaction};
use trie_vm_factories::Factories;
use evm::{VMType, FinalizationResult};
use vm::{self, ActionParams};
use vm::{self, ActionParams, CreateContractAddress};
use ethtrie;
use account_state::{CleanupMode, State};
use substate::Substate;
@ -265,7 +265,7 @@ impl<'a> EvmTestClient<'a> {
// Apply transaction
let result = self.state.apply_with_tracing(&env_info, self.spec.engine.machine(), &transaction, tracer, vm_tracer);
let scheme = self.spec.engine.machine().create_address_scheme(env_info.number);
let scheme = CreateContractAddress::FromSenderAndNonce;
// Touch the coinbase at the end of the test to simulate
// miner reward.

View File

@ -42,7 +42,7 @@ use std::collections::BTreeMap;
use std::{fmt, error};
use builtin::Builtin;
use vm::{EnvInfo, Schedule, CreateContractAddress, CallType, ActionValue};
use vm::{EnvInfo, Schedule, CallType, ActionValue};
use error::Error;
use types::BlockNumber;
use types::header::{Header, ExtendedHeader};
@ -510,11 +510,6 @@ pub trait Engine: Sync + Send {
self.machine().signing_chain_id(env_info)
}
/// Returns new contract address generation scheme at given block number.
fn create_address_scheme(&self, number: BlockNumber) -> CreateContractAddress {
self.machine().create_address_scheme(number)
}
/// Verify a particular transaction is valid.
///
/// Unordered verification doesn't rely on the transaction execution order,

View File

@ -883,7 +883,7 @@ impl<'a, B: 'a + StateBackend> Executive<'a, B> {
let (result, output) = match t.action {
Action::Create => {
let (new_address, code_hash) = contract_address(self.machine.create_address_scheme(self.info.number), &sender, &nonce, &t.data);
let (new_address, code_hash) = contract_address(CreateContractAddress::FromSenderAndNonce, &sender, &nonce, &t.data);
let params = ActionParams {
code_address: new_address.clone(),
code_hash: code_hash,

View File

@ -25,9 +25,7 @@ use rlp::Rlp;
use types::transaction::{self, SYSTEM_ADDRESS, UNSIGNED_SENDER, UnverifiedTransaction, SignedTransaction};
use types::BlockNumber;
use types::header::Header;
use vm::{CallType, ActionParams, ActionValue, ParamsType};
use vm::{EnvInfo, Schedule, CreateContractAddress};
use vm::{CallType, ActionParams, ActionValue, ParamsType, EnvInfo, Schedule};
use block::ExecutedBlock;
use builtin::Builtin;
use call_contract::CallContract;
@ -343,11 +341,6 @@ impl Machine {
}
}
/// Returns new contract address generation scheme at given block number.
pub fn create_address_scheme(&self, _number: BlockNumber) -> CreateContractAddress {
CreateContractAddress::FromSenderAndNonce
}
/// Verify a particular transaction is valid, regardless of order.
pub fn verify_transaction_unordered(&self, t: UnverifiedTransaction, _header: &Header) -> Result<SignedTransaction, transaction::Error> {
Ok(SignedTransaction::new(t)?)

View File

@ -60,6 +60,7 @@ use executed::ExecutionError;
use executive::contract_address;
use spec::Spec;
use account_state::State;
use vm::CreateContractAddress;
/// Different possible definitions for pending transaction set.
#[derive(Debug, PartialEq)]
@ -1220,7 +1221,7 @@ impl miner::MinerService for Miner {
Action::Call(_) => None,
Action::Create => {
let sender = tx.sender();
Some(contract_address(self.engine.create_address_scheme(pending.header.number()), &sender, &tx.nonce, &tx.data).0)
Some(contract_address(CreateContractAddress::FromSenderAndNonce, &sender, &tx.nonce, &tx.data).0)
}
},
logs: receipt.logs.clone(),