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};
5use serde_json::value::RawValue;
6
7// Required for the subscription attributes below
8use reth_chain_state as _;
9
10/// Reth API namespace for reth-specific methods
11#[rpc(server, 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    ///
26    /// The receipt type depends on the node's network, which this trait cannot name, so the
27    /// outcome is returned serialized.
28    #[method(name = "getBlockExecutionOutcome")]
29    async fn reth_get_block_execution_outcome(
30        &self,
31        block_id: BlockId,
32        count: Option<U64>,
33    ) -> RpcResult<Option<Box<RawValue>>>;
34
35    /// Controls the JIT backend, if one is configured.
36    #[method(name = "jit")]
37    async fn reth_jit(&self, action: RethJitAction) -> RpcResult<()>;
38
39    /// Subscribe to json `ChainNotifications`
40    #[subscription(
41        name = "subscribeChainNotifications",
42        unsubscribe = "unsubscribeChainNotifications",
43        item = reth_chain_state::CanonStateNotification
44    )]
45    async fn reth_subscribe_chain_notifications(&self) -> jsonrpsee::core::SubscriptionResult;
46
47    /// Subscribe to persisted block notifications.
48    ///
49    /// Emits a notification with the block number and hash when a new block is persisted to disk.
50    #[subscription(
51        name = "subscribePersistedBlock",
52        unsubscribe = "unsubscribePersistedBlock",
53        item = alloy_eips::BlockNumHash
54    )]
55    async fn reth_subscribe_persisted_block(&self) -> jsonrpsee::core::SubscriptionResult;
56
57    /// Subscribe to finalized chain notifications.
58    ///
59    /// Buffers committed chain notifications and emits them once a new finalized block is received.
60    /// Each notification contains all committed chain segments up to the finalized block.
61    #[subscription(
62        name = "subscribeFinalizedChainNotifications",
63        unsubscribe = "unsubscribeFinalizedChainNotifications",
64        item = Vec<reth_chain_state::CanonStateNotification>
65    )]
66    async fn reth_subscribe_finalized_chain_notifications(
67        &self,
68    ) -> jsonrpsee::core::SubscriptionResult;
69}
70
71/// Supported `reth_jit` control actions.
72#[derive(Clone, Copy, Debug, Deserialize, Serialize)]
73#[serde(rename_all = "lowercase")]
74pub enum RethJitAction {
75    /// Enable JIT compilation for the backend.
76    Enable,
77    /// Disable JIT compilation for the backend.
78    Disable,
79    /// Pause background JIT compilation.
80    Pause,
81    /// Resume background JIT compilation.
82    Unpause,
83    /// Clear resident and persisted JIT artifacts.
84    Clear,
85}