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

Relayer nonce collisions #2157

Merged
merged 5 commits into from
Sep 2, 2024
Merged

Relayer nonce collisions #2157

merged 5 commits into from
Sep 2, 2024

Conversation

SurgeCode
Copy link
Contributor

Added a small section to the relayer page about how to handle high throughput relaying

@SurgeCode SurgeCode requested a review from bucanero as a code owner July 19, 2024 18:59
@gagdiez
Copy link
Collaborator

gagdiez commented Jul 22, 2024

I think what we actually need to explain goes more like this:

At the protocol level, transactions have a unique number that identifies them (nonce) that helps to mitigate reply attacks. Each key on an account has its own nonce, and the nonce is expected to increase with each signature the key creates.

When the relayer account (e.g. relayer.near) starts relaying a lot of transactions, it will quickly start to happen that nonces collide. For example, if 3 users interact with the relayer at the same time, the relayer will create 3 transactions Tx1, Tx2, Tx3 and send them in very short distance from each other. In our case, we can assume that Tx3 has the largest nonce, and Tx1 the smallest.

If Tx3 ends up being processed before Tx1 (because of some network issues one takes longer to be sent to the RPC, or simply because a node picks Tx3 before Tx1), then Tx3 will execute, but Tx1 and Tx2 will fail, because they have smaller nonce!

One way to mitigate this is to sign each transaction with a different key. Since nonce are key dependent, we can simply create 20 different keys for relayer.near, and go rotating which one we use to sign the transactions. This way, we can 20 transactions created simultaneously without the fear of them colliding on the nonce.

@DavidM-D
Copy link
Contributor

Can we just have "PAIN" in bold linking to this comment?

@gagdiez gagdiez merged commit 83dadcf into near:master Sep 2, 2024
1 of 3 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Status: Shipped 🚀
Development

Successfully merging this pull request may close these issues.

4 participants