seismic_reth/
main.rs

1#![allow(missing_docs)]
2
3use clap::Parser;
4use reth::cli::Cli;
5use reth_cli_commands::node::NoArgs;
6use reth_enclave::{start_blocking_mock_enclave_server, EnclaveClient};
7use reth_node_builder::{EngineNodeLauncher, TreeConfig};
8use reth_seismic_cli::chainspec::SeismicChainSpecParser;
9use reth_seismic_node::node::SeismicNode;
10use reth_seismic_rpc::ext::{EthApiExt, EthApiOverrideServer, SeismicApi, SeismicApiServer};
11use reth_tracing::tracing::*;
12use seismic_enclave::boot_genesis_streamlined_async;
13
14fn main() {
15    reth_cli_util::sigsegv_handler::install();
16
17    // Enable backtraces unless a RUST_BACKTRACE value has already been explicitly provided.
18    if std::env::var_os("RUST_BACKTRACE").is_none() {
19        std::env::set_var("RUST_BACKTRACE", "1");
20    }
21
22    if let Err(err) = Cli::<SeismicChainSpecParser, NoArgs>::parse().run(|builder, _| async move {
23        let engine_tree_config = TreeConfig::default();
24
25        // building additional endpoints seismic api
26        let seismic_api = SeismicApi::new(builder.config());
27
28        let node = builder
29            .node(SeismicNode::default())
30            .on_node_started(move |ctx| {
31                match ctx.config.enclave.mock_server {
32                    true => {
33                        ctx.task_executor.spawn(async move {
34                            start_blocking_mock_enclave_server(
35                                ctx.config.enclave.enclave_server_addr,
36                                ctx.config.enclave.enclave_server_port,
37                            )
38                            .await;
39                        });
40                    }
41                    false => {
42                        // Boots the enclave with random keys (aka enclave genesis boot)
43                        // Long term this should be removed and node operators should handle booting
44                        let enclave_client = EnclaveClient::builder()
45                            .ip(ctx.config.enclave.enclave_server_addr.to_string())
46                            .port(ctx.config.enclave.enclave_server_port)
47                            .build()
48                            .expect("Failed to build enclave client");
49
50                        ctx.task_executor.spawn(async move {
51                            boot_genesis_streamlined_async(&enclave_client)
52                                .await
53                                .expect("Failed to boot enclave");
54                        });
55                    }
56                }
57                Ok(())
58            })
59            .extend_rpc_modules(move |ctx| {
60                // replace eth_ namespace
61                ctx.modules.replace_configured(
62                    EthApiExt::new(ctx.registry.eth_api().clone(), EnclaveClient::default())
63                        .into_rpc(),
64                )?;
65
66                // add seismic_ namespace
67                ctx.modules.merge_configured(seismic_api.into_rpc())?;
68                info!(target: "reth::cli", "seismic api configured");
69                Ok(())
70            })
71            .launch_with_fn(|builder| {
72                let launcher = EngineNodeLauncher::new(
73                    builder.task_executor().clone(),
74                    builder.config().datadir(),
75                    engine_tree_config,
76                );
77                builder.launch_with(launcher)
78            })
79            .await?;
80        node.node_exit_future.await
81    }) {
82        eprintln!("Error: {err:?}");
83        std::process::exit(1);
84    }
85}