Skip to main content

reth_rpc_api/
debug.rs

1use alloy_eips::{BlockId, BlockNumberOrTag};
2use alloy_genesis::ChainConfig;
3use alloy_json_rpc::RpcObject;
4use alloy_primitives::{Address, Bytes, B256, U64};
5use alloy_rpc_types_debug::ExecutionWitness;
6use alloy_rpc_types_eth::{Account, AccountInfo, Bundle, Index, StateContext};
7use alloy_rpc_types_trace::geth::{
8    BlockTraceResult, GethDebugTracingCallOptions, GethDebugTracingOptions, GethTrace, TraceResult,
9};
10use jsonrpsee::{core::RpcResult, proc_macros::rpc};
11use reth_trie_common::{updates::TrieUpdates, ExecutionWitnessMode, HashedPostState};
12
13/// Debug rpc interface.
14#[cfg_attr(not(feature = "client"), rpc(server, namespace = "debug"))]
15#[cfg_attr(feature = "client", rpc(server, client, namespace = "debug"))]
16pub trait DebugApi<TxReq: RpcObject> {
17    /// Returns an RLP-encoded header.
18    #[method(name = "getRawHeader")]
19    async fn raw_header(&self, block_id: BlockId) -> RpcResult<Bytes>;
20
21    /// Returns an RLP-encoded block.
22    #[method(name = "getRawBlock")]
23    async fn raw_block(&self, block_id: BlockId) -> RpcResult<Bytes>;
24
25    /// Returns an EIP-2718 binary-encoded transaction.
26    ///
27    /// If this is a pooled EIP-4844 transaction, the blob sidecar is included.
28    #[method(name = "getRawTransaction")]
29    async fn raw_transaction(&self, hash: B256) -> RpcResult<Option<Bytes>>;
30
31    /// Returns an array of EIP-2718 binary-encoded transactions for the given [`BlockId`].
32    #[method(name = "getRawTransactions")]
33    async fn raw_transactions(&self, block_id: BlockId) -> RpcResult<Vec<Bytes>>;
34
35    /// Returns an array of EIP-2718 binary-encoded receipts.
36    #[method(name = "getRawReceipts")]
37    async fn raw_receipts(&self, block_id: BlockId) -> RpcResult<Vec<Bytes>>;
38
39    /// Returns an array of recent bad blocks that the client has seen on the network.
40    #[method(name = "getBadBlocks")]
41    async fn bad_blocks(&self) -> RpcResult<Vec<serde_json::Value>>;
42
43    /// Clears all transactions from the transaction pool.
44    #[method(name = "clearTxpool")]
45    async fn debug_clear_txpool(&self) -> RpcResult<()>;
46
47    /// Returns the structured logs created during the execution of EVM between two blocks
48    /// (excluding start) as a JSON object.
49    #[method(name = "traceChain")]
50    async fn debug_trace_chain(
51        &self,
52        start_exclusive: BlockNumberOrTag,
53        end_inclusive: BlockNumberOrTag,
54    ) -> RpcResult<Vec<BlockTraceResult>>;
55
56    /// The `debug_traceBlock` method will return a full stack trace of all invoked opcodes of all
57    /// transaction that were included in this block.
58    ///
59    /// This expects an rlp encoded block
60    ///
61    /// Note, the parent of this block must be present, or it will fail. For the second parameter
62    /// see [`GethDebugTracingOptions`] reference.
63    #[method(name = "traceBlock")]
64    async fn debug_trace_block(
65        &self,
66        rlp_block: Bytes,
67        opts: Option<GethDebugTracingOptions>,
68    ) -> RpcResult<Vec<TraceResult>>;
69
70    /// Similar to `debug_traceBlock`, `debug_traceBlockByHash` accepts a block hash and will replay
71    /// the block that is already present in the database. For the second parameter see
72    /// [`GethDebugTracingOptions`].
73    #[method(name = "traceBlockByHash")]
74    async fn debug_trace_block_by_hash(
75        &self,
76        block: B256,
77        opts: Option<GethDebugTracingOptions>,
78    ) -> RpcResult<Vec<TraceResult>>;
79
80    /// Similar to `debug_traceBlockByHash`, `debug_traceBlockByNumber` accepts a block number
81    /// [`BlockNumberOrTag`] and will replay the block that is already present in the database.
82    /// For the second parameter see [`GethDebugTracingOptions`].
83    #[method(name = "traceBlockByNumber")]
84    async fn debug_trace_block_by_number(
85        &self,
86        block: BlockNumberOrTag,
87        opts: Option<GethDebugTracingOptions>,
88    ) -> RpcResult<Vec<TraceResult>>;
89
90    /// The `debug_traceTransaction` debugging method will attempt to run the transaction in the
91    /// exact same manner as it was executed on the network. It will replay any transaction that
92    /// may have been executed prior to this one before it will finally attempt to execute the
93    /// transaction that corresponds to the given hash.
94    #[method(name = "traceTransaction")]
95    async fn debug_trace_transaction(
96        &self,
97        tx_hash: B256,
98        opts: Option<GethDebugTracingOptions>,
99    ) -> RpcResult<GethTrace>;
100
101    /// The `debug_traceCall` method lets you run an `eth_call` within the context of the given
102    /// block execution using the final state of parent block as the base.
103    ///
104    /// The first argument (just as in `eth_call`) is a transaction request.
105    /// The block can optionally be specified either by hash or by number as
106    /// the second argument.
107    /// The trace can be configured similar to `debug_traceTransaction`,
108    /// see [`GethDebugTracingOptions`]. The method returns the same output as
109    /// `debug_traceTransaction`.
110    #[method(name = "traceCall")]
111    async fn debug_trace_call(
112        &self,
113        request: TxReq,
114        block_id: Option<BlockId>,
115        opts: Option<GethDebugTracingCallOptions>,
116    ) -> RpcResult<GethTrace>;
117
118    /// The `debug_traceCallMany` method lets you run an `eth_callMany` within the context of the
119    /// given block execution using the final state of parent block as the base followed by n
120    /// transactions.
121    ///
122    /// The first argument is a list of bundles. Each bundle can overwrite the block headers. This
123    /// will affect all transaction in that bundle.
124    /// `BlockNumber` and `transaction_index` are optional. `Transaction_index`
125    /// specifies the number of tx in the block to replay and -1 means all transactions should be
126    /// replayed.
127    /// The trace can be configured similar to `debug_traceTransaction`.
128    /// State override apply to all bundles.
129    ///
130    /// This methods is similar to many `eth_callMany`, hence this returns nested lists of traces.
131    /// Where the length of the outer list is the number of bundles and the length of the inner list
132    /// (`Vec<GethTrace>`) is the number of transactions in the bundle.
133    #[method(name = "traceCallMany")]
134    async fn debug_trace_call_many(
135        &self,
136        bundles: Vec<Bundle<TxReq>>,
137        state_context: Option<StateContext>,
138        opts: Option<GethDebugTracingCallOptions>,
139    ) -> RpcResult<Vec<Vec<GethTrace>>>;
140
141    /// The `debug_executionWitness` method allows for re-execution of a block with the purpose of
142    /// generating an execution witness. The witness comprises of a map of all hashed trie nodes
143    /// to their preimages that were required during the execution of the block, including during
144    /// state root recomputation.
145    ///
146    /// The first argument is the block number or tag. The optional second argument selects the
147    /// witness generation mode and defaults to `legacy`.
148    #[method(name = "executionWitness")]
149    async fn debug_execution_witness(
150        &self,
151        block: BlockNumberOrTag,
152        mode: Option<ExecutionWitnessMode>,
153    ) -> RpcResult<ExecutionWitness>;
154
155    /// The `debug_executionWitnessByBlockHash` method allows for re-execution of a block with the
156    /// purpose of generating an execution witness. The witness comprises of a map of all hashed
157    /// trie nodes to their preimages that were required during the execution of the block,
158    /// including during state root recomputation.
159    ///
160    /// The first argument is the block hash. The optional second argument selects the witness
161    /// generation mode and defaults to `legacy`.
162    #[method(name = "executionWitnessByBlockHash")]
163    async fn debug_execution_witness_by_block_hash(
164        &self,
165        hash: B256,
166        mode: Option<ExecutionWitnessMode>,
167    ) -> RpcResult<ExecutionWitness>;
168
169    /// Returns account information, including the storage root, at the state after executing the
170    /// transaction with the given index in the block.
171    #[method(name = "accountAt")]
172    async fn debug_account_at(
173        &self,
174        block_id: BlockId,
175        tx_index: Index,
176        address: Address,
177    ) -> RpcResult<Option<Account>>;
178
179    /// Returns account information at the state after executing the transaction with the given
180    /// index in the block.
181    #[method(name = "accountInfoAt")]
182    async fn debug_account_info_at(
183        &self,
184        block_id: BlockId,
185        tx_index: Index,
186        address: Address,
187    ) -> RpcResult<Option<AccountInfo>>;
188
189    /// Enumerates all accounts at a given block with paging capability. `maxResults` are returned
190    /// in the page and the items have keys that come after the `start` key (hashed address).
191    ///
192    /// If incompletes is false, then accounts for which the key preimage (i.e: the address) doesn't
193    /// exist in db are skipped. NB: geth by default does not store preimages.
194    #[method(name = "accountRange")]
195    async fn debug_account_range(
196        &self,
197        block_number: BlockNumberOrTag,
198        start: Bytes,
199        max_results: u64,
200        nocode: bool,
201        nostorage: bool,
202        incompletes: bool,
203    ) -> RpcResult<()>;
204
205    /// Flattens the entire key-value database into a single level, removing all unused slots and
206    /// merging all keys.
207    #[method(name = "chaindbCompact")]
208    async fn debug_chaindb_compact(&self) -> RpcResult<()>;
209
210    /// Returns the current chain config.
211    #[method(name = "chainConfig")]
212    async fn debug_chain_config(&self) -> RpcResult<ChainConfig>;
213
214    /// Returns leveldb properties of the key-value database.
215    #[method(name = "chaindbProperty")]
216    async fn debug_chaindb_property(&self, property: String) -> RpcResult<()>;
217
218    /// Returns the code associated with a given hash at the specified block ID.
219    /// If no block ID is provided, it defaults to the latest block.
220    #[method(name = "codeByHash")]
221    async fn debug_code_by_hash(
222        &self,
223        hash: B256,
224        block_id: Option<BlockId>,
225    ) -> RpcResult<Option<Bytes>>;
226
227    /// Retrieves an ancient binary blob from the freezer. The freezer is a collection of
228    /// append-only immutable files. The first argument `kind` specifies which table to look up data
229    /// from. The list of all table kinds are as follows:
230    #[method(name = "dbAncient")]
231    async fn debug_db_ancient(&self, kind: String, number: u64) -> RpcResult<()>;
232
233    /// Returns the number of ancient items in the ancient store.
234    #[method(name = "dbAncients")]
235    async fn debug_db_ancients(&self) -> RpcResult<()>;
236
237    /// Returns the raw value of a key stored in the database.
238    #[method(name = "dbGet")]
239    async fn debug_db_get(&self, key: String) -> RpcResult<Option<Bytes>>;
240
241    /// Retrieves the state that corresponds to the block number and returns a list of accounts
242    /// (including storage and code).
243    #[method(name = "dumpBlock")]
244    async fn debug_dump_block(&self, number: BlockId) -> RpcResult<()>;
245
246    /// Forces garbage collection.
247    #[method(name = "freeOSMemory")]
248    async fn debug_free_os_memory(&self) -> RpcResult<()>;
249
250    /// Returns garbage collection statistics.
251    #[method(name = "gcStats")]
252    async fn debug_gc_stats(&self) -> RpcResult<()>;
253
254    /// Returns the first number where the node has accessible state on disk. This is the
255    /// post-state of that block and the pre-state of the next block. The (from, to) parameters
256    /// are the sequence of blocks to search, which can go either forwards or backwards.
257    ///
258    /// Note: to get the last state pass in the range of blocks in reverse, i.e. (last, first).
259    #[method(name = "getAccessibleState")]
260    async fn debug_get_accessible_state(
261        &self,
262        from: BlockNumberOrTag,
263        to: BlockNumberOrTag,
264    ) -> RpcResult<()>;
265
266    /// Returns all accounts that have changed between the two blocks specified. A change is defined
267    /// as a difference in nonce, balance, code hash, or storage hash. With one parameter, returns
268    /// the list of accounts modified in the specified block.
269    #[method(name = "getModifiedAccountsByHash")]
270    async fn debug_get_modified_accounts_by_hash(
271        &self,
272        start_hash: B256,
273        end_hash: B256,
274    ) -> RpcResult<()>;
275
276    /// Returns all accounts that have changed between the two blocks specified. A change is defined
277    /// as a difference in nonce, balance, code hash or storage hash.
278    #[method(name = "getModifiedAccountsByNumber")]
279    async fn debug_get_modified_accounts_by_number(
280        &self,
281        start_number: u64,
282        end_number: u64,
283    ) -> RpcResult<()>;
284
285    /// Executes a block (bad- or canon- or side-), and returns a list of intermediate roots: the
286    /// stateroot after each transaction.
287    #[method(name = "intermediateRoots")]
288    async fn debug_intermediate_roots(
289        &self,
290        block_hash: B256,
291        opts: Option<GethDebugTracingCallOptions>,
292    ) -> RpcResult<Vec<B256>>;
293
294    /// Returns detailed runtime memory statistics.
295    #[method(name = "memStats")]
296    async fn debug_mem_stats(&self) -> RpcResult<()>;
297
298    /// Returns the preimage for a sha3 hash, if known.
299    #[method(name = "preimage")]
300    async fn debug_preimage(&self, hash: B256) -> RpcResult<()>;
301
302    /// Retrieves a block and returns its pretty printed form.
303    #[method(name = "printBlock")]
304    async fn debug_print_block(&self, number: u64) -> RpcResult<()>;
305
306    /// Fetches and retrieves the seed hash of the block by number.
307    #[method(name = "seedHash")]
308    async fn debug_seed_hash(&self, number: u64) -> RpcResult<B256>;
309
310    /// Sets the garbage collection target percentage. A negative value disables garbage collection.
311    #[method(name = "setGCPercent")]
312    async fn debug_set_gc_percent(&self, v: i32) -> RpcResult<()>;
313
314    /// Sets the current head of the local chain by block number. Note, this is a destructive action
315    /// and may severely damage your chain. Use with extreme caution.
316    #[method(name = "setHead")]
317    async fn debug_set_head(&self, number: U64) -> RpcResult<()>;
318
319    /// Configures how often in-memory state tries are persisted to disk. The interval needs to be
320    /// in a format parsable by a time.Duration. Note that the interval is not wall-clock time.
321    /// Rather it is accumulated block processing time after which the state should be flushed.
322    #[method(name = "setTrieFlushInterval")]
323    async fn debug_set_trie_flush_interval(&self, interval: String) -> RpcResult<()>;
324
325    /// Used to obtain info about a block.
326    #[method(name = "standardTraceBadBlockToFile")]
327    async fn debug_standard_trace_bad_block_to_file(
328        &self,
329        block: BlockNumberOrTag,
330        opts: Option<GethDebugTracingCallOptions>,
331    ) -> RpcResult<()>;
332
333    /// This method is similar to `debug_standardTraceBlockToFile`, but can be used to obtain info
334    /// about a block which has been rejected as invalid (for some reason).
335    #[method(name = "standardTraceBlockToFile")]
336    async fn debug_standard_trace_block_to_file(
337        &self,
338        block: BlockNumberOrTag,
339        opts: Option<GethDebugTracingCallOptions>,
340    ) -> RpcResult<()>;
341
342    /// Returns the state root of the `HashedPostState` on top of the state for the given block with
343    /// trie updates.
344    #[method(name = "stateRootWithUpdates")]
345    async fn debug_state_root_with_updates(
346        &self,
347        hashed_state: HashedPostState,
348        block_id: Option<BlockId>,
349    ) -> RpcResult<(B256, TrieUpdates)>;
350
351    /// Returns the storage at the given block height and transaction index. The result can be
352    /// paged by providing a `maxResult` to cap the number of storage slots returned as well as
353    /// specifying the offset via `keyStart` (hash of storage key).
354    #[method(name = "storageRangeAt")]
355    async fn debug_storage_range_at(
356        &self,
357        block_hash: B256,
358        tx_idx: usize,
359        contract_address: Address,
360        key_start: B256,
361        max_result: u64,
362    ) -> RpcResult<()>;
363
364    /// Returns the structured logs created during the execution of EVM against a block pulled
365    /// from the pool of bad ones and returns them as a JSON object. For the second parameter see
366    /// `TraceConfig` reference.
367    #[method(name = "traceBadBlock")]
368    async fn debug_trace_bad_block(
369        &self,
370        block_hash: B256,
371        opts: Option<GethDebugTracingCallOptions>,
372    ) -> RpcResult<Vec<TraceResult>>;
373}