Skip to content

Commit

Permalink
remove unnecessary Context override param
Browse files Browse the repository at this point in the history
  • Loading branch information
ralexstokes committed Oct 19, 2023
1 parent bd69c15 commit 6d06357
Show file tree
Hide file tree
Showing 5 changed files with 12 additions and 17 deletions.
2 changes: 1 addition & 1 deletion bin/mev/src/cmd/boost.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ impl Command {
info!("configured for {network}");

if let Some(config) = config.boost {
Ok(Service::from(network, config).spawn(None)?.await?)
Ok(Service::from(network, config).spawn()?.await?)
} else {
Err(anyhow!("missing boost config from file provided"))
}
Expand Down
2 changes: 1 addition & 1 deletion bin/mev/src/cmd/relay.rs
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ impl Command {
info!("configured for {network}");

if let Some(config) = config.relay {
let service = Service::from(network, config).spawn(None).await?;
let service = Service::from(network, config).spawn().await?;
Ok(service.await?)
} else {
Err(anyhow!("missing relay config from file provided"))
Expand Down
5 changes: 2 additions & 3 deletions mev-boost-rs/src/service.rs
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ impl Service {
}

/// Spawns a new [`RelayMux`] and [`BlindedBlockProviderServer`] task
pub fn spawn(self, context: Option<Context>) -> Result<ServiceHandle, Error> {
pub fn spawn(self) -> Result<ServiceHandle, Error> {
let Self { host, port, relays, network } = self;

if relays.is_empty() {
Expand All @@ -71,8 +71,7 @@ impl Service {
}
}

let context =
if let Some(context) = context { context } else { Context::try_from(&network)? };
let context = Context::try_from(&network)?;
let relays = relays.into_iter().map(Relay::from);
let clock = context.clock().unwrap_or_else(|| {
let genesis_time = networks::typical_genesis_time(&context);
Expand Down
15 changes: 6 additions & 9 deletions mev-boost-rs/tests/integration.rs
Original file line number Diff line number Diff line change
Expand Up @@ -75,10 +75,8 @@ async fn test_end_to_end() {

let genesis_validators_root = Root::try_from([23u8; 32].as_ref()).unwrap();

let mut context = Context::for_mainnet();
// mock epoch values to transition across forks
context.bellatrix_fork_epoch = 12;
context.capella_fork_epoch = 22;
let network = Network::Sepolia;
let context = Context::try_from(&network).unwrap();

// NOTE: non-default secret key required. otherwise public key is point at infinity and
// signature verification will fail.
Expand All @@ -94,12 +92,11 @@ async fn test_end_to_end() {

// start mux server
let mut config = Config::default();
config.relays.push(format!("http://{relay_public_key}@127.0.0.1:{port}"));
config.relays.push(format!("http://{relay_public_key:?}@127.0.0.1:{port}"));

let mux_port = config.port;
let network = Network::Sepolia;
let service = Service::from(network, config);
service.spawn(Some(context.clone())).unwrap();
service.spawn().unwrap();

let beacon_node = RelayClient::new(ApiClient::new(
Url::parse(&format!("http://127.0.0.1:{mux_port}")).unwrap(),
Expand Down Expand Up @@ -142,8 +139,8 @@ async fn propose_block(
) {
let fork = if shuffling_index == 0 { Fork::Bellatrix } else { Fork::Capella };
let current_slot = match fork {
Fork::Bellatrix => 32 + context.bellatrix_fork_epoch * context.slots_per_epoch,
Fork::Capella => 32 + context.capella_fork_epoch * context.slots_per_epoch,
Fork::Bellatrix => 30 + context.bellatrix_fork_epoch * context.slots_per_epoch,
Fork::Capella => 30 + context.capella_fork_epoch * context.slots_per_epoch,
_ => unimplemented!(),
};
let parent_hash = Hash32::try_from([shuffling_index as u8; 32].as_ref()).unwrap();
Expand Down
5 changes: 2 additions & 3 deletions mev-relay-rs/src/service.rs
Original file line number Diff line number Diff line change
Expand Up @@ -54,11 +54,10 @@ impl Service {

/// Configures the [`Relay`] and the [`BlindedBlockProviderServer`] and spawns both to
/// individual tasks
pub async fn spawn(self, context: Option<Context>) -> Result<ServiceHandle, Error> {
pub async fn spawn(self) -> Result<ServiceHandle, Error> {
let Self { host, port, beacon_node, network, secret_key } = self;

let context =
if let Some(context) = context { context } else { Context::try_from(&network)? };
let context = Context::try_from(&network)?;
let clock = context.clock().unwrap_or_else(|| {
let genesis_time = networks::typical_genesis_time(&context);
context.clock_at(genesis_time)
Expand Down

0 comments on commit 6d06357

Please sign in to comment.