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

protential page crach when tx.wait() and switching chain simultaneously #4806

Open
coverlv opened this issue Aug 14, 2024 · 0 comments
Open
Assignees
Labels
investigate Under investigation and may be a bug. v6 Issues regarding v6

Comments

@coverlv
Copy link

coverlv commented Aug 14, 2024

Ethers Version

6.11.1

Search Terms

No response

Describe the Problem

assumption: A-chain's block number is extremely higher then B-chain's

Reproduction steps:

  1. switch to A-chain
  2. send transaction
  3. tx.wait()
  4. switch to B-chain
  5. stall for 3s
  6. switch back to A-chain
  7. page crashes

online demo

https://codesandbox.io/p/devbox/festive-cohen-8t7d6c

in this demo, sepolia(A)'s block number is 6498382 much higher than cronos_zkevm(B)'s block number (213236).

the possible cause I found is related to PollingBlockSubscriber, it will run a long foreach loop in this case, refer to this line:

for (let b = this.#blockNumber + 1; b <= blockNumber; b++) {
   // ...
    await this.#provider.emit("block", b);
}

Xnip2024-08-14_19-54-09

Code Snippet

const provider = new BrowserProvider(window.ethereum);
    const signer = await provider.getSigner();
    const contract = new BaseContract(
      "...",
      erc20Api,
      signer
    );
    const tx = await contract.approve(
      "...",
      10
    );

    tx.wait();

    await window.ethereum.request({
      method: "wallet_switchEthereumChain",
      params: [
        {
          chainId: "0x11a",
        },
      ],
    });

    await sleep(3000);

    await window.ethereum.request({
      method: "wallet_switchEthereumChain",
      params: [
        {
          chainId: "0xaa36a7",
        },
      ],
    });

Contract ABI

No response

Errors

page crashes

Environment

Browser (Chrome, Safari, etc)

Environment (Other)

No response

@coverlv coverlv added investigate Under investigation and may be a bug. v6 Issues regarding v6 labels Aug 14, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
investigate Under investigation and may be a bug. v6 Issues regarding v6
Projects
None yet
Development

No branches or pull requests

2 participants