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#[cfg_attr(not(feature = "client"), rpc(server, namespace = "testing"))]
47#[cfg_attr(feature = "client", rpc(server, client, namespace = "testing"))]
48pub trait TestingApi {
49    /// Builds a block using the provided parent, payload attributes, and transactions.
50    ///
51    /// See <https://github.com/marcindsobczak/execution-apis/blob/main/src/testing/testing_buildBlockV1.md>
52    #[method(name = "buildBlockV1")]
53    async fn build_block_v1(
54        &self,
55        parent_block_hash: B256,
56        payload_attributes: PayloadAttributes,
57        transactions: Option<Vec<Bytes>>,
58        extra_data: Option<Bytes>,
59    ) -> jsonrpsee::core::RpcResult<TestingBuildBlockResponseV1>;
60
61    /// Builds a block on top of the current canonical head, inserts it, and makes it canonical.
62    ///
63    /// See <https://github.com/ethereum/execution-apis/pull/801>
64    #[method(name = "commitBlockV1")]
65    async fn commit_block_v1(
66        &self,
67        payload_attributes: PayloadAttributes,
68        transactions: Option<Vec<Bytes>>,
69        extra_data: Option<Bytes>,
70    ) -> jsonrpsee::core::RpcResult<B256>;
71}