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
This commit is contained in:
parent
aa8487c1d0
commit
3b23817936
@ -1571,22 +1571,27 @@ impl Call for Client {
|
|||||||
let schedule = machine.schedule(env_info.number);
|
let schedule = machine.schedule(env_info.number);
|
||||||
Executive::new(&mut clone, &env_info, &machine, &schedule)
|
Executive::new(&mut clone, &env_info, &machine, &schedule)
|
||||||
.transact_virtual(&tx, options())
|
.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) {
|
if !cond(upper) {
|
||||||
upper = max_upper;
|
upper = max_upper;
|
||||||
match exec(upper) {
|
match exec(upper) {
|
||||||
Some(false) => return Err(CallError::Exceptional),
|
Ok(v) => {
|
||||||
None => {
|
if let Some(exception) = v.exception {
|
||||||
|
return Err(CallError::Exceptional(exception))
|
||||||
|
}
|
||||||
|
},
|
||||||
|
Err(_e) => {
|
||||||
trace!(target: "estimate_gas", "estimate_gas failed with {}", upper);
|
trace!(target: "estimate_gas", "estimate_gas failed with {}", upper);
|
||||||
let err = ExecutionError::Internal(format!("Requires higher than upper limit of {}", upper));
|
let err = ExecutionError::Internal(format!("Requires higher than upper limit of {}", upper));
|
||||||
return Err(err.into())
|
return Err(err.into())
|
||||||
},
|
}
|
||||||
_ => {},
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
let lower = t.gas_required(&self.engine.schedule(env_info.number)).into();
|
let lower = t.gas_required(&self.engine.schedule(env_info.number)).into();
|
||||||
|
@ -167,7 +167,7 @@ pub enum CallError {
|
|||||||
/// Couldn't find requested block's state in the chain.
|
/// Couldn't find requested block's state in the chain.
|
||||||
StatePruned,
|
StatePruned,
|
||||||
/// Couldn't find an amount of gas that didn't result in an exception.
|
/// Couldn't find an amount of gas that didn't result in an exception.
|
||||||
Exceptional,
|
Exceptional(vm::Error),
|
||||||
/// Corrupt state.
|
/// Corrupt state.
|
||||||
StateCorrupt,
|
StateCorrupt,
|
||||||
/// Error executing.
|
/// Error executing.
|
||||||
@ -187,7 +187,7 @@ impl fmt::Display for CallError {
|
|||||||
let msg = match *self {
|
let msg = match *self {
|
||||||
TransactionNotFound => "Transaction couldn't be found in the chain".into(),
|
TransactionNotFound => "Transaction couldn't be found in the chain".into(),
|
||||||
StatePruned => "Couldn't find the transaction block's state 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(),
|
StateCorrupt => "Stored state found to be corrupted.".into(),
|
||||||
Execution(ref e) => format!("{}", e),
|
Execution(ref e) => format!("{}", e),
|
||||||
};
|
};
|
||||||
|
@ -173,11 +173,11 @@ pub fn state_corrupt() -> Error {
|
|||||||
internal("State corrupt", "")
|
internal("State corrupt", "")
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn exceptional() -> Error {
|
pub fn exceptional<T: fmt::Display>(data: T) -> Error {
|
||||||
Error {
|
Error {
|
||||||
code: ErrorCode::ServerError(codes::EXCEPTION_ERROR),
|
code: ErrorCode::ServerError(codes::EXCEPTION_ERROR),
|
||||||
message: "The execution failed due to an exception.".into(),
|
message: "The execution failed due to an exception.".into(),
|
||||||
data: None,
|
data: Some(Value::String(data.to_string())),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -467,7 +467,7 @@ pub fn call(error: CallError) -> Error {
|
|||||||
match error {
|
match error {
|
||||||
CallError::StatePruned => state_pruned(),
|
CallError::StatePruned => state_pruned(),
|
||||||
CallError::StateCorrupt => state_corrupt(),
|
CallError::StateCorrupt => state_corrupt(),
|
||||||
CallError::Exceptional => exceptional(),
|
CallError::Exceptional(e) => exceptional(e),
|
||||||
CallError::Execution(e) => execution(e),
|
CallError::Execution(e) => execution(e),
|
||||||
CallError::TransactionNotFound => internal("{}, this should not be the case with eth_call, most likely a bug.", CallError::TransactionNotFound),
|
CallError::TransactionNotFound => internal("{}, this should not be the case with eth_call, most likely a bug.", CallError::TransactionNotFound),
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user