mirror of
https://github.com/sigp/lighthouse.git
synced 2026-05-31 05:07:12 +00:00
Breakup RPCBlock into LookupBlock & RangeSyncBlock (#8860)
Co-Authored-By: Mark Mackey <mark@sigmaprime.io>
This commit is contained in:
@@ -1,6 +1,6 @@
|
||||
use beacon_chain::{
|
||||
BeaconChainTypes,
|
||||
block_verification_types::{AvailableBlockData, RpcBlock},
|
||||
block_verification_types::{AvailableBlockData, RangeSyncBlock},
|
||||
data_availability_checker::DataAvailabilityChecker,
|
||||
data_column_verification::CustodyDataColumn,
|
||||
get_block_root,
|
||||
@@ -200,7 +200,7 @@ impl<E: EthSpec> RangeBlockComponentsRequest<E> {
|
||||
&mut self,
|
||||
da_checker: Arc<DataAvailabilityChecker<T>>,
|
||||
spec: Arc<ChainSpec>,
|
||||
) -> Option<Result<Vec<RpcBlock<E>>, CouplingError>>
|
||||
) -> Option<Result<Vec<RangeSyncBlock<E>>, CouplingError>>
|
||||
where
|
||||
T: BeaconChainTypes<EthSpec = E>,
|
||||
{
|
||||
@@ -288,7 +288,7 @@ impl<E: EthSpec> RangeBlockComponentsRequest<E> {
|
||||
blobs: Vec<Arc<BlobSidecar<E>>>,
|
||||
da_checker: Arc<DataAvailabilityChecker<T>>,
|
||||
spec: Arc<ChainSpec>,
|
||||
) -> Result<Vec<RpcBlock<E>>, CouplingError>
|
||||
) -> Result<Vec<RangeSyncBlock<E>>, CouplingError>
|
||||
where
|
||||
T: BeaconChainTypes<EthSpec = E>,
|
||||
{
|
||||
@@ -335,7 +335,7 @@ impl<E: EthSpec> RangeBlockComponentsRequest<E> {
|
||||
})?;
|
||||
let block_data = AvailableBlockData::new_with_blobs(blobs);
|
||||
responses.push(
|
||||
RpcBlock::new(block, Some(block_data), &da_checker, spec.clone())
|
||||
RangeSyncBlock::new(block, block_data, &da_checker, spec.clone())
|
||||
.map_err(|e| CouplingError::BlobPeerFailure(format!("{e:?}")))?,
|
||||
)
|
||||
}
|
||||
@@ -360,7 +360,7 @@ impl<E: EthSpec> RangeBlockComponentsRequest<E> {
|
||||
attempt: usize,
|
||||
da_checker: Arc<DataAvailabilityChecker<T>>,
|
||||
spec: Arc<ChainSpec>,
|
||||
) -> Result<Vec<RpcBlock<E>>, CouplingError>
|
||||
) -> Result<Vec<RangeSyncBlock<E>>, CouplingError>
|
||||
where
|
||||
T: BeaconChainTypes<EthSpec = E>,
|
||||
{
|
||||
@@ -388,12 +388,12 @@ impl<E: EthSpec> RangeBlockComponentsRequest<E> {
|
||||
|
||||
// Now iterate all blocks ensuring that the block roots of each block and data column match,
|
||||
// plus we have columns for our custody requirements
|
||||
let mut rpc_blocks = Vec::with_capacity(blocks.len());
|
||||
let mut range_sync_blocks = Vec::with_capacity(blocks.len());
|
||||
|
||||
let exceeded_retries = attempt >= MAX_COLUMN_RETRIES;
|
||||
for block in blocks {
|
||||
let block_root = get_block_root(&block);
|
||||
rpc_blocks.push(if block.num_expected_blobs() > 0 {
|
||||
range_sync_blocks.push(if block.num_expected_blobs() > 0 {
|
||||
let Some(mut data_columns_by_index) = data_columns_by_block.remove(&block_root)
|
||||
else {
|
||||
let responsible_peers = column_to_peer.iter().map(|c| (*c.0, *c.1)).collect();
|
||||
@@ -441,11 +441,11 @@ impl<E: EthSpec> RangeBlockComponentsRequest<E> {
|
||||
|
||||
let block_data = AvailableBlockData::new_with_data_columns(custody_columns.iter().map(|c| c.as_data_column().clone()).collect::<Vec<_>>());
|
||||
|
||||
RpcBlock::new(block, Some(block_data), &da_checker, spec.clone())
|
||||
RangeSyncBlock::new(block, block_data, &da_checker, spec.clone())
|
||||
.map_err(|e| CouplingError::InternalError(format!("{:?}", e)))?
|
||||
} else {
|
||||
// Block has no data, expects zero columns
|
||||
RpcBlock::new(block, Some(AvailableBlockData::NoData), &da_checker, spec.clone())
|
||||
RangeSyncBlock::new(block, AvailableBlockData::NoData, &da_checker, spec.clone())
|
||||
.map_err(|e| CouplingError::InternalError(format!("{:?}", e)))?
|
||||
});
|
||||
}
|
||||
@@ -458,7 +458,7 @@ impl<E: EthSpec> RangeBlockComponentsRequest<E> {
|
||||
debug!(?remaining_roots, "Not all columns consumed for block");
|
||||
}
|
||||
|
||||
Ok(rpc_blocks)
|
||||
Ok(range_sync_blocks)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -947,7 +947,7 @@ mod tests {
|
||||
}
|
||||
|
||||
let result: Result<
|
||||
Vec<beacon_chain::block_verification_types::RpcBlock<E>>,
|
||||
Vec<beacon_chain::block_verification_types::RangeSyncBlock<E>>,
|
||||
crate::sync::block_sidecar_coupling::CouplingError,
|
||||
> = info.responses(da_checker.clone(), spec.clone()).unwrap();
|
||||
assert!(result.is_err());
|
||||
@@ -981,10 +981,10 @@ mod tests {
|
||||
// WHEN: Attempting to get responses again
|
||||
let result = info.responses(da_checker, spec).unwrap();
|
||||
|
||||
// THEN: Should succeed with complete RPC blocks
|
||||
// THEN: Should succeed with complete RangeSync blocks
|
||||
assert!(result.is_ok());
|
||||
let rpc_blocks = result.unwrap();
|
||||
assert_eq!(rpc_blocks.len(), 2);
|
||||
let range_sync_blocks = result.unwrap();
|
||||
assert_eq!(range_sync_blocks.len(), 2);
|
||||
}
|
||||
|
||||
#[test]
|
||||
|
||||
Reference in New Issue
Block a user