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

watchContractEvent doing requests with invalid block range #2470

Closed
1 task done
Lopol2010 opened this issue Jul 3, 2024 · 1 comment
Closed
1 task done

watchContractEvent doing requests with invalid block range #2470

Lopol2010 opened this issue Jul 3, 2024 · 1 comment

Comments

@Lopol2010
Copy link

Lopol2010 commented Jul 3, 2024

Check existing issues

Viem Version

2.16.1

Current Behavior

When listening events via watchContractEvent, console is filled with error:
RPC Request failed:
code: -32000, message: invalid block range params

Request body: "method":"eth_getLogs" ..."fromBlock":"0x2649c99" ... "toBlock":"0x2649c97"

As you can see fromBlock is greater than toBlock.
I assume bug appears in these lines:

fromBlock: previousBlockNumber + 1n,
toBlock: blockNumber,

Expected Behavior

The case with invalid block range should be handled by watchContractEvent function, so that it won't make request with invalid block range.

Steps To Reproduce

Listen for BSC mainnet contract events via RPC node https://rpc.ankr.com/bsc
And these arguments:

    let unwatch = client.watchContractEvent({
        abi: ...,
        address: ...,
        pollingInterval: 4000,
        eventName: ...,
        onError: err => { console.log("[Listener] error:", err); },
        onLogs: logs => {
        }
    })

Link to Minimal Reproducible Example

No response

Anything else?

No response

@jxom
Copy link
Member

jxom commented Jul 3, 2024

Hmm, must be some load balancing issue on the RPC Provider side. Will add a guard to fix.

@jxom jxom closed this as completed in f12dfdb Jul 4, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants