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
|
|
|
|
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(),
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
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,
|
|
|
|
pub unique_id: &'a str,
|
|
|
|
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)
|
2020-10-25 22:15:46 +00:00
|
|
|
.join(self.unique_id)
|
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
|
|
|
}
|
|
|
|
|
|
|
|
macro_rules! define_net {
|
2020-09-26 01:58:31 +00:00
|
|
|
($title: ident, $macro_title: tt, $name: tt, $genesis_is_known: tt) => {
|
2020-07-29 06:39:29 +00:00
|
|
|
#[macro_use]
|
|
|
|
pub mod $title {
|
|
|
|
use super::*;
|
|
|
|
|
2020-09-11 01:43:13 +00:00
|
|
|
pub const ETH2_NET_DIR: Eth2NetArchiveAndDirectory = Eth2NetArchiveAndDirectory {
|
2020-07-29 06:39:29 +00:00
|
|
|
name: $name,
|
2020-10-25 22:15:46 +00:00
|
|
|
unique_id: $name,
|
2020-07-29 06:39:29 +00:00
|
|
|
genesis_is_known: $genesis_is_known,
|
|
|
|
};
|
|
|
|
|
2020-12-08 05:41:10 +00:00
|
|
|
// A wrapper around `std::include_bytes` which includes a file from a specific network
|
2020-07-29 06:39:29 +00:00
|
|
|
// directory. Used by upstream crates to import files at compile time.
|
|
|
|
#[macro_export]
|
|
|
|
macro_rules! $macro_title {
|
|
|
|
($base_dir: tt, $filename: tt) => {
|
2020-10-25 22:15:46 +00:00
|
|
|
include_bytes!(concat!(
|
|
|
|
$base_dir,
|
|
|
|
"/",
|
2020-12-08 05:41:10 +00:00
|
|
|
predefined_networks_dir!(),
|
2020-10-25 22:15:46 +00:00
|
|
|
"/",
|
|
|
|
$name,
|
|
|
|
"/",
|
|
|
|
$filename
|
|
|
|
))
|
2020-07-29 06:39:29 +00:00
|
|
|
};
|
|
|
|
}
|
|
|
|
}
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
2020-11-16 05:11:35 +00:00
|
|
|
define_net!(pyrmont, include_pyrmont_file, "pyrmont", true);
|
2020-10-07 10:10:35 +00:00
|
|
|
|
2020-11-24 12:21:00 +00:00
|
|
|
define_net!(mainnet, include_mainnet_file, "mainnet", true);
|
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-03-17 00:47:06 +00:00
|
|
|
define_net!(prater, include_prater_file, "prater", true);
|