reth_bench/bench/mod.rs
1//! `reth benchmark` command. Collection of various benchmarking routines.
2
3use clap::{Parser, Subcommand};
4use reth_cli_runner::CliContext;
5use reth_node_core::args::LogArgs;
6use reth_tracing::FileWorkerGuard;
7
8mod context;
9mod new_payload_fcu;
10mod new_payload_only;
11mod output;
12mod send_payload;
13
14/// `reth bench` command
15#[derive(Debug, Parser)]
16pub struct BenchmarkCommand {
17 #[command(subcommand)]
18 command: Subcommands,
19
20 #[command(flatten)]
21 logs: LogArgs,
22}
23
24/// `reth benchmark` subcommands
25#[derive(Subcommand, Debug)]
26pub enum Subcommands {
27 /// Benchmark which calls `newPayload`, then `forkchoiceUpdated`.
28 NewPayloadFcu(new_payload_fcu::Command),
29
30 /// Benchmark which only calls subsequent `newPayload` calls.
31 NewPayloadOnly(new_payload_only::Command),
32
33 /// Command for generating and sending an `engine_newPayload` request constructed from an RPC
34 /// block.
35 ///
36 /// This command takes a JSON block input (either from a file or stdin) and generates
37 /// an execution payload that can be used with the `engine_newPayloadV*` API.
38 ///
39 /// One powerful use case is pairing this command with the `cast block` command, for example:
40 ///
41 /// `cast block latest--full --json | reth-bench send-payload --rpc-url localhost:5000
42 /// --jwt-secret $(cat ~/.local/share/reth/mainnet/jwt.hex)`
43 SendPayload(send_payload::Command),
44}
45
46impl BenchmarkCommand {
47 /// Execute `benchmark` command
48 pub async fn execute(self, ctx: CliContext) -> eyre::Result<()> {
49 // Initialize tracing
50 let _guard = self.init_tracing()?;
51
52 match self.command {
53 Subcommands::NewPayloadFcu(command) => command.execute(ctx).await,
54 Subcommands::NewPayloadOnly(command) => command.execute(ctx).await,
55 Subcommands::SendPayload(command) => command.execute(ctx).await,
56 }
57 }
58
59 /// Initializes tracing with the configured options.
60 ///
61 /// If file logging is enabled, this function returns a guard that must be kept alive to ensure
62 /// that all logs are flushed to disk.
63 pub fn init_tracing(&self) -> eyre::Result<Option<FileWorkerGuard>> {
64 let guard = self.logs.init_tracing()?;
65 Ok(guard)
66 }
67}