From 8c066be41fcf1f39f93cc16238d31d9ffc49ef9e Mon Sep 17 00:00:00 2001 From: ethDreamer <37123614+ethDreamer@users.noreply.github.com> Date: Tue, 23 Jan 2024 12:08:57 +0800 Subject: [PATCH] Small Readability Improvement in Networking Code (#5098) --- .../network/src/sync/block_lookups/common.rs | 3 +-- .../sync/block_lookups/single_block_lookup.rs | 17 ++++++++--------- 2 files changed, 9 insertions(+), 11 deletions(-) diff --git a/beacon_node/network/src/sync/block_lookups/common.rs b/beacon_node/network/src/sync/block_lookups/common.rs index 78b10473df6..d989fbb3362 100644 --- a/beacon_node/network/src/sync/block_lookups/common.rs +++ b/beacon_node/network/src/sync/block_lookups/common.rs @@ -101,11 +101,10 @@ pub trait RequestState { fn build_request_and_send( &mut self, id: Id, - already_downloaded: bool, cx: &SyncNetworkContext, ) -> Result<(), LookupRequestError> { // Check if request is necessary. - if already_downloaded || !matches!(self.get_state().state, State::AwaitingDownload) { + if !matches!(self.get_state().state, State::AwaitingDownload) { return Ok(()); } diff --git a/beacon_node/network/src/sync/block_lookups/single_block_lookup.rs b/beacon_node/network/src/sync/block_lookups/single_block_lookup.rs index 59931fadd7e..8c60621f1c7 100644 --- a/beacon_node/network/src/sync/block_lookups/single_block_lookup.rs +++ b/beacon_node/network/src/sync/block_lookups/single_block_lookup.rs @@ -114,19 +114,18 @@ impl SingleBlockLookup { &mut self, cx: &SyncNetworkContext, ) -> Result<(), LookupRequestError> { - let block_root = self.block_root(); let block_already_downloaded = self.block_already_downloaded(); let blobs_already_downloaded = self.blobs_already_downloaded(); - if block_already_downloaded && blobs_already_downloaded { - trace!(cx.log, "Lookup request already completed"; "block_root"=> ?block_root); - return Ok(()); + if !block_already_downloaded { + self.block_request_state + .build_request_and_send(self.id, cx)?; + } + if !blobs_already_downloaded { + self.blob_request_state + .build_request_and_send(self.id, cx)?; } - let id = self.id; - self.block_request_state - .build_request_and_send(id, block_already_downloaded, cx)?; - self.blob_request_state - .build_request_and_send(id, blobs_already_downloaded, cx) + Ok(()) } /// Returns a `CachedChild`, which is a wrapper around a `RpcBlock` that is either: