-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Revive, Estimate Gas with Binary Search #11000
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
40 commits
Select commit
Hold shift + click to select a range
1dfef66
Binary search in estimate fee
0xOmarA e8928fd
Updated binary search
0xOmarA 445276a
Update the gas estimation logic
0xOmarA a324840
Add tests for case that needs binary search
0xOmarA 97012e4
Fix issue in gas estimation
0xOmarA 3bce69c
Update from github-actions[bot] running command 'prdoc --audience run…
github-actions[bot] eb77362
Move binary search estimation to runtime API
0xOmarA 3212131
Remove unneeded import
0xOmarA 4e3868f
Switch SharedResources logging back to debug
0xOmarA 18b0020
Remove the gas limit override in differential tests
0xOmarA e15f0c9
Merge remote-tracking branch 'origin/master' into 0xOmarA/revive-gas-…
0xOmarA 7cf8e3e
Fix formatting
0xOmarA 965b882
Add test for estimation without enough gas
0xOmarA 11e3310
Fix `eth_estimate with insufficient funds to cover gas` test
0xOmarA 69d5d55
Merge remote-tracking branch 'origin/master' into 0xOmarA/revive-gas-…
0xOmarA 6a75a24
Simplify runtime API estimate gas
0xOmarA ac8ed63
Control when balance checks are performed
0xOmarA 94b5cd4
Rename one of the fixtures
0xOmarA c7d5d80
Change the default value of perform_balance_checks
0xOmarA 6e550e5
Increase margin
0xOmarA a73e9b3
Modify the balance checking behavior to match
0xOmarA 6be2888
Correct estimation logic
0xOmarA 435e698
Various fixes to the estimation logic
0xOmarA b689e81
Remove comments from fixture contract
0xOmarA a22a4d7
Merge remote-tracking branch 'origin/master' into 0xOmarA/revive-gas-…
0xOmarA 900b935
fix clippy lints
0xOmarA 8c9c1fe
Add affected pallets to the pr doc
0xOmarA 9757bfa
Remove accidentally committed claude file.
0xOmarA 91b7730
Rename test to a more accurate name
0xOmarA 1f82fc6
Better log message, including user's allowance.
0xOmarA 06b3f91
Merge remote-tracking branch 'origin/master' into 0xOmarA/revive-gas-…
0xOmarA 8948c3c
Fix pr doc
0xOmarA 1461132
Revert "Simplify runtime API estimate gas"
0xOmarA 87818be
Merge remote-tracking branch 'origin/master' into 0xOmarA/revive-gas-…
0xOmarA 0879f2a
Fix tests
0xOmarA dab8fd9
Merge branch 'master' into 0xOmarA/revive-gas-estimation-binary-search
0xOmarA 4ca3205
Update the commit hash of dt
0xOmarA 793beab
Update retester expectations
0xOmarA 93ff629
Merge remote-tracking branch 'origin/master' into 0xOmarA/revive-gas-…
0xOmarA dc3ed85
Fix formatting
0xOmarA File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,16 @@ | ||
| title: Revive, Estimate Gas with Binary Search | ||
| doc: | ||
| - audience: Runtime Dev | ||
| description: |- | ||
| # Description | ||
|
|
||
| This PR implements binary search for the gas estimation logic in the eth-rpc which means that gas estimations are no longer just simple dry runs but that binary search is now used to find the smallest gas limit at which the transaction would run. | ||
|
|
||
| This PR closes https://github.com/paritytech/contract-issues/issues/217 and also _kind of_ fixes https://github.com/paritytech/contract-issues/issues/259 or at least makes it harder to trigger the case in which we observe it, but the underlying issue still exists. | ||
|
|
||
| The binary search algorithm implemented in this PR is as close as possible to that used in Geth | ||
| crates: | ||
| - name: pallet-revive | ||
| bump: minor | ||
| - name: pallet-revive-eth-rpc | ||
| bump: minor |
15 changes: 15 additions & 0 deletions
15
substrate/frame/revive/fixtures/contracts/ContractRequiringBinarySearchForGasEstimation.sol
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,15 @@ | ||
| // SPDX-License-Identifier: MIT | ||
|
|
||
| pragma solidity >=0.8.4; | ||
|
|
||
| contract ContractRequiringBinarySearchForGasEstimation { | ||
| function main() public view { | ||
| this.expensive_operation{gas: gasleft() / 2}(); | ||
| } | ||
|
|
||
| function expensive_operation() external pure returns (uint256 sum) { | ||
| for (uint256 i = 0; i < 500; i++) { | ||
| sum += i * i; | ||
| } | ||
| } | ||
| } |
26 changes: 26 additions & 0 deletions
26
substrate/frame/revive/fixtures/contracts/ContractWithConsumeAllGas.sol
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,26 @@ | ||
| // SPDX-License-Identifier: MIT | ||
|
|
||
| pragma solidity >=0.4.21; | ||
|
|
||
| contract ContractWithConsumeAllGas { | ||
| function test() external { | ||
| assembly { | ||
| mstore(0, 0xcc572cf9) // main selector | ||
| mstore(32, 0xFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF) | ||
| mstore(64, 0xFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF) | ||
| let gas_value := div(mul(gas(), 1), 100) | ||
| let success := call(gas_value, address(), 0, 28, 68, 0, 0) | ||
|
|
||
| mstore(0, success) | ||
| return(0, 32) | ||
| } | ||
| } | ||
|
|
||
| function main(uint256 offset, uint256 len) external pure { | ||
| assembly { | ||
| // nullify memory ptr slot | ||
| mstore(0x40, 0) | ||
| revert(offset, len) | ||
| } | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.