ganache
ganache copied to clipboard
Automatic nonce generation race condition
Discussed in https://github.com/trufflesuite/truffle/discussions/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

Is there a way to reset the nonce for the truffle?
Thanks
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!
Hi Tyler Thanks for reaching out, much appreciated. Here are the version details

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 )
Thanks
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?
I am using the latest ganache 7.0

Also update truffle to the latest version of 5.5.2, however I still have the same issue while running the migration.
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.
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.
Hi Tyler Here is the link to the project - https://github.com/theblock-dev/ERC20Dex
Here are the version details

Steps to replicate -
- Go to the root of the project
- open truffle develop environment - truffle develop
- migrate the project - migrate --reset
Thanks
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.
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.
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!
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
@eggplantzzz - thanks a lot for your help and discussing with the ganache team.
Has this been fixed in the new ganache version 7.0.3? Thanks
@theblock-dev no, it's not fixed yet. This issue is actively being worked on though.