From 40c0b70b22de83cb4fea86250397fa568d08dbc9 Mon Sep 17 00:00:00 2001 From: Age Manning Date: Wed, 24 Jul 2019 21:31:49 +1000 Subject: [PATCH] Add interop chain spec and rename chain_id --- beacon_node/http_server/src/api.rs | 2 +- beacon_node/network/src/sync/simple_sync.rs | 10 +++---- beacon_node/rpc/src/beacon_node.rs | 2 +- beacon_node/src/main.rs | 3 +- beacon_node/src/run.rs | 18 +++++++++++- .../src/beacon_state/beacon_state_types.rs | 20 +++++++++++++ eth2/types/src/chain_spec.rs | 28 +++++++++++++++++-- protos/src/services.proto | 2 +- tests/ef_tests/eth2.0-spec-tests | 2 +- validator_client/src/main.rs | 9 ++++-- validator_client/src/service.rs | 6 ++-- 11 files changed, 83 insertions(+), 19 deletions(-) diff --git a/beacon_node/http_server/src/api.rs b/beacon_node/http_server/src/api.rs index a910808998..8cb023b02c 100644 --- a/beacon_node/http_server/src/api.rs +++ b/beacon_node/http_server/src/api.rs @@ -64,7 +64,7 @@ fn handle_fork(req: &mut Request) -> IronResult(beacon_chain: &BeaconChain) -> HelloMes let state = &beacon_chain.head().beacon_state; HelloMessage { - //TODO: Correctly define the chain/network id - network_id: spec.chain_id, - chain_id: u64::from(spec.chain_id), - latest_finalized_root: state.finalized_checkpoint.root, - latest_finalized_epoch: state.finalized_checkpoint.epoch, + network_id: spec.network_id, + //TODO: Correctly define the chain id + chain_id: spec.network_id as u64, + latest_finalized_root: state.finalized_root, + latest_finalized_epoch: state.finalized_epoch, best_root: beacon_chain.head().beacon_block_root, best_slot: state.slot, } diff --git a/beacon_node/rpc/src/beacon_node.rs b/beacon_node/rpc/src/beacon_node.rs index 631601ac95..5d635c9d1b 100644 --- a/beacon_node/rpc/src/beacon_node.rs +++ b/beacon_node/rpc/src/beacon_node.rs @@ -37,7 +37,7 @@ impl BeaconNodeService for BeaconNodeServiceInstance { node_info.set_fork(fork); node_info.set_genesis_time(genesis_time); node_info.set_genesis_slot(spec.genesis_slot.as_u64()); - node_info.set_chain_id(u32::from(spec.chain_id)); + node_info.set_network_id(u32::from(spec.network_id)); // send the node_info the requester let error_log = self.log.clone(); diff --git a/beacon_node/src/main.rs b/beacon_node/src/main.rs index dd0c695b4a..c61e0c6b62 100644 --- a/beacon_node/src/main.rs +++ b/beacon_node/src/main.rs @@ -136,6 +136,7 @@ fn main() { .help("Listen port for the HTTP server.") .takes_value(true), ) + /* Client related arguments */ .arg( Arg::with_name("api") .long("api") @@ -182,7 +183,7 @@ fn main() { from disk. A spec will be written to disk after this flag is used, so it is primarily used for creating eth2 spec files.") .takes_value(true) - .possible_values(&["mainnet", "minimal"]) + .possible_values(&["mainnet", "minimal", "interop"]) .default_value("minimal"), ) .arg( diff --git a/beacon_node/src/run.rs b/beacon_node/src/run.rs index 010993988c..c16d23e5f1 100644 --- a/beacon_node/src/run.rs +++ b/beacon_node/src/run.rs @@ -13,7 +13,7 @@ use tokio::runtime::Builder; use tokio::runtime::Runtime; use tokio::runtime::TaskExecutor; use tokio_timer::clock::Clock; -use types::{MainnetEthSpec, MinimalEthSpec}; +use types::{InteropEthSpec, MainnetEthSpec, MinimalEthSpec}; /// Reads the configuration and initializes a `BeaconChain` with the required types and parameters. /// @@ -90,6 +90,22 @@ pub fn run_beacon_node( runtime, log, ), + ("disk", "interop") => run::>( + &db_path, + client_config, + eth2_config, + executor, + runtime, + log, + ), + ("memory", "interop") => run::>( + &db_path, + client_config, + eth2_config, + executor, + runtime, + log, + ), (db_type, spec) => { error!(log, "Unknown runtime configuration"; "spec_constants" => spec, "db_type" => db_type); Err("Unknown specification and/or db_type.".into()) diff --git a/eth2/types/src/beacon_state/beacon_state_types.rs b/eth2/types/src/beacon_state/beacon_state_types.rs index 1dc34e1951..dd6ca32724 100644 --- a/eth2/types/src/beacon_state/beacon_state_types.rs +++ b/eth2/types/src/beacon_state/beacon_state_types.rs @@ -200,3 +200,23 @@ impl EthSpec for MinimalEthSpec { } pub type MinimalBeaconState = BeaconState; + +/// Interop testnet spec +#[derive(Clone, PartialEq, Debug, Default, Serialize, Deserialize)] +pub struct InteropEthSpec; + +impl EthSpec for InteropEthSpec { + type ShardCount = U8; + type SlotsPerHistoricalRoot = U64; + type LatestRandaoMixesLength = U64; + type LatestActiveIndexRootsLength = U64; + type LatestSlashedExitLength = U64; + type SlotsPerEpoch = U8; + type GenesisEpoch = U0; + + fn default_spec() -> ChainSpec { + ChainSpec::interop() + } +} + +pub type InteropBeaconState = BeaconState; diff --git a/eth2/types/src/chain_spec.rs b/eth2/types/src/chain_spec.rs index 2128c6ef11..d6eaa123de 100644 --- a/eth2/types/src/chain_spec.rs +++ b/eth2/types/src/chain_spec.rs @@ -92,7 +92,7 @@ pub struct ChainSpec { domain_transfer: u32, pub boot_nodes: Vec, - pub chain_id: u8, + pub network_id: u8, } impl ChainSpec { @@ -190,7 +190,7 @@ impl ChainSpec { * Network specific */ boot_nodes: vec![], - chain_id: 1, // mainnet chain id + network_id: 1, // mainnet network id } } @@ -202,13 +202,35 @@ impl ChainSpec { pub fn minimal() -> Self { // Note: bootnodes to be updated when static nodes exist. let boot_nodes = vec![]; + let genesis_slot = Slot::new(0); Self { target_committee_size: 4, shuffle_round_count: 10, min_genesis_active_validator_count: 64, max_epochs_per_crosslink: 4, - chain_id: 2, // lighthouse testnet chain id + min_attestation_inclusion_delay: 2, + genesis_slot, + network_id: 2, // lighthouse testnet network id + boot_nodes, + ..ChainSpec::mainnet() + } + } + + /// Interop testing spec + /// + /// This allows us to customize a chain spec for interop testing. + pub fn interop() -> Self { + let genesis_slot = Slot::new(0); + let boot_nodes = vec![]; + + Self { + seconds_per_slot: 12, + target_committee_size: 4, + shuffle_round_count: 10, + min_attestation_inclusion_delay: 2, + genesis_slot, + network_id: 13, boot_nodes, ..ChainSpec::mainnet() } diff --git a/protos/src/services.proto b/protos/src/services.proto index bf23ff391d..ba0462bbea 100644 --- a/protos/src/services.proto +++ b/protos/src/services.proto @@ -45,7 +45,7 @@ service AttestationService { message NodeInfoResponse { string version = 1; Fork fork = 2; - uint32 chain_id = 3; + uint32 network_id = 3; uint64 genesis_time = 4; uint64 genesis_slot = 5; } diff --git a/tests/ef_tests/eth2.0-spec-tests b/tests/ef_tests/eth2.0-spec-tests index aaa1673f50..d405782646 160000 --- a/tests/ef_tests/eth2.0-spec-tests +++ b/tests/ef_tests/eth2.0-spec-tests @@ -1 +1 @@ -Subproject commit aaa1673f508103e11304833e0456e4149f880065 +Subproject commit d405782646190595927cc0a59f504f7b00a760f3 diff --git a/validator_client/src/main.rs b/validator_client/src/main.rs index bd3919b5a7..756f829916 100644 --- a/validator_client/src/main.rs +++ b/validator_client/src/main.rs @@ -14,7 +14,7 @@ use protos::services_grpc::ValidatorServiceClient; use slog::{crit, error, info, o, Drain, Level}; use std::fs; use std::path::PathBuf; -use types::{Keypair, MainnetEthSpec, MinimalEthSpec}; +use types::{InteropEthSpec, Keypair, MainnetEthSpec, MinimalEthSpec}; pub const DEFAULT_SPEC: &str = "minimal"; pub const DEFAULT_DATA_DIR: &str = ".lighthouse-validator"; @@ -70,7 +70,7 @@ fn main() { .short("s") .help("The title of the spec constants for chain config.") .takes_value(true) - .possible_values(&["mainnet", "minimal"]) + .possible_values(&["mainnet", "minimal", "interop"]) .default_value("minimal"), ) .arg( @@ -214,6 +214,11 @@ fn main() { eth2_config, log.clone(), ), + "interop" => ValidatorService::::start::( + client_config, + eth2_config, + log.clone(), + ), other => { crit!(log, "Unknown spec constants"; "title" => other); return; diff --git a/validator_client/src/service.rs b/validator_client/src/service.rs index 3f99efe36a..c4ccbc2042 100644 --- a/validator_client/src/service.rs +++ b/validator_client/src/service.rs @@ -107,12 +107,12 @@ impl Service Service node_info.version.clone(), "Chain ID" => node_info.chain_id, "Genesis time" => genesis_time); + info!(log,"Beacon node connected"; "Node Version" => node_info.version.clone(), "Chain ID" => node_info.network_id, "Genesis time" => genesis_time); let proto_fork = node_info.get_fork(); let mut previous_version: [u8; 4] = [0; 4];