-
Notifications
You must be signed in to change notification settings - Fork 1.7k
Use binary chop to estimate gas accurately #4100
Conversation
/// 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 { |
There was a problem hiding this comment.
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.
Changes Unknown when pulling 3948511 on estimate-gas into ** on master**. |
Changes Unknown when pulling 3948511 on estimate-gas into ** on master**. |
@@ -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(), |
There was a problem hiding this comment.
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
Changes Unknown when pulling d3110b8 on estimate-gas into ** on master**. |
build failure looks spurious. maybe we should disable by default the |
Changes Unknown when pulling 3c7b377 on estimate-gas into ** on master**. |
Changes Unknown when pulling 3c7b377 on estimate-gas into ** on master**. |
* Initial sketch. * Building. * Fix a few things. * Fix issue, add tracing. * Address grumbles * Raise upper limit if needed * Fix test.
* 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.
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