Skip to content

Commit b99c376

Browse files
pioheiPiotr Heilman
andauthored
Add health server. (#433)
* Revert "revert: health_checks (#430)" This reverts commit 88c955e. * Make healtheck optional. --------- Co-authored-by: Piotr Heilman <piotr.heilman@toolsforhumanity.com>
1 parent 7d2acb7 commit b99c376

File tree

14 files changed

+1483
-12
lines changed

14 files changed

+1483
-12
lines changed

Cargo.lock

Lines changed: 88 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -201,6 +201,7 @@ alloy-op-evm = { version = "0.27", default-features = false }
201201
alloy-evm = { version = "0.27", default-features = false }
202202

203203
# rpc
204+
axum = "0.8"
204205
jsonrpsee = { version = "0.26.0", features = ["server", "client", "macros"] }
205206
jsonrpsee-core = { version = "0.26.0" }
206207
jsonrpsee-types = "0.26.0"
@@ -210,6 +211,7 @@ metrics = "0.24.0"
210211
metrics-derive = "0.1"
211212

212213
tokio = { version = "1.44.2", features = ["full"] }
214+
nix = { version = "0.29", features = ["fs"] }
213215
tokio-util = "0.7.15"
214216
tokio-stream = "0.1.17"
215217
tokio-tungstenite = "0.28.0"

crates/flashblocks/node/tests/p2p.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -218,6 +218,7 @@ async fn setup_node_extended_cfg(
218218
access_list: true,
219219
}),
220220
tx_peers: None,
221+
health: Default::default(),
221222
},
222223
builder_config: Default::default(),
223224
};

crates/tests/sepolia/src/cli/transactions.rs

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -443,8 +443,7 @@ pub async fn bundle_transactions(args: &BundleArgs) -> eyre::Result<Vec<Bytes>>
443443
let signer = args.std_private_key.parse::<PrivateKeySigner>()?;
444444
let sender = signer.address();
445445
let mut txs = vec![];
446-
let mut nonce = args.std_nonce;
447-
for _ in 0..args.tx_batch_size {
446+
for (nonce, _) in (args.std_nonce..).zip(0..args.tx_batch_size) {
448447
let tx = TransactionRequest {
449448
nonce: Some(nonce),
450449
value: None,
@@ -461,7 +460,6 @@ pub async fn bundle_transactions(args: &BundleArgs) -> eyre::Result<Vec<Bytes>>
461460
..Default::default()
462461
};
463462

464-
nonce += 1;
465463
txs.push(sign_transaction(tx, signer.clone()).await?)
466464
}
467465

crates/world/bin/src/main.rs

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ use reth_optimism_cli::{Cli, chainspec::OpChainSpecParser};
55
use reth_tracing::tracing::info;
66
use world_chain_node::{
77
FlashblocksOpApi, OpApiExtServer, args::WorldChainArgs, config::WorldChainNodeConfig,
8-
context::FlashblocksContext, node::WorldChainNode,
8+
context::FlashblocksContext, health::HealthConfig, node::WorldChainNode,
99
};
1010
use world_chain_rpc::{EthApiExtServer, SequencerClient, WorldChainEthApiExt};
1111

@@ -46,7 +46,7 @@ fn main() {
4646
let node = WorldChainNode::<FlashblocksContext>::new(config.clone());
4747
let NodeHandle {
4848
node_exit_future,
49-
node: _node,
49+
node,
5050
} = builder
5151
.node(node)
5252
.extend_rpc_modules(move |ctx| {
@@ -61,6 +61,17 @@ fn main() {
6161
})
6262
.launch()
6363
.await?;
64+
65+
if let Some(addr) = config.args.health.addr {
66+
let health_config = match &config.args.health.config {
67+
Some(path) => HealthConfig::from_file(path)?,
68+
None => HealthConfig::default(),
69+
};
70+
let health_server =
71+
health_config.build(addr, node.provider.clone(), node.network.clone());
72+
node.task_executor.spawn(health_server.serve());
73+
}
74+
6475
node_exit_future.await?;
6576

6677
Ok(())

crates/world/node/Cargo.toml

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,14 @@ alloy-signer-local.workspace = true
4545

4646
op-alloy-consensus.workspace = true
4747

48+
reth-network-api.workspace = true
49+
50+
axum.workspace = true
51+
serde.workspace = true
52+
serde_json.workspace = true
53+
async-trait.workspace = true
54+
nix.workspace = true
55+
alloy-consensus.workspace = true
4856
tokio.workspace = true
4957
eyre.workspace = true
5058
clap.workspace = true
@@ -59,6 +67,8 @@ world-chain-pool.workspace = true
5967
world-chain-test.workspace = true
6068
world-chain-node.workspace = true
6169

70+
reth-chainspec.workspace = true
71+
tokio = { version = "1", features = ["test-util"] }
6272
reth-db.workspace = true
6373
reth-e2e-test-utils.workspace = true
6474
reth-engine-primitives.workspace = true
@@ -68,6 +78,7 @@ reth-optimism-node = { workspace = true, features = ["test-utils"] }
6878
revm-primitives.workspace = true
6979
reth-basic-payload-builder.workspace = true
7080
reth-primitives.workspace = true
81+
reth-primitives-traits.workspace = true
7182
reth-tracing.workspace = true
7283
reth-network-api.workspace = true
7384
reth-eth-wire.workspace = true

crates/world/node/src/args.rs

Lines changed: 26 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,8 @@ use reth_network_peers::{PeerId, TrustedPeer};
1010
use reth_node_builder::NodeConfig;
1111
use reth_optimism_chainspec::OpChainSpec;
1212
use reth_optimism_node::args::RollupArgs;
13-
use std::str::FromStr;
14-
use tracing::{debug, info, warn};
13+
use std::{net::SocketAddr, path::PathBuf, str::FromStr};
14+
use tracing::{info, warn};
1515

1616
pub const DEFAULT_FLASHBLOCKS_BOOTNODES: &str = "enode://78ca7daeb63956cbc3985853d5699a6404d976a2612575563f46876968fdca2383a195ee7db40de348757b2256195996933708f351169ca3f3fe93ab2a774608@16.62.98.53:30303,enode://c96dcadf4cdea4c39ec3fd775637d9e67d455b856b1514cfcf55b72f873a34b96d69e47ccea9fc797a446d4e6948aa80f6b9d479a1727ca166758a900b08f422@16.63.14.166:30303,enode://15688a7b281c32a4da633252dcc5019d60f037ee9eb46d05093dd3023bdd688b9b207d10a39e054a5ed87db666b2cb75696f6537de74d1e1f8dcabc53dc8d2ab@16.63.123.160:30303";
1717

@@ -38,6 +38,24 @@ pub struct WorldChainArgs {
3838
/// Comma-separated list of peer IDs to which transactions should be propagated
3939
#[arg(long = "tx-peers", value_delimiter = ',', value_name = "PEER_ID")]
4040
pub tx_peers: Option<Vec<PeerId>>,
41+
42+
/// Health check args
43+
#[command(flatten)]
44+
pub health: HealthArgs,
45+
}
46+
47+
#[derive(Debug, Clone, Default, clap::Args)]
48+
#[command(next_help_heading = "Health")]
49+
pub struct HealthArgs {
50+
/// Enable the health HTTP server on this address (startup/ready/live endpoints).
51+
/// If omitted, no health server is started.
52+
#[arg(long = "health.addr")]
53+
pub addr: Option<SocketAddr>,
54+
55+
/// Path to health check configuration file (JSON).
56+
/// If omitted, all probes return 200 OK unconditionally.
57+
#[arg(long = "health.config")]
58+
pub config: Option<PathBuf>,
4159
}
4260

4361
impl WorldChainArgs {
@@ -76,10 +94,11 @@ impl WorldChainArgs {
7694
)?);
7795
}
7896

79-
if config.network.bootnodes.is_none() && self.flashblocks.is_some() {
80-
let bootnodes = parse_trusted_peer(DEFAULT_FLASHBLOCKS_BOOTNODES)?;
81-
debug!(target: "world_chain::network", ?bootnodes, "Setting default flashblocks bootnodes");
82-
config.network.bootnodes = Some(bootnodes);
97+
if let Some(bootnodes) = &mut config.network.bootnodes
98+
&& bootnodes.is_empty()
99+
&& self.flashblocks.is_some()
100+
{
101+
*bootnodes = parse_trusted_peer(DEFAULT_FLASHBLOCKS_BOOTNODES)?;
83102
}
84103

85104
if self.pbh.entrypoint == Address::default() {
@@ -336,6 +355,7 @@ mod tests {
336355
},
337356
flashblocks: None,
338357
tx_peers: Some(vec![peer_id.parse().unwrap()]),
358+
health: HealthArgs::default(),
339359
};
340360

341361
let spec = reth_optimism_chainspec::OpChainSpec::from_genesis(Genesis::default());

0 commit comments

Comments
 (0)