Use binary chop to estimate gas accurately (#4100)
* Initial sketch. * Building. * Fix a few things. * Fix issue, add tracing. * Address grumbles * Raise upper limit if needed * Fix test.
This commit is contained in:
@@ -671,13 +671,8 @@ impl<C, SN: ?Sized, S: ?Sized, M, EM> Eth for EthClient<C, SN, S, M, EM> where
|
||||
|
||||
let request = CallRequest::into(request);
|
||||
let signed = self.sign_call(request)?;
|
||||
let result = match num.0 {
|
||||
BlockNumber::Pending => take_weak!(self.miner).call(&*take_weak!(self.client), &signed, Default::default()),
|
||||
num => take_weak!(self.client).call(&signed, num.into(), Default::default()),
|
||||
};
|
||||
|
||||
result
|
||||
.map(|res| (res.gas_used + res.refunded).into())
|
||||
take_weak!(self.client).estimate_gas(&signed, num.0.into())
|
||||
.map(Into::into)
|
||||
.map_err(errors::from_call_error)
|
||||
}
|
||||
|
||||
|
||||
@@ -691,7 +691,7 @@ fn rpc_eth_estimate_gas() {
|
||||
"latest"],
|
||||
"id": 1
|
||||
}"#;
|
||||
let response = r#"{"jsonrpc":"2.0","result":"0xff35","id":1}"#;
|
||||
let response = r#"{"jsonrpc":"2.0","result":"0x5208","id":1}"#;
|
||||
|
||||
assert_eq!(tester.io.handle_request_sync(request), Some(response.to_owned()));
|
||||
}
|
||||
@@ -725,7 +725,7 @@ fn rpc_eth_estimate_gas_default_block() {
|
||||
}],
|
||||
"id": 1
|
||||
}"#;
|
||||
let response = r#"{"jsonrpc":"2.0","result":"0xff35","id":1}"#;
|
||||
let response = r#"{"jsonrpc":"2.0","result":"0x5208","id":1}"#;
|
||||
|
||||
assert_eq!(tester.io.handle_request_sync(request), Some(response.to_owned()));
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user