Skip to content
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 33 additions & 2 deletions src/builderhub/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,15 @@ use openssl::{
x509::X509,
};
use std::{
convert::Infallible, fmt::Debug, future::Future, io, net::SocketAddr, num::NonZero,
path::PathBuf, sync::Arc, time::Duration,
convert::Infallible,
fmt::Debug,
future::Future,
io,
net::SocketAddr,
num::NonZero,
path::{Path, PathBuf},
sync::Arc,
time::Duration,
};
use tokio::net::{lookup_host, ToSocketAddrs};

Expand Down Expand Up @@ -165,6 +172,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 <filepath>`) 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<Peer> =
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;

Expand Down
13 changes: 13 additions & 0 deletions src/cli.rs
Original file line number Diff line number Diff line change
Expand Up @@ -238,6 +238,18 @@ pub struct OrderflowIngressArgs {
#[clap(long, value_hint = ValueHint::Url, env = "BUILDERHUB_ENDPOINT", id = "BUILDERHUB_ENDPOINT")]
pub builder_hub_url: Option<String>,

/// 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`.
Comment thread
SozinM marked this conversation as resolved.
Outdated
#[clap(
long,
value_hint = ValueHint::FilePath,
env = "DEV_PEERS",
id = "DEV_PEERS",
conflicts_with = "BUILDERHUB_ENDPOINT"
)]
pub dev_peers: Option<PathBuf>,

/// Enable Prometheus metrics.
/// The metrics will be served at the given interface and port.
#[arg(long, env = "METRICS_ADDR", id = "METRICS_ADDR")]
Expand Down Expand Up @@ -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,
Expand Down
11 changes: 10 additions & 1 deletion src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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");
Comment thread
SozinM marked this conversation as resolved.
Outdated
}

let peer_store = local_peer_store.register(
local_signer,
Some(system_listener.local_addr().expect("bound").port()),
Expand Down
Loading