Skip to content

Commit

Permalink
Address comments
Browse files Browse the repository at this point in the history
  • Loading branch information
rahulksnv committed Aug 29, 2023
1 parent 72cf71d commit f367c03
Showing 1 changed file with 33 additions and 34 deletions.
67 changes: 33 additions & 34 deletions crates/sc-subspace-block-relay/src/consensus.rs
Original file line number Diff line number Diff line change
Expand Up @@ -161,7 +161,7 @@ where
&self,
who: PeerId,
request: BlockRequest<Block>,
) -> Result<Vec<u8>, RelayError> {
) -> Result<Vec<BlockData<Block>>, RelayError> {
let start_ts = Instant::now();
let network_peer_handle = self
.network
Expand Down Expand Up @@ -197,18 +197,47 @@ where
};

// Assemble the final response
let downloaded = vec![initial_response.partial_block.block_data(body)].encode();
let downloaded = vec![initial_response.partial_block.block_data(body)];
tracing::debug!(
target: LOG_TARGET,
block_hash = ?initial_response.block_hash,
download_len = %downloaded.len(),
download_bytes = %downloaded.encoded_size(),
%local_miss,
duration = ?start_ts.elapsed(),
"block_download",
);
Ok(downloaded)
}

/// Downloads the requested blocks from the peer, without using the relay protocol.
async fn full_download(
&self,
who: PeerId,
request: BlockRequest<Block>,
) -> Result<Vec<BlockData<Block>>, RelayError> {
let start_ts = Instant::now();
let network_peer_handle = self
.network
.network_peer_handle(self.protocol_name.clone(), who)?;

let server_request: ServerRequest<Block, ProtoClient::Request> =
ServerRequest::FullDownload(FullDownloadRequest(request.clone()));
let full_response = network_peer_handle
.request::<_, FullDownloadResponse<Block>>(server_request)
.await?;
let downloaded = full_response.0;

tracing::debug!(
target: LOG_TARGET,
?request,
download_blocks = %downloaded.len(),
download_bytes = %downloaded.encoded_size(),
duration = ?start_ts.elapsed(),
"full_download",
);
Ok(downloaded)
}

/// Resolves the extrinsics from the initial response
async fn resolve_extrinsics<Request>(
&self,
Expand Down Expand Up @@ -242,36 +271,6 @@ where
.collect();
Ok((extrinsics, local_miss))
}

/// Downloads the requested blocks from the peer, without using the relay protocol.
async fn full_download(
&self,
who: PeerId,
request: BlockRequest<Block>,
) -> Result<Vec<u8>, RelayError> {
let start_ts = Instant::now();
let network_peer_handle = self
.network
.network_peer_handle(self.protocol_name.clone(), who)?;

let server_request: ServerRequest<Block, ProtoClient::Request> =
ServerRequest::FullDownload(FullDownloadRequest(request.clone()));
let full_response = network_peer_handle
.request::<_, FullDownloadResponse<Block>>(server_request)
.await?;
let downloaded_blocks = full_response.0.len();
let downloaded = full_response.0.encode();

tracing::debug!(
target: LOG_TARGET,
?request,
%downloaded_blocks,
download_len = %downloaded.len(),
duration = ?start_ts.elapsed(),
"full_download",
);
Ok(downloaded)
}
}

#[async_trait]
Expand All @@ -294,7 +293,7 @@ where
self.download(who, request.clone()).await
};
match ret {
Ok(downloaded) => Ok(Ok(downloaded)),
Ok(blocks) => Ok(Ok(blocks.encode())),
Err(error) => {
tracing::debug!(
target: LOG_TARGET,
Expand Down

0 comments on commit f367c03

Please sign in to comment.