From 2edb4abaf145b708c44f915fa98f0deb7ab43d12 Mon Sep 17 00:00:00 2001 From: gajinder Date: Sun, 5 May 2024 17:26:13 +0530 Subject: [PATCH 1/6] dedup relay endpoints in boost and builder configs --- mev-rs/src/relay.rs | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/mev-rs/src/relay.rs b/mev-rs/src/relay.rs index 7bb65238..9c67bcec 100644 --- a/mev-rs/src/relay.rs +++ b/mev-rs/src/relay.rs @@ -29,6 +29,21 @@ impl TryFrom for RelayEndpoint { } } +impl hash::Hash for RelayEndpoint { + fn hash(&self, state: &mut H) { + self.public_key.hash(state); + } +} + +impl cmp::PartialEq for RelayEndpoint { + fn eq(&self, other: &Self) -> bool { + self.public_key == other.public_key + } +} + +impl cmp::Eq for RelayEndpoint {} + + impl fmt::Debug for RelayEndpoint { fn fmt(&self, f: &mut fmt::Formatter<'_>) -> Result<(), fmt::Error> { f.write_str(self.url.as_str()) From dd1afba18a367ff171079318f29edb992c004901 Mon Sep 17 00:00:00 2001 From: gajinder Date: Sun, 5 May 2024 22:05:05 +0530 Subject: [PATCH 2/6] use hashset instead of vec to dedub boost service relay endpoint --- mev-boost-rs/src/service.rs | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/mev-boost-rs/src/service.rs b/mev-boost-rs/src/service.rs index 92b196b2..4d3941b5 100644 --- a/mev-boost-rs/src/service.rs +++ b/mev-boost-rs/src/service.rs @@ -11,6 +11,7 @@ use serde::Deserialize; use std::{future::Future, net::Ipv4Addr, pin::Pin, task::Poll}; use tokio::task::{JoinError, JoinHandle}; use tracing::{info, warn}; +use std::collections::HashSet; #[derive(Debug, Deserialize)] pub struct Config { @@ -29,7 +30,7 @@ impl Default for Config { pub struct Service { host: Ipv4Addr, port: u16, - relays: Vec, + relays: HashSet, network: Network, config: Config, } @@ -37,8 +38,12 @@ pub struct Service { impl Service { pub fn from(network: Network, config: Config) -> Self { let relays = parse_relay_endpoints(&config.relays); + let mut relayset: HashSet = HashSet::new(); + for relay in relays.into_iter(){ + relayset.insert(relay); + } - Self { host: config.host, port: config.port, relays, network, config } + Self { host: config.host, port: config.port, relays: relayset, network, config } } /// Spawns a new [`RelayMux`] and [`BlindedBlockProviderServer`] task From 9c9c61429407b6652215d301b494f6a65dd59e87 Mon Sep 17 00:00:00 2001 From: gajinder Date: Sun, 5 May 2024 22:26:05 +0530 Subject: [PATCH 3/6] restore to vec in service --- mev-boost-rs/src/service.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/mev-boost-rs/src/service.rs b/mev-boost-rs/src/service.rs index 4d3941b5..43e54122 100644 --- a/mev-boost-rs/src/service.rs +++ b/mev-boost-rs/src/service.rs @@ -30,7 +30,7 @@ impl Default for Config { pub struct Service { host: Ipv4Addr, port: u16, - relays: HashSet, + relays: Vec, network: Network, config: Config, } @@ -43,7 +43,7 @@ impl Service { relayset.insert(relay); } - Self { host: config.host, port: config.port, relays: relayset, network, config } + Self { host: config.host, port: config.port, relays: Vec::from_iter(relayset), network, config } } /// Spawns a new [`RelayMux`] and [`BlindedBlockProviderServer`] task From 97aa3b34162e573ea33dc483d2f68b3177012916 Mon Sep 17 00:00:00 2001 From: gajinder Date: Sun, 5 May 2024 22:40:58 +0530 Subject: [PATCH 4/6] dedup auctioneer config relays --- mev-build-rs/src/auctioneer/service.rs | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/mev-build-rs/src/auctioneer/service.rs b/mev-build-rs/src/auctioneer/service.rs index 48006b52..8acf70ff 100644 --- a/mev-build-rs/src/auctioneer/service.rs +++ b/mev-build-rs/src/auctioneer/service.rs @@ -17,7 +17,7 @@ use mev_rs::{ relay::parse_relay_endpoints, signing::sign_builder_message, types::{block_submission, BidTrace, SignedBidSubmission}, - BlindedBlockRelayer, Relay, + BlindedBlockRelayer, Relay, RelayEndpoint, }; use reth::{ api::{EngineTypes, PayloadBuilderAttributes}, @@ -155,8 +155,13 @@ impl< context: Arc, genesis_time: u64, ) -> Self { - let relays = - parse_relay_endpoints(&config.relays).into_iter().map(Relay::from).collect::>(); + let relays = parse_relay_endpoints(&config.relays); + let mut relayset: HashSet = HashSet::new(); + for relay in relays.into_iter(){ + relayset.insert(relay); + } + + let relays = relayset.into_iter().map(Relay::from).collect::>(); config.public_key = config.secret_key.public_key(); From 514a368d19bd8d9ab348d2c96e1378a985980a76 Mon Sep 17 00:00:00 2001 From: gajinder Date: Fri, 10 May 2024 20:15:22 +0530 Subject: [PATCH 5/6] directly use vec dedup --- mev-boost-rs/src/service.rs | 7 +------ mev-build-rs/src/auctioneer/service.rs | 11 +++-------- mev-rs/src/relay.rs | 14 +++++++------- 3 files changed, 11 insertions(+), 21 deletions(-) diff --git a/mev-boost-rs/src/service.rs b/mev-boost-rs/src/service.rs index 43e54122..92b196b2 100644 --- a/mev-boost-rs/src/service.rs +++ b/mev-boost-rs/src/service.rs @@ -11,7 +11,6 @@ use serde::Deserialize; use std::{future::Future, net::Ipv4Addr, pin::Pin, task::Poll}; use tokio::task::{JoinError, JoinHandle}; use tracing::{info, warn}; -use std::collections::HashSet; #[derive(Debug, Deserialize)] pub struct Config { @@ -38,12 +37,8 @@ pub struct Service { impl Service { pub fn from(network: Network, config: Config) -> Self { let relays = parse_relay_endpoints(&config.relays); - let mut relayset: HashSet = HashSet::new(); - for relay in relays.into_iter(){ - relayset.insert(relay); - } - Self { host: config.host, port: config.port, relays: Vec::from_iter(relayset), network, config } + Self { host: config.host, port: config.port, relays, network, config } } /// Spawns a new [`RelayMux`] and [`BlindedBlockProviderServer`] task diff --git a/mev-build-rs/src/auctioneer/service.rs b/mev-build-rs/src/auctioneer/service.rs index 8acf70ff..48006b52 100644 --- a/mev-build-rs/src/auctioneer/service.rs +++ b/mev-build-rs/src/auctioneer/service.rs @@ -17,7 +17,7 @@ use mev_rs::{ relay::parse_relay_endpoints, signing::sign_builder_message, types::{block_submission, BidTrace, SignedBidSubmission}, - BlindedBlockRelayer, Relay, RelayEndpoint, + BlindedBlockRelayer, Relay, }; use reth::{ api::{EngineTypes, PayloadBuilderAttributes}, @@ -155,13 +155,8 @@ impl< context: Arc, genesis_time: u64, ) -> Self { - let relays = parse_relay_endpoints(&config.relays); - let mut relayset: HashSet = HashSet::new(); - for relay in relays.into_iter(){ - relayset.insert(relay); - } - - let relays = relayset.into_iter().map(Relay::from).collect::>(); + let relays = + parse_relay_endpoints(&config.relays).into_iter().map(Relay::from).collect::>(); config.public_key = config.secret_key.public_key(); diff --git a/mev-rs/src/relay.rs b/mev-rs/src/relay.rs index 9c67bcec..07aa96a2 100644 --- a/mev-rs/src/relay.rs +++ b/mev-rs/src/relay.rs @@ -30,20 +30,19 @@ impl TryFrom for RelayEndpoint { } impl hash::Hash for RelayEndpoint { - fn hash(&self, state: &mut H) { - self.public_key.hash(state); - } + fn hash(&self, state: &mut H) { + self.public_key.hash(state); + } } impl cmp::PartialEq for RelayEndpoint { - fn eq(&self, other: &Self) -> bool { - self.public_key == other.public_key - } + fn eq(&self, other: &Self) -> bool { + self.public_key == other.public_key + } } impl cmp::Eq for RelayEndpoint {} - impl fmt::Debug for RelayEndpoint { fn fmt(&self, f: &mut fmt::Formatter<'_>) -> Result<(), fmt::Error> { f.write_str(self.url.as_str()) @@ -72,6 +71,7 @@ pub fn parse_relay_endpoints(relay_urls: &[String]) -> Vec { if relays.is_empty() { error!("no relays could be loaded from the configuration; please fix and restart"); } + relays.dedup(); relays } From 778053c63c3210b286a244160bea3718fb0cab54 Mon Sep 17 00:00:00 2001 From: gajinder Date: Fri, 10 May 2024 20:41:11 +0530 Subject: [PATCH 6/6] sort and dedup --- mev-rs/src/relay.rs | 10 ++-------- 1 file changed, 2 insertions(+), 8 deletions(-) diff --git a/mev-rs/src/relay.rs b/mev-rs/src/relay.rs index 07aa96a2..e4db40d4 100644 --- a/mev-rs/src/relay.rs +++ b/mev-rs/src/relay.rs @@ -13,6 +13,7 @@ use std::{cmp, fmt, hash, ops::Deref}; use tracing::{error, warn}; use url::Url; +#[derive(PartialOrd, Ord, Eq)] pub struct RelayEndpoint { url: Url, public_key: BlsPublicKey, @@ -29,20 +30,12 @@ impl TryFrom for RelayEndpoint { } } -impl hash::Hash for RelayEndpoint { - fn hash(&self, state: &mut H) { - self.public_key.hash(state); - } -} - impl cmp::PartialEq for RelayEndpoint { fn eq(&self, other: &Self) -> bool { self.public_key == other.public_key } } -impl cmp::Eq for RelayEndpoint {} - impl fmt::Debug for RelayEndpoint { fn fmt(&self, f: &mut fmt::Formatter<'_>) -> Result<(), fmt::Error> { f.write_str(self.url.as_str()) @@ -71,6 +64,7 @@ pub fn parse_relay_endpoints(relay_urls: &[String]) -> Vec { if relays.is_empty() { error!("no relays could be loaded from the configuration; please fix and restart"); } + relays.sort(); relays.dedup(); relays }