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.

NonceManager increments nonce even if transaction fails

See original GitHub issue

I understand this isn’t trivial to fix fully, but if a transaction fails to send (e.g. with insufficient balance), the nonce is wrong afterwards and every future transaction also fails.

I think these easy cases should be fixable by just doing

try {
	const tx = await this.nonceManager.sendTransaction({
		to: i.address,
		value: parseEther(i.amount),
	});
} catch (e) {
	console.error("could not send tx", "nonce=", e?.transaction?.nonce);
	this.nonceManager._deltaCount--;
}

except inside the sendTransaction function

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Comments:7 (2 by maintainers)

github_iconTop GitHub Comments

2reactions
garyng2000commented, Jul 25, 2020

@phiresky yes, this nonce(which is not even nonce but really serial counter) thing is really bad. Imagine in real life you run a business and issued 10 checks to your suppliers and if the first one is not cashed, the other 9 can’t either. You would be out of business in no time.

We have to re-design our application to use multiple ‘agent’ wallet and put our serialization logic(if needed) in the contract logic itself. Though most of the time, there doesn’t need to have serialization. Say a typical ERC20(like the above situation), it would go through so long the balance is enough, regardless when the transaction is picked up(gas price can be different).

1reaction
roderikcommented, Aug 7, 2020

We have done some extensive work on this and I can tell you that what we have settled on is:

  • some sort of ordered queue per sender
  • blocking sending and verification that the TX was accepted by the node (is not “slow”)
  • several retries + filling the gaps with empty tx and queuing the failed ones at the end of the queue
  • a “transaction set” concept if you have dependent transactions in one go.

Now we do work on consortium chains, so we do not often have issues with nodes accepting TX and then halfway through losing one in the middle of a run.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Does nonce increase when the transaction fail?
There is no hard requirement that it increments every time although wallets tend to do that in the background. Given that transactions must...
Read more >
Managing nonces - Nethereum Documentation
Each node will process transactions from a specific account in a strict order according to the value of its nonce, hence the nonce...
Read more >
ethers-io/Lobby - Gitter
The nonce manager will fetch the latest from the backend, and then increment ... don't even know if they support a paid level...
Read more >
Sending Web3 Transactions In Node.js — Nonce Hell.
It starts at zero for your first transaction and increments by one (+1) for subsequent transactions. This allows each transaction from an address...
Read more >
Experimental - ethers
The NonceManager is designed to manage the nonce for a Signer, automatically increasing it as it sends transactions. Currently the NonceManager does not...
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