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