Skip to content

Commit

Permalink
Address comments
Browse files Browse the repository at this point in the history
  • Loading branch information
rahulksnv committed Oct 7, 2023
1 parent 578a99d commit 9b2137a
Showing 1 changed file with 10 additions and 12 deletions.
22 changes: 10 additions & 12 deletions substrate/client/network/sync/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1405,22 +1405,20 @@ where

/// Get the set of downloaded blocks that are ready to be queued for import.
fn ready_blocks(&mut self) -> Vec<IncomingBlock<B>> {
let target_block = self.best_queued_number + One::one();
let start_block = self.best_queued_number + One::one();

// Verify that the parent of the first available block is in the chain.
// If not, we are downloading from a fork. In this case, wait until
// the start block has a parent on chain.
let parent_on_chain =
self.blocks.first_ready_block_hdr(target_block).map_or(false, |hdr| {
let parent_status =
self.block_status(hdr.parent_hash()).unwrap_or(BlockStatus::Unknown);
parent_status == BlockStatus::InChainWithState ||
parent_status == BlockStatus::Queued
});
let parent_on_chain = self.blocks.first_ready_block_hdr(start_block).map_or(false, |hdr| {
let parent_status =
self.block_status(hdr.parent_hash()).unwrap_or(BlockStatus::Unknown);
parent_status == BlockStatus::InChainWithState || parent_status == BlockStatus::Queued
});

if parent_on_chain {
self.blocks
.ready_blocks(target_block)
.ready_blocks(start_block)
.into_iter()
.map(|block_data| {
let justifications = block_data
Expand Down Expand Up @@ -3425,7 +3423,7 @@ mod test {
client.clone(),
ProtocolName::from("test-block-announce-protocol"),
1,
64,
max_blocks_per_request,
None,
chain_sync_network_handle,
)
Expand Down Expand Up @@ -3613,7 +3611,7 @@ mod test {
client.clone(),
ProtocolName::from("test-block-announce-protocol"),
1,
64,
max_blocks_per_request,
None,
chain_sync_network_handle,
)
Expand Down Expand Up @@ -3647,7 +3645,7 @@ mod test {
}

// The response for the 64 blocks is returned in two parts:
// part 1: last 61 blocks [18..79], part 2: first 3 blocks [16-17].
// part 1: last 62 blocks [18..79], part 2: first 2 blocks [16-17].
// Even though the first part extends the current chain ending at 18,
// it should not result in an import yet.
let resp_1_from = common_ancestor as u64 + max_blocks_per_request as u64;
Expand Down

0 comments on commit 9b2137a

Please sign in to comment.