Skip to content

Commit

Permalink
Remove some unnecessary error types to reduce amount of changes
Browse files Browse the repository at this point in the history
  • Loading branch information
jimmygchen committed Jul 13, 2023
1 parent b6601f7 commit e9c6305
Show file tree
Hide file tree
Showing 5 changed files with 10 additions and 43 deletions.
17 changes: 2 additions & 15 deletions testing/node_test_rig/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -37,26 +37,14 @@ pub struct LocalBeaconNode<E: EthSpec> {
pub datadir: TempDir,
}

#[derive(Debug)]
pub enum LocalBeaconNodeError {
TimeoutError,
StartupError(String),
}

impl ToString for LocalBeaconNodeError {
fn to_string(&self) -> String {
format!("{:?}", self)
}
}

impl<E: EthSpec> LocalBeaconNode<E> {
/// Starts a new, production beacon node on the tokio runtime in the given `context`.
///
/// The node created is using the same types as the node we use in production.
pub async fn production(
context: RuntimeContext<E>,
mut client_config: ClientConfig,
) -> Result<Self, LocalBeaconNodeError> {
) -> Result<Self, String> {
// Creates a temporary directory that will be deleted once this `TempDir` is dropped.
let datadir = TempBuilder::new()
.prefix("lighthouse_node_test_rig")
Expand All @@ -71,12 +59,11 @@ impl<E: EthSpec> LocalBeaconNode<E> {
ProductionBeaconNode::new(context, client_config),
)
.await
.map_err(|_| LocalBeaconNodeError::TimeoutError)?
.map_err(|_| format!("Beacon node startup timed out after {:?}", STARTUP_TIMEOUT))?
.map(move |client| Self {
client: client.into_inner(),
datadir,
})
.map_err(LocalBeaconNodeError::StartupError)
}
}

Expand Down
4 changes: 1 addition & 3 deletions testing/simulator/src/eth1_sim.rs
Original file line number Diff line number Diff line change
Expand Up @@ -378,8 +378,6 @@ async fn create_local_network<E: EthSpec>(
beacon_config.execution_layer = Some(el_config);
}

let network = LocalNetwork::new(context, beacon_config.clone())
.await
.map_err(|e| e.to_string())?;
let network = LocalNetwork::new(context, beacon_config.clone()).await?;
Ok((network, beacon_config))
}
24 changes: 5 additions & 19 deletions testing/simulator/src/local_network.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
use node_test_rig::{
environment::RuntimeContext,
eth2::{types::StateId, BeaconNodeHttpClient},
ClientConfig, LocalBeaconNode, LocalBeaconNodeError, LocalExecutionNode, LocalValidatorClient,
MockExecutionConfig, MockServerConfig, ValidatorConfig, ValidatorFiles,
ClientConfig, LocalBeaconNode, LocalExecutionNode, LocalValidatorClient, MockExecutionConfig,
MockServerConfig, ValidatorConfig, ValidatorFiles,
};
use parking_lot::RwLock;
use sensitive_url::SensitiveUrl;
Expand Down Expand Up @@ -53,23 +53,12 @@ impl<E: EthSpec> Deref for LocalNetwork<E> {
}
}

#[derive(Debug)]
pub enum LocalNetworkError {
LocalBeaconNodeError(LocalBeaconNodeError),
}

impl ToString for LocalNetworkError {
fn to_string(&self) -> String {
format!("{:?}", self)
}
}

impl<E: EthSpec> LocalNetwork<E> {
/// Creates a new network with a single `BeaconNode` and a connected `ExecutionNode`.
pub async fn new(
context: RuntimeContext<E>,
mut beacon_config: ClientConfig,
) -> Result<Self, LocalNetworkError> {
) -> Result<Self, String> {
beacon_config.network.set_ipv4_listening_address(
std::net::Ipv4Addr::UNSPECIFIED,
BOOTNODE_PORT,
Expand Down Expand Up @@ -104,8 +93,7 @@ impl<E: EthSpec> LocalNetwork<E> {

let beacon_node =
LocalBeaconNode::production(context.service_context("boot_node".into()), beacon_config)
.await
.map_err(LocalNetworkError::LocalBeaconNodeError)?;
.await?;
Ok(Self {
inner: Arc::new(Inner {
context,
Expand Down Expand Up @@ -200,9 +188,7 @@ impl<E: EthSpec> LocalNetwork<E> {
self.context.service_context(format!("node_{}", count)),
beacon_config,
)
.await
.map_err(|e| e.to_string())?;

.await?;
if is_proposer {
self_1.proposer_nodes.write().push(beacon_node);
} else {
Expand Down
4 changes: 1 addition & 3 deletions testing/simulator/src/no_eth1_sim.rs
Original file line number Diff line number Diff line change
Expand Up @@ -95,9 +95,7 @@ pub fn run_no_eth1_sim(matches: &ArgMatches) -> Result<(), String> {
beacon_config.network.enr_address = (Some(Ipv4Addr::LOCALHOST), None);

let main_future = async {
let network = LocalNetwork::new(context.clone(), beacon_config.clone())
.await
.map_err(|e| e.to_string())?;
let network = LocalNetwork::new(context.clone(), beacon_config.clone()).await?;
/*
* One by one, add beacon nodes to the network.
*/
Expand Down
4 changes: 1 addition & 3 deletions testing/simulator/src/sync_sim.rs
Original file line number Diff line number Diff line change
Expand Up @@ -106,9 +106,7 @@ fn syncing_sim(
/*
* Create a new `LocalNetwork` with one beacon node.
*/
let network = LocalNetwork::new(context, beacon_config.clone())
.await
.map_err(|e| e.to_string())?;
let network = LocalNetwork::new(context, beacon_config.clone()).await?;

/*
* Add a validator client which handles all validators from the genesis state.
Expand Down

0 comments on commit e9c6305

Please sign in to comment.