pass in data availability boundary to the get_blobs method
This commit is contained in:
parent
a4ea1761bb
commit
2225e6ac89
@ -963,15 +963,25 @@ impl<T: BeaconChainTypes> BeaconChain<T> {
|
|||||||
)>,
|
)>,
|
||||||
Error,
|
Error,
|
||||||
> {
|
> {
|
||||||
if let (Some(block), Some(blobs)) = (
|
// If there is no data availability boundary, the Eip4844 fork is disabled.
|
||||||
self.early_attester_cache.get_block(*block_root),
|
if let Some(finalized_data_availability_boundary) =
|
||||||
self.early_attester_cache.get_blobs(*block_root),
|
self.finalized_data_availability_boundary()
|
||||||
) {
|
{
|
||||||
return Ok(Some((block, blobs)));
|
// Only use the attester cache if we can find both the block and blob
|
||||||
}
|
if let (Some(block), Some(blobs)) = (
|
||||||
if let Some(block) = self.get_block(block_root).await?.map(Arc::new) {
|
self.early_attester_cache.get_block(*block_root),
|
||||||
let blobs = self.get_blobs(block_root)?.map(Arc::new);
|
self.early_attester_cache.get_blobs(*block_root),
|
||||||
Ok(blobs.map(|blobs| (block, blobs)))
|
) {
|
||||||
|
Ok(Some((block, blobs)))
|
||||||
|
// Attempt to get the block and blobs from the database
|
||||||
|
} else if let Some(block) = self.get_block(block_root).await?.map(Arc::new) {
|
||||||
|
let blobs = self
|
||||||
|
.get_blobs(block_root, finalized_data_availability_boundary)?
|
||||||
|
.map(Arc::new);
|
||||||
|
Ok(blobs.map(|blobs| (block, blobs)))
|
||||||
|
} else {
|
||||||
|
Ok(None)
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
Ok(None)
|
Ok(None)
|
||||||
}
|
}
|
||||||
@ -1046,7 +1056,7 @@ impl<T: BeaconChainTypes> BeaconChain<T> {
|
|||||||
|
|
||||||
/// Returns the blobs at the given root, if any.
|
/// Returns the blobs at the given root, if any.
|
||||||
///
|
///
|
||||||
/// Returns `Ok(None)` if the blobs and associated block are not found.
|
/// Returns `Ok(None)` if the blobs and associated block are not found.
|
||||||
///
|
///
|
||||||
/// If we can find the corresponding block in our database, we know whether we *should* have
|
/// If we can find the corresponding block in our database, we know whether we *should* have
|
||||||
/// blobs. If we should have blobs and no blobs are found, this will error. If we shouldn't,
|
/// blobs. If we should have blobs and no blobs are found, this will error. If we shouldn't,
|
||||||
@ -1060,6 +1070,7 @@ impl<T: BeaconChainTypes> BeaconChain<T> {
|
|||||||
pub fn get_blobs(
|
pub fn get_blobs(
|
||||||
&self,
|
&self,
|
||||||
block_root: &Hash256,
|
block_root: &Hash256,
|
||||||
|
data_availability_boundary: Epoch,
|
||||||
) -> Result<Option<BlobsSidecar<T::EthSpec>>, Error> {
|
) -> Result<Option<BlobsSidecar<T::EthSpec>>, Error> {
|
||||||
match self.store.get_blobs(block_root)? {
|
match self.store.get_blobs(block_root)? {
|
||||||
Some(blobs) => Ok(Some(blobs)),
|
Some(blobs) => Ok(Some(blobs)),
|
||||||
@ -1076,13 +1087,11 @@ impl<T: BeaconChainTypes> BeaconChain<T> {
|
|||||||
};
|
};
|
||||||
if expected_kzg_commitments.is_empty() {
|
if expected_kzg_commitments.is_empty() {
|
||||||
Ok(BlobsSidecar::empty_from_parts(*block_root, block.slot()))
|
Ok(BlobsSidecar::empty_from_parts(*block_root, block.slot()))
|
||||||
|
} else if data_availability_boundary <= block.epoch() {
|
||||||
|
// We should have blobs for all blocks younger than the boundary.
|
||||||
|
Err(Error::BlobsUnavailable)
|
||||||
} else {
|
} else {
|
||||||
if let Some(boundary) = self.data_availability_boundary() {
|
// We shouldn't have blobs for blocks older than the boundary.
|
||||||
// We should have blobs for all blocks younger than the boundary.
|
|
||||||
if boundary <= block.epoch() {
|
|
||||||
return Err(Error::BlobsUnavailable);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
Err(Error::BlobsOlderThanDataAvailabilityBoundary(block.epoch()))
|
Err(Error::BlobsOlderThanDataAvailabilityBoundary(block.epoch()))
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
@ -267,9 +267,9 @@ impl<T: BeaconChainTypes> Worker<T> {
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
Err(BeaconChainError::NoKzgCommitmentsFieldOnBlock) => {
|
Err(BeaconChainError::NoKzgCommitmentsFieldOnBlock) => {
|
||||||
error!(
|
debug!(
|
||||||
self.log,
|
self.log,
|
||||||
"No kzg_commitments field in block";
|
"Peer requested blobs for a pre-eip4844 block";
|
||||||
"peer" => %peer_id,
|
"peer" => %peer_id,
|
||||||
"block_root" => ?root,
|
"block_root" => ?root,
|
||||||
);
|
);
|
||||||
@ -283,49 +283,22 @@ impl<T: BeaconChainTypes> Worker<T> {
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
Err(BeaconChainError::BlobsOlderThanDataAvailabilityBoundary(block_epoch)) => {
|
Err(BeaconChainError::BlobsOlderThanDataAvailabilityBoundary(block_epoch)) => {
|
||||||
let finalized_data_availability_boundary = self.chain.finalized_data_availability_boundary();
|
debug!(
|
||||||
|
self.log,
|
||||||
match finalized_data_availability_boundary {
|
"Peer requested block and blobs older than the data availability \
|
||||||
Some(boundary_epoch) => {
|
boundary for ByRoot request, no blob found";
|
||||||
if block_epoch >= boundary_epoch {
|
"peer" => %peer_id,
|
||||||
error!(
|
"request_root" => ?root,
|
||||||
self.log,
|
"block_epoch" => ?block_epoch,
|
||||||
"Peer requested block and blob that should be available, but no blob found";
|
);
|
||||||
"request" => %request,
|
self.send_error_response(
|
||||||
"peer" => %peer_id,
|
peer_id,
|
||||||
"request_root" => ?root,
|
RPCResponseErrorCode::ResourceUnavailable,
|
||||||
"finalized_data_availability_boundary" => %boundary_epoch,
|
"Blobs older than data availability boundary".into(),
|
||||||
);
|
request_id,
|
||||||
self.send_error_response(
|
);
|
||||||
peer_id,
|
send_response = false;
|
||||||
RPCResponseErrorCode::ResourceUnavailable,
|
break;
|
||||||
"Blobs older than data availability boundary".into(),
|
|
||||||
request_id,
|
|
||||||
);
|
|
||||||
send_response = false;
|
|
||||||
break;
|
|
||||||
} else {
|
|
||||||
debug!(
|
|
||||||
self.log,
|
|
||||||
"Peer requested block and blob older than the data availability \
|
|
||||||
boundary for ByRoot request, no blob found";
|
|
||||||
"peer" => %peer_id,
|
|
||||||
"request_root" => ?root,
|
|
||||||
"finalized_data_availability_boundary" => ?finalized_data_availability_boundary,
|
|
||||||
);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
None => {
|
|
||||||
debug!(self.log, "Eip4844 fork is disabled");
|
|
||||||
self.send_error_response(
|
|
||||||
peer_id,
|
|
||||||
RPCResponseErrorCode::ResourceUnavailable,
|
|
||||||
"Eip4844 fork is disabled".into(),
|
|
||||||
request_id,
|
|
||||||
);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
Err(BeaconChainError::BlockHashMissingFromExecutionLayer(_)) => {
|
Err(BeaconChainError::BlockHashMissingFromExecutionLayer(_)) => {
|
||||||
debug!(
|
debug!(
|
||||||
@ -670,35 +643,13 @@ impl<T: BeaconChainTypes> Worker<T> {
|
|||||||
|
|
||||||
let start_slot = Slot::from(req.start_slot);
|
let start_slot = Slot::from(req.start_slot);
|
||||||
let start_epoch = start_slot.epoch(T::EthSpec::slots_per_epoch());
|
let start_epoch = start_slot.epoch(T::EthSpec::slots_per_epoch());
|
||||||
let data_availability_boundary = self.chain.data_availability_boundary();
|
let data_availability_boundary = match self.chain.data_availability_boundary() {
|
||||||
|
Some(boundary) => boundary,
|
||||||
let serve_blobs_from_slot = match data_availability_boundary {
|
|
||||||
Some(data_availability_boundary_epoch) => {
|
|
||||||
if Some(start_epoch) < data_availability_boundary {
|
|
||||||
let oldest_blob_slot = self
|
|
||||||
.chain
|
|
||||||
.store
|
|
||||||
.get_blob_info()
|
|
||||||
.map(|blob_info| blob_info.oldest_blob_slot);
|
|
||||||
|
|
||||||
debug!(
|
|
||||||
self.log,
|
|
||||||
"Range request start slot is older than data availability boundary";
|
|
||||||
"requested_slot" => %req.start_slot,
|
|
||||||
"oldest_known_slot" => oldest_blob_slot,
|
|
||||||
"data_availability_boundary" => data_availability_boundary
|
|
||||||
);
|
|
||||||
|
|
||||||
data_availability_boundary_epoch.start_slot(T::EthSpec::slots_per_epoch())
|
|
||||||
} else {
|
|
||||||
start_slot
|
|
||||||
}
|
|
||||||
}
|
|
||||||
None => {
|
None => {
|
||||||
debug!(self.log, "Eip4844 fork is disabled");
|
debug!(self.log, "Eip4844 fork is disabled");
|
||||||
self.send_error_response(
|
self.send_error_response(
|
||||||
peer_id,
|
peer_id,
|
||||||
RPCResponseErrorCode::ResourceUnavailable,
|
RPCResponseErrorCode::ServerError,
|
||||||
"Eip4844 fork is disabled".into(),
|
"Eip4844 fork is disabled".into(),
|
||||||
request_id,
|
request_id,
|
||||||
);
|
);
|
||||||
@ -706,6 +657,26 @@ impl<T: BeaconChainTypes> Worker<T> {
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
let serve_blobs_from_slot = if start_epoch < data_availability_boundary {
|
||||||
|
let oldest_blob_slot = self
|
||||||
|
.chain
|
||||||
|
.store
|
||||||
|
.get_blob_info()
|
||||||
|
.map(|blob_info| blob_info.oldest_blob_slot);
|
||||||
|
|
||||||
|
debug!(
|
||||||
|
self.log,
|
||||||
|
"Range request start slot is older than data availability boundary";
|
||||||
|
"requested_slot" => %req.start_slot,
|
||||||
|
"oldest_known_slot" => oldest_blob_slot,
|
||||||
|
"data_availability_boundary" => data_availability_boundary
|
||||||
|
);
|
||||||
|
|
||||||
|
data_availability_boundary.start_slot(T::EthSpec::slots_per_epoch())
|
||||||
|
} else {
|
||||||
|
start_slot
|
||||||
|
};
|
||||||
|
|
||||||
// Should not send more than max request blocks
|
// Should not send more than max request blocks
|
||||||
if req.count > MAX_REQUEST_BLOBS_SIDECARS {
|
if req.count > MAX_REQUEST_BLOBS_SIDECARS {
|
||||||
req.count = MAX_REQUEST_BLOBS_SIDECARS;
|
req.count = MAX_REQUEST_BLOBS_SIDECARS;
|
||||||
@ -785,7 +756,7 @@ impl<T: BeaconChainTypes> Worker<T> {
|
|||||||
let mut send_response = true;
|
let mut send_response = true;
|
||||||
|
|
||||||
for root in block_roots {
|
for root in block_roots {
|
||||||
match self.chain.get_blobs(&root) {
|
match self.chain.get_blobs(&root, data_availability_boundary) {
|
||||||
Ok(Some(blobs)) => {
|
Ok(Some(blobs)) => {
|
||||||
blobs_sent += 1;
|
blobs_sent += 1;
|
||||||
self.send_network_message(NetworkMessage::SendResponse {
|
self.send_network_message(NetworkMessage::SendResponse {
|
||||||
|
Loading…
Reference in New Issue
Block a user