fix: check for duplicate request types on validation (#14056)

This commit is contained in:
joshieDo
2025-01-29 00:08:31 +00:00
committed by GitHub
parent 01309ec03a
commit d6e055dffa

View File

@ -376,8 +376,8 @@ pub enum PayloadKind {
/// The first byte of each element is the `request_type` and the remaining bytes are the
/// `request_data`. Elements of the list **MUST** be ordered by `request_type` in ascending order.
/// Elements with empty `request_data` **MUST** be excluded from the list. If any element is out of
/// order or has a length of 1-byte or shorter, client software **MUST** return `-32602: Invalid
/// params` error.
/// order, has a length of 1-byte or shorter, or more than one element has the same type byte,
/// client software **MUST** return `-32602: Invalid params` error.
pub fn validate_execution_requests(requests: &[Bytes]) -> Result<(), EngineObjectValidationError> {
let mut last_request_type = None;
for request in requests {
@ -394,6 +394,12 @@ pub fn validate_execution_requests(requests: &[Bytes]) -> Result<(), EngineObjec
))
}
if Some(request_type) == last_request_type {
return Err(EngineObjectValidationError::InvalidParams(
"DuplicatedExecutionRequestType".to_string().into(),
))
}
last_request_type = Some(request_type);
}
Ok(())
@ -449,5 +455,16 @@ mod tests {
validate_execution_requests(&requests_out_of_order),
Err(EngineObjectValidationError::InvalidParams(_))
);
let duplicate_request_types = [
Bytes::from_iter([1, 2]),
Bytes::from_iter([3, 3]),
Bytes::from_iter([4, 5]),
Bytes::from_iter([4, 4]),
];
assert_matches!(
validate_execution_requests(&duplicate_request_types),
Err(EngineObjectValidationError::InvalidParams(_))
);
}
}