Skip to content
This repository has been archived by the owner on Oct 19, 2024. It is now read-only.

subscribe_blocks() is not working #684

Closed
stephenctw opened this issue Dec 13, 2021 · 6 comments
Closed

subscribe_blocks() is not working #684

stephenctw opened this issue Dec 13, 2021 · 6 comments
Labels
bug Something isn't working

Comments

@stephenctw
Copy link

Version
0.6.2

Platform
WSL2 (Linux LAPTOP-163CP44A 4.19.104-microsoft-standard #1 SMP Wed Feb 19 06:37:35 UTC 2020 x86_64 x86_64 x86_64 GNU/Linux)

Description
ethers::provider::subscribe_blocks() not responding, the wss endpoint is valid that subscribe_pending_txs() is working properly.

I tried this code:

use ethers::prelude::*;
use ethers_providers::Ws;

use std::time::Duration;

#[tokio::main]
async fn main() -> std::result::Result<(), Box<dyn std::error::Error>> {
    let ws_endpoint = "wss://goerli.infura.io/ws/v3/<PROJECT_ID>";

    let ws = Ws::connect(ws_endpoint).await?;

    println!("endpoint ready?: {}", ws.ready());

    let provider = Provider::new(ws).interval(Duration::from_millis(2000));

    let mut stream = provider.subscribe_blocks().await?.take(5);
    // let mut stream = provider.subscribe_pending_txs().await?.take(5);

    println!("Stream created! Entering loop...");
    while let Some(block) = stream.next().await {
        dbg!(block);
    }

    Ok(())
}
@stephenctw stephenctw added the bug Something isn't working label Dec 13, 2021
@gakonst
Copy link
Owner

gakonst commented Dec 13, 2021

Given that we're not hitting this bug in the test I wonder if this has to do with some network delay / bug in our websocket implementation?

@stephenctw
Copy link
Author

I can confirm subscribe_blocks() is working fine with local hardhat node. subscribe_pending_txs() works with goerli + infura.

@gakonst
Copy link
Owner

gakonst commented Dec 19, 2021

This is quite weird. I tested with Alchemy and it's working, but I am not getting any results from Infura. (Same code as yours, just replaced Infura URL with Alchemy)

@nanne007
Copy link
Contributor

I can confirm subscribe_blocks() is working fine with local hardhat node. subscribe_pending_txs() works with goerli + infura.

Is your serde_json arbitrary_precision enabled ?
I met the same problem, and found out it related to serde_json.

@stephenctw
Copy link
Author

I can confirm subscribe_blocks() is working fine with local hardhat node. subscribe_pending_txs() works with goerli + infura.

Is your serde_json arbitrary_precision enabled ? I met the same problem, and found out it related to serde_json.

Can you give an example how it works with the arbitrary_precision feature enabled?

@stephenctw
Copy link
Author

@lerencao do you have a working example with the arbitrary_precision feature?

erwanor added a commit to erwanor/ethers-rs that referenced this issue Jan 24, 2022
Infura streams notifications with jsonrpc all capitalized. This fails to
deserialize on our end because serde expect a precise match ressembling
the Notification jsonrpc field.

Fixes gakonst#684.
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

3 participants