Fix block and blob coupling in the network context (#4086)

* update docs

* introduce a temp enum to model an adjusted `BlockWrapper` and fix blob coupling

* fix compilation issue

* fix blob coupling in the network context

* review comments
This commit is contained in:
Divma
2023-03-15 11:04:45 -05:00
committed by GitHub
parent 2ef3ebbef3
commit 2c9477de43
3 changed files with 80 additions and 42 deletions

View File

@@ -18,7 +18,13 @@ use slog::{debug, trace, warn};
use std::collections::hash_map::Entry;
use std::sync::Arc;
use tokio::sync::mpsc;
use types::{BlobsSidecar, EthSpec, SignedBeaconBlock};
use types::{BlobSidecar, EthSpec, SignedBeaconBlock};
// Temporary struct to handle incremental changes in the meantime.
pub enum TempBlockWrapper<T: EthSpec> {
Block(Arc<SignedBeaconBlock<T>>),
BlockAndBlobList(Arc<SignedBeaconBlock<T>>, Vec<Arc<BlobSidecar<T>>>),
}
pub struct BlocksAndBlobsByRangeResponse<T: EthSpec> {
pub batch_id: BatchId,
@@ -71,7 +77,7 @@ pub struct SyncNetworkContext<T: BeaconChainTypes> {
/// Small enumeration to make dealing with block and blob requests easier.
pub enum BlockOrBlobs<T: EthSpec> {
Block(Option<Arc<SignedBeaconBlock<T>>>),
Blobs(Option<Arc<BlobsSidecar<T>>>),
Blobs(Option<Arc<BlobSidecar<T>>>),
}
impl<T: EthSpec> From<Option<Arc<SignedBeaconBlock<T>>>> for BlockOrBlobs<T> {
@@ -80,8 +86,8 @@ impl<T: EthSpec> From<Option<Arc<SignedBeaconBlock<T>>>> for BlockOrBlobs<T> {
}
}
impl<T: EthSpec> From<Option<Arc<BlobsSidecar<T>>>> for BlockOrBlobs<T> {
fn from(blob: Option<Arc<BlobsSidecar<T>>>) -> Self {
impl<T: EthSpec> From<Option<Arc<BlobSidecar<T>>>> for BlockOrBlobs<T> {
fn from(blob: Option<Arc<BlobSidecar<T>>>) -> Self {
BlockOrBlobs::Blobs(blob)
}
}
@@ -323,13 +329,25 @@ impl<T: BeaconChainTypes> SyncNetworkContext<T> {
block_blob_info,
} = entry.remove();
Some((
chain_id,
BlocksAndBlobsByRangeResponse {
batch_id,
responses: block_blob_info.into_responses(),
},
))
let responses = block_blob_info.into_responses();
let unimplemented_info = match responses {
Ok(responses) => {
let infos = responses
.into_iter()
.map(|temp_block_wrapper| match temp_block_wrapper {
TempBlockWrapper::Block(block) => {
format!("slot{}", block.slot())
}
TempBlockWrapper::BlockAndBlobList(block, blob_list) => {
format!("slot{}({} blobs)", block.slot(), blob_list.len())
}
})
.collect::<Vec<_>>();
infos.join(", ")
}
Err(e) => format!("Error: {e}"),
};
unimplemented!("Here we are supposed to return a block possibly paired with a Bundle of blobs, but only have a list of individual blobs. This is what we got from the network: ChainId[{chain_id}] BatchId[{batch_id}] {unimplemented_info}")
} else {
None
}
@@ -396,10 +414,26 @@ impl<T: BeaconChainTypes> SyncNetworkContext<T> {
if info.is_finished() {
// If the request is finished, dequeue everything
let (batch_id, info) = entry.remove();
Some(BlocksAndBlobsByRangeResponse {
batch_id,
responses: info.into_responses(),
})
let responses = info.into_responses();
let unimplemented_info = match responses {
Ok(responses) => {
let infos = responses
.into_iter()
.map(|temp_block_wrapper| match temp_block_wrapper {
TempBlockWrapper::Block(block) => {
format!("slot{}", block.slot())
}
TempBlockWrapper::BlockAndBlobList(block, blob_list) => {
format!("slot{}({} blobs)", block.slot(), blob_list.len())
}
})
.collect::<Vec<_>>();
infos.join(", ")
}
Err(e) => format!("Error: {e}"),
};
unimplemented!("Here we are supposed to return a block possibly paired with a Bundle of blobs for backfill, but only have a list of individual blobs. This is what we got from the network: BatchId[{batch_id}]{unimplemented_info}")
} else {
None
}