Improvements and optimisations to estimate_gas (#4142)
* Return 0 instead of error with out of gas on estimate_gas * Fix stuff up. * Another estimate gas fix. * Alter balance to maximum possible rather than GP=0. * Only increase to amount strictly necessary. * Improvements and optimisations to estimate_gas. - Introduce proper error type - Avoid building costly traces * Fix tests. * Actually fix testsActually fix tests
This commit is contained in:
committed by
Arkadiy Paronyan
parent
41da1a0a79
commit
311730ea95
@@ -908,7 +908,7 @@ impl BlockChainClient for Client {
|
||||
|
||||
Executive::new(&mut state, &env_info, &*self.engine, &self.factories.vm)
|
||||
.transact(&tx, options.clone())
|
||||
.map(|r| r.trace[0].result.succeeded())
|
||||
.map(|r| r.exception.is_some())
|
||||
.unwrap_or(false)
|
||||
};
|
||||
|
||||
|
||||
@@ -22,7 +22,7 @@ use action_params::ActionParams;
|
||||
use evm::Ext;
|
||||
|
||||
/// Evm errors.
|
||||
#[derive(Debug, Clone, Copy)]
|
||||
#[derive(Debug, Clone, Copy, PartialEq)]
|
||||
pub enum Error {
|
||||
/// `OutOfGas` is returned when transaction execution runs out of gas.
|
||||
/// The state should be reverted to the state from before the
|
||||
|
||||
@@ -463,8 +463,9 @@ impl<'a> Executive<'a> {
|
||||
|
||||
match result {
|
||||
Err(evm::Error::Internal) => Err(ExecutionError::Internal),
|
||||
Err(_) => {
|
||||
Err(exception) => {
|
||||
Ok(Executed {
|
||||
exception: Some(exception),
|
||||
gas: t.gas,
|
||||
gas_used: t.gas,
|
||||
refunded: U256::zero(),
|
||||
@@ -479,6 +480,7 @@ impl<'a> Executive<'a> {
|
||||
},
|
||||
_ => {
|
||||
Ok(Executed {
|
||||
exception: None,
|
||||
gas: t.gas,
|
||||
gas_used: gas_used,
|
||||
refunded: refunded,
|
||||
|
||||
@@ -18,6 +18,7 @@
|
||||
|
||||
use util::{Bytes, U256, Address, U512};
|
||||
use rlp::*;
|
||||
use evm;
|
||||
use trace::{VMTrace, FlatTrace};
|
||||
use types::log_entry::LogEntry;
|
||||
use types::state_diff::StateDiff;
|
||||
@@ -65,6 +66,9 @@ impl Decodable for CallType {
|
||||
#[derive(Debug, PartialEq, Clone)]
|
||||
#[cfg_attr(feature = "ipc", binary)]
|
||||
pub struct Executed {
|
||||
/// True if the outer call/create resulted in an exceptional exit.
|
||||
pub exception: Option<evm::Error>,
|
||||
|
||||
/// Gas paid up front for execution of transaction.
|
||||
pub gas: U256,
|
||||
|
||||
@@ -178,6 +182,8 @@ pub enum CallError {
|
||||
TransactionNotFound,
|
||||
/// Couldn't find requested block's state in the chain.
|
||||
StatePruned,
|
||||
/// Couldn't find an amount of gas that didn't result in an exception.
|
||||
Exceptional,
|
||||
/// Error executing.
|
||||
Execution(ExecutionError),
|
||||
}
|
||||
@@ -195,6 +201,7 @@ impl fmt::Display for CallError {
|
||||
let msg = match *self {
|
||||
TransactionNotFound => "Transaction couldn't be found in the chain".into(),
|
||||
StatePruned => "Couldn't find the transaction block's state in the chain".into(),
|
||||
Exceptional => "An exception happened in the execution".into(),
|
||||
Execution(ref e) => format!("{}", e),
|
||||
};
|
||||
|
||||
|
||||
Reference in New Issue
Block a user