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

Adjust robustness of MTX broadcaster #1321

Merged
merged 5 commits into from
Feb 7, 2025
Merged

Conversation

area
Copy link
Member

@area area commented Jan 30, 2025

While investigating issues that users were having with the metatransaction broadcaster, this is where we've arrived, fixing two issues:

  • An error that would result in trying to hexlify a transaction response object, rather than a signed transaction. This was due to a confusion between signer.sendTransaction and provider.sendTransaction in the rebroadcasting logic.
  • Some sensitivity to accidentally re-using nonces. We weren't really using the NonceManager functionality, so I've reworked the ExtendedNonceManager a fair bit to use it, and it's now much closer to the default NonceManager but with rebroadcasting logic.

Reproducing issues around this determinsitically is hard; I've done my best with some tests, but I couldn't get the exact errors we saw in production. These changes are currently live on QA, and will hit production before the next release (or maybe even before this is merged), so it's going to be an ongoing battle, but let's still review / improve these changes as normal!

error: { message: `Error: VM Exception while processing transaction: reverted with reason string '${decoded[0]}'` },
id: req.body.id,
});
console.log(error);
Copy link
Member

Choose a reason for hiding this comment

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

Is this meant to be part of the final implementation?

Copy link
Member Author

Choose a reason for hiding this comment

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

Yeah, I guess this can be removed now that we have the try/catch.

hardhat.config.js Outdated Show resolved Hide resolved
packages/package-utils/ExtendedNonceManager.js Outdated Show resolved Hide resolved
packages/package-utils/ExtendedNonceManager.js Outdated Show resolved Hide resolved
@area
Copy link
Member Author

area commented Jan 31, 2025

A demoralising update.

From the frontend side, we need to guarantee, as strongly as possible, that the hash returned is the hash of the transaction that does the metatransaction. The previous implementation, rebroadcasting the transaction if it did not succeed, does not guarantee that (as if we have to change the nonce, the hash will change).

I've ended up at this much simpler implementation that refreshes the nonce every request (as a typical signer would), but retrying if an error relating to the nonce is seen when doing so, and only returning the transaction hash when that doesn't happen (which will be when the transaction is mined).

For cases where the broadcaster ends up behind, it'll catch-up, and for cases where the broadcaster ends up ahead it'll reset itself. The latter can't be tested properly locally currently, as hardhat returns an error if you use a too-big nonce, which is not typical (usually, such a transaction would sit in the mempool of a node until dropped or all the in-between nonces are filled in). That would all work with a typical signer - the custom retry functionality deals with situations where multiple requests are made simultaneously and we end up with nonce collisions.

The (previous) 'clever' version might be appropriate to use with the wormhole relayer - where we don't care about the transaction hash of something happening, we just care about it happening, but it can use this provider for now, as well, as far as I'm concerned.

@area area force-pushed the fix/mtx-broadcaster-rebroadcasts branch from 0c55baa to 7024774 Compare January 31, 2025 16:02
Copy link
Member

@kronosapiens kronosapiens left a comment

Choose a reason for hiding this comment

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

Looks good to me

@area area force-pushed the fix/mtx-broadcaster-rebroadcasts branch from 7024774 to c9f3c19 Compare February 6, 2025 10:18
@area area merged commit 6554f07 into develop Feb 7, 2025
2 checks passed
@area area deleted the fix/mtx-broadcaster-rebroadcasts branch February 7, 2025 10:15
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants