Skip to content
This repository has been archived by the owner on Feb 26, 2024. It is now read-only.

Automatic nonce generation race condition #2489

Open
theblock-dev opened this issue Feb 24, 2022 · 14 comments · May be fixed by #3498
Open

Automatic nonce generation race condition #2489

theblock-dev opened this issue Feb 24, 2022 · 14 comments · May be fixed by #3498

Comments

@theblock-dev
Copy link

Discussed in trufflesuite/truffle#4774

Originally posted by theblock-dev February 24, 2022
Hi All
While running the truffle migrate --reset command, I am getting into nonce issue. The migration code seems to be fine and I can not seem to find any issue with it. Here is the error I am getting

image

Is there a way to reset the nonce for the truffle?

Thanks

@eggplantzzz
Copy link
Contributor

Hey @theblock-dev, can you give me a little more information about what you are doing? For example, can you tell me what version of Truffle you are using, what network you are migrating to, and what provider you are furnishing? If you have your truffle-config.js and wouldn't mind sharing it that would also be helpful. Let me know and I'll try and help troubleshoot!

@theblock-dev
Copy link
Author

Hi Tyler
Thanks for reaching out, much appreciated.
Here are the version details

image

I am migrating it to the local ganache cli. Attached are the truffle-config.js and 2_deploy_contracts.js files ( Pls extract the zip )

config.zip

Thanks

@eggplantzzz
Copy link
Contributor

Sure! Can you try upgrading Truffle to the latest version? Also, if you are using ganache-cli, upgrade to the latest Ganache as well if you can. It has been renamed just ganache. You will have to uninstall ganache-cli first.

So npm uninstall -g ganache-cli && npm install -g ganache should install v7 (the latest) for you. You then run it with ganache.

Is your project on Github?

@theblock-dev
Copy link
Author

I am using the latest ganache 7.0
image

Also update truffle to the latest version of 5.5.2, however I still have the same issue while running the migration.

@theblock-dev
Copy link
Author

I downgraded the truffle version to 5.4.23, and the issue got resolved automatically. I have not idea why the higher version gave this error.
However, now I have a different issue. Truffle now gives out of gas while running migration.

@eggplantzzz
Copy link
Contributor

Actually the latest Ganaceh is 7.0.2 I believe. Is your project on GitHub so I can take a look and try to figure out what might be happening? If there is a problem with the latest version of Truffle then I would like to try and document it so we can fix it. Let me know if you have a code sample and steps for reliably reproducing this error.

@theblock-dev
Copy link
Author

Hi Tyler
Here is the link to the project - https://github.com/theblock-dev/ERC20Dex

Here are the version details
image

Steps to replicate -

  1. Go to the root of the project
  2. open truffle develop environment - truffle develop
  3. migrate the project - migrate --reset

Thanks

@eggplantzzz
Copy link
Contributor

Thanks @theblock-dev! I'll go ahead and see if I can reproduce the problem you are having and hopefully have some advice for you.

@eggplantzzz
Copy link
Contributor

eggplantzzz commented Mar 1, 2022

So I have reproduced your error and found the issue. The problem is with how you are asynchronously creating transactions with transferSeedToken. You are using map to create a bunch of transactions but they are not executing in the order of the nonces, I think this has to do with how Ganache's "instamine" mode works as it tries to process each transaction as it receives it. When Truffle creates these transactions it gives them each nonces (in order of course), but when Ganache goes to actually try and execute the transactions they are out of order.

If I run Ganache separately and set a block time (which causes instamine mode to be off) it seems to get past the area causing problems. When I run your example with a plain old for loop everything seems to run smoothly because we can ensure that the transactions are being processed in the order of the nonces.

I think this will not cause a problem when using a real network like Rinkeby as it will just throw each into the pool and wait until each's turn comes up. But as a workaround you could just remove the map and await each call to transferSeedToken. Let me chat with some of the Ganache team to see if I can get some more info about this behavior.

@eggplantzzz
Copy link
Contributor

So after a bit of troubleshooting with the Ganache team, it looks like there is an issue in Ganache. I'm going to transfer this issue there so we can get it triaged and fixed. Thanks for reporting this @theblock-dev!

@eggplantzzz eggplantzzz transferred this issue from trufflesuite/truffle Mar 1, 2022
@eggplantzzz eggplantzzz changed the title Issue while running migrate --- Tx does not have the correct nonce - Automatic nonce generation race condition Mar 1, 2022
@Juan-de-Costa-Rica
Copy link

Just chiming in to say I am having the exact same issue.

I don't run into the issue when using ganache-cli (v6.12.2), only when I upgrade to to ganache v7.0.2

@theblock-dev
Copy link
Author

@eggplantzzz - thanks a lot for your help and discussing with the ganache team.

@theblock-dev
Copy link
Author

Has this been fixed in the new ganache version 7.0.3? Thanks

@davidmurdoch
Copy link
Member

@theblock-dev no, it's not fixed yet. This issue is actively being worked on though.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
Status: Backlog
Development

Successfully merging a pull request may close this issue.

5 participants