Skip to main content

reth_rpc_api/
reth.rs

1use alloy_eips::BlockId;
2use alloy_primitives::{map::AddressMap, U256, U64};
3use jsonrpsee::{core::RpcResult, proc_macros::rpc};
4use serde::{Deserialize, Serialize};
5
6// Required for the subscription attributes below
7use reth_chain_state as _;
8
9/// Reth API namespace for reth-specific methods
10#[cfg_attr(not(feature = "client"), rpc(server, namespace = "reth"))]
11#[cfg_attr(feature = "client", rpc(server, client, namespace = "reth"))]
12pub trait RethApi {
13    /// Returns all ETH balance changes in a block
14    #[method(name = "getBalanceChangesInBlock")]
15    async fn reth_get_balance_changes_in_block(
16        &self,
17        block_id: BlockId,
18    ) -> RpcResult<AddressMap<U256>>;
19
20    /// Re-executes a block (or a range of blocks) and returns the execution outcome including
21    /// receipts, state changes, and EIP-7685 requests.
22    ///
23    /// If `count` is provided, re-executes `count` consecutive blocks starting from `block_id`
24    /// and returns the merged execution outcome.
25    #[method(name = "getBlockExecutionOutcome")]
26    async fn reth_get_block_execution_outcome(
27        &self,
28        block_id: BlockId,
29        count: Option<U64>,
30    ) -> RpcResult<Option<serde_json::Value>>;
31
32    /// Controls the revmc JIT backend.
33    #[method(name = "jit")]
34    async fn reth_jit(&self, action: RethJitAction) -> RpcResult<()>;
35
36    /// Subscribe to json `ChainNotifications`
37    #[subscription(
38        name = "subscribeChainNotifications",
39        unsubscribe = "unsubscribeChainNotifications",
40        item = reth_chain_state::CanonStateNotification
41    )]
42    async fn reth_subscribe_chain_notifications(&self) -> jsonrpsee::core::SubscriptionResult;
43
44    /// Subscribe to persisted block notifications.
45    ///
46    /// Emits a notification with the block number and hash when a new block is persisted to disk.
47    #[subscription(
48        name = "subscribePersistedBlock",
49        unsubscribe = "unsubscribePersistedBlock",
50        item = alloy_eips::BlockNumHash
51    )]
52    async fn reth_subscribe_persisted_block(&self) -> jsonrpsee::core::SubscriptionResult;
53
54    /// Subscribe to finalized chain notifications.
55    ///
56    /// Buffers committed chain notifications and emits them once a new finalized block is received.
57    /// Each notification contains all committed chain segments up to the finalized block.
58    #[subscription(
59        name = "subscribeFinalizedChainNotifications",
60        unsubscribe = "unsubscribeFinalizedChainNotifications",
61        item = Vec<reth_chain_state::CanonStateNotification>
62    )]
63    async fn reth_subscribe_finalized_chain_notifications(
64        &self,
65    ) -> jsonrpsee::core::SubscriptionResult;
66}
67
68/// Supported `reth_jit` control actions.
69#[derive(Clone, Copy, Debug, Deserialize, Serialize)]
70#[serde(rename_all = "lowercase")]
71pub enum RethJitAction {
72    /// Enable JIT compilation for the backend.
73    Enable,
74    /// Disable JIT compilation for the backend.
75    Disable,
76    /// Pause background JIT compilation.
77    Pause,
78    /// Resume background JIT compilation.
79    Unpause,
80    /// Clear resident and persisted JIT artifacts.
81    Clear,
82}