-
-
Notifications
You must be signed in to change notification settings - Fork 1.7k
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
Add revert reason to exceptions #1026
Add revert reason to exceptions #1026
Conversation
I am not a fan of this approach - is revert reason only available for ethCall? |
Unfortunately yes at this time. As far as I'm aware, the only way to retrieve the revert reason for a transaction is to execute an ethCall with said tx data. See for reference: JS & Go similar implementation: Original solidity merged PR that added the feature to v0.4.22: ethereum/solidity#3364 |
related to #1024 - seems like besu does not need the second call to get the revert reason |
@lyotam Could you provide an example response of something that reverts please |
Sure, as I added to ContractTest.java, Here is an example result for EthCall result that reverted: However for transaction that reverts, there is no revert reason data available, for example: |
…t-reason-exceptions # Conflicts: # core/src/main/java/org/web3j/tx/Contract.java
I see - so we can put the revertReason in the transaction receipt? |
We can add a field called revertReason to TransactionReceipt but I don't see how we can populate it unless we force an ethCall for each reverted transaction, an approach that I chose to avoid here but is possible of course. Regarding Besu, it seems that they implemented an optional mechanism to produce the revertReason which needs to be enabled when starting the client which may use significant amount of memory: https://besu.hyperledger.org/en/stable/HowTo/Send-Transactions/Revert-Reason/ Another possibility is to add a flag, similar to Besu's approach , to the Contract sendTransaction method which if enabled will call ethCall and populate the revertReason field. This way will have a unified approach between Besu and other clients and also implement Besu's revertReason in the process. |
This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions. |
…ert-reason-exceptions � Conflicts: � core/src/test/java/org/web3j/tx/ContractTest.java � core/src/test/java/org/web3j/tx/ReadonlyTransactionManagerTest.java
…rt-reason-exceptions � Conflicts: � core/src/main/java/org/web3j/tx/ClientTransactionManager.java � core/src/main/java/org/web3j/tx/RawTransactionManager.java � core/src/main/java/org/web3j/tx/ReadonlyTransactionManager.java � core/src/main/java/org/web3j/tx/TransactionManager.java
I like this approach - I think the flag should be true by default in web3j - i.e. by default if the transaction fails we will do an ethCall to get the revert reason. |
…rt-reason-exceptions
Added the changes as discussed. Also confirmed it is working with Besu & Quorum Transaction Managers (For Besu it will extract the reason when #1132 is fixed). Please review. |
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.
LGTM
What does this PR do?
Adds the revert reason for contract calls and transactions which were reverted by the EVM to the respective exception thrown, using the already implemented ethCall.getRevertReason method.
For transactions, because it requires an additional EthCall to retrieve it, I added an optional sendTransactionWithRevertReason method to Contract that will retrieve it only if the txn reverts.
Where should the reviewer start?
TransactionManager.java (for calls)
Contract.java (for transactions)
Why is it needed?
Currently not only that the reverted calls & txns are missing the revert reason string when exception is thrown, they also don't provide the required txn information (hash for example) to retrieve it using additional call.
This adjusts the error flow for calls & txns while including the reverted string and TransactionReceipt in the exception.