Skip to content

Commit f8afedd

Browse files
authored
fix(l1): return invalid payload for invalid transactions in new payload endpoint (#2561)
**Motivation** This fixes the failing consume-engine hive tests on Prague and Cancun <!-- Why does this pull request exist? What are its goals? --> **Description** * Return `INVALID` payload status when we fail to decode transactions as per spec ([Step 6 item 1](https://github.com/ethereum/execution-apis/blob/main/src/engine/paris.md#engine_newpayloadv1)) <!-- A clear and concise general description of the changes this PR introduces --> <!-- Link to issues: Resolves #111, Resolves #222 --> Closes #issue_number
1 parent 521a9b6 commit f8afedd

File tree

1 file changed

+39
-9
lines changed

1 file changed

+39
-9
lines changed

crates/networking/rpc/engine/payload.rs

+39-9
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ use ethrex_common::types::requests::{compute_requests_hash, EncodedRequests};
55
use ethrex_common::types::{Block, BlockBody, BlockHash, BlockNumber, Fork};
66
use ethrex_common::{H256, U256};
77
use ethrex_p2p::sync::SyncMode;
8+
use ethrex_rlp::error::RLPDecodeError;
89
use serde_json::Value;
910
use tracing::{error, info, warn};
1011

@@ -34,7 +35,14 @@ impl RpcHandler for NewPayloadV1Request {
3435

3536
async fn handle(&self, context: RpcApiContext) -> Result<Value, RpcErr> {
3637
validate_execution_payload_v1(&self.payload)?;
37-
let block = get_block_from_payload(&self.payload, None, None)?;
38+
let block = match get_block_from_payload(&self.payload, None, None) {
39+
Ok(block) => block,
40+
Err(err) => {
41+
return Ok(serde_json::to_value(PayloadStatus::invalid_with_err(
42+
&err.to_string(),
43+
))?)
44+
}
45+
};
3846
let payload_status = handle_new_payload_v1_v2(&self.payload, block, context).await?;
3947
serde_json::to_value(payload_status).map_err(|error| RpcErr::Internal(error.to_string()))
4048
}
@@ -59,8 +67,14 @@ impl RpcHandler for NewPayloadV2Request {
5967
// Behave as a v1
6068
validate_execution_payload_v1(&self.payload)?;
6169
}
62-
63-
let block = get_block_from_payload(&self.payload, None, None)?;
70+
let block = match get_block_from_payload(&self.payload, None, None) {
71+
Ok(block) => block,
72+
Err(err) => {
73+
return Ok(serde_json::to_value(PayloadStatus::invalid_with_err(
74+
&err.to_string(),
75+
))?)
76+
}
77+
};
6478
let payload_status = handle_new_payload_v1_v2(&self.payload, block, context).await?;
6579
serde_json::to_value(payload_status).map_err(|error| RpcErr::Internal(error.to_string()))
6680
}
@@ -105,8 +119,18 @@ impl RpcHandler for NewPayloadV3Request {
105119
}
106120

107121
async fn handle(&self, context: RpcApiContext) -> Result<Value, RpcErr> {
108-
let block =
109-
get_block_from_payload(&self.payload, Some(self.parent_beacon_block_root), None)?;
122+
let block = match get_block_from_payload(
123+
&self.payload,
124+
Some(self.parent_beacon_block_root),
125+
None,
126+
) {
127+
Ok(block) => block,
128+
Err(err) => {
129+
return Ok(serde_json::to_value(PayloadStatus::invalid_with_err(
130+
&err.to_string(),
131+
))?)
132+
}
133+
};
110134
validate_fork(&block, Fork::Cancun, &context)?;
111135
validate_execution_payload_v3(&self.payload)?;
112136
let payload_status = handle_new_payload_v3(
@@ -205,11 +229,18 @@ impl RpcHandler for NewPayloadV4Request {
205229
validate_execution_requests(&self.execution_requests)?;
206230

207231
let requests_hash = compute_requests_hash(&self.execution_requests);
208-
let block = get_block_from_payload(
232+
let block = match get_block_from_payload(
209233
&self.payload,
210234
Some(self.parent_beacon_block_root),
211235
Some(requests_hash),
212-
)?;
236+
) {
237+
Ok(block) => block,
238+
Err(err) => {
239+
return Ok(serde_json::to_value(PayloadStatus::invalid_with_err(
240+
&err.to_string(),
241+
))?)
242+
}
243+
};
213244

214245
let chain_config = context.storage.get_chain_config()?;
215246

@@ -645,14 +676,13 @@ fn get_block_from_payload(
645676
payload: &ExecutionPayload,
646677
parent_beacon_block_root: Option<H256>,
647678
requests_hash: Option<H256>,
648-
) -> Result<Block, RpcErr> {
679+
) -> Result<Block, RLPDecodeError> {
649680
let block_hash = payload.block_hash;
650681
info!("Received new payload with block hash: {block_hash:#x}");
651682

652683
payload
653684
.clone()
654685
.into_block(parent_beacon_block_root, requests_hash)
655-
.map_err(|error| RpcErr::Internal(error.to_string()))
656686
}
657687

658688
fn validate_block_hash(payload: &ExecutionPayload, block: &Block) -> Result<(), RpcErr> {

0 commit comments

Comments
 (0)