Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add list of default relays and config to enable them #321

Open
wants to merge 8 commits into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 3 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
7 changes: 1 addition & 6 deletions config-live-example.toml
Original file line number Diff line number Diff line change
Expand Up @@ -34,12 +34,7 @@ max_concurrent_seals = 4
sbundle_mergeable_signers = []
live_builders = ["mp-ordering", "mgp-ordering", "merging"]

[[relays]]
name = "flashbots"
url = "https://0xac6e77dfe25ecd6110b8e780608cce0dab71fdd5ebea22a16c0205200f2f8e2e3ad3b71d3499c54ad14d6c21b41a37ae@boost-relay.flashbots.net"
priority = 0
use_ssz_for_submit = false
use_gzip_for_submit = false
enabled_relays = ["flashbots"]

[[builders]]
name = "mgp-ordering"
Expand Down
2 changes: 2 additions & 0 deletions config-optimism-local.toml
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@ ignore_cancellable_orders = true
sbundle_mergeable_signers = []
live_builders = ["mp-ordering"]

enabled_relays = ["custom"]

[[relays]]
name = "custom"
url = "http://0xac6e77dfe25ecd6110b8e780608cce0dab71fdd5ebea22a16c0205200f2f8e2e3ad3b71d3499c54ad14d6c21b41a37ae@localhost:5555"
Expand Down
7 changes: 1 addition & 6 deletions config-playground.toml
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,4 @@ ignore_cancellable_orders = true
sbundle_mergeable_signers = []
live_builders = ["mp-ordering", "mgp-ordering", "parallel"]

[[relays]]
name = "custom"
url = "http://0xac6e77dfe25ecd6110b8e780608cce0dab71fdd5ebea22a16c0205200f2f8e2e3ad3b71d3499c54ad14d6c21b41a37ae@localhost:5555"
priority = 0
use_ssz_for_submit = false
use_gzip_for_submit = false
enabled_relays = ["playground"]
141 changes: 138 additions & 3 deletions crates/rbuilder/src/live_builder/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ use ethereum_consensus::{
state_transition::Context as ContextEth,
};
use eyre::Context;
use lazy_static::lazy_static;
use reth::revm::cached::CachedReads;
use reth_chainspec::{Chain, ChainSpec, NamedChain};
use reth_db::{Database, DatabaseEnv};
Expand All @@ -65,7 +66,7 @@ use std::{
sync::Arc,
time::Duration,
};
use tracing::info;
use tracing::{info, warn};
use url::Url;

/// We initialize the wallet with the last full day. This should be enough for any bidder.
Expand Down Expand Up @@ -108,6 +109,8 @@ pub struct Config {
pub struct L1Config {
// Relay Submission configuration
pub relays: Vec<RelayConfig>,
pub enabled_relays: Vec<String>,

pub dry_run: bool,
#[serde_as(deserialize_as = "OneOrMany<_>")]
pub dry_run_validation_url: Vec<String>,
Expand Down Expand Up @@ -139,6 +142,7 @@ impl Default for L1Config {
fn default() -> Self {
Self {
relays: vec![],
enabled_relays: vec![],
dry_run: false,
dry_run_validation_url: vec![],
relay_secret_key: "".into(),
Expand Down Expand Up @@ -169,9 +173,47 @@ impl L1Config {
}

pub fn create_relays(&self) -> eyre::Result<Vec<MevBoostRelay>> {
let mut relays = DEFAULT_RELAYS.to_vec();
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Wouldn't it feel more natural/easy to use a map string->cfg instead of vector + find name?


for relay in self.relays.clone() {
if let Some(default) = relays.iter_mut().find(|d| d.name == relay.name) {
// If found in defaults, update it with an or operation
*default = default.clone() | relay.clone();
} else {
// If not found in defaults, add as new relay
relays.push(relay.clone());
}

// Emit warning if this relay is defined but not enabled
if !self.enabled_relays.contains(&relay.name) {
warn!(
"Relay '{}' is defined but not enabled in enabled_relays",
relay.name
);
}
}

let mut results = Vec::new();
for relay in &self.relays {
results.push(MevBoostRelay::from_config(relay)?);
for relay_name in &self.enabled_relays {
match relays.iter().find(|r| r.name == *relay_name) {
Some(relay) => match MevBoostRelay::from_config(relay) {
Ok(relay) => {
info!(
"Created relay: {:?} (priority: {})",
relay_name, relay.priority
);
results.push(relay)
}
Err(e) => {
return Err(eyre::eyre!(
"Failed to create relay {}: {:?}",
relay_name,
e
))
}
},
None => return Err(eyre::eyre!("Relay {} not found in relays list", relay_name)),
}
}
Ok(results)
}
Expand Down Expand Up @@ -596,6 +638,72 @@ fn get_signing_domain(
Ok(B256::from(&compute_builder_domain(&cl_context)?))
}

lazy_static! {
static ref DEFAULT_RELAYS: Vec<RelayConfig> = vec![
RelayConfig {
name: "flashbots".to_string(),
url: Some("http://k8s-default-boostrel-9f278153f5-947835446.us-east-2.elb.amazonaws.com".to_string()),
use_ssz_for_submit: true,
use_gzip_for_submit: false,
priority: 0,
optimistic: false,
interval_between_submissions_ms: Some(250),
authorization_header: None,
builder_id_header: None,
api_token_header: None,
},
RelayConfig {
name: "ultrasound-us".to_string(),
url: Some("https://relay-builders-us.ultrasound.money".to_string()),
use_ssz_for_submit: true,
use_gzip_for_submit: true,
priority: 0,
optimistic: true,
interval_between_submissions_ms: None,
authorization_header: None,
builder_id_header: None,
api_token_header: None,
},
RelayConfig {
name: "ultrasound-eu".to_string(),
url: Some("https://relay-builders-eu.ultrasound.money".to_string()),
use_ssz_for_submit: true,
use_gzip_for_submit: true,
priority: 0,
optimistic: true,
interval_between_submissions_ms: None,
authorization_header: None,
builder_id_header: None,
api_token_header: None,
},
RelayConfig {
name: "agnostic".to_string(),
url:Some("https://0xa7ab7a996c8584251c8f925da3170bdfd6ebc75d50f5ddc4050a6fdc77f2a3b5fce2cc750d0865e05d7228af97d69561@agnostic-relay.net".to_string()),
use_ssz_for_submit: true,
use_gzip_for_submit: true,
priority: 0,
optimistic: true,
interval_between_submissions_ms: None,
authorization_header: None,
builder_id_header: None,
api_token_header: None,
},
// Local relay configuration for the playground
RelayConfig {
name: "playground".to_string(),
url:Some("http://0xac6e77dfe25ecd6110b8e780608cce0dab71fdd5ebea22a16c0205200f2f8e2e3ad3b71d3499c54ad14d6c21b41a37ae@localhost:5555".to_string()),
priority: 0,
use_ssz_for_submit: false,
use_gzip_for_submit: false,
optimistic: false,
interval_between_submissions_ms: None,
authorization_header: None,
builder_id_header: None,
api_token_header: None,
}
];
}

#[cfg(test)]
mod test {
use super::*;
Expand Down Expand Up @@ -653,6 +761,33 @@ mod test {
.contains(&"http://localhost:3500".to_string()));
}

#[test]
fn test_parse_enabled_relays() {
let mut p = PathBuf::from(env!("CARGO_MANIFEST_DIR"));
p.push("./src/live_builder/testdata/config_with_relay_override.toml");

let config: Config = load_config_toml_and_env(p.clone()).expect("Config load");

let relays = config.l1_config.create_relays().unwrap();
assert_eq!(relays.len(), 1);
assert_eq!(relays[0].id, "playground");
assert_eq!(relays[0].priority, 10);
}

#[test]
fn test_parse_empty_relay_url() {
let mut p = PathBuf::from(env!("CARGO_MANIFEST_DIR"));
p.push("./src/live_builder/testdata/config_with_relay_empty_url.toml");

let config: Config = load_config_toml_and_env(p).expect("Config load");
assert!(config
.l1_config
.create_relays()
.unwrap_err()
.to_string()
.contains("url is required"));
}

#[test]
fn test_parse_backtest_example_config() {
let mut p = PathBuf::from(env!("CARGO_MANIFEST_DIR"));
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
log_json = true
log_level = "info,rbuilder=debug"
redacted_telemetry_server_port = 6061
redacted_telemetry_server_ip = "0.0.0.0"
full_telemetry_server_port = 6060
full_telemetry_server_ip = "0.0.0.0"

chain = "mainnet"
reth_datadir = "/mnt/data/reth"

coinbase_secret_key = "env:COINBASE_SECRET_KEY"
relay_secret_key = "env:RELAY_SECRET_KEY"
optimistic_relay_secret_key = "env:OPTIMISTIC_RELAY_SECRET_KEY"

# cl_node_url can be a single value, array of values, or passed by an environment variables with values separated with a comma
# cl_node_url = "http://localhost:3500"
cl_node_url = ["env:CL_NODE_URL"]
jsonrpc_server_port = 8645
jsonrpc_server_ip = "0.0.0.0"
el_node_ipc_path = "/tmp/reth.ipc"
extra_data = "βš‘πŸ€–"

blocklist_file_path = "./blocklist.json"

dry_run = true
dry_run_validation_url = "http://localhost:8545"

ignore_cancellable_orders = true

max_concurrent_seals = 4

# genesis_fork_version = "0x00112233"

sbundle_mergeable_signers = []
live_builders = ["mp-ordering", "mgp-ordering", "merging"]

enabled_relays = ["custom"]

[[relays]]
name = "custom"
priority = 10
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
log_json = true
log_level = "info,rbuilder=debug"
redacted_telemetry_server_port = 6061
redacted_telemetry_server_ip = "0.0.0.0"
full_telemetry_server_port = 6060
full_telemetry_server_ip = "0.0.0.0"

chain = "mainnet"
reth_datadir = "/mnt/data/reth"

coinbase_secret_key = "env:COINBASE_SECRET_KEY"
relay_secret_key = "env:RELAY_SECRET_KEY"
optimistic_relay_secret_key = "env:OPTIMISTIC_RELAY_SECRET_KEY"

# cl_node_url can be a single value, array of values, or passed by an environment variables with values separated with a comma
# cl_node_url = "http://localhost:3500"
cl_node_url = ["env:CL_NODE_URL"]
jsonrpc_server_port = 8645
jsonrpc_server_ip = "0.0.0.0"
el_node_ipc_path = "/tmp/reth.ipc"
extra_data = "βš‘πŸ€–"

blocklist_file_path = "./blocklist.json"

dry_run = true
dry_run_validation_url = "http://localhost:8545"

ignore_cancellable_orders = true

max_concurrent_seals = 4

# genesis_fork_version = "0x00112233"

sbundle_mergeable_signers = []
live_builders = ["mp-ordering", "mgp-ordering", "merging"]

enabled_relays = ["playground"]

[[relays]]
name = "playground"
priority = 10
39 changes: 35 additions & 4 deletions crates/rbuilder/src/primitives/mev_boost.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
use crate::mev_boost::{RelayClient, SubmitBlockErr, SubmitBlockRequest};
use governor::{DefaultDirectRateLimiter, Quota, RateLimiter};
use serde::{Deserialize, Deserializer};
use std::ops::BitOr;
use std::{env, sync::Arc, time::Duration};
use url::Url;

Expand All @@ -11,7 +12,8 @@ pub type MevBoostRelayID = String;
#[serde(deny_unknown_fields)]
pub struct RelayConfig {
pub name: String,
pub url: String,
pub url: Option<String>,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A RelayConfig with no url makes no sense. Why the Option?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The idea is to be able to update one of the default relays like:

relays = ["flashbots"]

[[relays]]
name = "flashbots"
use_gzip_for_submit = true

But this cannot be done because url is required.

#[serde(default)]
pub priority: usize,
// true->ssz false->json
#[serde(default)]
Expand All @@ -33,7 +35,7 @@ pub struct RelayConfig {
impl RelayConfig {
pub fn with_url(self, url: &str) -> Self {
Self {
url: url.to_string(),
url: Some(url.to_string()),
..self
}
}
Expand All @@ -46,6 +48,30 @@ impl RelayConfig {
}
}

impl BitOr for RelayConfig {
type Output = Self;

fn bitor(self, other: Self) -> Self {
if self.name != other.name {
return self;
}
Self {
name: self.name,
url: other.url.or(self.url),
priority: self.priority | other.priority,
use_ssz_for_submit: self.use_ssz_for_submit | other.use_ssz_for_submit,
use_gzip_for_submit: self.use_gzip_for_submit | other.use_gzip_for_submit,
optimistic: self.optimistic | other.optimistic,
authorization_header: other.authorization_header.or(self.authorization_header),
builder_id_header: other.builder_id_header.or(self.builder_id_header),
api_token_header: other.api_token_header.or(self.api_token_header),
interval_between_submissions_ms: other
.interval_between_submissions_ms
.or(self.interval_between_submissions_ms),
}
}
}

/// Wrapper over RelayClient that allows to submit blocks and
/// hides the particular configuration (eg: ssz, gip, optimistic).
/// Sometimes the client is used externally.
Expand All @@ -66,8 +92,13 @@ pub struct MevBoostRelay {

impl MevBoostRelay {
pub fn from_config(config: &RelayConfig) -> eyre::Result<Self> {
let url = config
.url
.as_ref()
.ok_or_else(|| eyre::eyre!("url is required"))?;

let client = {
let url: Url = config.url.parse()?;
let url: Url = url.parse()?;
RelayClient::from_url(
url,
config.authorization_header.clone(),
Expand Down Expand Up @@ -135,7 +166,7 @@ mod test {

let config: RelayConfig = toml::from_str(example).unwrap();
assert_eq!(config.name, "relay1");
assert_eq!(config.url, "url");
assert_eq!(config.url.expect("url expected"), "url");
assert_eq!(config.priority, 0);
assert_eq!(config.authorization_header.unwrap(), "AAA");
assert_eq!(config.builder_id_header.unwrap(), "BBB");
Expand Down
Loading