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

Use binary chop to estimate gas accurately #4100

Merged
merged 7 commits into from
Jan 10, 2017
Merged

Use binary chop to estimate gas accurately #4100

merged 7 commits into from
Jan 10, 2017

Conversation

gavofyork
Copy link
Contributor

@gavofyork gavofyork commented Jan 10, 2017

Introduces a binary chop algorithm to determine an accurate idea of how much gas a call/transaction needs to succeed.

Could do with a bit of DRYing up to avoid code duplication between client and miner - that might wait for a follow up refactoring PR, though.

Could also do with a slightly better error when the amount of gas required exceeds the block gas limit.

Could also be optimised by avoiding the costly tx tracing and instead passing the exception status of the outer call back from Executive::transact.

Closes #3930, #3749, #2061

@gavofyork gavofyork added A3-inprogress ⏳ Pull request is in progress. No review needed at this stage. M6-rpcapi 📣 RPC API. labels Jan 10, 2017
/// Find transition point between `lower` and `upper` where `cond` changes from `false` to `true`.
/// Returns the lowest value between `lower` and `upper` for which `cond` returns true.
/// We assert: `cond(lower) = false`, `cond(upper) = true`
pub fn binary_chop<F>(mut lower: U256, mut upper: U256, mut cond: F) -> U256 where F: FnMut(U256) -> bool {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does this really belong in client? Should either be in a utility file or an inline function within estimate_gas if that's truly the only place it's useful.

@coveralls
Copy link

Coverage Status

Changes Unknown when pulling 3948511 on estimate-gas into ** on master**.

@coveralls
Copy link

Coverage Status

Changes Unknown when pulling 3948511 on estimate-gas into ** on master**.

@arkpar arkpar added A0-pleasereview 🤓 Pull request needs code review. and removed A3-inprogress ⏳ Pull request is in progress. No review needed at this stage. labels Jan 10, 2017
@@ -848,7 +848,7 @@ impl BlockChainClient for Client {
difficulty: header.difficulty(),
last_hashes: last_hashes,
gas_used: U256::zero(),
gas_limit: U256::max_value(),
gas_limit: header.gas_limit(),
Copy link
Collaborator

@arkpar arkpar Jan 10, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

One of the use cases for gas estimation is to see how much over the block gas limit it is. geth sets the hard estimation limit to 50M

@arkpar arkpar added A5-grumble 🔥 Pull request has minor issues that must be addressed before merging. and removed A0-pleasereview 🤓 Pull request needs code review. labels Jan 10, 2017
@coveralls
Copy link

Coverage Status

Changes Unknown when pulling d3110b8 on estimate-gas into ** on master**.

@gavofyork gavofyork added A0-pleasereview 🤓 Pull request needs code review. and removed A5-grumble 🔥 Pull request has minor issues that must be addressed before merging. labels Jan 10, 2017
@arkpar arkpar added A8-looksgood 🦄 Pull request is reviewed well. and removed A0-pleasereview 🤓 Pull request needs code review. labels Jan 10, 2017
@gavofyork
Copy link
Contributor Author

build failure looks spurious. maybe we should disable by default the should_get_price_info test?

@arkpar arkpar added A7-looksgoodtestsfail 🤖 Pull request is reviewed well, but cannot be merged due to tests failing. and removed A8-looksgood 🦄 Pull request is reviewed well. labels Jan 10, 2017
@arkpar arkpar added B0-patch A8-looksgood 🦄 Pull request is reviewed well. and removed A7-looksgoodtestsfail 🤖 Pull request is reviewed well, but cannot be merged due to tests failing. labels Jan 10, 2017
@coveralls
Copy link

Coverage Status

Changes Unknown when pulling 3c7b377 on estimate-gas into ** on master**.

@coveralls
Copy link

Coverage Status

Changes Unknown when pulling 3c7b377 on estimate-gas into ** on master**.

@gavofyork gavofyork merged commit 23feb79 into master Jan 10, 2017
@gavofyork gavofyork deleted the estimate-gas branch January 10, 2017 17:56
arkpar pushed a commit that referenced this pull request Jan 10, 2017
* Initial sketch.

* Building.

* Fix a few things.

* Fix issue, add tracing.

* Address grumbles

* Raise upper limit if needed

* Fix test.
@keorn keorn mentioned this pull request Jan 11, 2017
gavofyork pushed a commit that referenced this pull request Jan 11, 2017
* Ignore get_price_info test by default. (#4112)

* Auto-detect hex encoded bytes in sha3 (#4108)

* Auto-detect hex encoded bytes in sha3

* Using types/isHex

* Removing unused imports

* 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.

* Fixing decoding API with signatures in names (#4125)

* Fix call/estimate_gas (#4121)

* Return 0 instead of error with out of gas on estimate_gas

* Fix stuff up.
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
A8-looksgood 🦄 Pull request is reviewed well. M6-rpcapi 📣 RPC API.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants