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

JsonRpcProvider pollingInterval option is not used in tx.wait() #4644

Closed
PierreJeanjacquot opened this issue Mar 12, 2024 · 3 comments
Closed
Assignees
Labels
bug Verified to be an issue. fixed/complete This Bug is fixed or Enhancement is complete and published. v6 Issues regarding v6

Comments

@PierreJeanjacquot
Copy link

Ethers Version

ethers@6.11.1

Search Terms

JsonRpcProvider, pollingInterval

Describe the Problem

The pollingInterval option of JsonRpcProvider is not used for transaction wait(), instead a default 4000 ms value is used.

It may be linked to the pollingInterval value being hardcoded in the constructor.

this.#pollingInterval = 4000;

this fix in provider-jsonrpc.ts seems to do the trick but I did not check the other impacts:

export class JsonRpcApiPollingProvider extends JsonRpcApiProvider {
    #pollingInterval;
    constructor(network, options) {
        super(network, options);

        this.#pollingInterval = options.pollingInterval ?? 4000; // use option when it exists
    }

Also I'm not sure why 4000 is hardcoded as the value is available in defaultOptions.pollingInterval

Code Snippet

import { JsonRpcProvider, Wallet } from "ethers";

// The following snippet can be tested on a hardhat or anvil node with a 1s blocktime.

const provider = new JsonRpcProvider("http://localhost:8545", undefined, {
  pollingInterval: 1000,
});

const wallet = new Wallet(process.env.PRIVATE_KEY).connect(provider);

console.log("provider.pollingInterval", provider.pollingInterval);
// provider.pollingInterval 4000
console.log(
  'provider._getOption("pollingInterval")',
  provider._getOption("pollingInterval")
);
// provider._getOption("pollingInterval") 1000

const tx = await wallet.sendTransaction({ to: wallet.address, data: "0x" });
console.time("tx");
await tx.wait();
console.timeEnd("tx");
// tx: 4.094s

Contract ABI

No response

Errors

No response

Environment

No response

Environment (Other)

No response

@sealer3
Copy link

sealer3 commented Apr 30, 2024

As a temporary fix, you can set the pollingInterval property after the constructor:

provider.pollingInterval = 1000;

@ricmoo ricmoo added bug Verified to be an issue. on-deck This Enhancement or Bug is currently being worked on. next-patch Issues scheduled for the next arch release. and removed investigate Under investigation and may be a bug. labels Apr 30, 2024
@ricmoo
Copy link
Member

ricmoo commented Apr 30, 2024

This does appear to be a bug. I'll get a fix out in the next patch.

@ricmoo
Copy link
Member

ricmoo commented May 1, 2024

Fixed in v6.12.1.

Thanks! :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Verified to be an issue. 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

3 participants