use alloy_primitives::{Bytes, B256, U256};
#[derive(Debug, derive_more::Display)]
pub enum PayloadError {
#[display("invalid payload extra data: {_0}")]
ExtraData(Bytes),
#[display("invalid payload base fee: {_0}")]
BaseFee(U256),
#[display("invalid payload blob gas used: {_0}")]
BlobGasUsed(U256),
#[display("invalid payload excess blob gas: {_0}")]
ExcessBlobGas(U256),
#[display("withdrawals present in pre-shanghai payload")]
PreShanghaiBlockWithWithdrawals,
#[display("withdrawals missing in post-shanghai payload")]
PostShanghaiBlockWithoutWithdrawals,
#[display("parent beacon block root present in pre-cancun payload")]
PreCancunBlockWithParentBeaconBlockRoot,
#[display("blob transactions present in pre-cancun payload")]
PreCancunBlockWithBlobTransactions,
#[display("blob gas used present in pre-cancun payload")]
PreCancunBlockWithBlobGasUsed,
#[display("excess blob gas present in pre-cancun payload")]
PreCancunBlockWithExcessBlobGas,
#[display("cancun fields present in pre-cancun payload")]
PreCancunWithCancunFields,
#[display("parent beacon block root missing in post-cancun payload")]
PostCancunBlockWithoutParentBeaconBlockRoot,
#[display("blob gas used missing in post-cancun payload")]
PostCancunBlockWithoutBlobGasUsed,
#[display("excess blob gas missing in post-cancun payload")]
PostCancunBlockWithoutExcessBlobGas,
#[display("cancun fields missing in post-cancun payload")]
PostCancunWithoutCancunFields,
#[display("eip 7702 transactions present in pre-prague payload")]
PrePragueBlockWithEip7702Transactions,
#[display("requests present in pre-prague payload")]
PrePragueBlockRequests,
#[display("block hash mismatch: want {execution}, got {consensus}")]
BlockHash {
execution: B256,
consensus: B256,
},
#[display("expected blob versioned hashes do not match the given transactions")]
InvalidVersionedHashes,
#[display("{_0}")]
Decode(alloy_rlp::Error),
}
impl core::error::Error for PayloadError {}
impl From<alloy_rlp::Error> for PayloadError {
fn from(value: alloy_rlp::Error) -> Self {
Self::Decode(value)
}
}
impl PayloadError {
#[inline]
pub const fn is_block_hash_mismatch(&self) -> bool {
matches!(self, Self::BlockHash { .. })
}
#[inline]
pub const fn is_invalid_versioned_hashes(&self) -> bool {
matches!(self, Self::InvalidVersionedHashes)
}
}
#[derive(Clone, Copy, Debug, PartialEq, Eq, derive_more::Display)]
pub enum PayloadValidationError {
#[display("links to previously rejected block")]
LinksToRejectedPayload,
#[display("invalid block number")]
InvalidBlockNumber,
#[display("invalid merkle root: (remote: {remote:?} local: {local:?})")]
InvalidStateRoot {
remote: B256,
local: B256,
},
}
impl core::error::Error for PayloadValidationError {}