Move the substate module into ethcore/executive (#10867)
* substate is not a part of account-state * fn cleanup_mode is a part of executive.rs * test_cleanup_mode
This commit is contained in:
parent
f53c3e582c
commit
34cdeac2a6
3
Cargo.lock
generated
3
Cargo.lock
generated
@ -20,7 +20,6 @@ dependencies = [
|
||||
"common-types 0.1.0",
|
||||
"derive_more 0.15.0 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"ethereum-types 0.6.0 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"evm 0.1.0",
|
||||
"hash-db 0.12.4 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"journaldb 0.2.0",
|
||||
"keccak-hash 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
@ -40,7 +39,6 @@ dependencies = [
|
||||
"trace 0.1.0",
|
||||
"trie-db 0.12.4 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"trie-vm-factories 0.1.0",
|
||||
"vm 0.1.0",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
@ -2882,7 +2880,6 @@ dependencies = [
|
||||
"parity-updater 1.12.0",
|
||||
"parity-version 2.7.0",
|
||||
"parking_lot 0.8.0 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"patricia-trie-ethereum 0.1.0",
|
||||
"pretty_assertions 0.1.2 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"rand 0.6.1 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"rand_xorshift 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
|
@ -10,7 +10,6 @@ common-types = { path = "../types"}
|
||||
derive_more = "0.15.0"
|
||||
ethereum-types = "0.6.0"
|
||||
ethtrie = { package = "patricia-trie-ethereum", path = "../../util/patricia-trie-ethereum" }
|
||||
evm = { path = "../evm" }
|
||||
trie-vm-factories = { path = "../trie-vm-factories" }
|
||||
hash-db = "0.12.4"
|
||||
journaldb = { path = "../../util/journaldb" }
|
||||
@ -28,7 +27,6 @@ rlp = "0.4.0"
|
||||
serde = { version = "1.0", features = ["derive"] }
|
||||
trace = { path = "../trace" }
|
||||
trie-db = "0.12.4"
|
||||
vm = { path = "../vm" }
|
||||
|
||||
[dev-dependencies]
|
||||
account-db = { path = "../account-db" }
|
||||
|
@ -24,7 +24,6 @@
|
||||
|
||||
pub mod account;
|
||||
pub mod backend;
|
||||
pub mod substate;
|
||||
pub mod state;
|
||||
pub mod error;
|
||||
|
||||
@ -32,6 +31,5 @@ pub use {
|
||||
account::Account,
|
||||
backend::Backend,
|
||||
error::Error,
|
||||
substate::Substate,
|
||||
state::{State, CleanupMode},
|
||||
};
|
||||
|
@ -218,7 +218,7 @@ enum RequireCache {
|
||||
}
|
||||
|
||||
/// Mode of dealing with null accounts.
|
||||
#[derive(PartialEq)]
|
||||
#[derive(Debug, PartialEq)]
|
||||
pub enum CleanupMode<'a> {
|
||||
/// Create accounts which would be null.
|
||||
ForceCreate,
|
||||
|
@ -28,7 +28,8 @@ use trie_vm_factories::Factories;
|
||||
use evm::{VMType, FinalizationResult};
|
||||
use vm::{self, ActionParams};
|
||||
use ethtrie;
|
||||
use account_state::{CleanupMode, Substate, State};
|
||||
use account_state::{CleanupMode, State};
|
||||
use substate::Substate;
|
||||
|
||||
use executive_state::ExecutiveState;
|
||||
|
||||
|
@ -21,7 +21,8 @@ use std::sync::Arc;
|
||||
use hash::keccak;
|
||||
use ethereum_types::{H256, U256, U512, Address};
|
||||
use bytes::{Bytes, BytesRef};
|
||||
use account_state::{Backend as StateBackend, State, Substate, CleanupMode};
|
||||
use account_state::{Backend as StateBackend, State, CleanupMode};
|
||||
use substate::Substate;
|
||||
use executed::ExecutionError;
|
||||
use machine::Machine;
|
||||
use evm::{CallType, Finalize, FinalizationResult};
|
||||
@ -106,6 +107,15 @@ pub fn into_contract_create_result(result: vm::Result<FinalizationResult>, addre
|
||||
}
|
||||
}
|
||||
|
||||
/// Get the cleanup mode object from this.
|
||||
pub fn cleanup_mode<'a>(substate: &'a mut Substate, schedule: &Schedule) -> CleanupMode<'a> {
|
||||
match (schedule.kill_dust != CleanDustMode::Off, schedule.no_empty, schedule.kill_empty) {
|
||||
(false, false, _) => CleanupMode::ForceCreate,
|
||||
(false, true, false) => CleanupMode::NoEmpty,
|
||||
(false, true, true) | (true, _, _,) => CleanupMode::TrackTouched(&mut substate.touched),
|
||||
}
|
||||
}
|
||||
|
||||
/// Transaction execution options.
|
||||
#[derive(Copy, Clone, PartialEq)]
|
||||
pub struct TransactOptions<T, V> {
|
||||
@ -302,7 +312,7 @@ impl<'a> CallCreateExecutive<'a> {
|
||||
|
||||
fn transfer_exec_balance<B: 'a + StateBackend>(params: &ActionParams, schedule: &Schedule, state: &mut State<B>, substate: &mut Substate) -> vm::Result<()> {
|
||||
if let ActionValue::Transfer(val) = params.value {
|
||||
state.transfer_balance(¶ms.sender, ¶ms.address, &val, substate.to_cleanup_mode(&schedule))?;
|
||||
state.transfer_balance(¶ms.sender, ¶ms.address, &val, cleanup_mode(substate, &schedule))?;
|
||||
}
|
||||
|
||||
Ok(())
|
||||
@ -312,7 +322,7 @@ impl<'a> CallCreateExecutive<'a> {
|
||||
let nonce_offset = if schedule.no_empty { 1 } else { 0 }.into();
|
||||
let prev_bal = state.balance(¶ms.address)?;
|
||||
if let ActionValue::Transfer(val) = params.value {
|
||||
state.sub_balance(¶ms.sender, &val, &mut substate.to_cleanup_mode(&schedule))?;
|
||||
state.sub_balance(¶ms.sender, &val, &mut cleanup_mode(substate, &schedule))?;
|
||||
state.new_contract(¶ms.address, val.saturating_add(prev_bal), nonce_offset, params.code_version)?;
|
||||
} else {
|
||||
state.new_contract(¶ms.address, prev_bal, nonce_offset, params.code_version)?;
|
||||
@ -865,7 +875,11 @@ impl<'a, B: 'a + StateBackend> Executive<'a, B> {
|
||||
if !schedule.keep_unsigned_nonce || !t.is_unsigned() {
|
||||
self.state.inc_nonce(&sender)?;
|
||||
}
|
||||
self.state.sub_balance(&sender, &U256::try_from(gas_cost).expect("Total cost (value + gas_cost) is lower than max allowed balance (U256); gas_cost has to fit U256; qed"), &mut substate.to_cleanup_mode(&schedule))?;
|
||||
self.state.sub_balance(
|
||||
&sender,
|
||||
&U256::try_from(gas_cost).expect("Total cost (value + gas_cost) is lower than max allowed balance (U256); gas_cost has to fit U256; qed"),
|
||||
&mut cleanup_mode(&mut substate, &schedule)
|
||||
)?;
|
||||
|
||||
let (result, output) = match t.action {
|
||||
Action::Create => {
|
||||
@ -1142,7 +1156,7 @@ impl<'a, B: 'a + StateBackend> Executive<'a, B> {
|
||||
// Below: NoEmpty is safe since the sender must already be non-null to have sent this transaction
|
||||
self.state.add_balance(&sender, &refund_value, CleanupMode::NoEmpty)?;
|
||||
trace!("exec::finalize: Compensating author: fees_value={}, author={}\n", fees_value, &self.info.author);
|
||||
self.state.add_balance(&self.info.author, &fees_value, substate.to_cleanup_mode(&schedule))?;
|
||||
self.state.add_balance(&self.info.author, &fees_value, cleanup_mode(&mut substate, &schedule))?;
|
||||
|
||||
// perform suicides
|
||||
for address in &substate.suicides {
|
||||
@ -1194,6 +1208,7 @@ impl<'a, B: 'a + StateBackend> Executive<'a, B> {
|
||||
mod tests {
|
||||
use std::sync::Arc;
|
||||
use std::str::FromStr;
|
||||
use std::collections::HashSet;
|
||||
use rustc_hex::FromHex;
|
||||
use ethkey::{Generator, Random};
|
||||
use super::*;
|
||||
@ -1202,7 +1217,8 @@ mod tests {
|
||||
use evm::{Factory, VMType};
|
||||
use error::ExecutionError;
|
||||
use machine::Machine;
|
||||
use account_state::{Substate, CleanupMode};
|
||||
use account_state::CleanupMode;
|
||||
use substate::Substate;
|
||||
use test_helpers::{get_temp_state_with_factory, get_temp_state};
|
||||
use trace::trace;
|
||||
use trace::{FlatTrace, Tracer, NoopTracer, ExecutiveTracer};
|
||||
@ -1221,6 +1237,33 @@ mod tests {
|
||||
machine
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_cleanup_mode() {
|
||||
let address = Address::from_str("0f572e5295c57f15886f9b263e2f6d2d6c7b5ec6").unwrap();
|
||||
let mut touched = HashSet::new();
|
||||
touched.insert(address);
|
||||
|
||||
let mut substate = Substate::default();
|
||||
substate.touched = touched.clone();
|
||||
|
||||
assert_eq!(CleanupMode::ForceCreate, cleanup_mode(&mut substate, &Schedule::new_frontier()));
|
||||
assert_eq!(CleanupMode::ForceCreate, cleanup_mode(&mut substate, &Schedule::new_homestead()));
|
||||
assert_eq!(CleanupMode::TrackTouched(&mut touched), cleanup_mode(&mut substate, &Schedule::new_byzantium()));
|
||||
assert_eq!(CleanupMode::TrackTouched(&mut touched), cleanup_mode(&mut substate, &Schedule::new_constantinople()));
|
||||
|
||||
assert_eq!(CleanupMode::TrackTouched(&mut touched), cleanup_mode(&mut substate, &{
|
||||
let mut schedule = Schedule::new_homestead();
|
||||
schedule.kill_dust = CleanDustMode::BasicOnly;
|
||||
schedule
|
||||
}));
|
||||
|
||||
assert_eq!(CleanupMode::NoEmpty, cleanup_mode(&mut substate, &{
|
||||
let mut schedule = Schedule::new_homestead();
|
||||
schedule.no_empty = true;
|
||||
schedule
|
||||
}));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_contract_address() {
|
||||
let address = Address::from_str("0f572e5295c57f15886f9b263e2f6d2d6c7b5ec6").unwrap();
|
||||
|
@ -19,7 +19,8 @@ use std::cmp;
|
||||
use std::sync::Arc;
|
||||
use ethereum_types::{H256, U256, Address, BigEndianHash};
|
||||
use bytes::Bytes;
|
||||
use account_state::{Backend as StateBackend, State, Substate, CleanupMode};
|
||||
use account_state::{Backend as StateBackend, State, CleanupMode};
|
||||
use substate::Substate;
|
||||
use machine::Machine;
|
||||
use executive::*;
|
||||
use vm::{
|
||||
@ -388,7 +389,7 @@ impl<'a, T: 'a, V: 'a, B: 'a> Ext for Externalities<'a, T, V, B>
|
||||
&address,
|
||||
refund_address,
|
||||
&balance,
|
||||
self.substate.to_cleanup_mode(&self.schedule)
|
||||
cleanup_mode(&mut self.substate, &self.schedule)
|
||||
)?;
|
||||
}
|
||||
|
||||
@ -435,7 +436,8 @@ impl<'a, T: 'a, V: 'a, B: 'a> Ext for Externalities<'a, T, V, B>
|
||||
mod tests {
|
||||
use ethereum_types::{U256, Address};
|
||||
use evm::{EnvInfo, Ext, CallType};
|
||||
use account_state::{State, Substate};
|
||||
use account_state::State;
|
||||
use substate::Substate;
|
||||
use test_helpers::get_temp_state;
|
||||
use super::*;
|
||||
use trace::{NoopTracer, NoopVMTracer};
|
||||
|
@ -17,7 +17,8 @@
|
||||
use std::path::Path;
|
||||
use std::sync::Arc;
|
||||
use super::test_common::*;
|
||||
use account_state::{Backend as StateBackend, State, Substate};
|
||||
use account_state::{Backend as StateBackend, State};
|
||||
use substate::Substate;
|
||||
use executive::*;
|
||||
use evm::{VMType, Finalize};
|
||||
use vm::{
|
||||
|
@ -164,6 +164,7 @@ pub mod spec;
|
||||
pub mod verification;
|
||||
|
||||
mod externalities;
|
||||
mod substate;
|
||||
mod transaction_ext;
|
||||
mod tx_filter;
|
||||
|
||||
|
@ -35,7 +35,8 @@ use client::BlockInfo;
|
||||
use error::Error;
|
||||
use executive::Executive;
|
||||
use spec::CommonParams;
|
||||
use account_state::{CleanupMode, Substate};
|
||||
use account_state::CleanupMode;
|
||||
use substate::Substate;
|
||||
use trace::{NoopTracer, NoopVMTracer};
|
||||
use tx_filter::TransactionFilter;
|
||||
|
||||
|
@ -45,7 +45,8 @@ use machine::Machine;
|
||||
use pod::PodState;
|
||||
use spec::Genesis;
|
||||
use spec::seal::Generic as GenericSeal;
|
||||
use account_state::{Backend, State, Substate, backend::Basic as BasicBackend};
|
||||
use account_state::{Backend, State, backend::Basic as BasicBackend};
|
||||
use substate::Substate;
|
||||
use trace::{NoopTracer, NoopVMTracer};
|
||||
|
||||
pub use ethash::OptimizeFor;
|
||||
|
@ -16,12 +16,8 @@
|
||||
|
||||
//! Execution environment substate.
|
||||
use std::collections::HashSet;
|
||||
|
||||
use common_types::log_entry::LogEntry;
|
||||
use ethereum_types::Address;
|
||||
use evm::{CleanDustMode, Schedule};
|
||||
|
||||
use crate::state::CleanupMode;
|
||||
use types::log_entry::LogEntry;
|
||||
|
||||
/// State changes which should be applied in finalize,
|
||||
/// after transaction is fully executed.
|
||||
@ -57,21 +53,12 @@ impl Substate {
|
||||
self.sstore_clears_refund += s.sstore_clears_refund;
|
||||
self.contracts_created.extend(s.contracts_created);
|
||||
}
|
||||
|
||||
/// Get the cleanup mode object from this.
|
||||
pub fn to_cleanup_mode(&mut self, schedule: &Schedule) -> CleanupMode {
|
||||
match (schedule.kill_dust != CleanDustMode::Off, schedule.no_empty, schedule.kill_empty) {
|
||||
(false, false, _) => CleanupMode::ForceCreate,
|
||||
(false, true, false) => CleanupMode::NoEmpty,
|
||||
(false, true, true) | (true, _, _,) => CleanupMode::TrackTouched(&mut self.touched),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use common_types::log_entry::LogEntry;
|
||||
use ethereum_types::Address;
|
||||
use types::log_entry::LogEntry;
|
||||
use super::Substate;
|
||||
|
||||
#[test]
|
@ -21,7 +21,7 @@ use hash::keccak;
|
||||
use vm::{EnvInfo, ActionParams, ActionValue, CallType, ParamsType};
|
||||
use evm::{Factory, VMType};
|
||||
use executive::Executive;
|
||||
use account_state::Substate;
|
||||
use substate::Substate;
|
||||
use test_helpers::get_temp_state_with_factory;
|
||||
use trace::{NoopVMTracer, NoopTracer};
|
||||
use types::transaction::SYSTEM_ADDRESS;
|
||||
|
@ -25,7 +25,6 @@ use ethjson;
|
||||
use pod::PodState;
|
||||
use types::transaction;
|
||||
use vm::ActionParams;
|
||||
use account_state::State;
|
||||
|
||||
/// VM execution informant
|
||||
pub trait Informant: trace::VMTracer {
|
||||
|
@ -70,7 +70,6 @@ ethcore = { path = "../ethcore", features = ["test-helpers"] }
|
||||
ethcore-accounts = { path = "../accounts" }
|
||||
ethcore-io = { path = "../util/io" }
|
||||
ethcore-network = { path = "../util/network" }
|
||||
patricia-trie-ethereum = { path = "../util/patricia-trie-ethereum" }
|
||||
fake-fetch = { path = "../util/fake-fetch" }
|
||||
macros = { path = "../util/macros" }
|
||||
pretty_assertions = "0.1"
|
||||
|
@ -105,8 +105,6 @@ extern crate rand_xorshift;
|
||||
#[cfg(test)]
|
||||
extern crate ethjson;
|
||||
#[cfg(test)]
|
||||
extern crate patricia_trie_ethereum as ethtrie;
|
||||
#[cfg(test)]
|
||||
extern crate transaction_pool as txpool;
|
||||
|
||||
#[cfg(test)]
|
||||
|
@ -26,11 +26,9 @@ use ethcore::engines::{Engine, signer::EngineSigner};
|
||||
use ethcore::error::Error;
|
||||
use ethcore::miner::{self, MinerService, AuthoringParams, FilterOptions};
|
||||
use ethereum_types::{H256, U256, Address};
|
||||
use ethtrie;
|
||||
use miner::pool::local_transactions::Status as LocalTransactionStatus;
|
||||
use miner::pool::{verifier, VerifiedTransaction, QueueStatus};
|
||||
use parking_lot::{RwLock, Mutex};
|
||||
use account_state::state::StateInfo;
|
||||
use types::transaction::{self, UnverifiedTransaction, SignedTransaction, PendingTransaction};
|
||||
use txpool;
|
||||
use types::BlockNumber;
|
||||
|
Loading…
Reference in New Issue
Block a user