Skip to main content

reth_rpc_api/
testing.rs

1//! Testing namespace for building a block in a single call.
2//!
3//! This follows the `testing_buildBlockV1` specification. **Highly sensitive:**
4//! testing-only, powerful enough to include arbitrary transactions; must stay
5//! disabled by default and never be exposed on public-facing RPC without an
6//! explicit operator flag.
7
8use alloy_primitives::{Bytes, B256};
9use alloy_rpc_types_engine::{
10    ExecutionPayloadEnvelopeV5, ExecutionPayloadEnvelopeV6, PayloadAttributes,
11};
12use jsonrpsee::proc_macros::rpc;
13use serde::{Deserialize, Serialize};
14
15pub use alloy_rpc_types_engine::{TestingBuildBlockRequestV1, TESTING_BUILD_BLOCK_V1};
16
17/// Capability string for `testing_commitBlockV1`.
18pub const TESTING_COMMIT_BLOCK_V1: &str = "testing_commitBlockV1";
19
20/// Response of `testing_buildBlockV1`.
21///
22/// Blocks after Amsterdam carry the block access list and the slot number in the payload.
23#[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize)]
24#[serde(untagged)]
25pub enum TestingBuildBlockResponseV1 {
26    // Try V6 first: V5 accepts unknown fields and would discard the Amsterdam payload fields.
27    /// Payload envelope of a block after Amsterdam.
28    V6(ExecutionPayloadEnvelopeV6),
29    /// Payload envelope of a block before Amsterdam.
30    V5(ExecutionPayloadEnvelopeV5),
31}
32
33/// Testing RPC interface for building a block in a single call.
34///
35/// # Enabling
36///
37/// This namespace is disabled by default for security reasons. To enable it,
38/// add `testing` to the `--http.api` flag:
39///
40/// ```sh
41/// reth node --http --http.api eth,testing
42/// ```
43///
44/// **Warning:** Never expose this on public-facing RPC endpoints without proper
45/// authentication.
46#[rpc(server, namespace = "testing")]
47pub trait TestingApi {
48    /// Builds a block using the provided parent, payload attributes, and transactions.
49    ///
50    /// See <https://github.com/marcindsobczak/execution-apis/blob/main/src/testing/testing_buildBlockV1.md>
51    #[method(name = "buildBlockV1")]
52    async fn build_block_v1(
53        &self,
54        parent_block_hash: B256,
55        payload_attributes: PayloadAttributes,
56        transactions: Option<Vec<Bytes>>,
57        extra_data: Option<Bytes>,
58    ) -> jsonrpsee::core::RpcResult<TestingBuildBlockResponseV1>;
59
60    /// Builds a block on top of the current canonical head, inserts it, and makes it canonical.
61    ///
62    /// See <https://github.com/ethereum/execution-apis/pull/801>
63    #[method(name = "commitBlockV1")]
64    async fn commit_block_v1(
65        &self,
66        payload_attributes: PayloadAttributes,
67        transactions: Option<Vec<Bytes>>,
68        extra_data: Option<Bytes>,
69    ) -> jsonrpsee::core::RpcResult<B256>;
70}