From 342ee4a41b272ea1f6a88f113421c3a5991a3dfe Mon Sep 17 00:00:00 2001 From: Matthias Seitz Date: Mon, 18 Dec 2023 18:03:53 +0100 Subject: [PATCH] chore: add error struct for checking builder submissions (#5820) --- crates/rpc/rpc-types/src/relay/error.rs | 40 +++++++++++++++++++ .../rpc-types/src/{relay.rs => relay/mod.rs} | 4 +- 2 files changed, 43 insertions(+), 1 deletion(-) create mode 100644 crates/rpc/rpc-types/src/relay/error.rs rename crates/rpc/rpc-types/src/{relay.rs => relay/mod.rs} (99%) diff --git a/crates/rpc/rpc-types/src/relay/error.rs b/crates/rpc/rpc-types/src/relay/error.rs new file mode 100644 index 0000000000..92c5104980 --- /dev/null +++ b/crates/rpc/rpc-types/src/relay/error.rs @@ -0,0 +1,40 @@ +//! Error types for the relay. + +use alloy_primitives::B256; + +/// Error thrown by the `validateBuilderSubmission` endpoints if the message differs from payload. +#[derive(Debug, thiserror::Error)] +pub enum ValidateBuilderSubmissionEqualityError { + /// Thrown if parent hash mismatches + #[error("incorrect ParentHash {actual}, expected {expected}")] + IncorrectParentHash { + /// The expected parent hash + expected: B256, + /// The actual parent hash + actual: B256, + }, + /// Thrown if block hash mismatches + #[error("incorrect BlockHash {actual}, expected {expected}")] + IncorrectBlockHash { + /// The expected block hash + expected: B256, + /// The actual block hash + actual: B256, + }, + /// Thrown if block hash mismatches + #[error("incorrect GasLimit {actual}, expected {expected}")] + IncorrectGasLimit { + /// The expected gas limit + expected: u64, + /// The actual gas limit + actual: B256, + }, + /// Thrown if block hash mismatches + #[error("incorrect GasUsed {actual}, expected {expected}")] + IncorrectGasUsed { + /// The expected gas used + expected: u64, + /// The actual gas used + actual: B256, + }, +} diff --git a/crates/rpc/rpc-types/src/relay.rs b/crates/rpc/rpc-types/src/relay/mod.rs similarity index 99% rename from crates/rpc/rpc-types/src/relay.rs rename to crates/rpc/rpc-types/src/relay/mod.rs index e5473134af..e4882891e8 100644 --- a/crates/rpc/rpc-types/src/relay.rs +++ b/crates/rpc/rpc-types/src/relay/mod.rs @@ -10,6 +10,8 @@ use alloy_primitives::{Address, B256, U256}; use serde::{Deserialize, Serialize}; use serde_with::{serde_as, DisplayFromStr}; +pub mod error; + /// Represents an entry of the `/relay/v1/builder/validators` endpoint #[serde_as] #[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)] @@ -324,7 +326,7 @@ mod tests { #[test] fn test_can_parse_validation_request_body() { const VALIDATION_REQUEST_BODY: &str = - include_str!("../test_data/relay/single_payload.json"); + include_str!("../../test_data/relay/single_payload.json"); let _validation_request_body: BuilderBlockValidationRequest = serde_json::from_str(VALIDATION_REQUEST_BODY).unwrap();