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