question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Feature request: wait for n confirmations between migration transactions (nonce too low error with Infura)

See original GitHub issue

Issue

Deploying to mainnet via INFURA using Truffle is susceptible to breaking. Errors I’ve seen:

gas price too low This happens when a tx is in the mempool and you send another tx with the same nonce.

nonce too low This happens when a tx has been mined but you send another tx with the same nonce.

These things can happen when you talk to INFURA because they run many nodes behind a load balancer. Lets say you send a tx to node A, which later tells you the tx has been mined. Truffle now prepares to move onto the next tx it needs to send and queries INFURA for the nonce it should use for the sending address, and happens to get routed to node B. The block that node A saw hasn’t propagated to node B yet, so node B tells you to use the nonce of the prior transaction!

Steps to Reproduce

You can’t reproduce it deterministically, and it really only happens on mainnet because the peering situation is apparently bad, but try deploying something with a few txs to mainnet. Use this repo if you like: https://github.com/skmgoldin/tcr

Expected Behavior

The issue could be resolved if I could specify to Truffle a number of blocks to wait after a tx has been mined before sending the next tx.

When the number of blocks has elapsed, Truffle should double check at that point that the original transaction was actually mined, since it’s possible it got the original mined alert for a block that ultimately wound up uncle’d. If that block was in fact uncle’d, wait again for the tx to be mined and repeat.

Actual Results

I can’t specify a block depth to wait on. So I get these failures.

Environment

  • Operating System: Ubuntu 16
  • Truffle version: 4.0.5
  • Ethereum client: INFURA
  • node version: 8
  • npm version: 5

Issue Analytics

  • State:closed
  • Created 6 years ago
  • Reactions:8
  • Comments:10 (1 by maintainers)

github_iconTop GitHub Comments

3reactions
cgeweckecommented, Feb 23, 2018

Small update @skmgoldin.

This is a really good idea - adding it to the work underway to migrate to Web3 1.0 at truffle-contract 95. We could have truffle-deployer expose Web3’s new event emitter interface and the pattern for waiting might look something like:

module.exports = function (deployer) {
  deployer.then(function() {
     return new Promise(function(accept, reject){
       deployer
         .deploy(MyContract)
         .on("confirmation", (number, receipt) => {
            if (number === 10) accept(receipt);
         })
         .catch(reject)
      });
   }).then(function(receipt){
      //... ready to deploy something else ...
   }).catch(function(error){
      // ... :/ ...
   })
});

For record keeping, these are related:

  • PR at Web3 to address issue with the confirmation handlers not firing repeatedly for test clients.
  • truffle-deployer 18
0reactions
jlindberg-osscommented, Nov 29, 2018

I got stuck on this issue too. This workaround solved it for me: https://ethereum.stackexchange.com/questions/44349/truffle-infura-on-mainnet-nonce-too-low-error

Read more comments on GitHub >

github_iconTop Results From Across the Web

Truffle + Infura on Mainnet: Nonce too low error
This nonce problem could be due to chain reorgs. Since you're deploying everything from a single address, you could get the nonce once...
Read more >
Truffle deployment problem - Support - Forum - POA Network
Issue : Feature request: wait for n confirmations between migration transactions (nonce too low error with Infura).
Read more >
Documentation - Ethers.js
Returns the number of transactions address has ever sent, as of blockTag. This value is required to be the nonce for the next...
Read more >
Network API — Brownie 1.19.2 documentation - Read the Docs
If the transaction reverts or you do not wait for a confirmation, a TransactionReceipt is returned instead. >>> Token [] >>> t =...
Read more >
Pocket Network: Welcome
The Requests page for a given App shows the success and error rates for your ... transactions on these chains often wait for...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found