Skip to content

Commit

Permalink
add blockchain client graceful shutdown
Browse files Browse the repository at this point in the history
  • Loading branch information
gabriel-aranha-cw committed Jul 29, 2024
1 parent facad2f commit 2a57d9c
Showing 1 changed file with 6 additions and 0 deletions.
6 changes: 6 additions & 0 deletions src/infra/blockchain_client/blockchain_client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ use crate::ext::DisplayExt;
use crate::ext::JsonValue;
use crate::infra::tracing::TracingExt;
use crate::log_and_err;
use crate::GlobalState;

#[derive(Debug)]
pub struct BlockchainClient {
Expand Down Expand Up @@ -231,10 +232,15 @@ impl BlockchainClient {
// -------------------------------------------------------------------------

pub async fn subscribe_new_heads(&self) -> anyhow::Result<Subscription<ExternalBlock>> {
const TASK_NAME: &str = "blockchain::subscribe_new_heads";
tracing::debug!("subscribing to newHeads event");

let mut first_attempt = true;
loop {
if GlobalState::is_shutdown_warn(TASK_NAME) {
return Err(anyhow::anyhow!("shutdown warning"));
};

let ws_read = self.require_ws().await?;
let result = ws_read
.subscribe::<ExternalBlock, Vec<JsonValue>>("eth_subscribe", vec![JsonValue::String("newHeads".to_owned())], "eth_unsubscribe")
Expand Down

0 comments on commit 2a57d9c

Please sign in to comment.