mirror of
https://github.com/hl-archive-node/nanoreth.git
synced 2025-12-06 19:09:54 +00:00
chore(rpc): add proper engine_newPayload error messages (#2118)
This commit is contained in:
@ -21,6 +21,8 @@ tokio-stream = "0.1"
|
||||
|
||||
# misc
|
||||
thiserror = "1.0.37"
|
||||
jsonrpsee-types = "0.16"
|
||||
jsonrpsee-core = "0.16"
|
||||
|
||||
[dev-dependencies]
|
||||
reth-interfaces = { path = "../../interfaces", features = ["test-utils"] }
|
||||
|
||||
@ -98,7 +98,7 @@ impl<Client: HeaderProvider + BlockProvider + StateProviderFactory + EvmEnvProvi
|
||||
}
|
||||
|
||||
if start == 0 || count == 0 {
|
||||
return Err(EngineApiError::InvalidParams)
|
||||
return Err(EngineApiError::InvalidBodiesRange { start, count })
|
||||
}
|
||||
|
||||
let mut result = Vec::with_capacity(count as usize);
|
||||
@ -295,7 +295,10 @@ mod tests {
|
||||
handle.send_message(EngineApiMessage::GetPayloadBodiesByRange(
|
||||
start, count, result_tx,
|
||||
));
|
||||
assert_matches!(result_rx.await, Ok(Err(EngineApiError::InvalidParams)));
|
||||
assert_matches!(
|
||||
result_rx.await,
|
||||
Ok(Err(EngineApiError::InvalidBodiesRange { .. }))
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@ -1,3 +1,4 @@
|
||||
use jsonrpsee_types::error::{INTERNAL_ERROR_CODE, INVALID_PARAMS_CODE};
|
||||
use reth_beacon_consensus::BeaconEngineError;
|
||||
use reth_primitives::{H256, U256};
|
||||
use thiserror::Error;
|
||||
@ -22,9 +23,23 @@ pub enum EngineApiError {
|
||||
/// The length that was requested.
|
||||
len: u64,
|
||||
},
|
||||
/// The params are invalid.
|
||||
#[error("Invalid params")]
|
||||
InvalidParams,
|
||||
/// Thrown if engine_getPayloadBodiesByRangeV1 contains an invalid range
|
||||
#[error("invalid start or count, start: {start} count: {count}")]
|
||||
InvalidBodiesRange {
|
||||
/// Start of the range
|
||||
start: u64,
|
||||
/// requested number of items
|
||||
count: u64,
|
||||
},
|
||||
/// Thrown if engine_forkchoiceUpdatedV1 contains withdrawals
|
||||
#[error("withdrawals not supported in V1")]
|
||||
WithdrawalsNotSupportedInV1,
|
||||
/// Thrown if engine_forkchoiceUpdated contains no withdrawals after Shanghai
|
||||
#[error("no withdrawals post-shanghai")]
|
||||
NoWithdrawalsPostShanghai,
|
||||
/// Thrown if engine_forkchoiceUpdated contains withdrawals before Shanghai
|
||||
#[error("withdrawals pre-shanghai")]
|
||||
HasWithdrawalsPreShanghai,
|
||||
/// Terminal total difficulty mismatch during transition configuration exchange.
|
||||
#[error(
|
||||
"Invalid transition terminal total difficulty. Execution: {execution}. Consensus: {consensus}"
|
||||
@ -52,3 +67,29 @@ pub enum EngineApiError {
|
||||
#[error(transparent)]
|
||||
Internal(Box<dyn std::error::Error + Send + Sync>),
|
||||
}
|
||||
|
||||
impl From<EngineApiError> for jsonrpsee_types::error::CallError {
|
||||
fn from(error: EngineApiError) -> Self {
|
||||
let code = match error {
|
||||
EngineApiError::InvalidBodiesRange { .. } |
|
||||
EngineApiError::WithdrawalsNotSupportedInV1 |
|
||||
EngineApiError::NoWithdrawalsPostShanghai |
|
||||
EngineApiError::HasWithdrawalsPreShanghai => INVALID_PARAMS_CODE,
|
||||
EngineApiError::PayloadUnknown => UNKNOWN_PAYLOAD_CODE,
|
||||
EngineApiError::PayloadRequestTooLarge { .. } => REQUEST_TOO_LARGE_CODE,
|
||||
// Any other server error
|
||||
_ => INTERNAL_ERROR_CODE,
|
||||
};
|
||||
jsonrpsee_types::error::CallError::Custom(jsonrpsee_types::error::ErrorObject::owned(
|
||||
code,
|
||||
error.to_string(),
|
||||
None::<()>,
|
||||
))
|
||||
}
|
||||
}
|
||||
|
||||
impl From<EngineApiError> for jsonrpsee_core::error::Error {
|
||||
fn from(error: EngineApiError) -> Self {
|
||||
jsonrpsee_types::error::CallError::from(error).into()
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user