diff --git a/node/src/exchange.rs b/node/src/exchange.rs index c92c28407..67aaa3b88 100644 --- a/node/src/exchange.rs +++ b/node/src/exchange.rs @@ -152,7 +152,6 @@ where }, peer, } => { - //let responder = RequestResponseResponder::new(&mut self.req_resp, channel); self.server_handler .on_request_received(peer, request_id, request, channel); } diff --git a/node/src/exchange/server.rs b/node/src/exchange/server.rs index 3be75caef..f6472a036 100644 --- a/node/src/exchange/server.rs +++ b/node/src/exchange/server.rs @@ -13,11 +13,11 @@ use libp2p::{ PeerId, }; use tendermint::hash::Algorithm; -use tracing::{error, info, instrument, warn}; +use tracing::{instrument, trace}; use crate::exchange::utils::{ExtendedHeaderExt, HeaderRequestExt, HeaderResponseExt}; use crate::exchange::ResponseType; -use crate::store::{Store, StoreError}; +use crate::store::Store; type StoreJobType = dyn Future + Send; @@ -74,7 +74,7 @@ where } pub(super) fn on_response_sent(&mut self, peer: PeerId, request_id: RequestId) { - info!("response_sent; request_id: {request_id}, peer: {peer}"); + trace!("response_sent; request_id: {request_id}, peer: {peer}"); } pub(super) fn on_failure( @@ -84,7 +84,7 @@ where error: InboundFailure, ) { // TODO: cancel job if libp2p already failed it? - info!("on_failure; request_id: {request_id}, peer: {peer}, error: {error:?}"); + trace!("on_failure; request_id: {request_id}, peer: {peer}, error: {error:?}"); } fn parse_request(&self, request: HeaderRequest) -> Option<(u64, header_request::Data)> { @@ -120,8 +120,7 @@ where { let response = match store.get_head().await { Ok(head) => head.to_header_response(), - Err(StoreError::NotFound) => HeaderResponse::not_found(), - Err(_) => HeaderResponse::invalid(), + Err(_) => HeaderResponse::not_found(), }; (channel, vec![response]) @@ -131,18 +130,13 @@ async fn handle_request_by_hash(store: Arc, channel: C, hash: Vec) where S: Store, { - let hash = match Hash::from_bytes(Algorithm::Sha256, &hash) { - Ok(h) => h, - Err(e) => { - error!("error decoding hash: {e}"); - return (channel, vec![HeaderResponse::invalid()]); - } + let Ok(hash) = Hash::from_bytes(Algorithm::Sha256, &hash) else { + return (channel, vec![HeaderResponse::invalid()]); }; let response = match store.get_by_hash(&hash).await { Ok(head) => head.to_header_response(), - Err(StoreError::NotFound) => HeaderResponse::not_found(), - Err(_) => HeaderResponse::invalid(), + Err(_) => HeaderResponse::not_found(), }; (channel, vec![response]) @@ -157,19 +151,16 @@ async fn handle_request_by_height( where S: Store, { - info!("get by height {origin} +{amount}"); - - let mut r = vec![]; + let mut responses = vec![]; for i in origin..origin + amount { let response = match store.get_by_height(i).await { Ok(head) => head.to_header_response(), - Err(StoreError::NotFound) => HeaderResponse::not_found(), - Err(_) => HeaderResponse::invalid(), + Err(_) => HeaderResponse::not_found(), }; - r.push(response); + responses.push(response); } - (channel, r) + (channel, responses) } async fn handle_invalid_request(channel: C) -> (C, ResponseType) diff --git a/node/src/exchange/utils.rs b/node/src/exchange/utils.rs index e3f9be061..d7e5d2736 100644 --- a/node/src/exchange/utils.rs +++ b/node/src/exchange/utils.rs @@ -96,24 +96,6 @@ impl ExtendedHeaderExt for ExtendedHeader { } } -/* -impl ToHeaderResponse for Result { - fn to_header_response(&self) -> HeaderResponse { - match self { - Ok(h) => h.to_header_response(), - Err(e) => HeaderResponse { - // TODO: how forthcoming should we be with errors and description? - body: vec![], - status_code: match e { - StoreError::NotFound => StatusCode::NotFound.into(), - _ => StatusCode::Invalid.into(), - }, - }, - } - } -} -*/ - #[cfg(test)] mod tests { use super::*;