-
Notifications
You must be signed in to change notification settings - Fork 996
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
Expose contract call reverts to mappings #1120
Comments
This looks like a solid plan. My only feedback is that I think we've had at least one request for accessing the revert reason. I think Justin from Synthetix asked for it so it may be worth trying to include depending on the cost. |
I agree, if that's possible that would be great. I'm not sure it is though. That aside, the plan looks great! |
@leoyvens By "revert reason" we mean the reason why the Ethereum call failed. That's different from transactions failing. Let's say you call a view function
then it would be great if we could get the assertion error back and pass it back to the mapping. |
@Jannis I understand, that's further client/language specific behaviour so we should wait for an EIP like ethereum/EIPs#838 before exposing that. I've been investigating in what scenarios we can detect a revert. I've tested against Infura and Alchemy, I believe Infura follows the Geth response format and Alchemy follows the Parity response format. I've tested reverts with and without a reason string. The conclusion so far is that we can detect a revert in Alchemy/Parity in all tested situations, but for Infura/Geth we'll only be able to detect reverts in Solidity contracts that call |
Hey guys - this is looking really promising. Just a few questions:
|
@justinjmoses hey, thanks for dropping by! Answers:
|
Thanks @leoyvens.
|
This is the plan for fixing the issue first reported in graphprotocol/support#21.
Rationale / Use Cases
Several subgraphs have had the need to handle reverts in a contract call, currently the behaviour of reverts is not consistent, depending on the ethereum node's response we either fail the subgraph or return the revert data as the return value, neither of which are desirable. We should change this so that the semantics are:
Requirements
Proposed User Experience
A first question is if we should attempt to expose the revert reason. For a first implementation I'd say no, it's hard enough to determinstically determine if the call was reverted or not, and I don't believe the current use cases have a necessity of inspecting the revert reason.
The AssemblyScript return value of a contract call will need to change so to account for the possibility of a revert. Since try/catch mechanisms are not an option in AS, the mapping will need to explicitly handle the result value. To maintain convenience for calls that are assumed to not revert and to avoid breaking changes, we'll continue to generate call functions as we do today, and additionally generate a version prefixed with
try_
which returns a result value, as described by @Jannis in this comment.Proposed Implementation
In the node, the ethereum-adapter will detect reverts based on how they're presented by the latest stable of Geth and Parity, and by the current responses of Infura and Alchemy. The
ethereum.call
host export will returnnull
in case of a revert.In graph-ts, the following type will added:
In graph-cli, for each contract call two functions will be generated, one that aborts on revert and one that exposes the revert. The first will be the same as the functions we already generate, with the change that they will check for
null
and abort with a good error message in that case. The second will prefixed withtry_
and return aCallResult<T>
whereT
is the return type of the call. If the call returnednull
, thenvalue
will be something meaningless andisOk
will befalse
.Proposed Documentation Updates
The section 'AssemblyScript API -> Access to Smart Contract State' should be updated to describe when and how to use the
try_
functions.Proposed Tests / Acceptance Criteria
Unit tests for codegen.
Manual end-to-end testing of a subgraph calling
try_
functions against the latest stable of Geth and Parity, and also Infura and Alchemy.Tasks
ethereum.call
host export in case of a revert.class CallResult<T>
null
in the generated call methods.try_
variant of call methods.The text was updated successfully, but these errors were encountered: