Skip to content

Commit

Permalink
cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
fl0rek committed Sep 21, 2023
1 parent 334bd58 commit 60bd68e
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 40 deletions.
1 change: 0 additions & 1 deletion node/src/exchange.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down
33 changes: 12 additions & 21 deletions node/src/exchange/server.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<C> = dyn Future<Output = (C, ResponseType)> + Send;

Expand Down Expand Up @@ -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(
Expand All @@ -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)> {
Expand Down Expand Up @@ -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])
Expand All @@ -131,18 +130,13 @@ async fn handle_request_by_hash<S, C>(store: Arc<S>, channel: C, hash: Vec<u8>)
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])
Expand All @@ -157,19 +151,16 @@ async fn handle_request_by_height<S, C>(
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<C>(channel: C) -> (C, ResponseType)
Expand Down
18 changes: 0 additions & 18 deletions node/src/exchange/utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -96,24 +96,6 @@ impl ExtendedHeaderExt for ExtendedHeader {
}
}

/*
impl ToHeaderResponse for Result<ExtendedHeader, StoreError> {
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::*;
Expand Down

0 comments on commit 60bd68e

Please sign in to comment.