Add --staking flag (#1641)

## Issue Addressed

Closes #1472 

## Proposed Changes

Add `--staking` ~~and`staking-with-eth1-endpoint`~~ flag to improve UX for stakers.


Co-authored-by: Paul Hauner <paul@paulhauner.com>
This commit is contained in:
Pawan Dhananjay 2020-09-23 01:19:58 +00:00
parent b75df29501
commit 80ecafaae4
5 changed files with 60 additions and 5 deletions

View File

@ -599,8 +599,15 @@ where
.ok_or_else(|| "caching_eth1_backend requires a chain spec".to_string())?;
// Check if the eth1 endpoint we connect to is on the correct network id.
// Note: This check also effectively checks the eth1 http connection before the beacon chain
// is completely started and fails loudly if there is an issue.
let network_id =
eth1::http::get_network_id(&config.endpoint, Duration::from_millis(15_000)).await?;
eth1::http::check_eth1_endpoint(&config.endpoint, Duration::from_millis(15_000))
.await
.map_err(|_| "Error connecting to eth1 node.\n\
Please ensure that you have an eth1 http server running locally on localhost:8545 \
or pass an external endpoint using `--eth1-endpoint <SERVER-ADDRESS>`.\n\
Also ensure that `eth` and `net` apis are enabled on the eth1 http server.".to_string())?;
if network_id != config.network_id {
return Err(format!(

View File

@ -55,6 +55,19 @@ impl FromStr for Eth1NetworkId {
}
}
/// Checks that the provided eth1 node has all the relevant api endpoints open
/// and returns the network id.
pub async fn check_eth1_endpoint(
endpoint: &str,
timeout: Duration,
) -> Result<Eth1NetworkId, String> {
// Checks that the "eth" api works as expected.
let _block_number = get_block_number(endpoint, timeout).await?;
// Checks that the "net" api works as expected.
let network_id = get_network_id(endpoint, timeout).await?;
Ok(network_id)
}
/// Get the eth1 network id of the given endpoint.
pub async fn get_network_id(endpoint: &str, timeout: Duration) -> Result<Eth1NetworkId, String> {
let response_body = send_rpc_request(endpoint, "net_version", json!([]), timeout).await?;

View File

@ -193,6 +193,19 @@ pub fn cli_app<'a, 'b>() -> App<'a, 'b> {
.takes_value(true),
)
/*
* Standard staking flags
*/
.arg(
Arg::with_name("staking")
.long("staking")
.help("Standard option for a staking beacon node. Equivalent to \
`lighthouse bn --http --eth1 `. This will enable the http server on localhost:5052 \
and try connecting to an eth1 node on localhost:8545")
.takes_value(false)
)
/*
* Eth1 Integration
*/

View File

@ -4,7 +4,7 @@ use clap_utils::BAD_TESTNET_DIR_MESSAGE;
use client::{config::DEFAULT_DATADIR, ClientConfig, ClientGenesis};
use eth2_libp2p::{multiaddr::Protocol, Enr, Multiaddr, NetworkConfig, PeerIdSerialized};
use eth2_testnet_config::Eth2TestnetConfig;
use slog::{crit, info, Logger};
use slog::{crit, info, warn, Logger};
use ssz::Encode;
use std::cmp;
use std::fs;
@ -83,6 +83,16 @@ pub fn get_config<E: EthSpec>(
false,
)?;
/*
* Staking flag
* Note: the config values set here can be overwritten by other more specific cli params
*/
if cli_args.is_present("staking") {
client_config.rest_api.enabled = true;
client_config.sync_eth1_chain = true;
}
/*
* Http server
*/
@ -112,6 +122,15 @@ pub fn get_config<E: EthSpec>(
client_config.rest_api.allow_origin = allow_origin.to_string();
}
// Log a warning indicating an open HTTP server if it wasn't specified explicitly
// (e.g. using the --staking flag).
if cli_args.is_present("staking") {
warn!(
log,
"Running HTTP server on port {}", client_config.rest_api.port
);
}
/*
* Websocket server
*/
@ -426,7 +445,7 @@ pub fn set_network_config(
if cli_args.is_present("disable-discovery") {
config.disable_discovery = true;
slog::warn!(log, "Discovery is disabled. New peers will not be found");
warn!(log, "Discovery is disabled. New peers will not be found");
}
Ok(())

View File

@ -47,7 +47,7 @@ the internet and maintains a view of the chain.
Start your beacon node with:
```bash
lighthouse --testnet medalla beacon --eth1 --http
lighthouse --testnet medalla beacon --staking
```
> The `--testnet` parameter is optional. Omitting it will default to the
@ -55,8 +55,11 @@ Start your beacon node with:
> Current values are either `altona` or `medalla`. This is true for all the
> following commands in this document.
>Note: the `--http` flag enables the HTTP API for the validator client. And the `--eth1` flag tells the beacon node that it should sync with an Ethereum1 node (e.g. Geth). These flags are only required if you wish to run a validator.
You can also pass an external http endpoint (e.g. Infura) for the Eth1 node using the `--eth1-endpoint` flag:
```bash
lighthouse --testnet medalla beacon --staking --eth1-endpoint <ETH1-SERVER>
```
Your beacon node has started syncing when you see the following (truncated)
log: