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

eth/nodeclient: Set contract nonces manually. #1482

Merged
merged 1 commit into from
Feb 22, 2022

Conversation

JoeGruffins
Copy link
Member

The v0 contract will reuse account nonces if the tx is not yet
confirmed. To avoid that get the next nonce from the light eth node pool
api while holding the nodeClient nonceSendMtx and set manually. Hold the
mutex until the tx has been sent or errors on sending.

closes #1467

The v0 contract will reuse account nonces if the tx is not yet
confirmed. To avoid that get the next nonce from the light eth node pool
api while holding the nodeClient nonceSendMtx and set manually. Hold the
mutex until the tx has been sent or errors on sending.
@JoeGruffins
Copy link
Member Author

JoeGruffins commented Feb 21, 2022

Tested with low fee txn and concurrent sends. Seems to always set the next nonce correctly. This runs the risk of a tx getting stuck ofc if the fee it too low, which is a bigger problem than with utxo based coins, and one that should be considered more, imo.

Copy link
Contributor

@martonp martonp left a comment

Choose a reason for hiding this comment

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

This LGTM. The code could go into a helper function though to avoid repeating it.

Copy link
Contributor

@martonp martonp left a comment

Choose a reason for hiding this comment

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

Why not just put this code into txOpts?

@JoeGruffins
Copy link
Member Author

Why not just put this code into txOpts?

I think the mtx needs to be held until after the tx has either made it into the pool or not, so after attempting to send. I'm not sure of the actual behavior, but if it will give you the next nonce before a tx is sent, then if one fails you would be skipping the nonce and no longer be able to send. If it will give you the same nonce until it has a tx in the pool using it, then you would be grabbing the same nonce for multiple txn until one is in the pool.

@JoeGruffins
Copy link
Member Author

I don't think the helper would be much shorter if I want to hold that mutex outside of the sending function.

@chappjc
Copy link
Member

chappjc commented Feb 22, 2022

Yeah let's run with it as is. The key is holding the nonce mutex until the tx hits txpool.

@chappjc chappjc merged commit 2fa8601 into decred:master Feb 22, 2022
@chappjc chappjc added this to the 0.5 milestone Apr 21, 2022
@chappjc chappjc added the ETH label Aug 26, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

eth: Redeems and refunds can be overwritten and lost without error.
3 participants