2021-08-30 23:27:28 +00:00
|
|
|
//! This crate primarily exists to serve the `common/eth2_network_configs` crate, by providing the
|
|
|
|
//! canonical list of built-in-networks and some tooling to help include those configurations in the
|
|
|
|
//! `lighthouse` binary.
|
|
|
|
//!
|
|
|
|
//! It also provides some additional structs which are useful to other components of `lighthouse`
|
|
|
|
//! (e.g., `Eth2Config`).
|
|
|
|
|
2020-07-29 06:39:29 +00:00
|
|
|
use std::env;
|
|
|
|
use std::path::PathBuf;
|
2020-10-28 22:19:38 +00:00
|
|
|
use types::{ChainSpec, EthSpecId};
|
2019-06-08 17:17:03 +00:00
|
|
|
|
2021-08-30 23:27:28 +00:00
|
|
|
pub use paste::paste;
|
|
|
|
|
2020-10-25 22:15:46 +00:00
|
|
|
// A macro is used to define this constant so it can be used with `include_bytes!`.
|
|
|
|
#[macro_export]
|
2020-12-08 05:41:10 +00:00
|
|
|
macro_rules! predefined_networks_dir {
|
2020-10-25 22:15:46 +00:00
|
|
|
() => {
|
2020-12-08 05:41:10 +00:00
|
|
|
"built_in_network_configs"
|
2020-10-25 22:15:46 +00:00
|
|
|
};
|
|
|
|
}
|
|
|
|
|
2020-12-08 05:41:10 +00:00
|
|
|
pub const PREDEFINED_NETWORKS_DIR: &str = predefined_networks_dir!();
|
2020-10-25 22:15:46 +00:00
|
|
|
pub const GENESIS_FILE_NAME: &str = "genesis.ssz";
|
|
|
|
pub const GENESIS_ZIP_FILE_NAME: &str = "genesis.ssz.zip";
|
|
|
|
|
2019-06-08 17:17:03 +00:00
|
|
|
/// The core configuration of a Lighthouse beacon node.
|
2021-01-19 09:39:51 +00:00
|
|
|
#[derive(Debug, Clone)]
|
2019-06-08 17:17:03 +00:00
|
|
|
pub struct Eth2Config {
|
2020-10-28 22:19:38 +00:00
|
|
|
pub eth_spec_id: EthSpecId,
|
2019-06-08 17:17:03 +00:00
|
|
|
pub spec: ChainSpec,
|
|
|
|
}
|
|
|
|
|
|
|
|
impl Default for Eth2Config {
|
|
|
|
fn default() -> Self {
|
|
|
|
Self {
|
2020-10-28 22:19:38 +00:00
|
|
|
eth_spec_id: EthSpecId::Minimal,
|
2019-06-08 17:17:03 +00:00
|
|
|
spec: ChainSpec::minimal(),
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-06-08 21:53:22 +00:00
|
|
|
impl Eth2Config {
|
|
|
|
pub fn mainnet() -> Self {
|
|
|
|
Self {
|
2020-10-28 22:19:38 +00:00
|
|
|
eth_spec_id: EthSpecId::Mainnet,
|
2019-06-08 21:53:22 +00:00
|
|
|
spec: ChainSpec::mainnet(),
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
pub fn minimal() -> Self {
|
|
|
|
Self {
|
2020-10-28 22:19:38 +00:00
|
|
|
eth_spec_id: EthSpecId::Minimal,
|
2019-06-08 21:53:22 +00:00
|
|
|
spec: ChainSpec::minimal(),
|
|
|
|
}
|
|
|
|
}
|
2022-01-27 22:58:33 +00:00
|
|
|
|
|
|
|
pub fn gnosis() -> Self {
|
|
|
|
Self {
|
|
|
|
eth_spec_id: EthSpecId::Gnosis,
|
|
|
|
spec: ChainSpec::gnosis(),
|
|
|
|
}
|
|
|
|
}
|
2019-06-08 21:53:22 +00:00
|
|
|
}
|
|
|
|
|
2020-07-29 06:39:29 +00:00
|
|
|
/// A directory that can be built by downloading files via HTTP.
|
|
|
|
///
|
2020-12-08 05:41:10 +00:00
|
|
|
/// Used by the `eth2_network_config` crate to initialize the network directories during build and
|
2020-07-29 06:39:29 +00:00
|
|
|
/// access them at runtime.
|
|
|
|
#[derive(Copy, Clone, Debug, PartialEq)]
|
2020-09-11 01:43:13 +00:00
|
|
|
pub struct Eth2NetArchiveAndDirectory<'a> {
|
2020-07-29 06:39:29 +00:00
|
|
|
pub name: &'a str,
|
2022-07-20 23:16:56 +00:00
|
|
|
pub config_dir: &'a str,
|
2020-07-29 06:39:29 +00:00
|
|
|
pub genesis_is_known: bool,
|
|
|
|
}
|
|
|
|
|
2020-09-11 01:43:13 +00:00
|
|
|
impl<'a> Eth2NetArchiveAndDirectory<'a> {
|
2020-07-29 06:39:29 +00:00
|
|
|
/// The directory that should be used to store files downloaded for this net.
|
2020-10-25 22:15:46 +00:00
|
|
|
pub fn dir(&self) -> PathBuf {
|
2020-07-29 06:39:29 +00:00
|
|
|
env::var("CARGO_MANIFEST_DIR")
|
|
|
|
.expect("should know manifest dir")
|
|
|
|
.parse::<PathBuf>()
|
|
|
|
.expect("should parse manifest dir as path")
|
2020-12-08 05:41:10 +00:00
|
|
|
.join(PREDEFINED_NETWORKS_DIR)
|
2022-07-20 23:16:56 +00:00
|
|
|
.join(self.config_dir)
|
2020-09-11 01:43:13 +00:00
|
|
|
}
|
|
|
|
|
2020-10-25 22:15:46 +00:00
|
|
|
pub fn genesis_state_archive(&self) -> PathBuf {
|
|
|
|
self.dir().join(GENESIS_ZIP_FILE_NAME)
|
2020-09-11 01:43:13 +00:00
|
|
|
}
|
2020-07-29 06:39:29 +00:00
|
|
|
}
|
|
|
|
|
2021-08-30 23:27:28 +00:00
|
|
|
/// Indicates that the `genesis.ssz.zip` file is present on the filesystem. This means that the
|
|
|
|
/// deposit ceremony has concluded and the final genesis `BeaconState` is known.
|
|
|
|
const GENESIS_STATE_IS_KNOWN: bool = true;
|
|
|
|
|
|
|
|
#[derive(Copy, Clone, Debug, PartialEq)]
|
|
|
|
pub struct HardcodedNet {
|
|
|
|
pub name: &'static str,
|
2022-07-20 23:16:56 +00:00
|
|
|
pub config_dir: &'static str,
|
2021-08-30 23:27:28 +00:00
|
|
|
pub genesis_is_known: bool,
|
|
|
|
pub config: &'static [u8],
|
|
|
|
pub deploy_block: &'static [u8],
|
|
|
|
pub boot_enr: &'static [u8],
|
|
|
|
pub genesis_state_bytes: &'static [u8],
|
|
|
|
}
|
|
|
|
|
|
|
|
/// Defines an `Eth2NetArchiveAndDirectory` for some network.
|
|
|
|
///
|
|
|
|
/// It also defines a `include_<title>_file!` macro which provides a wrapper around
|
|
|
|
/// `std::include_bytes`, allowing the inclusion of bytes from the specific testnet directory.
|
|
|
|
macro_rules! define_archive {
|
2022-07-20 23:16:56 +00:00
|
|
|
($name_ident: ident, $config_dir: tt, $genesis_is_known: ident) => {
|
2021-08-30 23:27:28 +00:00
|
|
|
paste! {
|
|
|
|
#[macro_use]
|
|
|
|
pub mod $name_ident {
|
|
|
|
use super::*;
|
|
|
|
|
|
|
|
pub const ETH2_NET_DIR: Eth2NetArchiveAndDirectory = Eth2NetArchiveAndDirectory {
|
2022-07-20 23:16:56 +00:00
|
|
|
name: stringify!($name_ident),
|
|
|
|
config_dir: $config_dir,
|
2021-08-30 23:27:28 +00:00
|
|
|
genesis_is_known: $genesis_is_known,
|
2020-07-29 06:39:29 +00:00
|
|
|
};
|
2021-08-30 23:27:28 +00:00
|
|
|
|
|
|
|
/// A wrapper around `std::include_bytes` which includes a file from a specific network
|
|
|
|
/// directory. Used by upstream crates to import files at compile time.
|
|
|
|
#[macro_export]
|
|
|
|
macro_rules! [<include_ $name_ident _file>] {
|
|
|
|
($this_crate: ident, $base_dir: tt, $filename: tt) => {
|
|
|
|
include_bytes!(concat!(
|
|
|
|
$base_dir,
|
|
|
|
"/",
|
|
|
|
$this_crate::predefined_networks_dir!(),
|
|
|
|
"/",
|
2022-07-20 23:16:56 +00:00
|
|
|
$config_dir,
|
2021-08-30 23:27:28 +00:00
|
|
|
"/",
|
|
|
|
$filename
|
|
|
|
))
|
|
|
|
};
|
|
|
|
}
|
2020-07-29 06:39:29 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
2021-08-30 23:27:28 +00:00
|
|
|
/// Creates a `HardcodedNet` definition for some network.
|
|
|
|
#[macro_export]
|
|
|
|
macro_rules! define_net {
|
|
|
|
($this_crate: ident, $mod: ident, $include_file: tt) => {{
|
|
|
|
use $this_crate::$mod::ETH2_NET_DIR;
|
|
|
|
|
|
|
|
$this_crate::HardcodedNet {
|
|
|
|
name: ETH2_NET_DIR.name,
|
2022-07-20 23:16:56 +00:00
|
|
|
config_dir: ETH2_NET_DIR.config_dir,
|
2021-08-30 23:27:28 +00:00
|
|
|
genesis_is_known: ETH2_NET_DIR.genesis_is_known,
|
|
|
|
config: $this_crate::$include_file!($this_crate, "../", "config.yaml"),
|
|
|
|
deploy_block: $this_crate::$include_file!($this_crate, "../", "deploy_block.txt"),
|
|
|
|
boot_enr: $this_crate::$include_file!($this_crate, "../", "boot_enr.yaml"),
|
|
|
|
genesis_state_bytes: $this_crate::$include_file!($this_crate, "../", "genesis.ssz"),
|
|
|
|
}
|
|
|
|
}};
|
|
|
|
}
|
|
|
|
|
|
|
|
/// Calls `define_net` on a list of networks, and then defines two more lists:
|
|
|
|
///
|
|
|
|
/// - `HARDCODED_NETS`: a list of all the networks defined by this macro.
|
|
|
|
/// - `HARDCODED_NET_NAMES`: a list of the *names* of the networks defined by this macro.
|
|
|
|
#[macro_export]
|
|
|
|
macro_rules! define_nets {
|
2022-07-20 23:16:56 +00:00
|
|
|
($this_crate: ident, $($name_ident: ident,)+) => {
|
2021-08-30 23:27:28 +00:00
|
|
|
$this_crate::paste! {
|
|
|
|
$(
|
|
|
|
const [<$name_ident:upper>]: $this_crate::HardcodedNet = $this_crate::define_net!($this_crate, $name_ident, [<include_ $name_ident _file>]);
|
|
|
|
)+
|
|
|
|
const HARDCODED_NETS: &[$this_crate::HardcodedNet] = &[$([<$name_ident:upper>],)+];
|
2022-07-20 23:16:56 +00:00
|
|
|
pub const HARDCODED_NET_NAMES: &[&'static str] = &[$(stringify!($name_ident),)+];
|
2021-08-30 23:27:28 +00:00
|
|
|
}
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
/// The canonical macro for defining built-in network configurations.
|
|
|
|
///
|
|
|
|
/// This macro will provide:
|
|
|
|
///
|
|
|
|
/// - An `Eth2NetArchiveAndDirectory` for each network.
|
|
|
|
/// - `ETH2_NET_DIRS`: a list of all the above `Eth2NetArchiveAndDirectory`.
|
|
|
|
/// - The `instantiate_hardcoded_nets` macro (see its documentation).
|
|
|
|
///
|
|
|
|
/// ## Design Justification
|
|
|
|
///
|
|
|
|
/// Ultimately, this macro serves as a single list of all the networks. The reason it is structured
|
|
|
|
/// in such a complex web-of-macros way is because two requirements of built-in (hard-coded) networks:
|
|
|
|
///
|
|
|
|
/// 1. We must use `std::include_bytes!` to "bake" arbitrary bytes (genesis states, etc) into the binary.
|
|
|
|
/// 2. We must use a `build.rs` script to decompress the genesis state from a zip file, before we
|
|
|
|
/// can include those bytes.
|
|
|
|
///
|
|
|
|
/// Because of these two constraints, we must first define all of the networks and the paths to
|
|
|
|
/// their files in this crate. Then, we must use another crate (`eth2_network_configs`) to run a
|
|
|
|
/// `build.rs` which will unzip the genesis states. Then, that `eth2_network_configs` crate can
|
|
|
|
/// perform the final step of using `std::include_bytes` to bake the files (bytes) into the binary.
|
|
|
|
macro_rules! define_hardcoded_nets {
|
2022-07-20 23:16:56 +00:00
|
|
|
($(($name_ident: ident, $config_dir: tt, $genesis_is_known: ident)),+) => {
|
2021-08-30 23:27:28 +00:00
|
|
|
$(
|
2022-07-20 23:16:56 +00:00
|
|
|
define_archive!($name_ident, $config_dir, $genesis_is_known);
|
2021-08-30 23:27:28 +00:00
|
|
|
)+
|
|
|
|
|
|
|
|
pub const ETH2_NET_DIRS: &[Eth2NetArchiveAndDirectory<'static>] = &[$($name_ident::ETH2_NET_DIR,)+];
|
2020-10-07 10:10:35 +00:00
|
|
|
|
2021-08-30 23:27:28 +00:00
|
|
|
/// This macro is designed to be called by an external crate. When called, it will
|
|
|
|
/// define in that external crate:
|
|
|
|
///
|
|
|
|
/// - A `HardcodedNet` for each network.
|
|
|
|
/// - `HARDCODED_NETS`: a list of all the above `HardcodedNet`.
|
|
|
|
/// - `HARDCODED_NET_NAMES`: a list of all the names of the above `HardcodedNet` (as `&str`).
|
|
|
|
#[macro_export]
|
|
|
|
macro_rules! instantiate_hardcoded_nets {
|
|
|
|
($this_crate: ident) => {
|
2022-07-20 23:16:56 +00:00
|
|
|
$this_crate::define_nets!($this_crate, $($name_ident,)+);
|
2021-08-30 23:27:28 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
};
|
|
|
|
}
|
Add --testnet mainnet and start HTTP server before genesis (#1862)
## Issue Addressed
NA
## Proposed Changes
- Adds support for `--testnet mainnet`
- Start HTTP server prior to genesis
## Additional Info
**Note: This is an incomplete work-in-progress. Use Lighthouse for mainnet at your own risk.**
With this PR, you can check the deposits:
```bash
lighthouse --testnet mainnet bn --http
```
```bash
curl localhost:5052/lighthouse/eth1/deposit_cache | jq
```
```json
{
"data": [
{
"deposit_data": {
"pubkey": "0x854980aa9bf2e84723e1fa6ef682e3537257984cc9cb1daea2ce6b268084b414f0bb43206e9fa6fd7a202357d6eb2b0d",
"withdrawal_credentials": "0x00cacf703c658b802d55baa2a5c1777500ef5051fc084330d2761bcb6ab6182b",
"amount": "32000000000",
"signature": "0xace226cdfd9da6b1d827c3a6ab93f91f53e8e090eb6ca5ee7c7c5fe3acc75558240ca9291684a2a7af5cac67f0558d1109cc95309f5cdf8c125185ec9dcd22635f900d791316924aed7c40cff2ffccdac0d44cf496853db678c8c53745b3545b"
},
"block_number": 3492981,
"index": 0,
"signature_is_valid": true
},
{
"deposit_data": {
"pubkey": "0x93da03a71bc4ed163c2f91c8a54ea3ba2461383dd615388fd494670f8ce571b46e698fc8d04b49e4a8ffe653f581806b",
"withdrawal_credentials": "0x006ebfbb7c8269a78018c8b810492979561d0404d74ba9c234650baa7524dcc4",
"amount": "32000000000",
"signature": "0x8d1f4a1683f798a76effcc6e2cdb8c3eed5a79123d201c5ecd4ab91f768a03c30885455b8a952aeec3c02110457f97ae0a60724187b6d4129d7c352f2e1ac19b4210daacd892fe4629ad3260ce2911dceae3890b04ed28267b2d8cb831f6a92d"
},
"block_number": 3493427,
"index": 1,
"signature_is_valid": true
},
```
2020-11-09 05:04:03 +00:00
|
|
|
|
2021-08-30 23:27:28 +00:00
|
|
|
// Add a new "built-in" network by adding it to the list below.
|
|
|
|
//
|
|
|
|
// The last entry must not end with a comma, otherwise compilation will fail.
|
|
|
|
//
|
|
|
|
// This is the canonical place for defining the built-in network configurations that are present in
|
|
|
|
// the `common/eth2_network_config/built_in_network_configs` directory.
|
|
|
|
//
|
|
|
|
// Each net is defined as a three-tuple:
|
|
|
|
//
|
|
|
|
// 0. The name of the testnet as an "ident" (i.e. something that can be a Rust variable name).
|
|
|
|
// 1. The human-friendly name of the testnet (i.e. usually with "-" instead of "_").
|
|
|
|
// 2. A bool indicating if the genesis state is known and present as a `genesis.ssz.zip`.
|
|
|
|
//
|
|
|
|
// The directory containing the testnet files should match the human-friendly name (element 1).
|
|
|
|
define_hardcoded_nets!(
|
2022-07-20 23:16:56 +00:00
|
|
|
(
|
|
|
|
// Network name (must be unique among all networks).
|
|
|
|
mainnet,
|
|
|
|
// The name of the directory in the `eth2_network_config/built_in_network_configs`
|
|
|
|
// directory where the configuration files are located for this network.
|
|
|
|
"mainnet",
|
|
|
|
// Set to `true` if the genesis state can be found in the `built_in_network_configs`
|
|
|
|
// directory.
|
|
|
|
GENESIS_STATE_IS_KNOWN
|
|
|
|
),
|
|
|
|
(
|
|
|
|
// Network name (must be unique among all networks).
|
|
|
|
prater,
|
|
|
|
// The name of the directory in the `eth2_network_config/built_in_network_configs`
|
|
|
|
// directory where the configuration files are located for this network.
|
|
|
|
"prater",
|
|
|
|
// Set to `true` if the genesis state can be found in the `built_in_network_configs`
|
|
|
|
// directory.
|
|
|
|
GENESIS_STATE_IS_KNOWN
|
|
|
|
),
|
|
|
|
(
|
|
|
|
// Network name (must be unique among all networks).
|
|
|
|
goerli,
|
|
|
|
// The name of the directory in the `eth2_network_config/built_in_network_configs`
|
|
|
|
// directory where the configuration files are located for this network.
|
|
|
|
//
|
|
|
|
// The Goerli network is effectively an alias to Prater.
|
|
|
|
"prater",
|
|
|
|
// Set to `true` if the genesis state can be found in the `built_in_network_configs`
|
|
|
|
// directory.
|
|
|
|
GENESIS_STATE_IS_KNOWN
|
|
|
|
),
|
|
|
|
(
|
|
|
|
// Network name (must be unique among all networks).
|
|
|
|
gnosis,
|
|
|
|
// The name of the directory in the `eth2_network_config/built_in_network_configs`
|
|
|
|
// directory where the configuration files are located for this network.
|
|
|
|
"gnosis",
|
|
|
|
// Set to `true` if the genesis state can be found in the `built_in_network_configs`
|
|
|
|
// directory.
|
|
|
|
GENESIS_STATE_IS_KNOWN
|
|
|
|
),
|
|
|
|
(
|
|
|
|
// Network name (must be unique among all networks).
|
|
|
|
sepolia,
|
|
|
|
// The name of the directory in the `eth2_network_config/built_in_network_configs`
|
|
|
|
// directory where the configuration files are located for this network.
|
|
|
|
"sepolia",
|
|
|
|
// Set to `true` if the genesis state can be found in the `built_in_network_configs`
|
|
|
|
// directory.
|
|
|
|
GENESIS_STATE_IS_KNOWN
|
|
|
|
)
|
2021-08-30 23:27:28 +00:00
|
|
|
);
|