-
Notifications
You must be signed in to change notification settings - Fork 12
Expand file tree
/
Copy pathfull.rs
More file actions
163 lines (132 loc) · 4.6 KB
/
Copy pathfull.rs
File metadata and controls
163 lines (132 loc) · 4.6 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
use std::path::PathBuf;
use anyhow::{Context, Result};
pub use clap::Parser;
use katana_node::config::db::DbConfig;
use katana_node::config::metrics::MetricsConfig;
use katana_node::config::rpc::RpcConfig;
use katana_node::full;
use katana_node::full::Network;
use serde::{Deserialize, Serialize};
use tracing::info;
use crate::options::*;
pub(crate) const LOG_TARGET: &str = "katana::cli::full";
#[derive(Parser, Debug, Serialize, Deserialize, Default, Clone, PartialEq)]
#[command(next_help_heading = "Full node options")]
pub struct FullNodeArgs {
/// Don't print anything on startup.
#[arg(long)]
pub silent: bool,
/// Directory path of the database to initialize from.
///
/// The path must either be an empty directory or a directory which already contains a
/// previously initialized Katana database.
#[arg(long)]
#[arg(value_name = "PATH")]
pub db_dir: PathBuf,
#[arg(long = "eth.rpc")]
#[arg(value_name = "PATH")]
pub eth_rpc_url: String,
#[arg(long)]
pub network: Network,
/// Gateway API key for accessing the sequencer gateway.
#[arg(long)]
#[arg(value_name = "KEY")]
pub gateway_api_key: Option<String>,
#[command(flatten)]
pub logging: LoggingOptions,
#[command(flatten)]
pub tracer: TracerOptions,
#[cfg(feature = "server")]
#[command(flatten)]
pub metrics: MetricsOptions,
#[cfg(feature = "server")]
#[command(flatten)]
pub server: ServerOptions,
#[cfg(feature = "explorer")]
#[command(flatten)]
pub explorer: ExplorerOptions,
}
impl FullNodeArgs {
pub async fn execute(&self) -> Result<()> {
// Initialize logging with tracer
let tracer_config = self.tracer_config();
katana_tracing::init(self.logging.log_format, tracer_config).await?;
self.start_node().await
}
async fn start_node(&self) -> Result<()> {
// Build the node
let config = self.config()?;
let node = full::Node::build(config).context("failed to build full node")?;
if !self.silent {
info!(target: LOG_TARGET, "Starting full node");
}
// Launch the node
let handle = node.launch().await.context("failed to launch full node")?;
// Wait until an OS signal (ie SIGINT, SIGTERM) is received or the node is shutdown.
tokio::select! {
_ = katana_utils::wait_shutdown_signals() => {
// Gracefully shutdown the node before exiting
handle.stop().await?;
},
_ = handle.stopped() => { }
}
info!("Shutting down.");
Ok(())
}
fn config(&self) -> Result<full::Config> {
let db = self.db_config();
let rpc = self.rpc_config()?;
let metrics = self.metrics_config();
Ok(full::Config {
db,
rpc,
metrics,
network: self.network,
eth_rpc_url: self.eth_rpc_url.clone(),
gateway_api_key: self.gateway_api_key.clone(),
})
}
fn db_config(&self) -> DbConfig {
DbConfig { dir: Some(self.db_dir.clone()) }
}
fn rpc_config(&self) -> Result<RpcConfig> {
#[cfg(feature = "server")]
{
use std::time::Duration;
let cors_origins = self.server.http_cors_origins.clone();
Ok(RpcConfig {
apis: Default::default(),
port: self.server.http_port,
addr: self.server.http_addr,
max_connections: self.server.max_connections,
max_concurrent_estimate_fee_requests: None,
max_request_body_size: None,
max_response_body_size: None,
timeout: self.server.timeout.map(Duration::from_secs),
cors_origins,
#[cfg(feature = "explorer")]
explorer: self.explorer.explorer,
max_event_page_size: Some(self.server.max_event_page_size),
max_proof_keys: Some(self.server.max_proof_keys),
max_call_gas: Some(self.server.max_call_gas),
})
}
#[cfg(not(feature = "server"))]
{
Ok(RpcConfig::default())
}
}
fn metrics_config(&self) -> Option<MetricsConfig> {
#[cfg(feature = "server")]
if self.metrics.metrics {
Some(MetricsConfig { addr: self.metrics.metrics_addr, port: self.metrics.metrics_port })
} else {
None
}
#[cfg(not(feature = "server"))]
None
}
fn tracer_config(&self) -> Option<katana_tracing::TracerConfig> {
self.tracer.config()
}
}