Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

TX goes through but FallbackProvider throws 'already known' or 'nonce too low' error #4186

Closed
chicken-juju opened this issue Jun 29, 2023 · 1 comment
Assignees
Labels
enhancement New feature or improvement. fixed/complete This Bug is fixed or Enhancement is complete and published. v6 Issues regarding v6

Comments

@chicken-juju
Copy link

Ethers Version

6.6.2

Search Terms

provider

Describe the Problem

My provider is configured as follows

export const provider = new ethers.FallbackProvider([
  {
    provider: new ethers.JsonRpcProvider(process.env.NODE_URL_1),
    priority: 1,
    weight: 2
  },
  {
    provider: new ethers.JsonRpcProvider(process.env.NODE_URL_2),
    priority: 2,
    weight: 2
  },
  {
    provider: new ethers.JsonRpcProvider(process.env.NODE_URL_3),
    priority: 3,
    weight: 2
  }
])

When making a smart contract call await contractName.something() the TX succeeds on the explorer but ethers throws one of these errors-

Feed update failed Error: nonce has already been used (transaction="0x02f8b5820fa2830468d8843b9aca0084b2d05e0083030d409428e449afc8a04ed97ca840aa83b64c7c1f5f55ad80b84417835d1c000000000000000000000000000000000000000000000000000000000004809900000000000000000000000000000000000000000000000000000000649d5023c080a0b6c47a90cdae1b294a9349db737ab282ce77b9c201777efaa6b8c0446e0156c9a04d5a1d45dc73d4017e688797e583c232ca1382e1ecdfbf0377578282862cbf44", info={ "error": { "code": -32000, "message": "nonce too low" } }, code=NONCE_EXPIRED, version=6.6.2)
    at makeError (/home/hp/Documents/voodoo/voodoo-keeper-server/node_modules/ethers/src.ts/utils/errors.ts:677:21)
    at JsonRpcProvider.getRpcError (/home/hp/Documents/voodoo/voodoo-keeper-server/node_modules/ethers/src.ts/providers/provider-jsonrpc.ts:949:33)
    at /home/hp/Documents/voodoo/voodoo-keeper-server/node_modules/ethers/src.ts/providers/provider-jsonrpc.ts:524:45
    at processTicksAndRejections (node:internal/process/task_queues:95:5) {
  code: 'NONCE_EXPIRED',
  transaction: '0x02f8b5820fa2830468d8843b9aca0084b2d05e0083030d409428e449afc8a04ed97ca840aa83b64c7c1f5f55ad80b84417835d1c000000000000000000000000000000000000000000000000000000000004809900000000000000000000000000000000000000000000000000000000649d5023c080a0b6c47a90cdae1b294a9349db737ab282ce77b9c201777efaa6b8c0446e0156c9a04d5a1d45dc73d4017e688797e583c232ca1382e1ecdfbf0377578282862cbf44',
  info: { error: { code: -32000, message: 'nonce too low' } }
}
Feed update failed Error: could not coalesce error (error={ "code": -32000, "message": "already known" }, payload={ "id": 37, "jsonrpc": "2.0", "method": "eth_sendRawTransaction", "params": [ "0x02f8b5820fa2830468db843b9aca0084b2d05e0083030d409428e449afc8a04ed97ca840aa83b64c7c1f5f55ad80b84417835d1c00000000000000000000000000000000000000000000000000000000000480ee00000000000000000000000000000000000000000000000000000000649d50a1c080a08d69aa7c4989adaf2ae58f5f44d08ce7adb4a614b9fd02e26c4dde547a925d57a06f99a70f002bf589df028b26ccf6abf3f554da8feaa8e594b5f72e52a31ff7d8" ] }, code=UNKNOWN_ERROR, version=6.6.2)
    at makeError (/home/hp/Documents/voodoo/voodoo-keeper-server/node_modules/ethers/src.ts/utils/errors.ts:677:21)
    at JsonRpcProvider.getRpcError (/home/hp/Documents/voodoo/voodoo-keeper-server/node_modules/ethers/src.ts/providers/provider-jsonrpc.ts:977:25)
    at /home/hp/Documents/voodoo/voodoo-keeper-server/node_modules/ethers/src.ts/providers/provider-jsonrpc.ts:524:45
    at processTicksAndRejections (node:internal/process/task_queues:95:5) {
  code: 'UNKNOWN_ERROR',
  error: { code: -32000, message: 'already known' },
  payload: {
    method: 'eth_sendRawTransaction',
    params: [
      '0x02f8b5820fa2830468db843b9aca0084b2d05e0083030d409428e449afc8a04ed97ca840aa83b64c7c1f5f55ad80b84417835d1c00000000000000000000000000000000000000000000000000000000000480ee00000000000000000000000000000000000000000000000000000000649d50a1c080a08d69aa7c4989adaf2ae58f5f44d08ce7adb4a614b9fd02e26c4dde547a925d57a06f99a70f002bf589df028b26ccf6abf3f554da8feaa8e594b5f72e52a31ff7d8'
    ],
    id: 37,
    jsonrpc: '2.0'
  }
}

One reason could be that Ethers calls eth_sendRawTransaction on multiple RPC servers. The first TX succeeds and the duplicates fail. Some context about our setup. We want to run one JsonRpcProvider at a time. The others are for redundancy and are therefore have different priorities. The errors are not thrown if we leave a single RPC and comment out the rest.

Code Snippet

No response

Contract ABI

No response

Errors

No response

Environment

Ethereum (mainnet/ropsten/rinkeby/goerli), Altcoin - Please specify (e.g. Polygon), node.js (v12 or newer)

Environment (Other)

Fantom testnet

@chicken-juju chicken-juju added investigate Under investigation and may be a bug. v6 Issues regarding v6 labels Jun 29, 2023
@ricmoo ricmoo added enhancement New feature or improvement. on-deck This Enhancement or Bug is currently being worked on. minor-bump Planned for the next minor version bump. next-patch Issues scheduled for the next arch release. and removed investigate Under investigation and may be a bug. labels Nov 17, 2023
@ricmoo
Copy link
Member

ricmoo commented Nov 27, 2023

This has been fixed in 6.9.0.

Let me know if you still get any weird behaviour. I've also added a flexible FallbackProvider-based test suite to make it easy to add more tests for expected FallbackProvider behaviour.

Thanks! :)

@ricmoo ricmoo closed this as completed Nov 27, 2023
@ricmoo ricmoo added fixed/complete This Bug is fixed or Enhancement is complete and published. and removed on-deck This Enhancement or Bug is currently being worked on. minor-bump Planned for the next minor version bump. next-patch Issues scheduled for the next arch release. labels Nov 27, 2023
rrw-zilliqa added a commit to Zilliqa/ethers.js that referenced this issue Apr 29, 2024
* docs: fixed typo in jsdocs for Wallet.createRandom (ethers-io#4461)

* admin: added diff scripts for build page

* admin: updated dist files

* Added safe and finalized provider events (ethers-io#3921).

* tests: bumped Node versions for testing (ethers-io#4451)

* admin: style fix (ethers-io#4356)

* More robust FallbackProvider broadcast (ethers-io#4186, ethers-io#4297, ethers-io#4442).

* Account for provider config weight when kicking off a request in FallbackProvider (ethers-io#4298).

* Fixed ParamType formatting causing bad tuple full and minimal ABI output (ethers-io#4329, ethers-io#4479).

* Added Base network to AlchemyProvider (ethers-io#4384).

* Add auto-detected static network support to providers and allow customizing socket provider options (ethers-io#4199, ethers-io#4418, ethers-io#4441).

* Use provider-specified suggested priority fee when available, otherwise fallback onto existing logic of 1 gwei (ethers-io#4463).

* admin: updated dist files

* admin: update changelog after build-clean

* docs: Fixed some grammar in getting-started (ethers-io#4486, ethers-io#4487, ethers-io#4488)

* Fix uncatchable issue when sending transactions over JSON-RPC and provide some retry-recovery for missing v (ethers-io#4513).

* admin: update dist files

* Fix Base58 padding for string representation of binary data (ethers-io#4527).

* admin: updated dist files

* Limit decoded result imflation ratio from ABI-encoded data (ethers-io#4537).

* admin: updated dist files

* Better debugging output on fetch errors.

* docs: added StaticJsonRpcProvider to migration docs

* Fixed typo in Error string (ethers-io#4539).

* Fix EIP-712 type aliases for uint and int (ethers-io#4541).

* Added additional sepolia testnets.

* Updated third-party provider network URLs (ethers-io#4542).

* admin: updated dist files

* Fixed normalization and abstracted EIP-712 Array parsing (ethers-io#4541).

* admin: updated dist files

* tests: added testing for correct thrid-party URLs

* Updated thrid-part provider URLs for QuickNode.

* tests: rename test suite to follow naming convention

* admin: updated dist files

* Normalize EIP-712 types before computing the payload (ethers-io#4541).

* tests: add tests for EIP-712 payload aliases

* admin: updated dist files

---------

Co-authored-by: Richard Moore <me@ricmoo.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or improvement. fixed/complete This Bug is fixed or Enhancement is complete and published. v6 Issues regarding v6
Projects
None yet
Development

No branches or pull requests

2 participants