2016-12-11 19:14:42 +01:00
|
|
|
// Copyright 2015, 2016 Parity Technologies (UK) Ltd.
|
2016-02-05 13:40:41 +01:00
|
|
|
// This file is part of Parity.
|
|
|
|
|
|
|
|
// Parity is free software: you can redistribute it and/or modify
|
|
|
|
// it under the terms of the GNU General Public License as published by
|
|
|
|
// the Free Software Foundation, either version 3 of the License, or
|
|
|
|
// (at your option) any later version.
|
|
|
|
|
|
|
|
// Parity is distributed in the hope that it will be useful,
|
|
|
|
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
// GNU General Public License for more details.
|
|
|
|
|
|
|
|
// You should have received a copy of the GNU General Public License
|
|
|
|
// along with Parity. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
|
2016-08-03 18:35:48 +02:00
|
|
|
use std::cell::{RefCell, RefMut};
|
2016-10-06 01:53:23 +02:00
|
|
|
use std::collections::hash_map::Entry;
|
2016-11-15 14:53:30 +01:00
|
|
|
|
2016-10-24 18:35:25 +02:00
|
|
|
use receipt::Receipt;
|
2016-07-28 20:32:20 +02:00
|
|
|
use engines::Engine;
|
2016-10-24 18:35:25 +02:00
|
|
|
use env_info::EnvInfo;
|
|
|
|
use error::Error;
|
2016-04-06 13:05:58 +02:00
|
|
|
use executive::{Executive, TransactOptions};
|
2016-08-24 16:53:36 +02:00
|
|
|
use factory::Factories;
|
2016-07-28 20:31:29 +02:00
|
|
|
use trace::FlatTrace;
|
2016-01-14 16:46:32 +01:00
|
|
|
use pod_account::*;
|
2016-05-31 21:03:44 +02:00
|
|
|
use pod_state::{self, PodState};
|
|
|
|
use types::state_diff::StateDiff;
|
2016-10-24 18:35:25 +02:00
|
|
|
use transaction::SignedTransaction;
|
2016-09-27 18:02:11 +02:00
|
|
|
use state_db::StateDB;
|
2015-12-19 22:15:22 +01:00
|
|
|
|
2016-11-15 14:53:30 +01:00
|
|
|
use util::*;
|
2016-12-07 10:50:18 +01:00
|
|
|
|
2016-11-15 14:53:30 +01:00
|
|
|
use util::trie::recorder::{Recorder, BasicRecorder as TrieRecorder};
|
|
|
|
|
2016-08-18 15:24:27 +02:00
|
|
|
mod account;
|
|
|
|
mod substate;
|
|
|
|
|
|
|
|
pub use self::account::Account;
|
|
|
|
pub use self::substate::Substate;
|
|
|
|
|
2016-03-19 12:54:34 +01:00
|
|
|
/// Used to return information about an `State::apply` operation.
|
|
|
|
pub struct ApplyOutcome {
|
|
|
|
/// The receipt for the applied transaction.
|
|
|
|
pub receipt: Receipt,
|
|
|
|
/// The trace for the applied transaction, if None if tracing is disabled.
|
2016-07-28 20:31:29 +02:00
|
|
|
pub trace: Vec<FlatTrace>,
|
2016-03-19 12:54:34 +01:00
|
|
|
}
|
|
|
|
|
2016-02-03 13:20:32 +01:00
|
|
|
/// Result type for the execution ("application") of a transaction.
|
2016-03-19 12:54:34 +01:00
|
|
|
pub type ApplyResult = Result<ApplyOutcome, Error>;
|
2015-12-13 21:36:17 +01:00
|
|
|
|
2016-10-06 01:53:23 +02:00
|
|
|
#[derive(Eq, PartialEq, Clone, Copy, Debug)]
|
|
|
|
/// Account modification state. Used to check if the account was
|
|
|
|
/// Modified in between commits and overall.
|
|
|
|
enum AccountState {
|
2016-10-07 12:10:12 +02:00
|
|
|
/// Account was loaded from disk and never modified in this state object.
|
|
|
|
CleanFresh,
|
|
|
|
/// Account was loaded from the global cache and never modified.
|
|
|
|
CleanCached,
|
2016-10-06 01:53:23 +02:00
|
|
|
/// Account has been modified and is not committed to the trie yet.
|
2016-10-07 12:10:12 +02:00
|
|
|
/// This is set if any of the account data is changed, including
|
2016-10-06 01:53:23 +02:00
|
|
|
/// storage and code.
|
|
|
|
Dirty,
|
|
|
|
/// Account was modified and committed to the trie.
|
2016-10-07 12:10:12 +02:00
|
|
|
Committed,
|
2016-10-06 01:53:23 +02:00
|
|
|
}
|
|
|
|
|
2016-09-27 18:02:11 +02:00
|
|
|
#[derive(Debug)]
|
2016-10-06 01:53:23 +02:00
|
|
|
/// In-memory copy of the account data. Holds the optional account
|
|
|
|
/// and the modification status.
|
|
|
|
/// Account entry can contain existing (`Some`) or non-existing
|
|
|
|
/// account (`None`)
|
|
|
|
struct AccountEntry {
|
|
|
|
account: Option<Account>,
|
|
|
|
state: AccountState,
|
2016-09-27 18:02:11 +02:00
|
|
|
}
|
|
|
|
|
2016-10-06 01:53:23 +02:00
|
|
|
// Account cache item. Contains account data and
|
|
|
|
// modification state
|
2016-09-27 18:02:11 +02:00
|
|
|
impl AccountEntry {
|
|
|
|
fn is_dirty(&self) -> bool {
|
2016-10-06 01:53:23 +02:00
|
|
|
self.state == AccountState::Dirty
|
2016-09-27 18:02:11 +02:00
|
|
|
}
|
|
|
|
|
2016-10-06 01:53:23 +02:00
|
|
|
/// Clone dirty data into new `AccountEntry`. This includes
|
|
|
|
/// basic account data and modified storage keys.
|
2016-09-27 18:02:11 +02:00
|
|
|
/// Returns None if clean.
|
2016-10-06 01:53:23 +02:00
|
|
|
fn clone_if_dirty(&self) -> Option<AccountEntry> {
|
|
|
|
match self.is_dirty() {
|
|
|
|
true => Some(self.clone_dirty()),
|
|
|
|
false => None,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/// Clone dirty data into new `AccountEntry`. This includes
|
|
|
|
/// basic account data and modified storage keys.
|
|
|
|
fn clone_dirty(&self) -> AccountEntry {
|
|
|
|
AccountEntry {
|
|
|
|
account: self.account.as_ref().map(Account::clone_dirty),
|
|
|
|
state: self.state,
|
2016-09-27 18:02:11 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-10-06 15:54:05 +02:00
|
|
|
// Create a new account entry and mark it as dirty.
|
2016-10-06 01:53:23 +02:00
|
|
|
fn new_dirty(account: Option<Account>) -> AccountEntry {
|
|
|
|
AccountEntry {
|
|
|
|
account: account,
|
|
|
|
state: AccountState::Dirty,
|
|
|
|
}
|
|
|
|
}
|
2016-10-06 15:54:05 +02:00
|
|
|
|
|
|
|
// Create a new account entry and mark it as clean.
|
2016-10-06 01:53:23 +02:00
|
|
|
fn new_clean(account: Option<Account>) -> AccountEntry {
|
|
|
|
AccountEntry {
|
|
|
|
account: account,
|
2016-10-07 12:10:12 +02:00
|
|
|
state: AccountState::CleanFresh,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Create a new account entry and mark it as clean and cached.
|
|
|
|
fn new_clean_cached(account: Option<Account>) -> AccountEntry {
|
|
|
|
AccountEntry {
|
|
|
|
account: account,
|
|
|
|
state: AccountState::CleanCached,
|
2016-09-27 18:02:11 +02:00
|
|
|
}
|
|
|
|
}
|
2016-10-06 15:54:05 +02:00
|
|
|
|
|
|
|
// Replace data with another entry but preserve storage cache.
|
|
|
|
fn overwrite_with(&mut self, other: AccountEntry) {
|
|
|
|
self.state = other.state;
|
|
|
|
match other.account {
|
2016-10-27 08:28:12 +02:00
|
|
|
Some(acc) => {
|
|
|
|
if let Some(ref mut ours) = self.account {
|
2016-10-06 15:54:05 +02:00
|
|
|
ours.overwrite_with(acc);
|
2016-10-27 08:28:12 +02:00
|
|
|
}
|
2016-10-06 15:54:05 +02:00
|
|
|
},
|
|
|
|
None => self.account = None,
|
|
|
|
}
|
|
|
|
}
|
2016-09-27 18:02:11 +02:00
|
|
|
}
|
|
|
|
|
2015-12-13 23:12:22 +01:00
|
|
|
/// Representation of the entire state of all accounts in the system.
|
2016-09-27 18:02:11 +02:00
|
|
|
///
|
|
|
|
/// `State` can work together with `StateDB` to share account cache.
|
|
|
|
///
|
|
|
|
/// Local cache contains changes made locally and changes accumulated
|
|
|
|
/// locally from previous commits. Global cache reflects the database
|
|
|
|
/// state and never contains any changes.
|
|
|
|
///
|
2016-10-06 01:53:23 +02:00
|
|
|
/// Cache items contains account data, or the flag that account does not exist
|
|
|
|
/// and modification state (see `AccountState`)
|
|
|
|
///
|
2016-09-27 18:02:11 +02:00
|
|
|
/// Account data can be in the following cache states:
|
|
|
|
/// * In global but not local - something that was queried from the database,
|
|
|
|
/// but never modified
|
|
|
|
/// * In local but not global - something that was just added (e.g. new account)
|
|
|
|
/// * In both with the same value - something that was changed to a new value,
|
|
|
|
/// but changed back to a previous block in the same block (same State instance)
|
|
|
|
/// * In both with different values - something that was overwritten with a
|
|
|
|
/// new value.
|
|
|
|
///
|
|
|
|
/// All read-only state queries check local cache/modifications first,
|
|
|
|
/// then global state cache. If data is not found in any of the caches
|
|
|
|
/// it is loaded from the DB to the local cache.
|
|
|
|
///
|
2016-10-06 01:53:23 +02:00
|
|
|
/// **** IMPORTANT *************************************************************
|
|
|
|
/// All the modifications to the account data must set the `Dirty` state in the
|
|
|
|
/// `AccountEntry`. This is done in `require` and `require_or_from`. So just
|
|
|
|
/// use that.
|
|
|
|
/// ****************************************************************************
|
|
|
|
///
|
2016-10-07 13:34:32 +02:00
|
|
|
/// Upon destruction all the local cache data propagated into the global cache.
|
|
|
|
/// Propagated items might be rejected if current state is non-canonical.
|
2016-10-06 15:54:05 +02:00
|
|
|
///
|
2016-10-22 15:22:16 +02:00
|
|
|
/// State checkpointing.
|
2016-10-06 15:54:05 +02:00
|
|
|
///
|
2016-10-22 15:22:16 +02:00
|
|
|
/// A new checkpoint can be created with `checkpoint()`. checkpoints can be
|
2016-10-06 15:54:05 +02:00
|
|
|
/// created in a hierarchy.
|
2016-10-22 15:22:16 +02:00
|
|
|
/// When a checkpoint is active all changes are applied directly into
|
|
|
|
/// `cache` and the original value is copied into an active checkpoint.
|
|
|
|
/// Reverting a checkpoint with `revert_to_checkpoint` involves copying
|
|
|
|
/// original values from the latest checkpoint back into `cache`. The code
|
2016-10-06 15:54:05 +02:00
|
|
|
/// takes care not to overwrite cached storage while doing that.
|
2016-10-22 15:22:16 +02:00
|
|
|
/// checkpoint can be discateded with `discard_checkpoint`. All of the orignal
|
|
|
|
/// backed-up values are moved into a parent checkpoint (if any).
|
2016-10-06 15:54:05 +02:00
|
|
|
///
|
2015-12-13 21:36:17 +01:00
|
|
|
pub struct State {
|
2016-09-27 18:02:11 +02:00
|
|
|
db: StateDB,
|
2015-12-13 21:36:17 +01:00
|
|
|
root: H256,
|
2016-09-27 18:02:11 +02:00
|
|
|
cache: RefCell<HashMap<Address, AccountEntry>>,
|
2016-10-06 15:54:05 +02:00
|
|
|
// The original account is preserved in
|
2016-10-22 15:22:16 +02:00
|
|
|
checkpoints: RefCell<Vec<HashMap<Address, Option<AccountEntry>>>>,
|
2015-12-19 22:15:22 +01:00
|
|
|
account_start_nonce: U256,
|
2016-08-24 16:53:36 +02:00
|
|
|
factories: Factories,
|
2015-12-13 21:36:17 +01:00
|
|
|
}
|
|
|
|
|
2016-09-27 18:02:11 +02:00
|
|
|
#[derive(Copy, Clone)]
|
|
|
|
enum RequireCache {
|
|
|
|
None,
|
|
|
|
CodeSize,
|
|
|
|
Code,
|
|
|
|
}
|
|
|
|
|
2016-11-03 22:22:25 +01:00
|
|
|
#[derive(PartialEq)]
|
|
|
|
pub enum CleanupMode<'a> {
|
|
|
|
ForceCreate,
|
|
|
|
NoEmpty,
|
|
|
|
KillEmpty(&'a mut HashSet<Address>),
|
|
|
|
}
|
|
|
|
|
2016-06-07 20:44:09 +02:00
|
|
|
const SEC_TRIE_DB_UNWRAP_STR: &'static str = "A state can only be created with valid root. Creating a SecTrieDB with a valid root will not fail. \
|
|
|
|
Therefore creating a SecTrieDB with this state's root will not fail.";
|
|
|
|
|
2015-12-13 21:36:17 +01:00
|
|
|
impl State {
|
|
|
|
/// Creates new state with empty state root
|
2016-02-02 23:45:50 +01:00
|
|
|
#[cfg(test)]
|
2016-09-27 18:02:11 +02:00
|
|
|
pub fn new(mut db: StateDB, account_start_nonce: U256, factories: Factories) -> State {
|
2015-12-13 21:36:17 +01:00
|
|
|
let mut root = H256::new();
|
|
|
|
{
|
|
|
|
// init trie and reset root too null
|
2016-08-24 16:53:36 +02:00
|
|
|
let _ = factories.trie.create(db.as_hashdb_mut(), &mut root);
|
2015-12-13 21:36:17 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
State {
|
|
|
|
db: db,
|
|
|
|
root: root,
|
2015-12-19 22:15:22 +01:00
|
|
|
cache: RefCell::new(HashMap::new()),
|
2016-10-22 15:22:16 +02:00
|
|
|
checkpoints: RefCell::new(Vec::new()),
|
2015-12-19 22:15:22 +01:00
|
|
|
account_start_nonce: account_start_nonce,
|
2016-08-24 16:53:36 +02:00
|
|
|
factories: factories,
|
2015-12-13 21:36:17 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/// Creates new state with existing state root
|
2016-09-27 18:02:11 +02:00
|
|
|
pub fn from_existing(db: StateDB, root: H256, account_start_nonce: U256, factories: Factories) -> Result<State, TrieError> {
|
2016-06-07 20:44:09 +02:00
|
|
|
if !db.as_hashdb().contains(&root) {
|
2016-08-03 18:35:48 +02:00
|
|
|
return Err(TrieError::InvalidStateRoot(root));
|
2015-12-13 21:36:17 +01:00
|
|
|
}
|
2016-07-01 20:29:56 +02:00
|
|
|
|
|
|
|
let state = State {
|
|
|
|
db: db,
|
|
|
|
root: root,
|
|
|
|
cache: RefCell::new(HashMap::new()),
|
2016-10-22 15:22:16 +02:00
|
|
|
checkpoints: RefCell::new(Vec::new()),
|
2016-07-01 20:29:56 +02:00
|
|
|
account_start_nonce: account_start_nonce,
|
2016-08-24 16:53:36 +02:00
|
|
|
factories: factories
|
2016-07-01 20:29:56 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
Ok(state)
|
2015-12-13 21:36:17 +01:00
|
|
|
}
|
|
|
|
|
2016-10-22 15:22:16 +02:00
|
|
|
/// Create a recoverable checkpoint of this state.
|
|
|
|
pub fn checkpoint(&mut self) {
|
|
|
|
self.checkpoints.get_mut().push(HashMap::new());
|
2016-02-03 19:34:51 +01:00
|
|
|
}
|
|
|
|
|
2016-10-22 15:22:16 +02:00
|
|
|
/// Merge last checkpoint with previous.
|
|
|
|
pub fn discard_checkpoint(&mut self) {
|
|
|
|
// merge with previous checkpoint
|
|
|
|
let last = self.checkpoints.get_mut().pop();
|
|
|
|
if let Some(mut checkpoint) = last {
|
|
|
|
if let Some(ref mut prev) = self.checkpoints.get_mut().last_mut() {
|
2016-10-06 15:54:05 +02:00
|
|
|
if prev.is_empty() {
|
2016-10-22 15:22:16 +02:00
|
|
|
**prev = checkpoint;
|
2016-10-06 15:54:05 +02:00
|
|
|
} else {
|
2016-10-22 15:22:16 +02:00
|
|
|
for (k, v) in checkpoint.drain() {
|
2016-10-06 15:54:05 +02:00
|
|
|
prev.entry(k).or_insert(v);
|
|
|
|
}
|
2016-02-03 19:34:51 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-10-22 15:22:16 +02:00
|
|
|
/// Revert to the last checkpoint and discard it.
|
|
|
|
pub fn revert_to_checkpoint(&mut self) {
|
|
|
|
if let Some(mut checkpoint) = self.checkpoints.get_mut().pop() {
|
|
|
|
for (k, v) in checkpoint.drain() {
|
2016-02-03 19:34:51 +01:00
|
|
|
match v {
|
|
|
|
Some(v) => {
|
2016-10-13 23:28:56 +02:00
|
|
|
match self.cache.get_mut().entry(k) {
|
2016-10-06 15:54:05 +02:00
|
|
|
Entry::Occupied(mut e) => {
|
2016-10-22 15:22:16 +02:00
|
|
|
// Merge checkpointed changes back into the main account
|
2016-10-06 15:54:05 +02:00
|
|
|
// storage preserving the cache.
|
|
|
|
e.get_mut().overwrite_with(v);
|
|
|
|
},
|
|
|
|
Entry::Vacant(e) => {
|
|
|
|
e.insert(v);
|
|
|
|
}
|
|
|
|
}
|
2016-02-03 19:34:51 +01:00
|
|
|
},
|
|
|
|
None => {
|
2016-10-27 08:28:12 +02:00
|
|
|
if let Entry::Occupied(e) = self.cache.get_mut().entry(k) {
|
|
|
|
if e.get().is_dirty() {
|
|
|
|
e.remove();
|
|
|
|
}
|
2016-09-27 18:02:11 +02:00
|
|
|
}
|
2016-02-03 19:34:51 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-09-27 18:02:11 +02:00
|
|
|
fn insert_cache(&self, address: &Address, account: AccountEntry) {
|
2016-10-06 01:53:23 +02:00
|
|
|
// Dirty account which is not in the cache means this is a new account.
|
2016-10-22 15:22:16 +02:00
|
|
|
// It goes directly into the checkpoint as there's nothing to rever to.
|
2016-10-06 01:53:23 +02:00
|
|
|
//
|
|
|
|
// In all other cases account is read as clean first, and after that made
|
2016-10-22 15:22:16 +02:00
|
|
|
// dirty in and added to the checkpoint with `note_cache`.
|
2016-10-06 01:53:23 +02:00
|
|
|
if account.is_dirty() {
|
2016-10-22 15:22:16 +02:00
|
|
|
if let Some(ref mut checkpoint) = self.checkpoints.borrow_mut().last_mut() {
|
|
|
|
if !checkpoint.contains_key(address) {
|
|
|
|
checkpoint.insert(address.clone(), self.cache.borrow_mut().insert(address.clone(), account));
|
2016-10-06 01:53:23 +02:00
|
|
|
return;
|
|
|
|
}
|
2016-02-03 19:34:51 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
self.cache.borrow_mut().insert(address.clone(), account);
|
|
|
|
}
|
|
|
|
|
|
|
|
fn note_cache(&self, address: &Address) {
|
2016-10-22 15:22:16 +02:00
|
|
|
if let Some(ref mut checkpoint) = self.checkpoints.borrow_mut().last_mut() {
|
|
|
|
if !checkpoint.contains_key(address) {
|
|
|
|
checkpoint.insert(address.clone(), self.cache.borrow().get(address).map(AccountEntry::clone_dirty));
|
2016-02-03 19:34:51 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-12-16 20:02:28 +01:00
|
|
|
/// Destroy the current object and return root and database.
|
2016-09-27 18:02:11 +02:00
|
|
|
pub fn drop(mut self) -> (H256, StateDB) {
|
2016-10-07 13:34:32 +02:00
|
|
|
self.propagate_to_global_cache();
|
2015-12-19 19:03:42 +01:00
|
|
|
(self.root, self.db)
|
2015-12-16 20:02:28 +01:00
|
|
|
}
|
|
|
|
|
2015-12-19 22:15:22 +01:00
|
|
|
/// Return reference to root
|
|
|
|
pub fn root(&self) -> &H256 {
|
|
|
|
&self.root
|
|
|
|
}
|
|
|
|
|
2016-01-09 14:19:35 +01:00
|
|
|
/// Create a new contract at address `contract`. If there is already an account at the address
|
|
|
|
/// it will have its code reset, ready for `init_code()`.
|
2016-11-03 22:22:25 +01:00
|
|
|
pub fn new_contract(&mut self, contract: &Address, balance: U256, nonce_offset: U256) {
|
|
|
|
self.insert_cache(contract, AccountEntry::new_dirty(Some(Account::new_contract(balance, self.account_start_nonce + nonce_offset))));
|
2016-01-09 14:19:35 +01:00
|
|
|
}
|
|
|
|
|
2016-01-09 22:28:31 +01:00
|
|
|
/// Remove an existing account.
|
|
|
|
pub fn kill_account(&mut self, account: &Address) {
|
2016-10-06 01:53:23 +02:00
|
|
|
self.insert_cache(account, AccountEntry::new_dirty(None));
|
2016-01-09 22:28:31 +01:00
|
|
|
}
|
|
|
|
|
2016-01-12 12:34:14 +01:00
|
|
|
/// Determine whether an account exists.
|
|
|
|
pub fn exists(&self, a: &Address) -> bool {
|
2016-10-20 16:49:27 +02:00
|
|
|
// Bloom filter does not contain empty accounts, so it is important here to
|
2016-11-03 22:22:25 +01:00
|
|
|
// check if account exists in the database directly before EIP-161 is in effect.
|
2016-10-20 16:49:27 +02:00
|
|
|
self.ensure_cached(a, RequireCache::None, false, |a| a.is_some())
|
2016-01-12 12:34:14 +01:00
|
|
|
}
|
|
|
|
|
2016-11-03 22:22:25 +01:00
|
|
|
/// Determine whether an account exists and if not empty.
|
|
|
|
pub fn exists_and_not_null(&self, a: &Address) -> bool {
|
|
|
|
self.ensure_cached(a, RequireCache::None, false, |a| a.map_or(false, |a| !a.is_null()))
|
|
|
|
}
|
|
|
|
|
2015-12-16 18:20:23 +01:00
|
|
|
/// Get the balance of account `a`.
|
2015-12-19 22:15:22 +01:00
|
|
|
pub fn balance(&self, a: &Address) -> U256 {
|
2016-10-20 16:49:27 +02:00
|
|
|
self.ensure_cached(a, RequireCache::None, true,
|
2016-07-30 15:45:16 +02:00
|
|
|
|a| a.as_ref().map_or(U256::zero(), |account| *account.balance()))
|
2015-12-16 18:20:23 +01:00
|
|
|
}
|
|
|
|
|
2015-12-19 22:15:22 +01:00
|
|
|
/// Get the nonce of account `a`.
|
|
|
|
pub fn nonce(&self, a: &Address) -> U256 {
|
2016-10-20 16:49:27 +02:00
|
|
|
self.ensure_cached(a, RequireCache::None, true,
|
2016-08-04 18:17:39 +02:00
|
|
|
|a| a.as_ref().map_or(self.account_start_nonce, |account| *account.nonce()))
|
2015-12-19 22:15:22 +01:00
|
|
|
}
|
|
|
|
|
2016-11-27 11:11:56 +01:00
|
|
|
/// Get the storage root of account `a`.
|
|
|
|
pub fn storage_root(&self, a: &Address) -> Option<H256> {
|
|
|
|
self.ensure_cached(a, RequireCache::None, true,
|
|
|
|
|a| a.as_ref().and_then(|account| account.storage_root().cloned()))
|
|
|
|
}
|
|
|
|
|
2016-02-05 13:06:40 +01:00
|
|
|
/// Mutate storage of account `address` so that it is `value` for `key`.
|
2016-02-04 02:40:35 +01:00
|
|
|
pub fn storage_at(&self, address: &Address, key: &H256) -> H256 {
|
2016-09-27 18:02:11 +02:00
|
|
|
// Storage key search and update works like this:
|
|
|
|
// 1. If there's an entry for the account in the local cache check for the key and return it if found.
|
|
|
|
// 2. If there's an entry for the account in the global cache check for the key or load it into that account.
|
|
|
|
// 3. If account is missing in the global cache load it into the local cache and cache the key there.
|
|
|
|
|
|
|
|
// check local cache first without updating
|
|
|
|
{
|
|
|
|
let local_cache = self.cache.borrow_mut();
|
|
|
|
let mut local_account = None;
|
|
|
|
if let Some(maybe_acc) = local_cache.get(address) {
|
2016-10-06 01:53:23 +02:00
|
|
|
match maybe_acc.account {
|
|
|
|
Some(ref account) => {
|
2016-09-27 18:02:11 +02:00
|
|
|
if let Some(value) = account.cached_storage_at(key) {
|
|
|
|
return value;
|
|
|
|
} else {
|
|
|
|
local_account = Some(maybe_acc);
|
|
|
|
}
|
|
|
|
},
|
|
|
|
_ => return H256::new(),
|
|
|
|
}
|
|
|
|
}
|
|
|
|
// check the global cache and and cache storage key there if found,
|
|
|
|
// otherwise cache the account localy and cache storage key there.
|
|
|
|
if let Some(result) = self.db.get_cached(address, |acc| acc.map_or(H256::new(), |a| {
|
|
|
|
let account_db = self.factories.accountdb.readonly(self.db.as_hashdb(), a.address_hash(address));
|
|
|
|
a.storage_at(account_db.as_hashdb(), key)
|
|
|
|
})) {
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
if let Some(ref mut acc) = local_account {
|
2016-10-06 01:53:23 +02:00
|
|
|
if let Some(ref account) = acc.account {
|
2016-09-27 18:02:11 +02:00
|
|
|
let account_db = self.factories.accountdb.readonly(self.db.as_hashdb(), account.address_hash(address));
|
|
|
|
return account.storage_at(account_db.as_hashdb(), key)
|
|
|
|
} else {
|
|
|
|
return H256::new()
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2016-10-03 12:02:43 +02:00
|
|
|
|
|
|
|
// check bloom before any requests to trie
|
2016-11-03 22:22:25 +01:00
|
|
|
if !self.db.check_non_null_bloom(address) { return H256::zero() }
|
2016-10-03 12:02:43 +02:00
|
|
|
|
2016-09-27 18:02:11 +02:00
|
|
|
// account is not found in the global cache, get from the DB and insert into local
|
|
|
|
let db = self.factories.trie.readonly(self.db.as_hashdb(), &self.root).expect(SEC_TRIE_DB_UNWRAP_STR);
|
|
|
|
let maybe_acc = match db.get(address) {
|
2016-10-26 13:53:47 +02:00
|
|
|
Ok(acc) => acc.map(|v| Account::from_rlp(&v)),
|
2016-09-27 18:02:11 +02:00
|
|
|
Err(e) => panic!("Potential DB corruption encountered: {}", e),
|
|
|
|
};
|
|
|
|
let r = maybe_acc.as_ref().map_or(H256::new(), |a| {
|
|
|
|
let account_db = self.factories.accountdb.readonly(self.db.as_hashdb(), a.address_hash(address));
|
|
|
|
a.storage_at(account_db.as_hashdb(), key)
|
|
|
|
});
|
2016-10-06 01:53:23 +02:00
|
|
|
self.insert_cache(address, AccountEntry::new_clean(maybe_acc));
|
2016-09-27 18:02:11 +02:00
|
|
|
r
|
2015-12-19 22:15:22 +01:00
|
|
|
}
|
|
|
|
|
2016-09-27 18:02:11 +02:00
|
|
|
/// Get accounts' code.
|
2016-10-02 18:45:36 +02:00
|
|
|
pub fn code(&self, a: &Address) -> Option<Arc<Bytes>> {
|
2016-10-20 16:49:27 +02:00
|
|
|
self.ensure_cached(a, RequireCache::Code, true,
|
2016-10-02 18:45:36 +02:00
|
|
|
|a| a.as_ref().map_or(None, |a| a.code().clone()))
|
|
|
|
}
|
|
|
|
|
|
|
|
pub fn code_hash(&self, a: &Address) -> H256 {
|
2016-10-20 16:49:27 +02:00
|
|
|
self.ensure_cached(a, RequireCache::None, true,
|
2016-10-02 18:45:36 +02:00
|
|
|
|a| a.as_ref().map_or(SHA3_EMPTY, |a| a.code_hash()))
|
2016-09-22 19:58:42 +02:00
|
|
|
}
|
|
|
|
|
2016-09-27 18:02:11 +02:00
|
|
|
/// Get accounts' code size.
|
2016-09-22 19:58:42 +02:00
|
|
|
pub fn code_size(&self, a: &Address) -> Option<usize> {
|
2016-10-20 16:49:27 +02:00
|
|
|
self.ensure_cached(a, RequireCache::CodeSize, true,
|
2016-09-27 18:02:11 +02:00
|
|
|
|a| a.as_ref().and_then(|a| a.code_size()))
|
2015-12-19 22:15:22 +01:00
|
|
|
}
|
|
|
|
|
2015-12-16 18:20:23 +01:00
|
|
|
/// Add `incr` to the balance of account `a`.
|
2016-11-28 13:20:49 +01:00
|
|
|
#[cfg_attr(feature="dev", allow(single_match))]
|
2016-11-03 22:22:25 +01:00
|
|
|
pub fn add_balance(&mut self, a: &Address, incr: &U256, cleanup_mode: CleanupMode) {
|
2016-05-30 22:27:28 +02:00
|
|
|
trace!(target: "state", "add_balance({}, {}): {}", a, incr, self.balance(a));
|
2016-11-03 22:22:25 +01:00
|
|
|
let is_value_transfer = !incr.is_zero();
|
|
|
|
if is_value_transfer || (cleanup_mode == CleanupMode::ForceCreate && !self.exists(a)) {
|
2016-10-06 01:53:23 +02:00
|
|
|
self.require(a, false).add_balance(incr);
|
2016-11-03 22:22:25 +01:00
|
|
|
} else {
|
|
|
|
match cleanup_mode {
|
|
|
|
CleanupMode::KillEmpty(set) => if !is_value_transfer && self.exists(a) && !self.exists_and_not_null(a) {
|
|
|
|
set.insert(a.clone());
|
|
|
|
},
|
|
|
|
_ => {}
|
|
|
|
}
|
2016-10-06 01:53:23 +02:00
|
|
|
}
|
2015-12-16 18:20:23 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/// Subtract `decr` from the balance of account `a`.
|
|
|
|
pub fn sub_balance(&mut self, a: &Address, decr: &U256) {
|
2016-05-30 22:27:28 +02:00
|
|
|
trace!(target: "state", "sub_balance({}, {}): {}", a, decr, self.balance(a));
|
2016-10-06 01:53:23 +02:00
|
|
|
if !decr.is_zero() || !self.exists(a) {
|
|
|
|
self.require(a, false).sub_balance(decr);
|
|
|
|
}
|
2015-12-16 18:20:23 +01:00
|
|
|
}
|
|
|
|
|
2015-12-19 22:38:25 +01:00
|
|
|
/// Subtracts `by` from the balance of `from` and adds it to that of `to`.
|
2016-11-03 22:22:25 +01:00
|
|
|
pub fn transfer_balance(&mut self, from: &Address, to: &Address, by: &U256, cleanup_mode: CleanupMode) {
|
2015-12-19 22:38:25 +01:00
|
|
|
self.sub_balance(from, by);
|
2016-11-03 22:22:25 +01:00
|
|
|
self.add_balance(to, by, cleanup_mode);
|
2015-12-19 22:38:25 +01:00
|
|
|
}
|
|
|
|
|
2015-12-16 18:20:23 +01:00
|
|
|
/// Increment the nonce of account `a` by 1.
|
|
|
|
pub fn inc_nonce(&mut self, a: &Address) {
|
|
|
|
self.require(a, false).inc_nonce()
|
|
|
|
}
|
|
|
|
|
2015-12-19 19:00:19 +01:00
|
|
|
/// Mutate storage of account `a` so that it is `value` for `key`.
|
2015-12-19 22:15:22 +01:00
|
|
|
pub fn set_storage(&mut self, a: &Address, key: H256, value: H256) {
|
2016-10-06 01:53:23 +02:00
|
|
|
if self.storage_at(a, &key) != value {
|
|
|
|
self.require(a, false).set_storage(key, value)
|
|
|
|
}
|
2015-12-19 19:00:19 +01:00
|
|
|
}
|
|
|
|
|
2016-06-29 16:29:04 +02:00
|
|
|
/// Initialise the code of account `a` so that it is `code`.
|
2016-01-09 12:30:41 +01:00
|
|
|
/// NOTE: Account should have been created with `new_contract`.
|
|
|
|
pub fn init_code(&mut self, a: &Address, code: Bytes) {
|
2016-05-31 16:59:01 +02:00
|
|
|
self.require_or_from(a, true, || Account::new_contract(0.into(), self.account_start_nonce), |_|{}).init_code(code);
|
2015-12-19 19:00:19 +01:00
|
|
|
}
|
|
|
|
|
2016-06-29 16:29:04 +02:00
|
|
|
/// Reset the code of account `a` so that it is `code`.
|
|
|
|
pub fn reset_code(&mut self, a: &Address, code: Bytes) {
|
|
|
|
self.require_or_from(a, true, || Account::new_contract(0.into(), self.account_start_nonce), |_|{}).reset_code(code);
|
2016-07-22 14:47:23 +02:00
|
|
|
}
|
2016-06-29 16:29:04 +02:00
|
|
|
|
2015-12-19 22:38:25 +01:00
|
|
|
/// Execute a given transaction.
|
|
|
|
/// This will change the state accordingly.
|
2016-08-24 16:53:36 +02:00
|
|
|
pub fn apply(&mut self, env_info: &EnvInfo, engine: &Engine, t: &SignedTransaction, tracing: bool) -> ApplyResult {
|
2016-01-25 23:24:51 +01:00
|
|
|
// let old = self.to_pod();
|
2016-01-15 18:56:28 +01:00
|
|
|
|
2016-05-28 16:52:33 +02:00
|
|
|
let options = TransactOptions { tracing: tracing, vm_tracing: false, check_nonce: true };
|
2016-08-24 16:53:36 +02:00
|
|
|
let vm_factory = self.factories.vm.clone();
|
|
|
|
let e = try!(Executive::new(self, env_info, engine, &vm_factory).transact(t, options));
|
2016-01-15 18:56:28 +01:00
|
|
|
|
2016-01-25 23:37:49 +01:00
|
|
|
// TODO uncomment once to_pod() works correctly.
|
2016-05-31 21:03:44 +02:00
|
|
|
// trace!("Applied transaction. Diff:\n{}\n", state_diff::diff_pod(&old, &self.to_pod()));
|
2016-08-03 18:35:48 +02:00
|
|
|
try!(self.commit());
|
2016-01-15 02:52:37 +01:00
|
|
|
let receipt = Receipt::new(self.root().clone(), e.cumulative_gas_used, e.logs);
|
2016-08-17 19:25:02 +02:00
|
|
|
trace!(target: "state", "Transaction receipt: {:?}", receipt);
|
2016-03-19 12:54:34 +01:00
|
|
|
Ok(ApplyOutcome{receipt: receipt, trace: e.trace})
|
2015-12-20 13:16:12 +01:00
|
|
|
}
|
2015-12-19 22:38:25 +01:00
|
|
|
|
2016-01-09 18:20:31 +01:00
|
|
|
/// Commit accounts to SecTrieDBMut. This is similar to cpp-ethereum's dev::eth::commit.
|
2015-12-16 16:39:49 +01:00
|
|
|
/// `accounts` is mutable because we may need to commit the code or storage and record that.
|
2016-03-11 11:16:49 +01:00
|
|
|
#[cfg_attr(feature="dev", allow(match_ref_pats))]
|
2016-10-27 08:28:12 +02:00
|
|
|
#[cfg_attr(feature="dev", allow(needless_borrow))]
|
2016-09-27 18:02:11 +02:00
|
|
|
fn commit_into(
|
2016-08-24 16:53:36 +02:00
|
|
|
factories: &Factories,
|
2016-09-27 18:02:11 +02:00
|
|
|
db: &mut StateDB,
|
2016-08-03 18:35:48 +02:00
|
|
|
root: &mut H256,
|
2016-09-27 18:02:11 +02:00
|
|
|
accounts: &mut HashMap<Address, AccountEntry>
|
2016-08-03 18:35:48 +02:00
|
|
|
) -> Result<(), Error> {
|
2015-12-13 21:36:17 +01:00
|
|
|
// first, commit the sub trees.
|
2016-10-06 01:53:23 +02:00
|
|
|
for (address, ref mut a) in accounts.iter_mut().filter(|&(_, ref a)| a.is_dirty()) {
|
2016-10-27 08:28:12 +02:00
|
|
|
if let Some(ref mut account) = a.account {
|
2016-11-03 22:22:25 +01:00
|
|
|
let addr_hash = account.address_hash(address);
|
|
|
|
{
|
|
|
|
let mut account_db = factories.accountdb.create(db.as_hashdb_mut(), addr_hash);
|
|
|
|
account.commit_storage(&factories.trie, account_db.as_hashdb_mut());
|
|
|
|
account.commit_code(account_db.as_hashdb_mut());
|
|
|
|
}
|
2016-10-27 08:28:12 +02:00
|
|
|
if !account.is_empty() {
|
2016-11-03 22:22:25 +01:00
|
|
|
db.note_non_null_account(address);
|
2015-12-13 23:12:22 +01:00
|
|
|
}
|
|
|
|
}
|
2015-12-13 21:36:17 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
{
|
2016-10-20 23:41:15 +02:00
|
|
|
let mut trie = try!(factories.trie.from_existing(db.as_hashdb_mut(), root));
|
2016-10-06 01:53:23 +02:00
|
|
|
for (address, ref mut a) in accounts.iter_mut().filter(|&(_, ref a)| a.is_dirty()) {
|
2016-10-07 12:10:12 +02:00
|
|
|
a.state = AccountState::Committed;
|
2016-10-06 01:53:23 +02:00
|
|
|
match a.account {
|
|
|
|
Some(ref mut account) => {
|
2016-09-27 18:02:11 +02:00
|
|
|
try!(trie.insert(address, &account.rlp()));
|
|
|
|
},
|
2016-10-06 01:53:23 +02:00
|
|
|
None => {
|
2016-09-27 18:02:11 +02:00
|
|
|
try!(trie.remove(address));
|
2016-08-03 22:03:40 +02:00
|
|
|
},
|
2015-12-13 23:12:22 +01:00
|
|
|
}
|
2015-12-13 21:36:17 +01:00
|
|
|
}
|
|
|
|
}
|
2016-08-03 18:35:48 +02:00
|
|
|
|
|
|
|
Ok(())
|
2015-12-13 21:36:17 +01:00
|
|
|
}
|
|
|
|
|
2016-10-07 13:34:32 +02:00
|
|
|
/// Propagate local cache into shared canonical state cache.
|
|
|
|
fn propagate_to_global_cache(&mut self) {
|
2016-09-27 18:02:11 +02:00
|
|
|
let mut addresses = self.cache.borrow_mut();
|
2016-10-06 01:53:23 +02:00
|
|
|
trace!("Committing cache {:?} entries", addresses.len());
|
2016-10-07 12:10:12 +02:00
|
|
|
for (address, a) in addresses.drain().filter(|&(_, ref a)| a.state == AccountState::Committed || a.state == AccountState::CleanFresh) {
|
2016-10-07 13:34:32 +02:00
|
|
|
self.db.add_to_account_cache(address, a.account, a.state == AccountState::Committed);
|
2016-09-27 18:02:11 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-12-13 23:12:22 +01:00
|
|
|
/// Commits our cached account changes into the trie.
|
2016-08-03 18:35:48 +02:00
|
|
|
pub fn commit(&mut self) -> Result<(), Error> {
|
2016-10-22 15:22:16 +02:00
|
|
|
assert!(self.checkpoints.borrow().is_empty());
|
2016-09-27 18:02:11 +02:00
|
|
|
Self::commit_into(&self.factories, &mut self.db, &mut self.root, &mut *self.cache.borrow_mut())
|
2015-12-13 21:36:17 +01:00
|
|
|
}
|
2015-12-16 16:39:49 +01:00
|
|
|
|
2016-07-17 09:18:15 +02:00
|
|
|
/// Clear state cache
|
|
|
|
pub fn clear(&mut self) {
|
|
|
|
self.cache.borrow_mut().clear();
|
|
|
|
}
|
|
|
|
|
2016-02-02 23:45:50 +01:00
|
|
|
#[cfg(test)]
|
2016-02-03 15:33:58 +01:00
|
|
|
#[cfg(feature = "json-tests")]
|
|
|
|
/// Populate the state from `accounts`.
|
2016-01-14 12:27:35 +01:00
|
|
|
pub fn populate_from(&mut self, accounts: PodState) {
|
2016-10-22 15:22:16 +02:00
|
|
|
assert!(self.checkpoints.borrow().is_empty());
|
2016-01-14 12:27:35 +01:00
|
|
|
for (add, acc) in accounts.drain().into_iter() {
|
2016-10-06 01:53:23 +02:00
|
|
|
self.cache.borrow_mut().insert(add, AccountEntry::new_dirty(Some(Account::from_pod(acc))));
|
2016-01-13 01:19:05 +01:00
|
|
|
}
|
2015-12-19 22:38:25 +01:00
|
|
|
}
|
|
|
|
|
2016-01-13 12:14:11 +01:00
|
|
|
/// Populate a PodAccount map from this state.
|
2016-01-14 12:27:35 +01:00
|
|
|
pub fn to_pod(&self) -> PodState {
|
2016-10-22 15:22:16 +02:00
|
|
|
assert!(self.checkpoints.borrow().is_empty());
|
2016-01-13 12:14:11 +01:00
|
|
|
// TODO: handle database rather than just the cache.
|
2016-05-31 21:03:44 +02:00
|
|
|
// will need fat db.
|
2016-01-25 18:56:36 +01:00
|
|
|
PodState::from(self.cache.borrow().iter().fold(BTreeMap::new(), |mut m, (add, opt)| {
|
2016-10-06 01:53:23 +02:00
|
|
|
if let Some(ref acc) = opt.account {
|
2016-01-13 12:14:11 +01:00
|
|
|
m.insert(add.clone(), PodAccount::from_account(acc));
|
|
|
|
}
|
|
|
|
m
|
2016-01-14 12:27:35 +01:00
|
|
|
}))
|
2016-01-13 12:14:11 +01:00
|
|
|
}
|
|
|
|
|
2016-05-31 21:03:44 +02:00
|
|
|
fn query_pod(&mut self, query: &PodState) {
|
2016-10-13 23:28:56 +02:00
|
|
|
for (address, pod_account) in query.get().into_iter()
|
2016-10-27 08:28:12 +02:00
|
|
|
.filter(|&(a, _)| self.ensure_cached(a, RequireCache::Code, true, |a| a.is_some()))
|
2016-10-13 23:28:56 +02:00
|
|
|
{
|
|
|
|
// needs to be split into two parts for the refcell code here
|
|
|
|
// to work.
|
|
|
|
for key in pod_account.storage.keys() {
|
|
|
|
self.storage_at(address, key);
|
|
|
|
}
|
2016-06-05 18:24:17 +02:00
|
|
|
}
|
2016-05-31 21:03:44 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/// Returns a `StateDiff` describing the difference from `orig` to `self`.
|
|
|
|
/// Consumes self.
|
|
|
|
pub fn diff_from(&self, orig: State) -> StateDiff {
|
|
|
|
let pod_state_post = self.to_pod();
|
|
|
|
let mut state_pre = orig;
|
|
|
|
state_pre.query_pod(&pod_state_post);
|
|
|
|
pod_state::diff_pod(&state_pre.to_pod(), &pod_state_post)
|
|
|
|
}
|
|
|
|
|
2016-10-28 16:04:44 +02:00
|
|
|
// load required account data from the databases.
|
|
|
|
fn update_account_cache(require: RequireCache, account: &mut Account, state_db: &StateDB, db: &HashDB) {
|
|
|
|
match (account.is_cached(), require) {
|
|
|
|
(true, _) | (false, RequireCache::None) => {}
|
|
|
|
(false, require) => {
|
|
|
|
// if there's already code in the global cache, always cache it
|
|
|
|
// locally.
|
|
|
|
let hash = account.code_hash();
|
|
|
|
match state_db.get_cached_code(&hash) {
|
|
|
|
Some(code) => account.cache_given_code(code),
|
|
|
|
None => match require {
|
|
|
|
RequireCache::None => {},
|
|
|
|
RequireCache::Code => {
|
|
|
|
if let Some(code) = account.cache_code(db) {
|
|
|
|
// propagate code loaded from the database to
|
|
|
|
// the global code cache.
|
|
|
|
state_db.cache_code(hash, code)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
RequireCache::CodeSize => {
|
|
|
|
account.cache_code_size(db);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2015-12-16 18:20:23 +01:00
|
|
|
}
|
2015-12-19 19:00:19 +01:00
|
|
|
}
|
2016-09-27 18:02:11 +02:00
|
|
|
}
|
2016-07-30 15:45:16 +02:00
|
|
|
|
2016-09-27 18:02:11 +02:00
|
|
|
/// Check caches for required data
|
|
|
|
/// First searches for account in the local, then the shared cache.
|
|
|
|
/// Populates local cache if nothing found.
|
2016-10-20 16:49:27 +02:00
|
|
|
fn ensure_cached<F, U>(&self, a: &Address, require: RequireCache, check_bloom: bool, f: F) -> U
|
2016-09-27 18:02:11 +02:00
|
|
|
where F: Fn(Option<&Account>) -> U {
|
|
|
|
// check local cache first
|
|
|
|
if let Some(ref mut maybe_acc) = self.cache.borrow_mut().get_mut(a) {
|
2016-10-06 01:53:23 +02:00
|
|
|
if let Some(ref mut account) = maybe_acc.account {
|
2016-09-27 18:02:11 +02:00
|
|
|
let accountdb = self.factories.accountdb.readonly(self.db.as_hashdb(), account.address_hash(a));
|
2016-10-28 16:04:44 +02:00
|
|
|
Self::update_account_cache(require, account, &self.db, accountdb.as_hashdb());
|
2016-09-27 18:02:11 +02:00
|
|
|
return f(Some(account));
|
|
|
|
}
|
|
|
|
return f(None);
|
|
|
|
}
|
|
|
|
// check global cache
|
|
|
|
let result = self.db.get_cached(a, |mut acc| {
|
|
|
|
if let Some(ref mut account) = acc {
|
|
|
|
let accountdb = self.factories.accountdb.readonly(self.db.as_hashdb(), account.address_hash(a));
|
2016-10-28 16:04:44 +02:00
|
|
|
Self::update_account_cache(require, account, &self.db, accountdb.as_hashdb());
|
2016-09-27 18:02:11 +02:00
|
|
|
}
|
|
|
|
f(acc.map(|a| &*a))
|
|
|
|
});
|
|
|
|
match result {
|
|
|
|
Some(r) => r,
|
|
|
|
None => {
|
2016-10-03 12:02:43 +02:00
|
|
|
// first check bloom if it is not in database for sure
|
2016-11-03 22:22:25 +01:00
|
|
|
if check_bloom && !self.db.check_non_null_bloom(a) { return f(None); }
|
2016-10-03 12:02:43 +02:00
|
|
|
|
2016-09-27 18:02:11 +02:00
|
|
|
// not found in the global cache, get from the DB and insert into local
|
|
|
|
let db = self.factories.trie.readonly(self.db.as_hashdb(), &self.root).expect(SEC_TRIE_DB_UNWRAP_STR);
|
|
|
|
let mut maybe_acc = match db.get(a) {
|
2016-10-26 13:53:47 +02:00
|
|
|
Ok(acc) => acc.map(|v| Account::from_rlp(&v)),
|
2016-09-27 18:02:11 +02:00
|
|
|
Err(e) => panic!("Potential DB corruption encountered: {}", e),
|
|
|
|
};
|
|
|
|
if let Some(ref mut account) = maybe_acc.as_mut() {
|
|
|
|
let accountdb = self.factories.accountdb.readonly(self.db.as_hashdb(), account.address_hash(a));
|
2016-10-28 16:04:44 +02:00
|
|
|
Self::update_account_cache(require, account, &self.db, accountdb.as_hashdb());
|
2016-09-27 18:02:11 +02:00
|
|
|
}
|
|
|
|
let r = f(maybe_acc.as_ref());
|
2016-10-07 12:10:12 +02:00
|
|
|
self.insert_cache(a, AccountEntry::new_clean(maybe_acc));
|
2016-09-27 18:02:11 +02:00
|
|
|
r
|
|
|
|
}
|
|
|
|
}
|
2015-12-16 18:20:23 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/// Pull account `a` in our cache from the trie DB. `require_code` requires that the code be cached, too.
|
2016-08-03 18:35:48 +02:00
|
|
|
fn require<'a>(&'a self, a: &Address, require_code: bool) -> RefMut<'a, Account> {
|
2016-01-09 14:19:35 +01:00
|
|
|
self.require_or_from(a, require_code, || Account::new_basic(U256::from(0u8), self.account_start_nonce), |_|{})
|
2015-12-19 19:00:19 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/// Pull account `a` in our cache from the trie DB. `require_code` requires that the code be cached, too.
|
2016-01-09 14:19:35 +01:00
|
|
|
/// If it doesn't exist, make account equal the evaluation of `default`.
|
2016-08-03 18:35:48 +02:00
|
|
|
fn require_or_from<'a, F: FnOnce() -> Account, G: FnOnce(&mut Account)>(&'a self, a: &Address, require_code: bool, default: F, not_default: G)
|
|
|
|
-> RefMut<'a, Account>
|
|
|
|
{
|
|
|
|
let contains_key = self.cache.borrow().contains_key(a);
|
|
|
|
if !contains_key {
|
2016-09-27 18:02:11 +02:00
|
|
|
match self.db.get_cached_account(a) {
|
2016-10-07 12:10:12 +02:00
|
|
|
Some(acc) => self.insert_cache(a, AccountEntry::new_clean_cached(acc)),
|
2016-09-27 18:02:11 +02:00
|
|
|
None => {
|
2016-11-03 22:22:25 +01:00
|
|
|
let maybe_acc = if self.db.check_non_null_bloom(a) {
|
2016-10-03 12:02:43 +02:00
|
|
|
let db = self.factories.trie.readonly(self.db.as_hashdb(), &self.root).expect(SEC_TRIE_DB_UNWRAP_STR);
|
2016-10-27 08:28:12 +02:00
|
|
|
match db.get(a) {
|
2016-10-26 13:53:47 +02:00
|
|
|
Ok(Some(acc)) => AccountEntry::new_clean(Some(Account::from_rlp(&acc))),
|
2016-10-06 01:53:23 +02:00
|
|
|
Ok(None) => AccountEntry::new_clean(None),
|
2016-10-03 12:02:43 +02:00
|
|
|
Err(e) => panic!("Potential DB corruption encountered: {}", e),
|
2016-10-27 08:28:12 +02:00
|
|
|
}
|
|
|
|
} else {
|
2016-10-06 01:53:23 +02:00
|
|
|
AccountEntry::new_clean(None)
|
2016-09-27 18:02:11 +02:00
|
|
|
};
|
|
|
|
self.insert_cache(a, maybe_acc);
|
|
|
|
}
|
|
|
|
}
|
2016-02-03 19:34:51 +01:00
|
|
|
}
|
2016-10-06 01:53:23 +02:00
|
|
|
self.note_cache(a);
|
2016-08-03 18:35:48 +02:00
|
|
|
|
2016-10-20 23:41:15 +02:00
|
|
|
// at this point the entry is guaranteed to be in the cache.
|
2016-08-03 18:35:48 +02:00
|
|
|
RefMut::map(self.cache.borrow_mut(), |c| {
|
2016-10-20 23:41:15 +02:00
|
|
|
let mut entry = c.get_mut(a).expect("entry known to exist in the cache; qed");
|
|
|
|
|
|
|
|
match &mut entry.account {
|
|
|
|
&mut Some(ref mut acc) => not_default(acc),
|
|
|
|
slot => *slot = Some(default()),
|
|
|
|
}
|
|
|
|
|
2016-10-06 01:53:23 +02:00
|
|
|
// set the dirty flag after changing account data.
|
|
|
|
entry.state = AccountState::Dirty;
|
|
|
|
match entry.account {
|
|
|
|
Some(ref mut account) => {
|
2016-09-27 18:02:11 +02:00
|
|
|
if require_code {
|
|
|
|
let addr_hash = account.address_hash(a);
|
|
|
|
let accountdb = self.factories.accountdb.readonly(self.db.as_hashdb(), addr_hash);
|
2016-10-28 16:04:44 +02:00
|
|
|
Self::update_account_cache(RequireCache::Code, account, &self.db, accountdb.as_hashdb());
|
2016-09-27 18:02:11 +02:00
|
|
|
}
|
|
|
|
account
|
|
|
|
},
|
|
|
|
_ => panic!("Required account must always exist; qed"),
|
2015-12-16 16:39:49 +01:00
|
|
|
}
|
2016-08-03 18:35:48 +02:00
|
|
|
})
|
2015-12-16 16:39:49 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-11-15 14:53:30 +01:00
|
|
|
// LES state proof implementations.
|
|
|
|
impl State {
|
|
|
|
/// Prove an account's existence or nonexistence in the state trie.
|
|
|
|
/// Returns a merkle proof of the account's trie node with all nodes before `from_level`
|
|
|
|
/// omitted or an encountered trie error.
|
|
|
|
/// Requires a secure trie to be used for accurate results.
|
|
|
|
/// `account_key` == sha3(address)
|
|
|
|
pub fn prove_account(&self, account_key: H256, from_level: u32) -> Result<Vec<Bytes>, Box<TrieError>> {
|
|
|
|
let mut recorder = TrieRecorder::with_depth(from_level);
|
|
|
|
let trie = try!(TrieDB::new(self.db.as_hashdb(), &self.root));
|
|
|
|
let _ = try!(trie.get_recorded(&account_key, &mut recorder));
|
|
|
|
|
|
|
|
Ok(recorder.drain().into_iter().map(|r| r.data).collect())
|
|
|
|
}
|
|
|
|
|
|
|
|
/// Prove an account's storage key's existence or nonexistence in the state.
|
|
|
|
/// Returns a merkle proof of the account's storage trie with all nodes before
|
|
|
|
/// `from_level` omitted. Requires a secure trie to be used for correctness.
|
|
|
|
/// `account_key` == sha3(address)
|
|
|
|
/// `storage_key` == sha3(key)
|
|
|
|
pub fn prove_storage(&self, account_key: H256, storage_key: H256, from_level: u32) -> Result<Vec<Bytes>, Box<TrieError>> {
|
|
|
|
// TODO: probably could look into cache somehow but it's keyed by
|
|
|
|
// address, not sha3(address).
|
|
|
|
let trie = try!(TrieDB::new(self.db.as_hashdb(), &self.root));
|
|
|
|
let acc = match try!(trie.get(&account_key)) {
|
|
|
|
Some(rlp) => Account::from_rlp(&rlp),
|
|
|
|
None => return Ok(Vec::new()),
|
|
|
|
};
|
|
|
|
|
|
|
|
let account_db = self.factories.accountdb.readonly(self.db.as_hashdb(), account_key);
|
|
|
|
acc.prove_storage(account_db.as_hashdb(), storage_key, from_level)
|
|
|
|
}
|
|
|
|
|
|
|
|
/// Get code by address hash.
|
|
|
|
/// Only works when backed by a secure trie.
|
|
|
|
pub fn code_by_address_hash(&self, account_key: H256) -> Result<Option<Bytes>, Box<TrieError>> {
|
|
|
|
let trie = try!(TrieDB::new(self.db.as_hashdb(), &self.root));
|
|
|
|
let mut acc = match try!(trie.get(&account_key)) {
|
|
|
|
Some(rlp) => Account::from_rlp(&rlp),
|
|
|
|
None => return Ok(None),
|
|
|
|
};
|
|
|
|
|
|
|
|
let account_db = self.factories.accountdb.readonly(self.db.as_hashdb(), account_key);
|
|
|
|
Ok(acc.cache_code(account_db.as_hashdb()).map(|c| (&*c).clone()))
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-01-13 01:19:05 +01:00
|
|
|
impl fmt::Debug for State {
|
|
|
|
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
|
|
|
|
write!(f, "{:?}", self.cache.borrow())
|
2016-01-11 14:47:50 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-03-22 13:05:18 +01:00
|
|
|
impl Clone for State {
|
|
|
|
fn clone(&self) -> State {
|
2016-09-21 12:49:11 +02:00
|
|
|
let cache = {
|
2016-09-27 18:02:11 +02:00
|
|
|
let mut cache: HashMap<Address, AccountEntry> = HashMap::new();
|
2016-09-21 12:49:11 +02:00
|
|
|
for (key, val) in self.cache.borrow().iter() {
|
2016-10-06 01:53:23 +02:00
|
|
|
if let Some(entry) = val.clone_if_dirty() {
|
2016-09-27 18:02:11 +02:00
|
|
|
cache.insert(key.clone(), entry);
|
2016-09-21 12:49:11 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
cache
|
|
|
|
};
|
|
|
|
|
2016-03-22 13:05:18 +01:00
|
|
|
State {
|
2016-03-28 10:12:15 +02:00
|
|
|
db: self.db.boxed_clone(),
|
2016-03-22 13:05:18 +01:00
|
|
|
root: self.root.clone(),
|
2016-09-21 12:49:11 +02:00
|
|
|
cache: RefCell::new(cache),
|
2016-10-22 15:22:16 +02:00
|
|
|
checkpoints: RefCell::new(Vec::new()),
|
2016-03-22 13:05:18 +01:00
|
|
|
account_start_nonce: self.account_start_nonce.clone(),
|
2016-08-24 16:53:36 +02:00
|
|
|
factories: self.factories.clone(),
|
2016-03-22 13:05:18 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-12-16 16:39:49 +01:00
|
|
|
#[cfg(test)]
|
|
|
|
mod tests {
|
|
|
|
|
2016-11-14 17:47:56 +01:00
|
|
|
use std::sync::Arc;
|
|
|
|
use std::str::FromStr;
|
|
|
|
use rustc_serialize::hex::FromHex;
|
|
|
|
use super::*;
|
|
|
|
use util::{U256, H256, FixedHash, Address, Hashable};
|
|
|
|
use tests::helpers::*;
|
|
|
|
use devtools::*;
|
|
|
|
use env_info::EnvInfo;
|
|
|
|
use spec::*;
|
|
|
|
use transaction::*;
|
|
|
|
use util::log::init_log;
|
|
|
|
use trace::{FlatTrace, TraceError, trace};
|
|
|
|
use types::executed::CallType;
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn should_apply_create_transaction() {
|
|
|
|
init_log();
|
|
|
|
|
|
|
|
let temp = RandomTempPath::new();
|
|
|
|
let mut state = get_temp_state_in(temp.as_path());
|
|
|
|
|
|
|
|
let mut info = EnvInfo::default();
|
|
|
|
info.gas_limit = 1_000_000.into();
|
|
|
|
let engine = TestEngine::new(5);
|
|
|
|
|
|
|
|
let t = Transaction {
|
|
|
|
nonce: 0.into(),
|
|
|
|
gas_price: 0.into(),
|
|
|
|
gas: 100_000.into(),
|
|
|
|
action: Action::Create,
|
2016-05-31 16:59:01 +02:00
|
|
|
value: 100.into(),
|
2016-11-14 17:47:56 +01:00
|
|
|
data: FromHex::from_hex("601080600c6000396000f3006000355415600957005b60203560003555").unwrap(),
|
|
|
|
}.sign(&"".sha3(), None);
|
|
|
|
|
|
|
|
state.add_balance(t.sender().as_ref().unwrap(), &(100.into()), CleanupMode::NoEmpty);
|
|
|
|
let result = state.apply(&info, &engine, &t, true).unwrap();
|
|
|
|
let expected_trace = vec![FlatTrace {
|
|
|
|
trace_address: Default::default(),
|
|
|
|
subtraces: 0,
|
|
|
|
action: trace::Action::Create(trace::Create {
|
|
|
|
from: "9cce34f7ab185c7aba1b7c8140d620b4bda941d6".into(),
|
|
|
|
value: 100.into(),
|
|
|
|
gas: 77412.into(),
|
|
|
|
init: vec![96, 16, 128, 96, 12, 96, 0, 57, 96, 0, 243, 0, 96, 0, 53, 84, 21, 96, 9, 87, 0, 91, 96, 32, 53, 96, 0, 53, 85],
|
|
|
|
}),
|
|
|
|
result: trace::Res::Create(trace::CreateResult {
|
|
|
|
gas_used: U256::from(3224),
|
|
|
|
address: Address::from_str("8988167e088c87cd314df6d3c2b83da5acb93ace").unwrap(),
|
|
|
|
code: vec![96, 0, 53, 84, 21, 96, 9, 87, 0, 91, 96, 32, 53, 96, 0, 53]
|
|
|
|
}),
|
|
|
|
}];
|
|
|
|
|
|
|
|
assert_eq!(result.trace, expected_trace);
|
|
|
|
}
|
2015-12-19 19:00:19 +01:00
|
|
|
|
2016-11-14 17:47:56 +01:00
|
|
|
#[test]
|
|
|
|
fn should_work_when_cloned() {
|
|
|
|
init_log();
|
2016-03-27 14:35:27 +02:00
|
|
|
|
2016-11-14 17:47:56 +01:00
|
|
|
let a = Address::zero();
|
|
|
|
|
|
|
|
let temp = RandomTempPath::new();
|
|
|
|
let mut state = {
|
|
|
|
let mut state = get_temp_state_in(temp.as_path());
|
|
|
|
assert_eq!(state.exists(&a), false);
|
|
|
|
state.inc_nonce(&a);
|
|
|
|
state.commit().unwrap();
|
|
|
|
state.clone()
|
|
|
|
};
|
2016-03-27 14:35:27 +02:00
|
|
|
|
|
|
|
state.inc_nonce(&a);
|
2016-08-03 18:35:48 +02:00
|
|
|
state.commit().unwrap();
|
2016-11-14 17:47:56 +01:00
|
|
|
}
|
2016-03-27 14:35:27 +02:00
|
|
|
|
2016-11-14 17:47:56 +01:00
|
|
|
#[test]
|
|
|
|
fn should_trace_failed_create_transaction() {
|
|
|
|
init_log();
|
2016-03-27 14:35:27 +02:00
|
|
|
|
2016-11-14 17:47:56 +01:00
|
|
|
let temp = RandomTempPath::new();
|
|
|
|
let mut state = get_temp_state_in(temp.as_path());
|
|
|
|
|
|
|
|
let mut info = EnvInfo::default();
|
|
|
|
info.gas_limit = 1_000_000.into();
|
|
|
|
let engine = TestEngine::new(5);
|
2016-03-27 14:35:27 +02:00
|
|
|
|
2016-11-14 17:47:56 +01:00
|
|
|
let t = Transaction {
|
|
|
|
nonce: 0.into(),
|
|
|
|
gas_price: 0.into(),
|
|
|
|
gas: 100_000.into(),
|
|
|
|
action: Action::Create,
|
2016-05-31 16:59:01 +02:00
|
|
|
value: 100.into(),
|
2016-11-14 17:47:56 +01:00
|
|
|
data: FromHex::from_hex("5b600056").unwrap(),
|
|
|
|
}.sign(&"".sha3(), None);
|
|
|
|
|
|
|
|
state.add_balance(t.sender().as_ref().unwrap(), &(100.into()), CleanupMode::NoEmpty);
|
|
|
|
let result = state.apply(&info, &engine, &t, true).unwrap();
|
|
|
|
let expected_trace = vec![FlatTrace {
|
|
|
|
trace_address: Default::default(),
|
|
|
|
action: trace::Action::Create(trace::Create {
|
|
|
|
from: "9cce34f7ab185c7aba1b7c8140d620b4bda941d6".into(),
|
|
|
|
value: 100.into(),
|
|
|
|
gas: 78792.into(),
|
|
|
|
init: vec![91, 96, 0, 86],
|
|
|
|
}),
|
|
|
|
result: trace::Res::FailedCreate(TraceError::OutOfGas),
|
|
|
|
subtraces: 0
|
|
|
|
}];
|
|
|
|
|
|
|
|
assert_eq!(result.trace, expected_trace);
|
|
|
|
}
|
2016-03-20 12:04:31 +01:00
|
|
|
|
2016-11-14 17:47:56 +01:00
|
|
|
#[test]
|
|
|
|
fn should_trace_call_transaction() {
|
|
|
|
init_log();
|
|
|
|
|
|
|
|
let temp = RandomTempPath::new();
|
|
|
|
let mut state = get_temp_state_in(temp.as_path());
|
|
|
|
|
|
|
|
let mut info = EnvInfo::default();
|
|
|
|
info.gas_limit = 1_000_000.into();
|
|
|
|
let engine = TestEngine::new(5);
|
2016-03-20 12:04:31 +01:00
|
|
|
|
2016-11-14 17:47:56 +01:00
|
|
|
let t = Transaction {
|
|
|
|
nonce: 0.into(),
|
|
|
|
gas_price: 0.into(),
|
|
|
|
gas: 100_000.into(),
|
|
|
|
action: Action::Call(0xa.into()),
|
2016-05-31 16:59:01 +02:00
|
|
|
value: 100.into(),
|
2016-11-14 17:47:56 +01:00
|
|
|
data: vec![],
|
|
|
|
}.sign(&"".sha3(), None);
|
|
|
|
|
|
|
|
state.init_code(&0xa.into(), FromHex::from_hex("6000").unwrap());
|
|
|
|
state.add_balance(t.sender().as_ref().unwrap(), &(100.into()), CleanupMode::NoEmpty);
|
|
|
|
let result = state.apply(&info, &engine, &t, true).unwrap();
|
|
|
|
let expected_trace = vec![FlatTrace {
|
|
|
|
trace_address: Default::default(),
|
|
|
|
action: trace::Action::Call(trace::Call {
|
|
|
|
from: "9cce34f7ab185c7aba1b7c8140d620b4bda941d6".into(),
|
|
|
|
to: 0xa.into(),
|
|
|
|
value: 100.into(),
|
|
|
|
gas: 79000.into(),
|
|
|
|
input: vec![],
|
|
|
|
call_type: CallType::Call,
|
|
|
|
}),
|
|
|
|
result: trace::Res::Call(trace::CallResult {
|
|
|
|
gas_used: U256::from(3),
|
|
|
|
output: vec![]
|
|
|
|
}),
|
|
|
|
subtraces: 0,
|
|
|
|
}];
|
|
|
|
|
|
|
|
assert_eq!(result.trace, expected_trace);
|
|
|
|
}
|
2016-03-20 16:24:19 +01:00
|
|
|
|
2016-11-14 17:47:56 +01:00
|
|
|
#[test]
|
|
|
|
fn should_trace_basic_call_transaction() {
|
|
|
|
init_log();
|
|
|
|
|
|
|
|
let temp = RandomTempPath::new();
|
|
|
|
let mut state = get_temp_state_in(temp.as_path());
|
|
|
|
|
|
|
|
let mut info = EnvInfo::default();
|
|
|
|
info.gas_limit = 1_000_000.into();
|
|
|
|
let engine = TestEngine::new(5);
|
2016-03-20 16:24:19 +01:00
|
|
|
|
2016-11-14 17:47:56 +01:00
|
|
|
let t = Transaction {
|
|
|
|
nonce: 0.into(),
|
|
|
|
gas_price: 0.into(),
|
|
|
|
gas: 100_000.into(),
|
|
|
|
action: Action::Call(0xa.into()),
|
2016-05-31 16:59:01 +02:00
|
|
|
value: 100.into(),
|
2016-11-14 17:47:56 +01:00
|
|
|
data: vec![],
|
|
|
|
}.sign(&"".sha3(), None);
|
2016-03-21 11:24:03 +01:00
|
|
|
|
2016-11-14 17:47:56 +01:00
|
|
|
state.add_balance(t.sender().as_ref().unwrap(), &(100.into()), CleanupMode::NoEmpty);
|
|
|
|
let result = state.apply(&info, &engine, &t, true).unwrap();
|
|
|
|
let expected_trace = vec![FlatTrace {
|
|
|
|
trace_address: Default::default(),
|
|
|
|
action: trace::Action::Call(trace::Call {
|
|
|
|
from: "9cce34f7ab185c7aba1b7c8140d620b4bda941d6".into(),
|
|
|
|
to: 0xa.into(),
|
|
|
|
value: 100.into(),
|
|
|
|
gas: 79000.into(),
|
|
|
|
input: vec![],
|
|
|
|
call_type: CallType::Call,
|
|
|
|
}),
|
|
|
|
result: trace::Res::Call(trace::CallResult {
|
|
|
|
gas_used: U256::from(0),
|
|
|
|
output: vec![]
|
|
|
|
}),
|
|
|
|
subtraces: 0,
|
|
|
|
}];
|
|
|
|
|
|
|
|
assert_eq!(result.trace, expected_trace);
|
|
|
|
}
|
2016-03-20 17:51:22 +01:00
|
|
|
|
2016-11-14 17:47:56 +01:00
|
|
|
#[test]
|
|
|
|
fn should_trace_call_transaction_to_builtin() {
|
|
|
|
init_log();
|
2016-03-20 16:24:19 +01:00
|
|
|
|
2016-11-14 17:47:56 +01:00
|
|
|
let temp = RandomTempPath::new();
|
|
|
|
let mut state = get_temp_state_in(temp.as_path());
|
|
|
|
|
|
|
|
let mut info = EnvInfo::default();
|
|
|
|
info.gas_limit = 1_000_000.into();
|
|
|
|
let engine = &*Spec::new_test().engine;
|
|
|
|
|
|
|
|
let t = Transaction {
|
|
|
|
nonce: 0.into(),
|
|
|
|
gas_price: 0.into(),
|
|
|
|
gas: 100_000.into(),
|
|
|
|
action: Action::Call(0x1.into()),
|
2016-07-28 20:31:29 +02:00
|
|
|
value: 0.into(),
|
2016-11-14 17:47:56 +01:00
|
|
|
data: vec![],
|
|
|
|
}.sign(&"".sha3(), None);
|
|
|
|
|
|
|
|
let result = state.apply(&info, engine, &t, true).unwrap();
|
2016-03-20 19:20:37 +01:00
|
|
|
|
2016-11-14 17:47:56 +01:00
|
|
|
let expected_trace = vec![FlatTrace {
|
|
|
|
trace_address: Default::default(),
|
|
|
|
action: trace::Action::Call(trace::Call {
|
|
|
|
from: "9cce34f7ab185c7aba1b7c8140d620b4bda941d6".into(),
|
|
|
|
to: "0000000000000000000000000000000000000001".into(),
|
|
|
|
value: 0.into(),
|
|
|
|
gas: 79_000.into(),
|
|
|
|
input: vec![],
|
|
|
|
call_type: CallType::Call,
|
|
|
|
}),
|
|
|
|
result: trace::Res::Call(trace::CallResult {
|
|
|
|
gas_used: U256::from(3000),
|
|
|
|
output: vec![]
|
|
|
|
}),
|
|
|
|
subtraces: 0,
|
|
|
|
}];
|
|
|
|
|
|
|
|
assert_eq!(result.trace, expected_trace);
|
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn should_not_trace_subcall_transaction_to_builtin() {
|
|
|
|
init_log();
|
|
|
|
|
|
|
|
let temp = RandomTempPath::new();
|
|
|
|
let mut state = get_temp_state_in(temp.as_path());
|
2016-03-20 19:20:37 +01:00
|
|
|
|
2016-11-14 17:47:56 +01:00
|
|
|
let mut info = EnvInfo::default();
|
|
|
|
info.gas_limit = 1_000_000.into();
|
|
|
|
let engine = &*Spec::new_test().engine;
|
|
|
|
|
|
|
|
let t = Transaction {
|
|
|
|
nonce: 0.into(),
|
|
|
|
gas_price: 0.into(),
|
|
|
|
gas: 100_000.into(),
|
|
|
|
action: Action::Call(0xa.into()),
|
2016-05-31 16:59:01 +02:00
|
|
|
value: 0.into(),
|
2016-11-14 17:47:56 +01:00
|
|
|
data: vec![],
|
|
|
|
}.sign(&"".sha3(), None);
|
|
|
|
|
|
|
|
state.init_code(&0xa.into(), FromHex::from_hex("600060006000600060006001610be0f1").unwrap());
|
|
|
|
let result = state.apply(&info, engine, &t, true).unwrap();
|
|
|
|
|
|
|
|
let expected_trace = vec![FlatTrace {
|
|
|
|
trace_address: Default::default(),
|
|
|
|
action: trace::Action::Call(trace::Call {
|
|
|
|
from: "9cce34f7ab185c7aba1b7c8140d620b4bda941d6".into(),
|
|
|
|
to: 0xa.into(),
|
|
|
|
value: 0.into(),
|
|
|
|
gas: 79000.into(),
|
|
|
|
input: vec![],
|
|
|
|
call_type: CallType::Call,
|
|
|
|
}),
|
|
|
|
result: trace::Res::Call(trace::CallResult {
|
|
|
|
gas_used: U256::from(28_061),
|
|
|
|
output: vec![]
|
|
|
|
}),
|
|
|
|
subtraces: 0,
|
|
|
|
}];
|
|
|
|
|
|
|
|
assert_eq!(result.trace, expected_trace);
|
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn should_not_trace_callcode() {
|
|
|
|
init_log();
|
|
|
|
|
|
|
|
let temp = RandomTempPath::new();
|
|
|
|
let mut state = get_temp_state_in(temp.as_path());
|
|
|
|
|
|
|
|
let mut info = EnvInfo::default();
|
|
|
|
info.gas_limit = 1_000_000.into();
|
|
|
|
let engine = &*Spec::new_test().engine;
|
|
|
|
|
|
|
|
let t = Transaction {
|
|
|
|
nonce: 0.into(),
|
|
|
|
gas_price: 0.into(),
|
|
|
|
gas: 100_000.into(),
|
|
|
|
action: Action::Call(0xa.into()),
|
2016-07-28 20:31:29 +02:00
|
|
|
value: 0.into(),
|
2016-11-14 17:47:56 +01:00
|
|
|
data: vec![],
|
|
|
|
}.sign(&"".sha3(), None);
|
2016-03-20 19:20:37 +01:00
|
|
|
|
2016-11-14 17:47:56 +01:00
|
|
|
state.init_code(&0xa.into(), FromHex::from_hex("60006000600060006000600b611000f2").unwrap());
|
|
|
|
state.init_code(&0xb.into(), FromHex::from_hex("6000").unwrap());
|
|
|
|
let result = state.apply(&info, engine, &t, true).unwrap();
|
2016-03-20 19:20:37 +01:00
|
|
|
|
2016-11-14 17:47:56 +01:00
|
|
|
let expected_trace = vec![FlatTrace {
|
|
|
|
trace_address: Default::default(),
|
|
|
|
subtraces: 1,
|
|
|
|
action: trace::Action::Call(trace::Call {
|
|
|
|
from: "9cce34f7ab185c7aba1b7c8140d620b4bda941d6".into(),
|
|
|
|
to: 0xa.into(),
|
|
|
|
value: 0.into(),
|
|
|
|
gas: 79000.into(),
|
|
|
|
input: vec![],
|
|
|
|
call_type: CallType::Call,
|
|
|
|
}),
|
|
|
|
result: trace::Res::Call(trace::CallResult {
|
|
|
|
gas_used: 64.into(),
|
|
|
|
output: vec![]
|
|
|
|
}),
|
|
|
|
}, FlatTrace {
|
|
|
|
trace_address: vec![0].into_iter().collect(),
|
|
|
|
subtraces: 0,
|
|
|
|
action: trace::Action::Call(trace::Call {
|
|
|
|
from: 0xa.into(),
|
|
|
|
to: 0xa.into(),
|
|
|
|
value: 0.into(),
|
|
|
|
gas: 4096.into(),
|
|
|
|
input: vec![],
|
|
|
|
call_type: CallType::CallCode,
|
|
|
|
}),
|
|
|
|
result: trace::Res::Call(trace::CallResult {
|
|
|
|
gas_used: 3.into(),
|
|
|
|
output: vec![],
|
|
|
|
}),
|
|
|
|
}];
|
|
|
|
|
|
|
|
assert_eq!(result.trace, expected_trace);
|
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn should_not_trace_delegatecall() {
|
|
|
|
init_log();
|
|
|
|
|
|
|
|
let temp = RandomTempPath::new();
|
|
|
|
let mut state = get_temp_state_in(temp.as_path());
|
|
|
|
|
|
|
|
let mut info = EnvInfo::default();
|
|
|
|
info.gas_limit = 1_000_000.into();
|
|
|
|
info.number = 0x789b0;
|
|
|
|
let engine = &*Spec::new_test().engine;
|
|
|
|
|
|
|
|
println!("schedule.have_delegate_call: {:?}", engine.schedule(&info).have_delegate_call);
|
|
|
|
|
|
|
|
let t = Transaction {
|
|
|
|
nonce: 0.into(),
|
|
|
|
gas_price: 0.into(),
|
|
|
|
gas: 100_000.into(),
|
|
|
|
action: Action::Call(0xa.into()),
|
2016-07-28 20:31:29 +02:00
|
|
|
value: 0.into(),
|
2016-11-14 17:47:56 +01:00
|
|
|
data: vec![],
|
|
|
|
}.sign(&"".sha3(), None);
|
2016-03-20 16:24:19 +01:00
|
|
|
|
2016-11-14 17:47:56 +01:00
|
|
|
state.init_code(&0xa.into(), FromHex::from_hex("6000600060006000600b618000f4").unwrap());
|
|
|
|
state.init_code(&0xb.into(), FromHex::from_hex("6000").unwrap());
|
|
|
|
let result = state.apply(&info, engine, &t, true).unwrap();
|
|
|
|
|
|
|
|
let expected_trace = vec![FlatTrace {
|
|
|
|
trace_address: Default::default(),
|
|
|
|
subtraces: 1,
|
|
|
|
action: trace::Action::Call(trace::Call {
|
|
|
|
from: "9cce34f7ab185c7aba1b7c8140d620b4bda941d6".into(),
|
|
|
|
to: 0xa.into(),
|
|
|
|
value: 0.into(),
|
|
|
|
gas: 79000.into(),
|
|
|
|
input: vec![],
|
|
|
|
call_type: CallType::Call,
|
|
|
|
}),
|
|
|
|
result: trace::Res::Call(trace::CallResult {
|
|
|
|
gas_used: U256::from(61),
|
|
|
|
output: vec![]
|
|
|
|
}),
|
|
|
|
}, FlatTrace {
|
|
|
|
trace_address: vec![0].into_iter().collect(),
|
|
|
|
subtraces: 0,
|
|
|
|
action: trace::Action::Call(trace::Call {
|
|
|
|
from: "9cce34f7ab185c7aba1b7c8140d620b4bda941d6".into(),
|
|
|
|
to: 0xa.into(),
|
|
|
|
value: 0.into(),
|
|
|
|
gas: 32768.into(),
|
|
|
|
input: vec![],
|
|
|
|
call_type: CallType::DelegateCall,
|
|
|
|
}),
|
|
|
|
result: trace::Res::Call(trace::CallResult {
|
|
|
|
gas_used: 3.into(),
|
|
|
|
output: vec![],
|
|
|
|
}),
|
|
|
|
}];
|
|
|
|
|
|
|
|
assert_eq!(result.trace, expected_trace);
|
|
|
|
}
|
2016-03-21 11:24:03 +01:00
|
|
|
|
2016-11-14 17:47:56 +01:00
|
|
|
#[test]
|
|
|
|
fn should_trace_failed_call_transaction() {
|
|
|
|
init_log();
|
|
|
|
|
|
|
|
let temp = RandomTempPath::new();
|
|
|
|
let mut state = get_temp_state_in(temp.as_path());
|
|
|
|
|
|
|
|
let mut info = EnvInfo::default();
|
|
|
|
info.gas_limit = 1_000_000.into();
|
|
|
|
let engine = TestEngine::new(5);
|
2016-03-21 11:24:03 +01:00
|
|
|
|
2016-11-14 17:47:56 +01:00
|
|
|
let t = Transaction {
|
|
|
|
nonce: 0.into(),
|
|
|
|
gas_price: 0.into(),
|
|
|
|
gas: 100_000.into(),
|
|
|
|
action: Action::Call(0xa.into()),
|
2016-05-31 16:59:01 +02:00
|
|
|
value: 100.into(),
|
2016-11-14 17:47:56 +01:00
|
|
|
data: vec![],
|
|
|
|
}.sign(&"".sha3(), None);
|
|
|
|
|
|
|
|
state.init_code(&0xa.into(), FromHex::from_hex("5b600056").unwrap());
|
|
|
|
state.add_balance(t.sender().as_ref().unwrap(), &(100.into()), CleanupMode::NoEmpty);
|
|
|
|
let result = state.apply(&info, &engine, &t, true).unwrap();
|
|
|
|
let expected_trace = vec![FlatTrace {
|
|
|
|
trace_address: Default::default(),
|
|
|
|
action: trace::Action::Call(trace::Call {
|
|
|
|
from: "9cce34f7ab185c7aba1b7c8140d620b4bda941d6".into(),
|
|
|
|
to: 0xa.into(),
|
|
|
|
value: 100.into(),
|
|
|
|
gas: 79000.into(),
|
|
|
|
input: vec![],
|
|
|
|
call_type: CallType::Call,
|
|
|
|
}),
|
|
|
|
result: trace::Res::FailedCall(TraceError::OutOfGas),
|
|
|
|
subtraces: 0,
|
|
|
|
}];
|
|
|
|
|
|
|
|
assert_eq!(result.trace, expected_trace);
|
|
|
|
}
|
2016-03-21 11:24:03 +01:00
|
|
|
|
2016-11-14 17:47:56 +01:00
|
|
|
#[test]
|
|
|
|
fn should_trace_call_with_subcall_transaction() {
|
|
|
|
init_log();
|
2016-03-21 11:24:03 +01:00
|
|
|
|
2016-11-14 17:47:56 +01:00
|
|
|
let temp = RandomTempPath::new();
|
|
|
|
let mut state = get_temp_state_in(temp.as_path());
|
|
|
|
|
|
|
|
let mut info = EnvInfo::default();
|
|
|
|
info.gas_limit = 1_000_000.into();
|
|
|
|
let engine = TestEngine::new(5);
|
|
|
|
|
|
|
|
let t = Transaction {
|
|
|
|
nonce: 0.into(),
|
|
|
|
gas_price: 0.into(),
|
|
|
|
gas: 100_000.into(),
|
|
|
|
action: Action::Call(0xa.into()),
|
2016-05-31 16:59:01 +02:00
|
|
|
value: 100.into(),
|
2016-11-14 17:47:56 +01:00
|
|
|
data: vec![],
|
|
|
|
}.sign(&"".sha3(), None);
|
|
|
|
|
|
|
|
state.init_code(&0xa.into(), FromHex::from_hex("60006000600060006000600b602b5a03f1").unwrap());
|
|
|
|
state.init_code(&0xb.into(), FromHex::from_hex("6000").unwrap());
|
|
|
|
state.add_balance(t.sender().as_ref().unwrap(), &(100.into()), CleanupMode::NoEmpty);
|
|
|
|
let result = state.apply(&info, &engine, &t, true).unwrap();
|
|
|
|
|
|
|
|
let expected_trace = vec![FlatTrace {
|
|
|
|
trace_address: Default::default(),
|
|
|
|
subtraces: 1,
|
|
|
|
action: trace::Action::Call(trace::Call {
|
|
|
|
from: "9cce34f7ab185c7aba1b7c8140d620b4bda941d6".into(),
|
|
|
|
to: 0xa.into(),
|
|
|
|
value: 100.into(),
|
|
|
|
gas: 79000.into(),
|
|
|
|
input: vec![],
|
|
|
|
call_type: CallType::Call,
|
|
|
|
}),
|
|
|
|
result: trace::Res::Call(trace::CallResult {
|
|
|
|
gas_used: U256::from(69),
|
|
|
|
output: vec![]
|
|
|
|
}),
|
|
|
|
}, FlatTrace {
|
|
|
|
trace_address: vec![0].into_iter().collect(),
|
|
|
|
subtraces: 0,
|
|
|
|
action: trace::Action::Call(trace::Call {
|
|
|
|
from: 0xa.into(),
|
|
|
|
to: 0xb.into(),
|
|
|
|
value: 0.into(),
|
|
|
|
gas: 78934.into(),
|
|
|
|
input: vec![],
|
|
|
|
call_type: CallType::Call,
|
|
|
|
}),
|
|
|
|
result: trace::Res::Call(trace::CallResult {
|
|
|
|
gas_used: U256::from(3),
|
|
|
|
output: vec![]
|
|
|
|
}),
|
|
|
|
}];
|
|
|
|
|
|
|
|
assert_eq!(result.trace, expected_trace);
|
|
|
|
}
|
2016-03-20 16:24:19 +01:00
|
|
|
|
2016-11-14 17:47:56 +01:00
|
|
|
#[test]
|
|
|
|
fn should_trace_call_with_basic_subcall_transaction() {
|
|
|
|
init_log();
|
|
|
|
|
|
|
|
let temp = RandomTempPath::new();
|
|
|
|
let mut state = get_temp_state_in(temp.as_path());
|
|
|
|
|
|
|
|
let mut info = EnvInfo::default();
|
|
|
|
info.gas_limit = 1_000_000.into();
|
|
|
|
let engine = TestEngine::new(5);
|
2016-03-20 16:24:19 +01:00
|
|
|
|
2016-11-14 17:47:56 +01:00
|
|
|
let t = Transaction {
|
|
|
|
nonce: 0.into(),
|
|
|
|
gas_price: 0.into(),
|
|
|
|
gas: 100_000.into(),
|
|
|
|
action: Action::Call(0xa.into()),
|
2016-05-31 16:59:01 +02:00
|
|
|
value: 100.into(),
|
2016-11-14 17:47:56 +01:00
|
|
|
data: vec![],
|
|
|
|
}.sign(&"".sha3(), None);
|
|
|
|
|
|
|
|
state.init_code(&0xa.into(), FromHex::from_hex("60006000600060006045600b6000f1").unwrap());
|
|
|
|
state.add_balance(t.sender().as_ref().unwrap(), &(100.into()), CleanupMode::NoEmpty);
|
|
|
|
let result = state.apply(&info, &engine, &t, true).unwrap();
|
|
|
|
let expected_trace = vec![FlatTrace {
|
|
|
|
trace_address: Default::default(),
|
|
|
|
subtraces: 1,
|
|
|
|
action: trace::Action::Call(trace::Call {
|
|
|
|
from: "9cce34f7ab185c7aba1b7c8140d620b4bda941d6".into(),
|
|
|
|
to: 0xa.into(),
|
|
|
|
value: 100.into(),
|
|
|
|
gas: 79000.into(),
|
|
|
|
input: vec![],
|
|
|
|
call_type: CallType::Call,
|
|
|
|
}),
|
|
|
|
result: trace::Res::Call(trace::CallResult {
|
|
|
|
gas_used: U256::from(31761),
|
|
|
|
output: vec![]
|
|
|
|
}),
|
|
|
|
}, FlatTrace {
|
|
|
|
trace_address: vec![0].into_iter().collect(),
|
|
|
|
subtraces: 0,
|
|
|
|
action: trace::Action::Call(trace::Call {
|
|
|
|
from: 0xa.into(),
|
|
|
|
to: 0xb.into(),
|
|
|
|
value: 69.into(),
|
|
|
|
gas: 2300.into(),
|
|
|
|
input: vec![],
|
|
|
|
call_type: CallType::Call,
|
|
|
|
}),
|
|
|
|
result: trace::Res::Call(trace::CallResult::default()),
|
|
|
|
}];
|
|
|
|
|
|
|
|
assert_eq!(result.trace, expected_trace);
|
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn should_not_trace_call_with_invalid_basic_subcall_transaction() {
|
|
|
|
init_log();
|
2016-03-20 16:24:19 +01:00
|
|
|
|
2016-11-14 17:47:56 +01:00
|
|
|
let temp = RandomTempPath::new();
|
|
|
|
let mut state = get_temp_state_in(temp.as_path());
|
|
|
|
|
|
|
|
let mut info = EnvInfo::default();
|
|
|
|
info.gas_limit = 1_000_000.into();
|
|
|
|
let engine = TestEngine::new(5);
|
2016-03-20 16:24:19 +01:00
|
|
|
|
2016-11-14 17:47:56 +01:00
|
|
|
let t = Transaction {
|
|
|
|
nonce: 0.into(),
|
|
|
|
gas_price: 0.into(),
|
|
|
|
gas: 100_000.into(),
|
|
|
|
action: Action::Call(0xa.into()),
|
2016-05-31 16:59:01 +02:00
|
|
|
value: 100.into(),
|
2016-11-14 17:47:56 +01:00
|
|
|
data: vec![],
|
|
|
|
}.sign(&"".sha3(), None);
|
|
|
|
|
|
|
|
state.init_code(&0xa.into(), FromHex::from_hex("600060006000600060ff600b6000f1").unwrap()); // not enough funds.
|
|
|
|
state.add_balance(t.sender().as_ref().unwrap(), &(100.into()), CleanupMode::NoEmpty);
|
|
|
|
let result = state.apply(&info, &engine, &t, true).unwrap();
|
|
|
|
let expected_trace = vec![FlatTrace {
|
|
|
|
trace_address: Default::default(),
|
|
|
|
subtraces: 0,
|
2016-04-30 17:41:24 +02:00
|
|
|
action: trace::Action::Call(trace::Call {
|
2016-11-14 17:47:56 +01:00
|
|
|
from: "9cce34f7ab185c7aba1b7c8140d620b4bda941d6".into(),
|
|
|
|
to: 0xa.into(),
|
|
|
|
value: 100.into(),
|
|
|
|
gas: 79000.into(),
|
|
|
|
input: vec![],
|
|
|
|
call_type: CallType::Call,
|
|
|
|
}),
|
|
|
|
result: trace::Res::Call(trace::CallResult {
|
|
|
|
gas_used: U256::from(31761),
|
|
|
|
output: vec![]
|
|
|
|
}),
|
|
|
|
}];
|
|
|
|
|
|
|
|
assert_eq!(result.trace, expected_trace);
|
|
|
|
}
|
2016-03-20 12:04:31 +01:00
|
|
|
|
2016-11-14 17:47:56 +01:00
|
|
|
#[test]
|
|
|
|
fn should_trace_failed_subcall_transaction() {
|
|
|
|
init_log();
|
|
|
|
|
|
|
|
let temp = RandomTempPath::new();
|
|
|
|
let mut state = get_temp_state_in(temp.as_path());
|
2016-03-20 12:04:31 +01:00
|
|
|
|
2016-11-14 17:47:56 +01:00
|
|
|
let mut info = EnvInfo::default();
|
|
|
|
info.gas_limit = 1_000_000.into();
|
|
|
|
let engine = TestEngine::new(5);
|
|
|
|
|
|
|
|
let t = Transaction {
|
|
|
|
nonce: 0.into(),
|
|
|
|
gas_price: 0.into(),
|
|
|
|
gas: 100_000.into(),
|
|
|
|
action: Action::Call(0xa.into()),
|
2016-07-22 14:47:23 +02:00
|
|
|
value: 100.into(),
|
2016-11-14 17:47:56 +01:00
|
|
|
data: vec![],//600480600b6000396000f35b600056
|
|
|
|
}.sign(&"".sha3(), None);
|
|
|
|
|
|
|
|
state.init_code(&0xa.into(), FromHex::from_hex("60006000600060006000600b602b5a03f1").unwrap());
|
|
|
|
state.init_code(&0xb.into(), FromHex::from_hex("5b600056").unwrap());
|
|
|
|
state.add_balance(t.sender().as_ref().unwrap(), &(100.into()), CleanupMode::NoEmpty);
|
|
|
|
let result = state.apply(&info, &engine, &t, true).unwrap();
|
|
|
|
let expected_trace = vec![FlatTrace {
|
|
|
|
trace_address: Default::default(),
|
|
|
|
subtraces: 1,
|
|
|
|
action: trace::Action::Call(trace::Call {
|
|
|
|
from: "9cce34f7ab185c7aba1b7c8140d620b4bda941d6".into(),
|
|
|
|
to: 0xa.into(),
|
|
|
|
value: 100.into(),
|
|
|
|
gas: 79000.into(),
|
|
|
|
input: vec![],
|
|
|
|
call_type: CallType::Call,
|
|
|
|
}),
|
|
|
|
result: trace::Res::Call(trace::CallResult {
|
|
|
|
gas_used: U256::from(79_000),
|
|
|
|
output: vec![]
|
|
|
|
}),
|
|
|
|
}, FlatTrace {
|
|
|
|
trace_address: vec![0].into_iter().collect(),
|
|
|
|
subtraces: 0,
|
|
|
|
action: trace::Action::Call(trace::Call {
|
|
|
|
from: 0xa.into(),
|
|
|
|
to: 0xb.into(),
|
|
|
|
value: 0.into(),
|
|
|
|
gas: 78934.into(),
|
|
|
|
input: vec![],
|
|
|
|
call_type: CallType::Call,
|
|
|
|
}),
|
|
|
|
result: trace::Res::FailedCall(TraceError::OutOfGas),
|
|
|
|
}];
|
|
|
|
|
|
|
|
assert_eq!(result.trace, expected_trace);
|
|
|
|
}
|
2016-07-22 14:47:23 +02:00
|
|
|
|
2016-11-14 17:47:56 +01:00
|
|
|
#[test]
|
|
|
|
fn should_trace_call_with_subcall_with_subcall_transaction() {
|
|
|
|
init_log();
|
2016-07-22 14:47:23 +02:00
|
|
|
|
2016-11-14 17:47:56 +01:00
|
|
|
let temp = RandomTempPath::new();
|
2016-01-31 10:52:07 +01:00
|
|
|
let mut state = get_temp_state_in(temp.as_path());
|
2015-12-19 19:00:19 +01:00
|
|
|
|
2016-11-14 17:47:56 +01:00
|
|
|
let mut info = EnvInfo::default();
|
|
|
|
info.gas_limit = 1_000_000.into();
|
|
|
|
let engine = TestEngine::new(5);
|
2015-12-19 19:00:19 +01:00
|
|
|
|
2016-11-14 17:47:56 +01:00
|
|
|
let t = Transaction {
|
|
|
|
nonce: 0.into(),
|
|
|
|
gas_price: 0.into(),
|
|
|
|
gas: 100_000.into(),
|
|
|
|
action: Action::Call(0xa.into()),
|
|
|
|
value: 100.into(),
|
|
|
|
data: vec![],
|
|
|
|
}.sign(&"".sha3(), None);
|
|
|
|
|
|
|
|
state.init_code(&0xa.into(), FromHex::from_hex("60006000600060006000600b602b5a03f1").unwrap());
|
|
|
|
state.init_code(&0xb.into(), FromHex::from_hex("60006000600060006000600c602b5a03f1").unwrap());
|
|
|
|
state.init_code(&0xc.into(), FromHex::from_hex("6000").unwrap());
|
|
|
|
state.add_balance(t.sender().as_ref().unwrap(), &(100.into()), CleanupMode::NoEmpty);
|
|
|
|
let result = state.apply(&info, &engine, &t, true).unwrap();
|
|
|
|
let expected_trace = vec![FlatTrace {
|
|
|
|
trace_address: Default::default(),
|
|
|
|
subtraces: 1,
|
|
|
|
action: trace::Action::Call(trace::Call {
|
|
|
|
from: "9cce34f7ab185c7aba1b7c8140d620b4bda941d6".into(),
|
|
|
|
to: 0xa.into(),
|
|
|
|
value: 100.into(),
|
|
|
|
gas: 79000.into(),
|
|
|
|
input: vec![],
|
|
|
|
call_type: CallType::Call,
|
|
|
|
}),
|
|
|
|
result: trace::Res::Call(trace::CallResult {
|
|
|
|
gas_used: U256::from(135),
|
|
|
|
output: vec![]
|
|
|
|
}),
|
|
|
|
}, FlatTrace {
|
|
|
|
trace_address: vec![0].into_iter().collect(),
|
|
|
|
subtraces: 1,
|
|
|
|
action: trace::Action::Call(trace::Call {
|
|
|
|
from: 0xa.into(),
|
|
|
|
to: 0xb.into(),
|
|
|
|
value: 0.into(),
|
|
|
|
gas: 78934.into(),
|
|
|
|
input: vec![],
|
|
|
|
call_type: CallType::Call,
|
|
|
|
}),
|
|
|
|
result: trace::Res::Call(trace::CallResult {
|
|
|
|
gas_used: U256::from(69),
|
|
|
|
output: vec![]
|
|
|
|
}),
|
|
|
|
}, FlatTrace {
|
|
|
|
trace_address: vec![0, 0].into_iter().collect(),
|
|
|
|
subtraces: 0,
|
|
|
|
action: trace::Action::Call(trace::Call {
|
|
|
|
from: 0xb.into(),
|
|
|
|
to: 0xc.into(),
|
|
|
|
value: 0.into(),
|
|
|
|
gas: 78868.into(),
|
|
|
|
input: vec![],
|
|
|
|
call_type: CallType::Call,
|
|
|
|
}),
|
|
|
|
result: trace::Res::Call(trace::CallResult {
|
|
|
|
gas_used: U256::from(3),
|
|
|
|
output: vec![]
|
|
|
|
}),
|
|
|
|
}];
|
|
|
|
|
|
|
|
assert_eq!(result.trace, expected_trace);
|
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn should_trace_failed_subcall_with_subcall_transaction() {
|
|
|
|
init_log();
|
|
|
|
|
|
|
|
let temp = RandomTempPath::new();
|
2016-01-31 10:52:07 +01:00
|
|
|
let mut state = get_temp_state_in(temp.as_path());
|
2015-12-19 19:00:19 +01:00
|
|
|
|
2016-11-14 17:47:56 +01:00
|
|
|
let mut info = EnvInfo::default();
|
|
|
|
info.gas_limit = 1_000_000.into();
|
|
|
|
let engine = TestEngine::new(5);
|
2015-12-16 16:39:49 +01:00
|
|
|
|
2016-11-14 17:47:56 +01:00
|
|
|
let t = Transaction {
|
|
|
|
nonce: 0.into(),
|
|
|
|
gas_price: 0.into(),
|
|
|
|
gas: 100_000.into(),
|
|
|
|
action: Action::Call(0xa.into()),
|
|
|
|
value: 100.into(),
|
|
|
|
data: vec![],//600480600b6000396000f35b600056
|
|
|
|
}.sign(&"".sha3(), None);
|
|
|
|
|
|
|
|
state.init_code(&0xa.into(), FromHex::from_hex("60006000600060006000600b602b5a03f1").unwrap());
|
|
|
|
state.init_code(&0xb.into(), FromHex::from_hex("60006000600060006000600c602b5a03f1505b601256").unwrap());
|
|
|
|
state.init_code(&0xc.into(), FromHex::from_hex("6000").unwrap());
|
|
|
|
state.add_balance(t.sender().as_ref().unwrap(), &(100.into()), CleanupMode::NoEmpty);
|
|
|
|
let result = state.apply(&info, &engine, &t, true).unwrap();
|
|
|
|
|
|
|
|
let expected_trace = vec![FlatTrace {
|
|
|
|
trace_address: Default::default(),
|
|
|
|
subtraces: 1,
|
|
|
|
action: trace::Action::Call(trace::Call {
|
|
|
|
from: "9cce34f7ab185c7aba1b7c8140d620b4bda941d6".into(),
|
|
|
|
to: 0xa.into(),
|
|
|
|
value: 100.into(),
|
|
|
|
gas: 79000.into(),
|
|
|
|
input: vec![],
|
|
|
|
call_type: CallType::Call,
|
|
|
|
}),
|
|
|
|
result: trace::Res::Call(trace::CallResult {
|
|
|
|
gas_used: U256::from(79_000),
|
|
|
|
output: vec![]
|
|
|
|
})
|
|
|
|
}, FlatTrace {
|
|
|
|
trace_address: vec![0].into_iter().collect(),
|
|
|
|
subtraces: 1,
|
|
|
|
action: trace::Action::Call(trace::Call {
|
|
|
|
from: 0xa.into(),
|
|
|
|
to: 0xb.into(),
|
|
|
|
value: 0.into(),
|
|
|
|
gas: 78934.into(),
|
|
|
|
input: vec![],
|
|
|
|
call_type: CallType::Call,
|
|
|
|
}),
|
|
|
|
result: trace::Res::FailedCall(TraceError::OutOfGas),
|
|
|
|
}, FlatTrace {
|
|
|
|
trace_address: vec![0, 0].into_iter().collect(),
|
|
|
|
subtraces: 0,
|
|
|
|
action: trace::Action::Call(trace::Call {
|
|
|
|
from: 0xb.into(),
|
|
|
|
to: 0xc.into(),
|
|
|
|
value: 0.into(),
|
|
|
|
gas: 78868.into(),
|
|
|
|
call_type: CallType::Call,
|
|
|
|
input: vec![],
|
|
|
|
}),
|
|
|
|
result: trace::Res::Call(trace::CallResult {
|
|
|
|
gas_used: U256::from(3),
|
|
|
|
output: vec![]
|
|
|
|
}),
|
|
|
|
}];
|
|
|
|
|
|
|
|
assert_eq!(result.trace, expected_trace);
|
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn should_trace_suicide() {
|
|
|
|
init_log();
|
2015-12-16 16:39:49 +01:00
|
|
|
|
2016-11-14 17:47:56 +01:00
|
|
|
let temp = RandomTempPath::new();
|
2016-01-31 10:52:07 +01:00
|
|
|
let mut state = get_temp_state_in(temp.as_path());
|
2015-12-16 20:02:28 +01:00
|
|
|
|
2016-11-14 17:47:56 +01:00
|
|
|
let mut info = EnvInfo::default();
|
|
|
|
info.gas_limit = 1_000_000.into();
|
|
|
|
let engine = TestEngine::new(5);
|
2015-12-16 18:20:23 +01:00
|
|
|
|
2016-11-14 17:47:56 +01:00
|
|
|
let t = Transaction {
|
|
|
|
nonce: 0.into(),
|
|
|
|
gas_price: 0.into(),
|
|
|
|
gas: 100_000.into(),
|
|
|
|
action: Action::Call(0xa.into()),
|
|
|
|
value: 100.into(),
|
|
|
|
data: vec![],
|
|
|
|
}.sign(&"".sha3(), None);
|
|
|
|
|
|
|
|
state.init_code(&0xa.into(), FromHex::from_hex("73000000000000000000000000000000000000000bff").unwrap());
|
|
|
|
state.add_balance(&0xa.into(), &50.into(), CleanupMode::NoEmpty);
|
|
|
|
state.add_balance(t.sender().as_ref().unwrap(), &100.into(), CleanupMode::NoEmpty);
|
|
|
|
let result = state.apply(&info, &engine, &t, true).unwrap();
|
|
|
|
let expected_trace = vec![FlatTrace {
|
|
|
|
trace_address: Default::default(),
|
|
|
|
subtraces: 1,
|
|
|
|
action: trace::Action::Call(trace::Call {
|
|
|
|
from: "9cce34f7ab185c7aba1b7c8140d620b4bda941d6".into(),
|
|
|
|
to: 0xa.into(),
|
|
|
|
value: 100.into(),
|
|
|
|
gas: 79000.into(),
|
|
|
|
input: vec![],
|
|
|
|
call_type: CallType::Call,
|
|
|
|
}),
|
|
|
|
result: trace::Res::Call(trace::CallResult {
|
|
|
|
gas_used: 3.into(),
|
|
|
|
output: vec![]
|
|
|
|
}),
|
|
|
|
}, FlatTrace {
|
|
|
|
trace_address: vec![0].into_iter().collect(),
|
|
|
|
subtraces: 0,
|
|
|
|
action: trace::Action::Suicide(trace::Suicide {
|
|
|
|
address: 0xa.into(),
|
|
|
|
refund_address: 0xb.into(),
|
|
|
|
balance: 150.into(),
|
|
|
|
}),
|
|
|
|
result: trace::Res::None,
|
|
|
|
}];
|
|
|
|
|
|
|
|
assert_eq!(result.trace, expected_trace);
|
|
|
|
}
|
2016-01-09 22:28:31 +01:00
|
|
|
|
2016-11-14 17:47:56 +01:00
|
|
|
#[test]
|
|
|
|
fn code_from_database() {
|
|
|
|
let a = Address::zero();
|
|
|
|
let temp = RandomTempPath::new();
|
|
|
|
let (root, db) = {
|
|
|
|
let mut state = get_temp_state_in(temp.as_path());
|
|
|
|
state.require_or_from(&a, false, ||Account::new_contract(42.into(), 0.into()), |_|{});
|
|
|
|
state.init_code(&a, vec![1, 2, 3]);
|
|
|
|
assert_eq!(state.code(&a), Some(Arc::new([1u8, 2, 3].to_vec())));
|
|
|
|
state.commit().unwrap();
|
|
|
|
assert_eq!(state.code(&a), Some(Arc::new([1u8, 2, 3].to_vec())));
|
|
|
|
state.drop()
|
|
|
|
};
|
2016-11-03 22:22:25 +01:00
|
|
|
|
2016-11-14 17:47:56 +01:00
|
|
|
let state = State::from_existing(db, root, U256::from(0u8), Default::default()).unwrap();
|
|
|
|
assert_eq!(state.code(&a), Some(Arc::new([1u8, 2, 3].to_vec())));
|
|
|
|
}
|
2016-10-21 20:36:40 +02:00
|
|
|
|
2016-11-14 17:47:56 +01:00
|
|
|
#[test]
|
|
|
|
fn storage_at_from_database() {
|
|
|
|
let a = Address::zero();
|
|
|
|
let temp = RandomTempPath::new();
|
|
|
|
let (root, db) = {
|
|
|
|
let mut state = get_temp_state_in(temp.as_path());
|
|
|
|
state.set_storage(&a, H256::from(&U256::from(1u64)), H256::from(&U256::from(69u64)));
|
|
|
|
state.commit().unwrap();
|
|
|
|
state.drop()
|
|
|
|
};
|
|
|
|
|
|
|
|
let s = State::from_existing(db, root, U256::from(0u8), Default::default()).unwrap();
|
|
|
|
assert_eq!(s.storage_at(&a, &H256::from(&U256::from(1u64))), H256::from(&U256::from(69u64)));
|
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn get_from_database() {
|
|
|
|
let a = Address::zero();
|
|
|
|
let temp = RandomTempPath::new();
|
|
|
|
let (root, db) = {
|
|
|
|
let mut state = get_temp_state_in(temp.as_path());
|
|
|
|
state.inc_nonce(&a);
|
|
|
|
state.add_balance(&a, &U256::from(69u64), CleanupMode::NoEmpty);
|
|
|
|
state.commit().unwrap();
|
|
|
|
assert_eq!(state.balance(&a), U256::from(69u64));
|
|
|
|
state.drop()
|
|
|
|
};
|
|
|
|
|
|
|
|
let state = State::from_existing(db, root, U256::from(0u8), Default::default()).unwrap();
|
|
|
|
assert_eq!(state.balance(&a), U256::from(69u64));
|
2016-01-31 10:52:07 +01:00
|
|
|
assert_eq!(state.nonce(&a), U256::from(1u64));
|
2016-11-14 17:47:56 +01:00
|
|
|
}
|
2016-01-09 22:28:31 +01:00
|
|
|
|
2016-11-14 17:47:56 +01:00
|
|
|
#[test]
|
|
|
|
fn remove() {
|
|
|
|
let a = Address::zero();
|
|
|
|
let mut state_result = get_temp_state();
|
|
|
|
let mut state = state_result.reference_mut();
|
|
|
|
assert_eq!(state.exists(&a), false);
|
|
|
|
assert_eq!(state.exists_and_not_null(&a), false);
|
|
|
|
state.inc_nonce(&a);
|
2016-01-31 10:52:07 +01:00
|
|
|
assert_eq!(state.exists(&a), true);
|
2016-11-14 17:47:56 +01:00
|
|
|
assert_eq!(state.exists_and_not_null(&a), true);
|
2016-01-31 10:52:07 +01:00
|
|
|
assert_eq!(state.nonce(&a), U256::from(1u64));
|
|
|
|
state.kill_account(&a);
|
|
|
|
assert_eq!(state.exists(&a), false);
|
2016-11-14 17:47:56 +01:00
|
|
|
assert_eq!(state.exists_and_not_null(&a), false);
|
2016-01-31 10:52:07 +01:00
|
|
|
assert_eq!(state.nonce(&a), U256::from(0u64));
|
2016-11-14 17:47:56 +01:00
|
|
|
}
|
2016-01-09 22:28:31 +01:00
|
|
|
|
2016-11-14 17:47:56 +01:00
|
|
|
#[test]
|
|
|
|
fn empty_account_is_not_created() {
|
|
|
|
let a = Address::zero();
|
|
|
|
let path = RandomTempPath::new();
|
|
|
|
let db = get_temp_state_db_in(path.as_path());
|
|
|
|
let (root, db) = {
|
|
|
|
let mut state = State::new(db, U256::from(0), Default::default());
|
|
|
|
state.add_balance(&a, &U256::default(), CleanupMode::NoEmpty); // create an empty account
|
|
|
|
state.commit().unwrap();
|
|
|
|
state.drop()
|
|
|
|
};
|
|
|
|
let state = State::from_existing(db, root, U256::from(0u8), Default::default()).unwrap();
|
|
|
|
assert!(!state.exists(&a));
|
|
|
|
assert!(!state.exists_and_not_null(&a));
|
|
|
|
}
|
2016-01-09 22:28:31 +01:00
|
|
|
|
2016-11-14 17:47:56 +01:00
|
|
|
#[test]
|
|
|
|
fn empty_account_exists_when_creation_forced() {
|
|
|
|
let a = Address::zero();
|
|
|
|
let path = RandomTempPath::new();
|
|
|
|
let db = get_temp_state_db_in(path.as_path());
|
|
|
|
let (root, db) = {
|
|
|
|
let mut state = State::new(db, U256::from(0), Default::default());
|
|
|
|
state.add_balance(&a, &U256::default(), CleanupMode::ForceCreate); // create an empty account
|
|
|
|
state.commit().unwrap();
|
|
|
|
state.drop()
|
|
|
|
};
|
|
|
|
let state = State::from_existing(db, root, U256::from(0u8), Default::default()).unwrap();
|
|
|
|
assert!(state.exists(&a));
|
|
|
|
assert!(!state.exists_and_not_null(&a));
|
|
|
|
}
|
2015-12-16 18:28:04 +01:00
|
|
|
|
2016-11-14 17:47:56 +01:00
|
|
|
#[test]
|
|
|
|
fn remove_from_database() {
|
|
|
|
let a = Address::zero();
|
|
|
|
let temp = RandomTempPath::new();
|
|
|
|
let (root, db) = {
|
|
|
|
let mut state = get_temp_state_in(temp.as_path());
|
|
|
|
state.inc_nonce(&a);
|
|
|
|
state.commit().unwrap();
|
|
|
|
assert_eq!(state.exists(&a), true);
|
|
|
|
assert_eq!(state.nonce(&a), U256::from(1u64));
|
|
|
|
state.drop()
|
|
|
|
};
|
2015-12-16 18:20:23 +01:00
|
|
|
|
2016-11-14 17:47:56 +01:00
|
|
|
let (root, db) = {
|
|
|
|
let mut state = State::from_existing(db, root, U256::from(0u8), Default::default()).unwrap();
|
|
|
|
assert_eq!(state.exists(&a), true);
|
|
|
|
assert_eq!(state.nonce(&a), U256::from(1u64));
|
|
|
|
state.kill_account(&a);
|
|
|
|
state.commit().unwrap();
|
|
|
|
assert_eq!(state.exists(&a), false);
|
|
|
|
assert_eq!(state.nonce(&a), U256::from(0u64));
|
|
|
|
state.drop()
|
|
|
|
};
|
2015-12-16 16:39:49 +01:00
|
|
|
|
2016-11-14 17:47:56 +01:00
|
|
|
let state = State::from_existing(db, root, U256::from(0u8), Default::default()).unwrap();
|
|
|
|
assert_eq!(state.exists(&a), false);
|
|
|
|
assert_eq!(state.nonce(&a), U256::from(0u64));
|
|
|
|
}
|
2015-12-16 16:39:49 +01:00
|
|
|
|
2016-11-14 17:47:56 +01:00
|
|
|
#[test]
|
|
|
|
fn alter_balance() {
|
|
|
|
let mut state_result = get_temp_state();
|
|
|
|
let mut state = state_result.reference_mut();
|
|
|
|
let a = Address::zero();
|
|
|
|
let b = 1u64.into();
|
|
|
|
state.add_balance(&a, &U256::from(69u64), CleanupMode::NoEmpty);
|
|
|
|
assert_eq!(state.balance(&a), U256::from(69u64));
|
|
|
|
state.commit().unwrap();
|
|
|
|
assert_eq!(state.balance(&a), U256::from(69u64));
|
|
|
|
state.sub_balance(&a, &U256::from(42u64));
|
|
|
|
assert_eq!(state.balance(&a), U256::from(27u64));
|
|
|
|
state.commit().unwrap();
|
|
|
|
assert_eq!(state.balance(&a), U256::from(27u64));
|
|
|
|
state.transfer_balance(&a, &b, &U256::from(18u64), CleanupMode::NoEmpty);
|
|
|
|
assert_eq!(state.balance(&a), U256::from(9u64));
|
|
|
|
assert_eq!(state.balance(&b), U256::from(18u64));
|
|
|
|
state.commit().unwrap();
|
|
|
|
assert_eq!(state.balance(&a), U256::from(9u64));
|
|
|
|
assert_eq!(state.balance(&b), U256::from(18u64));
|
|
|
|
}
|
2016-02-05 12:58:18 +01:00
|
|
|
|
2016-11-14 17:47:56 +01:00
|
|
|
#[test]
|
|
|
|
fn alter_nonce() {
|
|
|
|
let mut state_result = get_temp_state();
|
|
|
|
let mut state = state_result.reference_mut();
|
|
|
|
let a = Address::zero();
|
|
|
|
state.inc_nonce(&a);
|
|
|
|
assert_eq!(state.nonce(&a), U256::from(1u64));
|
|
|
|
state.inc_nonce(&a);
|
|
|
|
assert_eq!(state.nonce(&a), U256::from(2u64));
|
|
|
|
state.commit().unwrap();
|
|
|
|
assert_eq!(state.nonce(&a), U256::from(2u64));
|
|
|
|
state.inc_nonce(&a);
|
|
|
|
assert_eq!(state.nonce(&a), U256::from(3u64));
|
|
|
|
state.commit().unwrap();
|
|
|
|
assert_eq!(state.nonce(&a), U256::from(3u64));
|
|
|
|
}
|
2016-02-05 12:58:18 +01:00
|
|
|
|
2016-11-14 17:47:56 +01:00
|
|
|
#[test]
|
|
|
|
fn balance_nonce() {
|
|
|
|
let mut state_result = get_temp_state();
|
|
|
|
let mut state = state_result.reference_mut();
|
|
|
|
let a = Address::zero();
|
|
|
|
assert_eq!(state.balance(&a), U256::from(0u64));
|
|
|
|
assert_eq!(state.nonce(&a), U256::from(0u64));
|
|
|
|
state.commit().unwrap();
|
|
|
|
assert_eq!(state.balance(&a), U256::from(0u64));
|
|
|
|
assert_eq!(state.nonce(&a), U256::from(0u64));
|
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn ensure_cached() {
|
|
|
|
let mut state_result = get_temp_state();
|
|
|
|
let mut state = state_result.reference_mut();
|
|
|
|
let a = Address::zero();
|
|
|
|
state.require(&a, false);
|
|
|
|
state.commit().unwrap();
|
|
|
|
assert_eq!(state.root().hex(), "0ce23f3c809de377b008a4a3ee94a0834aac8bec1f86e28ffe4fdb5a15b0c785");
|
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn checkpoint_basic() {
|
|
|
|
let mut state_result = get_temp_state();
|
|
|
|
let mut state = state_result.reference_mut();
|
|
|
|
let a = Address::zero();
|
|
|
|
state.checkpoint();
|
|
|
|
state.add_balance(&a, &U256::from(69u64), CleanupMode::NoEmpty);
|
|
|
|
assert_eq!(state.balance(&a), U256::from(69u64));
|
|
|
|
state.discard_checkpoint();
|
|
|
|
assert_eq!(state.balance(&a), U256::from(69u64));
|
|
|
|
state.checkpoint();
|
|
|
|
state.add_balance(&a, &U256::from(1u64), CleanupMode::NoEmpty);
|
|
|
|
assert_eq!(state.balance(&a), U256::from(70u64));
|
|
|
|
state.revert_to_checkpoint();
|
|
|
|
assert_eq!(state.balance(&a), U256::from(69u64));
|
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn checkpoint_nested() {
|
|
|
|
let mut state_result = get_temp_state();
|
|
|
|
let mut state = state_result.reference_mut();
|
|
|
|
let a = Address::zero();
|
|
|
|
state.checkpoint();
|
|
|
|
state.checkpoint();
|
|
|
|
state.add_balance(&a, &U256::from(69u64), CleanupMode::NoEmpty);
|
|
|
|
assert_eq!(state.balance(&a), U256::from(69u64));
|
|
|
|
state.discard_checkpoint();
|
|
|
|
assert_eq!(state.balance(&a), U256::from(69u64));
|
|
|
|
state.revert_to_checkpoint();
|
|
|
|
assert_eq!(state.balance(&a), U256::from(0));
|
|
|
|
}
|
2015-12-16 16:39:49 +01:00
|
|
|
|
2016-11-14 17:47:56 +01:00
|
|
|
#[test]
|
|
|
|
fn create_empty() {
|
|
|
|
let mut state_result = get_temp_state();
|
|
|
|
let mut state = state_result.reference_mut();
|
|
|
|
state.commit().unwrap();
|
|
|
|
assert_eq!(state.root().hex(), "56e81f171bcc55a6ff8345e692c0f86e5b48e01b996cadc001622fb5e363b421");
|
|
|
|
}
|
2016-10-13 23:28:56 +02:00
|
|
|
|
2016-11-14 17:47:56 +01:00
|
|
|
#[test]
|
|
|
|
fn should_not_panic_on_state_diff_with_storage() {
|
|
|
|
let state = get_temp_state();
|
|
|
|
let mut state = state.reference().clone();
|
2016-10-13 23:28:56 +02:00
|
|
|
|
2016-11-14 17:47:56 +01:00
|
|
|
let a: Address = 0xa.into();
|
|
|
|
state.init_code(&a, b"abcdefg".to_vec());
|
|
|
|
state.add_balance(&a, &256.into(), CleanupMode::NoEmpty);
|
|
|
|
state.set_storage(&a, 0xb.into(), 0xc.into());
|
2016-10-13 23:28:56 +02:00
|
|
|
|
2016-11-14 17:47:56 +01:00
|
|
|
let mut new_state = state.clone();
|
|
|
|
new_state.set_storage(&a, 0xb.into(), 0xd.into());
|
|
|
|
|
|
|
|
new_state.diff_from(state);
|
|
|
|
}
|
2016-10-13 23:28:56 +02:00
|
|
|
|
2016-08-10 16:29:40 +02:00
|
|
|
}
|