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:
Gav Wood
2017-01-10 18:56:41 +01:00
committed by GitHub
parent baa754cc52
commit 23feb7998f
9 changed files with 107 additions and 19 deletions

View File

@@ -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)
}

View File

@@ -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()));
}