0

I have a Rust application that communicates with the erigon API using websockets (specifically using the web3 crate). Lately, I've been experiencing instability with the responses from the server, as sometimes it doesn't respond as expected or it takes a long time for the response to arrive. Here is my current code setup:

#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {

    let ws = web3::transports::WebSocket::new("ws://192.168.1.10:8546").await?;
    let web3 = web3::Web3::new(ws.clone());
    let mut sub = web3.eth_subscribe().subscribe_new_heads().await?;

    println!("Got subscription id: {:?}", sub.id());

    while let Some(result) = sub.next().await {
        match result {
            Ok(block_header) => {
                let now = chrono::Local::now();
                println!("{}", now);
                println!("Got: {:?}", block_header.number);
            },
            Err(e) => println!("Error: {:?}", e),
        }
    }

    Ok(())

}

And the console message is here.

Got subscription id: SubscriptionId("0xf960fcba0ea013ac3cd1b035e3d8ce41")
2024-02-12 22:36:58.421287 +09:00 | Got: Some(19212238)
2024-02-12 22:36:58.421975 +09:00 | Got: Some(19212239)
2024-02-12 22:36:58.422099 +09:00 | Got: Some(19212240)
2024-02-12 22:36:58.422217 +09:00 | Got: Some(19212241)
2024-02-12 22:36:58.422325 +09:00 | Got: Some(19212242)
2024-02-12 22:36:58.425577 +09:00 | Got: Some(19212243)
2024-02-12 22:36:58.425977 +09:00 | Got: Some(19212244)
2024-02-12 22:36:58.426304 +09:00 | Got: Some(19212245)
2024-02-12 22:36:58.426737 +09:00 | Got: Some(19212246)
2024-02-12 22:36:58.427507 +09:00 | Got: Some(19212247)
2024-02-12 22:36:58.427820 +09:00 | Got: Some(19212248)
2024-02-12 22:36:58.428121 +09:00 | Got: Some(19212249)
2024-02-12 22:36:58.428398 +09:00 | Got: Some(19212250)
2024-02-12 22:36:58.428689 +09:00 | Got: Some(19212251)
2024-02-12 22:36:58.428994 +09:00 | Got: Some(19212252)
2024-02-12 22:36:58.429338 +09:00 | Got: Some(19212253)
2024-02-12 22:36:58.429644 +09:00 | Got: Some(19212254)
2024-02-12 22:36:58.430029 +09:00 | Got: Some(19212255)
2024-02-12 22:36:58.430331 +09:00 | Got: Some(19212256)
2024-02-12 22:36:58.430619 +09:00 | Got: Some(19212257)
2024-02-12 22:36:58.431020 +09:00 | Got: Some(19212258)
2024-02-12 22:36:58.431347 +09:00 | Got: Some(19212259)
2024-02-12 22:36:58.431815 +09:00 | Got: Some(19212260)
2024-02-12 22:36:58.432340 +09:00 | Got: Some(19212261)
2024-02-12 22:36:58.432542 +09:00 | Got: Some(19212262)
2024-02-12 22:36:58.434072 +09:00 | Got: Some(19212263)
2024-02-12 22:36:58.434292 +09:00 | Got: Some(19212264)
2024-02-12 22:36:58.434493 +09:00 | Got: Some(19212265)
2024-02-12 22:36:58.434717 +09:00 | Got: Some(19212266)
2024-02-12 22:36:58.434922 +09:00 | Got: Some(19212267)
2024-02-12 22:36:58.435129 +09:00 | Got: Some(19212268)
2024-02-12 22:36:58.435327 +09:00 | Got: Some(19212269)
2024-02-12 22:36:58.435527 +09:00 | Got: Some(19212270)

As shown in the console display above, information from multiple blocks is displayed together. Normally, information on one block should be displayed approximately every 12 seconds.

The Erigon start-up options are as follows.

erigon --internalcl --datadir=/erigon/datadir --http --ws --http.api "eth,erigon,net,web3,engine,admin,txpool,db" --http.addr "0.0.0.0" --db.read.concurrency 1000 --rpc.batch.concurrency 1000 --maxpeers 128 --txpool.globalslots 250000 --txpool.globalqueue 120000

Rust version is v1.75.0
web3 = "0.19.0"
tokio = "1.35.1"
chrono = "0.4.34"

How can I get information from erigon in real time (approximately every 12 seconds) whenever block information is generated?

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Browse other questions tagged or ask your own question.