Skip to content
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

On transaction failure, fetch revert reason with replayed transaction #57

Merged
merged 39 commits into from
Oct 25, 2023

Conversation

emizzle
Copy link
Contributor

@emizzle emizzle commented Oct 18, 2023

When calling .sendTransaction, the flow is:

  1. populate transaction with values, including gasLimit using estimateGas
  2. send transaction

In step 1, if there is an error during gas estimation, an EstimateGasError is raised with the revert reason.

In step 2, if the transaction receipt is returned with a status of failed (requires the transaction to be confirmed), the transaction is replayed at the previous block (the full state transitions of the previous block are including, and the state transitions from earlier txs of the same block are not included), and a revert reason is obtained from the replay. A ProviderError is raised with the revert reason.

The replay flow is:

  1. Get transaction at TransactionHash
  2. Deserialize that transaction into a PastTransaction type
  3. Convert PastTransaction to a Transaction
  4. Simulate the transaction at a block number by calling eth_sendTransaction, and providing the transaction object and a block number.

NOTE:

  1. This PR is based on top of prevent stuck transactions by async locking nonce sequencing (+ estimate gas) #55
  2. nim-chronicles was added in, with some discussion around not including it due to it not being versioned. It does, however appear to be versioned, but I'm not entirely sure if this is enough. The other option, which would suit a future PR, is to add chronicles as an optional dependency.

Copy link
Member

@AuHau AuHau left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It does look LGTM, but honestly I don't have that good understanding here so I would leave approval to @markspanbroek

Copy link
Member

@markspanbroek markspanbroek left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is great, thanks @emizzle!

I think I'd like review this again after the comments in #55 have been addressed. Some of them apply to this PR as well.

@emizzle
Copy link
Contributor Author

emizzle commented Oct 20, 2023

Ready for another review 👍

@emizzle
Copy link
Contributor Author

emizzle commented Oct 22, 2023

Note: nim-chronicles was added in this PR (originally was in #55), with some discussion around not including it due to it not being versioned. It does, however appear to be versioned, but I'm not entirely sure if this is enough. The other option, which would suit a future PR, is to add chronicles as an optional dependency.

Copy link
Member

@markspanbroek markspanbroek left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks great @emizzle! This is going to help us a lot in debugging transactions.

ethers.nimble Outdated
@@ -4,6 +4,7 @@ description = "library for interacting with Ethereum"
license = "MIT"

requires "nim >= 1.6.0"
requires "chronicles >= 0.10.3 & < 0.10.4"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would be a little less strict in the patch version; allowing all 0.10.x is probably ok.

Suggested change
requires "chronicles >= 0.10.3 & < 0.10.4"
requires "chronicles >= 0.10.3 & < 0.11.0"

@@ -1,4 +1,5 @@
import std/strutils
import ./contract
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Unused import?

@@ -5,6 +5,7 @@ import pkg/questionable
import pkg/stint
import pkg/ethers
import pkg/ethers/erc20
import pkg/ethers/wallet
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Unused import?

Base automatically changed from feat/cancel-tx-on-estimateGas-failure to main October 24, 2023 23:42
- remove auto-cancellation of failed transaction (failed during estimate gas) to prevent stuck txs
- replace it with an async lock during nonce sequencing + gas estimation
- simplified cancelTransaction (still exported) such that the new transaction is populated using populateTransaction, so that all gas and fees are reset
- moved reverting contract function into its own testing helpers module, and refactored any tests to use it
- updated the test helper reverts to check EstimateGasErrors
This would allow applications to use the nonce in case of an error, eg cancel the transaction to prevent stuck txs from occurring
eth_getTransactionByHash responses from geth don't include data, and there was an exception raised, "key not found: data"
@emizzle emizzle merged commit 2428b75 into main Oct 25, 2023
4 checks passed
@emizzle emizzle deleted the feat/include-nonce-in-error branch October 25, 2023 00:36
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants