Skip to content
This repository has been archived by the owner on Nov 6, 2020. It is now read-only.

Add trace information to eth_estimateGas #10519

Merged
merged 5 commits into from
Mar 27, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
19 changes: 12 additions & 7 deletions ethcore/src/client/client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1570,22 +1570,27 @@ impl Call for Client {
let schedule = machine.schedule(env_info.number);
Executive::new(&mut clone, &env_info, &machine, &schedule)
.transact_virtual(&tx, options())
.ok()
.map(|r| r.exception.is_none())
};

let cond = |gas| exec(gas).unwrap_or(false);
let cond = |gas| {
exec(gas)
.ok()
.map_or(false, |r| r.exception.is_none())
};

if !cond(upper) {
upper = max_upper;
match exec(upper) {
Some(false) => return Err(CallError::Exceptional),
None => {
Ok(v) => {
if let Some(exception) = v.exception {
return Err(CallError::Exceptional(exception))
}
},
Err(_e) => {
trace!(target: "estimate_gas", "estimate_gas failed with {}", upper);
let err = ExecutionError::Internal(format!("Requires higher than upper limit of {}", upper));
return Err(err.into())
},
_ => {},
}
}
}
let lower = t.gas_required(&self.engine.schedule(env_info.number)).into();
Expand Down
4 changes: 2 additions & 2 deletions ethcore/src/executed.rs
Original file line number Diff line number Diff line change
Expand Up @@ -167,7 +167,7 @@ pub enum CallError {
/// 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,
Exceptional(vm::Error),
/// Corrupt state.
StateCorrupt,
/// Error executing.
Expand All @@ -187,7 +187,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(),
Exceptional(ref e) => format!("An exception ({}) happened in the execution", e),
StateCorrupt => "Stored state found to be corrupted.".into(),
Execution(ref e) => format!("{}", e),
};
Expand Down
6 changes: 3 additions & 3 deletions rpc/src/v1/helpers/errors.rs
Original file line number Diff line number Diff line change
Expand Up @@ -173,11 +173,11 @@ pub fn state_corrupt() -> Error {
internal("State corrupt", "")
}

pub fn exceptional() -> Error {
pub fn exceptional<T: fmt::Display>(data: T) -> Error {
Error {
code: ErrorCode::ServerError(codes::EXCEPTION_ERROR),
message: "The execution failed due to an exception.".into(),
data: None,
data: Some(Value::String(data.to_string())),
}
}

Expand Down Expand Up @@ -467,7 +467,7 @@ pub fn call(error: CallError) -> Error {
match error {
CallError::StatePruned => state_pruned(),
CallError::StateCorrupt => state_corrupt(),
CallError::Exceptional => exceptional(),
CallError::Exceptional(e) => exceptional(e),
CallError::Execution(e) => execution(e),
CallError::TransactionNotFound => internal("{}, this should not be the case with eth_call, most likely a bug.", CallError::TransactionNotFound),
}
Expand Down