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);
 | 
			
		||||
			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();
 | 
			
		||||
 | 
			
		||||
@ -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.
 | 
			
		||||
@ -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),
 | 
			
		||||
		};
 | 
			
		||||
 | 
			
		||||
@ -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())),
 | 
			
		||||
	}
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
@ -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),
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
		Loading…
	
		Reference in New Issue
	
	Block a user