Skip to content

Commit

Permalink
Return result in client builder
Browse files Browse the repository at this point in the history
  • Loading branch information
paulhauner committed Sep 16, 2020
1 parent 09494e0 commit e49a3e1
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 35 deletions.
50 changes: 25 additions & 25 deletions beacon_node/client/src/builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -335,19 +335,25 @@ where
/// If type inference errors are being raised, see the comment on the definition of `Self`.
pub fn build(
self,
) -> Client<
Witness<
TStoreMigrator,
TSlotClock,
TEth1Backend,
TEthSpec,
TEventHandler,
THotStore,
TColdStore,
) -> Result<
Client<
Witness<
TStoreMigrator,
TSlotClock,
TEth1Backend,
TEthSpec,
TEventHandler,
THotStore,
TColdStore,
>,
>,
String,
> {
// TODO: fix unwrap.
let log = self.runtime_context.as_ref().unwrap().log().clone();
let runtime_context = self
.runtime_context
.as_ref()
.ok_or_else(|| "build requires a runtime context".to_string())?;
let log = runtime_context.log().clone();

let http_api_listen_addr = if self.http_api_config.enabled {
let ctx = Arc::new(http_api::Context {
Expand All @@ -358,16 +364,13 @@ where
log: log.clone(),
});

// TODO
let exit = self.runtime_context.as_ref().unwrap().executor.exit();
let exit = runtime_context.executor.exit();

let (listen_addr, server) = http_api::serve(ctx, exit)
.map_err(|e| format!("Unable to start HTTP API server: {:?}", e))
.unwrap(); // TODO
.map_err(|e| format!("Unable to start HTTP API server: {:?}", e))?;

self.runtime_context
runtime_context
.clone()
.unwrap()
.executor
.spawn_without_exit(async move { server.await }, "http-api");

Expand All @@ -386,15 +389,12 @@ where
log: log.clone(),
});

// TODO
let exit = self.runtime_context.as_ref().unwrap().executor.exit();
let exit = runtime_context.executor.exit();

let (listen_addr, server) = http_metrics::serve(ctx, exit)
.map_err(|e| format!("Unable to start HTTP API server: {:?}", e))
.unwrap(); // TODO
.map_err(|e| format!("Unable to start HTTP API server: {:?}", e))?;

self.runtime_context
.unwrap()
runtime_context
.executor
.spawn_without_exit(async move { server.await }, "http-api");

Expand All @@ -404,13 +404,13 @@ where
None
};

Client {
Ok(Client {
beacon_chain: self.beacon_chain,
network_globals: self.network_globals,
http_api_listen_addr,
http_metrics_listen_addr,
websocket_listen_addr: self.websocket_listen_addr,
}
})
}
}

Expand Down
19 changes: 9 additions & 10 deletions beacon_node/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -124,16 +124,15 @@ impl<E: EthSpec> ProductionBeaconNode<E> {
// Inject the executor into the discv5 network config.
client_config.network.discv5_config.executor = Some(Box::new(executor));

Ok(Self(
builder
.build_beacon_chain()?
.network(&client_config.network)
.await?
.notifier()?
.http_api_config(client_config.http_api.clone())
.http_metrics_config(client_config.http_metrics.clone())
.build(),
))
builder
.build_beacon_chain()?
.network(&client_config.network)
.await?
.notifier()?
.http_api_config(client_config.http_api.clone())
.http_metrics_config(client_config.http_metrics.clone())
.build()
.map(Self)
}

pub fn into_inner(self) -> ProductionClient<E> {
Expand Down

0 comments on commit e49a3e1

Please sign in to comment.