From 8c5c92be06bda815612c4041a15c82e92a19f79a Mon Sep 17 00:00:00 2001 From: realbigsean Date: Thu, 1 Jun 2023 08:50:03 -0400 Subject: [PATCH] fix bug in matching blocks and blobs in range sync --- beacon_node/network/src/sync/block_sidecar_coupling.rs | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/beacon_node/network/src/sync/block_sidecar_coupling.rs b/beacon_node/network/src/sync/block_sidecar_coupling.rs index 9a7250cfbd..7e5362a6f0 100644 --- a/beacon_node/network/src/sync/block_sidecar_coupling.rs +++ b/beacon_node/network/src/sync/block_sidecar_coupling.rs @@ -56,13 +56,17 @@ impl BlocksAndBlobsRequestInfo { if blob_list.is_empty() { responses.push(BlockWrapper::Block(block)) } else { - let mut blobs_fixed = Vec::with_capacity(T::max_blobs_per_block()); + let mut blobs_fixed = vec![None; T::max_blobs_per_block()]; for blob in blob_list { let blob_index = blob.index as usize; - if blob_index >= T::max_blobs_per_block() { + let Some(blob_opt) = blobs_fixed.get_mut(blob_index) else { return Err("Invalid blob index"); + }; + if blob_opt.is_some() { + return Err("Repeat blob index"); + } else { + *blob_opt = Some(blob); } - blobs_fixed.insert(blob_index, Some(blob)); } responses.push(BlockWrapper::BlockAndBlobs( block,