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:
Michael Sproul
2025-08-27 16:52:14 +10:00
committed by GitHub
parent ccf03e1c88
commit d235f2c697
15 changed files with 89 additions and 60 deletions

View File

@@ -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()

View File

@@ -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)
}
}

View File

@@ -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),
))
)
}
}