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

Error getting the nonce local testrpc when there's a revert #300

Closed
anxolin opened this issue Jan 3, 2019 · 2 comments
Closed

Error getting the nonce local testrpc when there's a revert #300

anxolin opened this issue Jan 3, 2019 · 2 comments

Comments

@anxolin
Copy link
Contributor

anxolin commented Jan 3, 2019

The nonce calculation fails in a local testrpc after you revert the state to a prior one.

The error:

    Error: the tx doesn't have the correct nonce. account has nonce of: 18 tx has nonce of: 19
        at /Users/anxo/code/gnosis/dx-services/node_modules/web3-provider-engine/subproviders/provider.js:19:36
        at XMLHttpRequest.request.onreadystatechange (/Users/anxo/code/gnosis/dx-services/node_modules/truffle-hdwallet-provider/node_modules/web3/lib/web3/httpprovider.js:118:13)
        at XMLHttpRequest.Object.<anonymous>.XMLHttpRequestEventTarget.dispatchEvent (/Users/anxo/code/gnosis/dx-services/node_modules/xhr2/lib/xhr2.js:64:18)
        at XMLHttpRequest.Object.<anonymous>.XMLHttpRequest._setReadyState (/Users/anxo/code/gnosis/dx-services/node_modules/xhr2/lib/xhr2.js:354:12)
        at XMLHttpRequest.Object.<anonymous>.XMLHttpRequest._onHttpResponseEnd (/Users/anxo/code/gnosis/dx-services/node_modules/xhr2/lib/xhr2.js:509:12)
        at IncomingMessage.<anonymous> (/Users/anxo/code/gnosis/dx-services/node_modules/xhr2/lib/xhr2.js:469:24)
        at IncomingMessage.emit (events.js:187:15)
        at IncomingMessage.EventEmitter.emit (domain.js:441:20)
        at endReadableNT (_stream_readable.js:1094:12)
        at process._tickCallback (internal/process/next_tick.js:63:19)

I believe the issue is because the NonceTrackerSubprovider is caching the nonce even after reverting the state of a the local ganache.

Reverting the state in a local testrpc is very common thing to do in order to make the test repeatable, and to avoid tests influence each other.

Clearing the cache, make sure, we get the new nonce from the new state of the blockchain.

@kiliw
Copy link

kiliw commented Apr 4, 2019

The cache is also not updated when a transaction simply fails. I assume the "sendRawTransaction" method is never called and as such the cached nonce is not increased. However ganache increases the nonce for the account trying to send the reverted (failed) transaction. I had a look at the code to see whether I could force some kind of update but I did not see a chance. Is there no way to just manually increase the nonce?

@kiliw
Copy link

kiliw commented Apr 4, 2019

Issue should be reopened: Make sure that whenever ganache increases the nonce, the cached nonce is also increased.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants