fix: return engine_getPayload error response (#2175)

This commit is contained in:
Dan Cline
2023-04-10 12:14:01 -04:00
committed by GitHub
parent d0da2a3e92
commit bbdeda3246
2 changed files with 18 additions and 16 deletions

View File

@ -1,28 +1,23 @@
use reth_miner::error::PayloadBuilderError;
use reth_rpc_types::engine::PayloadError;
use reth_rpc_types::engine::{EngineRpcError, PayloadError};
use reth_stages::PipelineError;
use thiserror::Error;
/// Beacon engine result.
pub type BeaconEngineResult<Ok> = Result<Ok, BeaconEngineError>;
// TODO: add conversions to codes for engine spec compliance
// one notable variant would be UnknownPayload
/// The error wrapper for the beacon consensus engine.
#[derive(Error, Debug)]
pub enum BeaconEngineError {
/// Forkchoice zero hash head received.
#[error("Received zero hash as forkchoice head")]
ForkchoiceEmptyHead,
/// Invalid payload attributes.
#[error("Invalid payload attributes")]
InvalidPayloadAttributes,
/// Pipeline channel closed.
#[error("Pipeline channel closed")]
PipelineChannelClosed,
/// Unknown payload
#[error("Unknown payload")]
UnknownPayload,
/// An error covered by the engine API standard error codes.
#[error(transparent)]
EngineApi(#[from] EngineRpcError),
/// Encountered a payload error.
#[error(transparent)]
Payload(#[from] PayloadError),

View File

@ -10,8 +10,8 @@ use reth_interfaces::{
use reth_miner::PayloadStore;
use reth_primitives::{BlockHash, BlockNumber, Header, SealedBlock, H256};
use reth_rpc_types::engine::{
ExecutionPayload, ExecutionPayloadEnvelope, ForkchoiceUpdated, PayloadAttributes, PayloadId,
PayloadStatus, PayloadStatusEnum,
EngineRpcError, ExecutionPayload, ExecutionPayloadEnvelope, ForkchoiceUpdated,
PayloadAttributes, PayloadId, PayloadStatus, PayloadStatusEnum,
};
use reth_stages::{stages::FINISH, Pipeline};
use reth_tasks::TaskSpawner;
@ -225,7 +225,7 @@ where
if attrs.timestamp <= header.timestamp.into() {
return Ok(ForkchoiceUpdated::new(PayloadStatus::from_status(
PayloadStatusEnum::Invalid {
validation_error: BeaconEngineError::InvalidPayloadAttributes.to_string(),
validation_error: EngineRpcError::InvalidPayloadAttributes.to_string(),
},
)))
}
@ -268,7 +268,7 @@ where
// for now just return the output from the payload store
match self.payload_store.get_execution_payload(payload_id) {
Some(payload) => Ok(payload),
None => Err(BeaconEngineError::UnknownPayload),
None => Err(EngineRpcError::UnknownPayload.into()),
}
}
@ -457,14 +457,21 @@ where
let _ = tx.send(Ok(response));
}
BeaconEngineMessage::GetPayload { payload_id, tx } => {
let response = match this.on_get_payload(payload_id) {
Ok(response) => response,
match this.on_get_payload(payload_id) {
Ok(response) => {
// good response, send it back
let _ = tx.send(Ok(response));
}
Err(BeaconEngineError::EngineApi(error)) => {
// specific error that we should report back to the client
error!(target: "consensus::engine", ?error, "Sending engine api error response");
let _ = tx.send(Err(BeaconEngineError::EngineApi(error)));
}
Err(error) => {
error!(target: "consensus::engine", ?error, "Error getting get payload response");
return Poll::Ready(Err(error))
}
};
let _ = tx.send(Ok(response));
}
}
}