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

Commit 178dea0

Browse files
fanatidniklasad1
authored andcommitted
Add trace information to eth_estimateGas (#10519)
* Add trace information to eth_estimateGas * replace unwrap better version * change vm::Error formatter to more user-friendly * remove extra error format * use map_or instead sequence of map/unwrap_or
1 parent 67e331b commit 178dea0

File tree

3 files changed

+17
-12
lines changed

3 files changed

+17
-12
lines changed

ethcore/src/client/client.rs

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1571,22 +1571,27 @@ impl Call for Client {
15711571
let schedule = machine.schedule(env_info.number);
15721572
Executive::new(&mut clone, &env_info, &machine, &schedule)
15731573
.transact_virtual(&tx, options())
1574-
.ok()
1575-
.map(|r| r.exception.is_none())
15761574
};
15771575

1578-
let cond = |gas| exec(gas).unwrap_or(false);
1576+
let cond = |gas| {
1577+
exec(gas)
1578+
.ok()
1579+
.map_or(false, |r| r.exception.is_none())
1580+
};
15791581

15801582
if !cond(upper) {
15811583
upper = max_upper;
15821584
match exec(upper) {
1583-
Some(false) => return Err(CallError::Exceptional),
1584-
None => {
1585+
Ok(v) => {
1586+
if let Some(exception) = v.exception {
1587+
return Err(CallError::Exceptional(exception))
1588+
}
1589+
},
1590+
Err(_e) => {
15851591
trace!(target: "estimate_gas", "estimate_gas failed with {}", upper);
15861592
let err = ExecutionError::Internal(format!("Requires higher than upper limit of {}", upper));
15871593
return Err(err.into())
1588-
},
1589-
_ => {},
1594+
}
15901595
}
15911596
}
15921597
let lower = t.gas_required(&self.engine.schedule(env_info.number)).into();

ethcore/src/executed.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -167,7 +167,7 @@ pub enum CallError {
167167
/// Couldn't find requested block's state in the chain.
168168
StatePruned,
169169
/// Couldn't find an amount of gas that didn't result in an exception.
170-
Exceptional,
170+
Exceptional(vm::Error),
171171
/// Corrupt state.
172172
StateCorrupt,
173173
/// Error executing.
@@ -187,7 +187,7 @@ impl fmt::Display for CallError {
187187
let msg = match *self {
188188
TransactionNotFound => "Transaction couldn't be found in the chain".into(),
189189
StatePruned => "Couldn't find the transaction block's state in the chain".into(),
190-
Exceptional => "An exception happened in the execution".into(),
190+
Exceptional(ref e) => format!("An exception ({}) happened in the execution", e),
191191
StateCorrupt => "Stored state found to be corrupted.".into(),
192192
Execution(ref e) => format!("{}", e),
193193
};

rpc/src/v1/helpers/errors.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -173,11 +173,11 @@ pub fn state_corrupt() -> Error {
173173
internal("State corrupt", "")
174174
}
175175

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

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

0 commit comments

Comments
 (0)