From 95c93ed7b58164d6e3fa8a5bf1c7a7edc4f762e5 Mon Sep 17 00:00:00 2001 From: Alexander Tesfamichael Date: Tue, 27 Aug 2024 19:22:20 +0200 Subject: [PATCH] feat(beacon_api): sprinkle logging --- src/beacon_api.rs | 23 +++++++++++++++++++---- 1 file changed, 19 insertions(+), 4 deletions(-) diff --git a/src/beacon_api.rs b/src/beacon_api.rs index 84cf107..64b0e85 100644 --- a/src/beacon_api.rs +++ b/src/beacon_api.rs @@ -2,6 +2,7 @@ use anyhow::anyhow; use rand::seq::SliceRandom; use reqwest::{StatusCode, Url}; use serde::Deserialize; +use tracing::debug; #[derive(Deserialize)] struct BeaconResponse { @@ -103,8 +104,12 @@ impl BeaconApi { // 1. Slot doesn't have a block. // 2. Slot is in the future and doesn't have a block yet. // 3. Slot is before the beacon node backfill limit. - StatusCode::NOT_FOUND => Ok(None), + StatusCode::NOT_FOUND => { + debug!("no block for slot {} on node {}", slot, node); + Ok(None) + } StatusCode::OK => { + debug!("found block for slot {} on node {}", slot, node); let block = res .json::>() .await @@ -135,7 +140,10 @@ impl BeaconApi { // Attempt to return the first Ok(Some) if any. for result in &results { match result { - Ok(Some(payload)) => return Ok(Some(payload.clone())), + Ok(Some(payload)) => { + debug!("at least one node has a block for slot {}", slot); + return Ok(Some(payload.clone())); + } Ok(None) => continue, Err(_) => continue, } @@ -144,17 +152,24 @@ impl BeaconApi { // Attempt to return the first Ok(None) if any. for result in &results { match result { - Ok(None) => return Ok(None), + Ok(None) => { + debug!("no node has a block for slot {}", slot); + return Ok(None); + } Ok(Some(_)) => continue, Err(_) => continue, } } // Return the first error if all Ok(None) and Ok(Some) are exhausted. + debug!( + "failed to successfully fetch block for slot {} on all nodes", + slot + ); results .into_iter() .next() - .expect("expect results to be all errors") + .expect("expect to results to not be empty") } // Method to fetch the sync status from a node