Cherry pick upstream PR for revert reason in eth_call (upstream #21083) #1425
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.
Description
This cherry-picks a PR from upstream that adds the revert reason to the error returned from
eth_call
if there was a revert.The
eth_call
behavior in case of a revert was as follows:data
property with the revert reason. web3 checks the error's data and generates and error with the revert reasonOn celo-blockchain, v1.2.x and earlier have the pre-1.9.14 behavior, master currently has the v1.9.14, and this PR pulls in the v1.9.15 behavior
Tested
Manually generated an
eth_call
request which reverts, using contractkit, and logged both the RPC response and contractkit's handlingWith this branch:
With master:
With v1.2.3:
The difference in errors between this PR and v1.2.x (
Error: Your request got reverted with the following reason string:
vsError: execution reverted:
) is due to the following code in contractkit: https://github.com/celo-org/celo-monorepo/blob/oneeman/cip35-e2e-tests/packages/sdk/connect/src/utils/rpc-caller.ts#L104-L112If the error has a message, this code generates a new error with that message, discarding the original error object, which has the
data
property (which is what web3 then uses if it's available, see https://github.com/ChainSafe/web3.js/blob/2c5a8ec7bbb678b8e718a28fd5fec7709bacde25/packages/web3-core-method/src/index.js#L624-L648).As a reference, this is the
error
object before this code inrpc-caller.ts
:Backwards compatibility
There was both a breaking change and a bug on master when merging in part of v1.9.14. Relative to v1.2.3, this PR results in a breaking change (
eth_call
now returns an error in case of revert rather than reporting a success with the revert reason in the return data). But this breaking change is already handled in web3 (and, specifically, the version of web3 used in contractkit), so both the old and new will result in an error when it should (see above). However, the message will be different (see above).