Skip to content

Commit

Permalink
Add feedback
Browse files Browse the repository at this point in the history
  • Loading branch information
ferranbt committed Jan 2, 2025
2 parents 8f5d572 + 20f8c83 commit 35b5a26
Show file tree
Hide file tree
Showing 4 changed files with 52 additions and 46 deletions.
4 changes: 2 additions & 2 deletions crates/rbuilder/src/bin/dummy-builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ use rbuilder::{
},
live_builder::{
base_config::{
DEFAULT_EL_NODE_IPC_PATH, DEFAULT_INCOMING_BUNDLES_PORT, DEFAULT_IP,
default_ip, DEFAULT_EL_NODE_IPC_PATH, DEFAULT_INCOMING_BUNDLES_PORT,
DEFAULT_RETH_DB_PATH,
},
config::create_provider_factory,
Expand Down Expand Up @@ -80,7 +80,7 @@ async fn main() -> eyre::Result<()> {
true,
DEFAULT_EL_NODE_IPC_PATH.parse().unwrap(),
DEFAULT_INCOMING_BUNDLES_PORT,
*DEFAULT_IP,
default_ip(),
DEFAULT_SERVE_MAX_CONNECTIONS,
DEFAULT_RESULTS_CHANNEL_TIMEOUT,
DEFAULT_INPUT_CHANNEL_BUFFER_SIZE,
Expand Down
18 changes: 15 additions & 3 deletions crates/rbuilder/src/blocklist/mod.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
use ahash::{HashSet, HashSetExt};
use alloy_primitives::Address;
use serde::{Deserialize, Deserializer};
use std::convert::TryFrom;
use std::fs::read_to_string;
use std::ops::Deref;
use std::path::PathBuf;

#[allow(clippy::len_without_is_empty)]
Expand Down Expand Up @@ -40,9 +42,11 @@ impl BlockList {
}
}

impl From<PathBuf> for BlockList {
fn from(path: PathBuf) -> Self {
Self::from_file(path).unwrap_or_else(|_| Self::new())
impl TryFrom<PathBuf> for BlockList {
type Error = eyre::Report; // Using eyre::Report since from_file returns eyre::Result

fn try_from(path: PathBuf) -> Result<Self, Self::Error> {
Self::from_file(path)
}
}

Expand All @@ -54,6 +58,14 @@ impl From<Vec<Address>> for BlockList {
}
}

impl Deref for BlockList {
type Target = HashSet<Address>;

fn deref(&self) -> &Self::Target {
&self.list
}
}

impl<'de> Deserialize<'de> for BlockList {
fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>
where
Expand Down
74 changes: 34 additions & 40 deletions crates/rbuilder/src/live_builder/base_config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ use crate::{
use alloy_primitives::{Address, B256};
use eyre::{eyre, Context};
use jsonrpsee::RpcModule;
use lazy_static::lazy_static;
use reth::chainspec::chain_value_parser;
use reth_chainspec::ChainSpec;
use reth_db::{Database, DatabaseEnv};
Expand Down Expand Up @@ -48,9 +47,13 @@ const ENV_PREFIX: &str = "env:";
#[serde(default, deny_unknown_fields)]
pub struct BaseConfig {
pub full_telemetry_server_port: u16,
pub full_telemetry_server_ip: Option<String>,
#[serde(default = "default_ip")]
pub full_telemetry_server_ip: Ipv4Addr,

pub redacted_telemetry_server_port: u16,
pub redacted_telemetry_server_ip: Option<String>,
#[serde(default = "default_ip")]
pub redacted_telemetry_server_ip: Ipv4Addr,

pub log_json: bool,
log_level: EnvOrValue<String>,
pub log_color: bool,
Expand All @@ -65,7 +68,8 @@ pub struct BaseConfig {

pub el_node_ipc_path: PathBuf,
pub jsonrpc_server_port: u16,
pub jsonrpc_server_ip: Option<String>,
#[serde(default = "default_ip")]
pub jsonrpc_server_ip: Ipv4Addr,

pub ignore_cancellable_orders: bool,
pub ignore_blobs: bool,
Expand All @@ -76,7 +80,9 @@ pub struct BaseConfig {
pub reth_static_files_path: Option<PathBuf>,

pub blocklist_file_path: BlockList,
pub extra_data: String,

#[serde(deserialize_with = "deserialize_extra_data")]
pub extra_data: Vec<u8>,

/// mev-share bundles coming from this address are treated in a special way(see [`ShareBundleMerger`])
pub sbundle_mergeable_signers: Option<Vec<Address>>,
Expand Down Expand Up @@ -108,14 +114,8 @@ pub struct BaseConfig {
pub backtest_protect_bundle_signers: Vec<Address>,
}

lazy_static! {
pub static ref DEFAULT_IP: Ipv4Addr = Ipv4Addr::new(0, 0, 0, 0);
}

fn parse_ip(ip: &Option<String>) -> Ipv4Addr {
ip.as_ref().map_or(*DEFAULT_IP, |s| {
s.parse::<Ipv4Addr>().unwrap_or(*DEFAULT_IP)
})
pub fn default_ip() -> Ipv4Addr {
Ipv4Addr::new(0, 0, 0, 0)
}

/// Loads config from toml file, some values can be loaded from env variables with the following syntax
Expand Down Expand Up @@ -157,14 +157,14 @@ impl BaseConfig {

pub fn redacted_telemetry_server_address(&self) -> SocketAddr {
SocketAddr::V4(SocketAddrV4::new(
self.redacted_telemetry_server_ip(),
self.redacted_telemetry_server_ip,
self.redacted_telemetry_server_port,
))
}

pub fn full_telemetry_server_address(&self) -> SocketAddr {
SocketAddr::V4(SocketAddrV4::new(
self.full_telemetry_server_ip(),
self.full_telemetry_server_ip,
self.full_telemetry_server_port,
))
}
Expand Down Expand Up @@ -221,8 +221,8 @@ impl BaseConfig {
provider,

coinbase_signer: self.coinbase_signer()?,
extra_data: self.extra_data()?,
blocklist: self.blocklist_file_path.clone(),
extra_data: self.extra_data.clone(),

global_cancellation: cancellation_token,

Expand All @@ -238,18 +238,6 @@ impl BaseConfig {
})
}

pub fn jsonrpc_server_ip(&self) -> Ipv4Addr {
parse_ip(&self.jsonrpc_server_ip)
}

pub fn redacted_telemetry_server_ip(&self) -> Ipv4Addr {
parse_ip(&self.redacted_telemetry_server_ip)
}

pub fn full_telemetry_server_ip(&self) -> Ipv4Addr {
parse_ip(&self.full_telemetry_server_ip)
}

pub fn chain_spec(&self) -> eyre::Result<Arc<ChainSpec>> {
chain_value_parser(&self.chain)
}
Expand Down Expand Up @@ -299,14 +287,6 @@ impl BaseConfig {
coinbase_signer_from_secret_key(&self.coinbase_secret_key.value()?)
}

pub fn extra_data(&self) -> eyre::Result<Vec<u8>> {
let extra_data = self.extra_data.clone().into_bytes();
if extra_data.len() > 32 {
return Err(eyre::eyre!("Extra data is too long"));
}
Ok(extra_data)
}

pub fn eth_rpc_provider(&self) -> eyre::Result<BoxedProvider> {
Ok(http_provider(self.backtest_fetch_eth_rpc_url.parse()?))
}
Expand Down Expand Up @@ -409,9 +389,9 @@ impl Default for BaseConfig {
fn default() -> Self {
Self {
full_telemetry_server_port: 6069,
full_telemetry_server_ip: None,
full_telemetry_server_ip: default_ip(),
redacted_telemetry_server_port: 6070,
redacted_telemetry_server_ip: None,
redacted_telemetry_server_ip: default_ip(),
log_json: false,
log_level: "info".into(),
log_color: false,
Expand All @@ -421,15 +401,15 @@ impl Default for BaseConfig {
flashbots_db: None,
el_node_ipc_path: "/tmp/reth.ipc".parse().unwrap(),
jsonrpc_server_port: DEFAULT_INCOMING_BUNDLES_PORT,
jsonrpc_server_ip: None,
jsonrpc_server_ip: default_ip(),
ignore_cancellable_orders: true,
ignore_blobs: false,
chain: "mainnet".to_string(),
reth_datadir: Some(DEFAULT_RETH_DB_PATH.parse().unwrap()),
reth_db_path: None,
reth_static_files_path: None,
blocklist_file_path: Default::default(),
extra_data: "extra_data_change_me".to_string(),
extra_data: b"extra_data_change_me".to_vec(),
root_hash_use_sparse_trie: false,
root_hash_compare_sparse_trie: false,
watchdog_timeout_sec: None,
Expand All @@ -448,6 +428,20 @@ impl Default for BaseConfig {
}
}

fn deserialize_extra_data<'de, D>(deserializer: D) -> Result<Vec<u8>, D::Error>
where
D: Deserializer<'de>,
{
let s = String::deserialize(deserializer)?;
let bytes = s.into_bytes();
if bytes.len() > 32 {
return Err(serde::de::Error::custom(
"Extra data is too long (max 32 bytes)",
));
}
Ok(bytes)
}

/// Open reth db and DB should be opened once per process but it can be cloned and moved to different threads.
pub fn create_provider_factory(
reth_datadir: Option<&Path>,
Expand Down
2 changes: 1 addition & 1 deletion crates/rbuilder/src/live_builder/order_input/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@ impl OrderInputConfig {
ignore_blobs: config.ignore_blobs,
ipc_path: el_node_ipc_path,
server_port: config.jsonrpc_server_port,
server_ip: config.jsonrpc_server_ip(),
server_ip: config.jsonrpc_server_ip,
serve_max_connections: 4096,
results_channel_timeout: Duration::from_millis(50),
input_channel_buffer_size: 10_000,
Expand Down

0 comments on commit 35b5a26

Please sign in to comment.