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

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

Closed
skmgoldin opened this issue Jan 23, 2018 · 10 comments

Comments

@skmgoldin
Copy link
Contributor

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
@cgewecke
Copy link
Contributor

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

@cgewecke cgewecke changed the title Feature request: wait for n confirmations between migration transactions Feature request: wait for n confirmations between migration transactions (nonce too low error with Infura) May 16, 2018
@jamesmorgan
Copy link

This would be great, I hit this often when minting large amounts of nfts 👍

@vzts
Copy link

vzts commented May 31, 2018

Suffering on this as well. I had to take the code to the remix to deploy, having failed from this error several times and it's costing too much real money..😭

@prographo
Copy link

Just had the "nonce too low" issue.

@boyangwang
Copy link

Any workarounds at the moment?

@prographo
Copy link

I just used remix to deploy.

Hokid added a commit to w12-platform/W12-Product-Blockchain-Protocol that referenced this issue Sep 28, 2018
Hokid added a commit to w12-platform/W12-Product-Blockchain-Protocol that referenced this issue Sep 28, 2018
@stale
Copy link

stale bot commented Nov 8, 2018

Thank you for raising this issue! It has been automatically marked as stale because it has not had recent activity. It will be closed in 7 days if no further activity occurs. If you would like to keep this issue open, please respond with information about the current state of this problem.

@stale stale bot added the stale label Nov 8, 2018
@stale
Copy link

stale bot commented Nov 15, 2018

There has been no new activity on this issue since it was marked as stale 7 days ago, so it is being automatically closed. If you'd like help with this or a different problem, please open a new issue. Thanks!

@stale stale bot closed this as completed Nov 15, 2018
@cckelly
Copy link

cckelly commented Nov 15, 2018

Just got this as well.

@jlindberg-oss
Copy link

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

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

No branches or pull requests

8 participants