From 6e3d62d7ba4d5993bcc911fea07a09e721d4ee3c Mon Sep 17 00:00:00 2001 From: Solar Mithril Date: Thu, 7 May 2026 21:38:01 +0400 Subject: [PATCH 1/4] Init --- src/builderhub/mod.rs | 28 +++++++++++++++++++++++++++- src/cli.rs | 13 +++++++++++++ src/lib.rs | 11 ++++++++++- 3 files changed, 50 insertions(+), 2 deletions(-) diff --git a/src/builderhub/mod.rs b/src/builderhub/mod.rs index 5c9abe63..712464f1 100644 --- a/src/builderhub/mod.rs +++ b/src/builderhub/mod.rs @@ -20,7 +20,9 @@ use openssl::{ }; use std::{ convert::Infallible, fmt::Debug, future::Future, io, net::SocketAddr, num::NonZero, - path::PathBuf, sync::Arc, time::Duration, + path::{Path, PathBuf}, + sync::Arc, + time::Duration, }; use tokio::net::{lookup_host, ToSocketAddrs}; @@ -165,6 +167,30 @@ impl LocalPeerStore { } } +impl LocalPeerStore { + /// Load peers from a JSON file and insert them into the store, keyed by their `name`. + /// + /// Used by dev mode (`--dev-peers `) to seed the local peer store from a static + /// list instead of using BuilderHub. + pub fn load_from_file(&self, path: &Path) -> Result<(), LocalPeerStoreLoadError> { + let bytes = std::fs::read(path).map_err(LocalPeerStoreLoadError::Io)?; + let peers: Vec = + serde_json::from_slice(&bytes).map_err(LocalPeerStoreLoadError::Parse)?; + for peer in peers { + self.builders.insert(peer.name.clone(), peer); + } + Ok(()) + } +} + +#[derive(Debug, thiserror::Error)] +pub enum LocalPeerStoreLoadError { + #[error("failed to read dev peers file: {0}")] + Io(#[source] io::Error), + #[error("failed to parse dev peers file: {0}")] + Parse(#[source] serde_json::Error), +} + impl PeerStore for LocalPeerStore { type Error = Infallible; diff --git a/src/cli.rs b/src/cli.rs index 05b5dd00..f9a46328 100644 --- a/src/cli.rs +++ b/src/cli.rs @@ -238,6 +238,18 @@ pub struct OrderflowIngressArgs { #[clap(long, value_hint = ValueHint::Url, env = "BUILDERHUB_ENDPOINT", id = "BUILDERHUB_ENDPOINT")] pub builder_hub_url: Option, + /// Path to a JSON file containing a static list of peers for development/testing. + /// When set, BuilderHub is not used and peers are loaded from this file (refreshed on the + /// regular peer update interval). Conflicts with `--builder-hub-url`. + #[clap( + long, + value_hint = ValueHint::FilePath, + env = "DEV_PEERS", + id = "DEV_PEERS", + conflicts_with = "BUILDERHUB_ENDPOINT" + )] + pub dev_peers: Option, + /// Enable Prometheus metrics. /// The metrics will be served at the given interface and port. #[arg(long, env = "METRICS_ADDR", id = "METRICS_ADDR")] @@ -376,6 +388,7 @@ impl Default for OrderflowIngressArgs { builder_name: String::from("buildernet"), builder_region: Region::US, builder_hub_url: None, + dev_peers: None, flashbots_signer: None, max_txs_per_bundle: 100, enable_rate_limiting: false, diff --git a/src/lib.rs b/src/lib.rs index d0478470..00758032 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -168,9 +168,18 @@ pub async fn run_with_listeners( task_executor .spawn_critical("run_update_peers", peer_updater.run(args.peer_update_interval_s)); } else { - tracing::warn!("No BuilderHub URL provided, running with local peer store"); let local_peer_store = LOCAL_PEER_STORE.clone(); + if let Some(dev_peers_path) = args.dev_peers.as_ref() { + tracing::warn!( + path = %dev_peers_path.display(), + "Running in dev mode with static peers from file" + ); + local_peer_store.load_from_file(dev_peers_path)?; + } else { + tracing::warn!("No BuilderHub URL provided, running with local peer store"); + } + let peer_store = local_peer_store.register( local_signer, Some(system_listener.local_addr().expect("bound").port()), From e5ce9bac6e02ffc54c8d8cacdb070e4828e6b07f Mon Sep 17 00:00:00 2001 From: Solar Mithril Date: Fri, 8 May 2026 10:08:06 +0400 Subject: [PATCH 2/4] Fix fmt --- src/builderhub/mod.rs | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/src/builderhub/mod.rs b/src/builderhub/mod.rs index 712464f1..8076b314 100644 --- a/src/builderhub/mod.rs +++ b/src/builderhub/mod.rs @@ -19,7 +19,12 @@ use openssl::{ x509::X509, }; use std::{ - convert::Infallible, fmt::Debug, future::Future, io, net::SocketAddr, num::NonZero, + convert::Infallible, + fmt::Debug, + future::Future, + io, + net::SocketAddr, + num::NonZero, path::{Path, PathBuf}, sync::Arc, time::Duration, From 85c99819b408c353e535512d1d86612cfdf177f5 Mon Sep 17 00:00:00 2001 From: Solar Mithril Date: Fri, 8 May 2026 13:27:56 +0400 Subject: [PATCH 3/4] Review comments --- src/builderhub/mod.rs | 6 ++++-- src/cli.rs | 4 ++-- src/lib.rs | 14 +++++--------- 3 files changed, 11 insertions(+), 13 deletions(-) diff --git a/src/builderhub/mod.rs b/src/builderhub/mod.rs index 8076b314..b3b7da29 100644 --- a/src/builderhub/mod.rs +++ b/src/builderhub/mod.rs @@ -174,17 +174,19 @@ impl LocalPeerStore { impl LocalPeerStore { /// Load peers from a JSON file and insert them into the store, keyed by their `name`. + /// Returns the number of peers loaded. /// /// Used by dev mode (`--dev-peers `) to seed the local peer store from a static /// list instead of using BuilderHub. - pub fn load_from_file(&self, path: &Path) -> Result<(), LocalPeerStoreLoadError> { + pub fn load_from_file(&self, path: &Path) -> Result { let bytes = std::fs::read(path).map_err(LocalPeerStoreLoadError::Io)?; let peers: Vec = serde_json::from_slice(&bytes).map_err(LocalPeerStoreLoadError::Parse)?; + let count = peers.len(); for peer in peers { self.builders.insert(peer.name.clone(), peer); } - Ok(()) + Ok(count) } } diff --git a/src/cli.rs b/src/cli.rs index f9a46328..27ff0796 100644 --- a/src/cli.rs +++ b/src/cli.rs @@ -239,8 +239,8 @@ pub struct OrderflowIngressArgs { pub builder_hub_url: Option, /// Path to a JSON file containing a static list of peers for development/testing. - /// When set, BuilderHub is not used and peers are loaded from this file (refreshed on the - /// regular peer update interval). Conflicts with `--builder-hub-url`. + /// When set, peers are loaded from this file once at startup into the local peer store. + /// Conflicts with `--builder-hub-url`. #[clap( long, value_hint = ValueHint::FilePath, diff --git a/src/lib.rs b/src/lib.rs index 00758032..5aa4c8a3 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -170,15 +170,11 @@ pub async fn run_with_listeners( } else { let local_peer_store = LOCAL_PEER_STORE.clone(); - if let Some(dev_peers_path) = args.dev_peers.as_ref() { - tracing::warn!( - path = %dev_peers_path.display(), - "Running in dev mode with static peers from file" - ); - local_peer_store.load_from_file(dev_peers_path)?; - } else { - tracing::warn!("No BuilderHub URL provided, running with local peer store"); - } + let static_peer_count = match args.dev_peers.as_ref() { + Some(path) => local_peer_store.load_from_file(path)?, + None => 0, + }; + tracing::warn!(static_peer_count, "running without builderhub"); let peer_store = local_peer_store.register( local_signer, From 7e43694d93e18ac365a4b5edcdf797db1fc1f9a9 Mon Sep 17 00:00:00 2001 From: Solar Mithril Date: Fri, 8 May 2026 14:28:57 +0400 Subject: [PATCH 4/4] Add example for dev peers file --- fixtures/dev-peers.example.json | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) create mode 100644 fixtures/dev-peers.example.json diff --git a/fixtures/dev-peers.example.json b/fixtures/dev-peers.example.json new file mode 100644 index 00000000..dd9f85ad --- /dev/null +++ b/fixtures/dev-peers.example.json @@ -0,0 +1,22 @@ +[ + { + "name": "proxy_us", + "ip": "127.0.0.1:5544", + "dns_name": "", + "orderflow_proxy": { + "ecdsa_pubkey_address": "0xFCAd0B19bB29D4674531d6f115237E16AfCE377c", + "region": "us" + }, + "instance": { "tls_cert": "" } + }, + { + "name": "proxy_eu", + "ip": "127.0.0.2:5544", + "dns_name": "", + "orderflow_proxy": { + "ecdsa_pubkey_address": "0x6A9296CEb89D12e1F53b2Dd5Df45d3ADB3A814c2", + "region": "eu" + }, + "instance": { "tls_cert": "" } + } +]