mirror of
https://github.com/sigp/lighthouse.git
synced 2026-03-03 00:31:50 +00:00
Delete RuntimeVariableList::from_vec (#7930)
This method is a footgun because it truncates the list. It is the source of a recent bug: - https://github.com/sigp/lighthouse/pull/7927 - Delete uses of `RuntimeVariableList::from_vec` and replace them with `::new` which does validation and can fail. - Propagate errors where possible, unwrap in tests and use `expect` for obviously-safe uses (in `chain_spec.rs`).
This commit is contained in:
@@ -865,10 +865,15 @@ impl<T: BeaconChainTypes> SyncNetworkContext<T> {
|
||||
// - RPCError(request_id): handled by `Self::on_single_block_response`
|
||||
// - Disconnect(peer_id) handled by `Self::peer_disconnected``which converts it to a
|
||||
// ` RPCError(request_id)`event handled by the above method
|
||||
let network_request = RequestType::BlocksByRoot(
|
||||
request
|
||||
.into_request(&self.fork_context)
|
||||
.map_err(RpcRequestSendError::InternalError)?,
|
||||
);
|
||||
self.network_send
|
||||
.send(NetworkMessage::SendRequest {
|
||||
peer_id,
|
||||
request: RequestType::BlocksByRoot(request.into_request(&self.fork_context)),
|
||||
request: network_request,
|
||||
app_request_id: AppRequestId::Sync(SyncRequestId::SingleBlock { id }),
|
||||
})
|
||||
.map_err(|_| RpcRequestSendError::InternalError("network send error".to_owned()))?;
|
||||
@@ -959,10 +964,16 @@ impl<T: BeaconChainTypes> SyncNetworkContext<T> {
|
||||
};
|
||||
|
||||
// Lookup sync event safety: Refer to `Self::block_lookup_request` `network_send.send` call
|
||||
let network_request = RequestType::BlobsByRoot(
|
||||
request
|
||||
.clone()
|
||||
.into_request(&self.fork_context)
|
||||
.map_err(RpcRequestSendError::InternalError)?,
|
||||
);
|
||||
self.network_send
|
||||
.send(NetworkMessage::SendRequest {
|
||||
peer_id,
|
||||
request: RequestType::BlobsByRoot(request.clone().into_request(&self.fork_context)),
|
||||
request: network_request,
|
||||
app_request_id: AppRequestId::Sync(SyncRequestId::SingleBlob { id }),
|
||||
})
|
||||
.map_err(|_| RpcRequestSendError::InternalError("network send error".to_owned()))?;
|
||||
|
||||
@@ -11,7 +11,7 @@ pub struct BlobsByRootSingleBlockRequest {
|
||||
}
|
||||
|
||||
impl BlobsByRootSingleBlockRequest {
|
||||
pub fn into_request(self, spec: &ForkContext) -> BlobsByRootRequest {
|
||||
pub fn into_request(self, spec: &ForkContext) -> Result<BlobsByRootRequest, String> {
|
||||
BlobsByRootRequest::new(
|
||||
self.indices
|
||||
.into_iter()
|
||||
|
||||
@@ -9,7 +9,8 @@ use super::{ActiveRequestItems, LookupVerifyError};
|
||||
pub struct BlocksByRootSingleRequest(pub Hash256);
|
||||
|
||||
impl BlocksByRootSingleRequest {
|
||||
pub fn into_request(self, fork_context: &ForkContext) -> BlocksByRootRequest {
|
||||
pub fn into_request(self, fork_context: &ForkContext) -> Result<BlocksByRootRequest, String> {
|
||||
// This should always succeed (single block root), but we return a `Result` for safety.
|
||||
BlocksByRootRequest::new(vec![self.0], fork_context)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -21,13 +21,13 @@ impl DataColumnsByRootSingleBlockRequest {
|
||||
) -> Result<DataColumnsByRootRequest<E>, &'static str> {
|
||||
let columns = VariableList::new(self.indices)
|
||||
.map_err(|_| "Number of indices exceeds total number of columns")?;
|
||||
Ok(DataColumnsByRootRequest::new(
|
||||
DataColumnsByRootRequest::new(
|
||||
vec![DataColumnsByRootIdentifier {
|
||||
block_root: self.block_root,
|
||||
columns,
|
||||
}],
|
||||
spec.max_request_blocks(fork_name),
|
||||
))
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -2303,7 +2303,7 @@ mod deneb_only {
|
||||
block,
|
||||
self.unknown_parent_blobs
|
||||
.take()
|
||||
.map(|vec| RuntimeVariableList::from_vec(vec, max_len)),
|
||||
.map(|vec| RuntimeVariableList::new(vec, max_len).unwrap()),
|
||||
)
|
||||
.unwrap();
|
||||
self.rig.parent_block_processed(
|
||||
|
||||
Reference in New Issue
Block a user