Add interop chain spec and rename chain_id
This commit is contained in:
parent
88e89f9ab2
commit
40c0b70b22
@ -64,7 +64,7 @@ fn handle_fork<T: BeaconChainTypes + 'static>(req: &mut Request) -> IronResult<R
|
||||
|
||||
let response = json!({
|
||||
"fork": beacon_chain.head().beacon_state.fork,
|
||||
"chain_id": beacon_chain.spec.chain_id
|
||||
"network_id": beacon_chain.spec.network_id
|
||||
});
|
||||
|
||||
Ok(Response::with((Status::Ok, response.to_string())))
|
||||
|
@ -914,11 +914,11 @@ fn hello_message<T: BeaconChainTypes>(beacon_chain: &BeaconChain<T>) -> 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,
|
||||
}
|
||||
|
@ -37,7 +37,7 @@ impl<T: BeaconChainTypes> BeaconNodeService for BeaconNodeServiceInstance<T> {
|
||||
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();
|
||||
|
@ -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(
|
||||
|
@ -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::<ClientType<DiskStore, InteropEthSpec>>(
|
||||
&db_path,
|
||||
client_config,
|
||||
eth2_config,
|
||||
executor,
|
||||
runtime,
|
||||
log,
|
||||
),
|
||||
("memory", "interop") => run::<ClientType<MemoryStore, InteropEthSpec>>(
|
||||
&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())
|
||||
|
@ -200,3 +200,23 @@ impl EthSpec for MinimalEthSpec {
|
||||
}
|
||||
|
||||
pub type MinimalBeaconState = BeaconState<MinimalEthSpec>;
|
||||
|
||||
/// 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<InteropEthSpec>;
|
||||
|
@ -92,7 +92,7 @@ pub struct ChainSpec {
|
||||
domain_transfer: u32,
|
||||
|
||||
pub boot_nodes: Vec<String>,
|
||||
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()
|
||||
}
|
||||
|
@ -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;
|
||||
}
|
||||
|
@ -1 +1 @@
|
||||
Subproject commit aaa1673f508103e11304833e0456e4149f880065
|
||||
Subproject commit d405782646190595927cc0a59f504f7b00a760f3
|
@ -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::<ValidatorServiceClient, Keypair>::start::<InteropEthSpec>(
|
||||
client_config,
|
||||
eth2_config,
|
||||
log.clone(),
|
||||
),
|
||||
other => {
|
||||
crit!(log, "Unknown spec constants"; "title" => other);
|
||||
return;
|
||||
|
@ -107,12 +107,12 @@ impl<B: BeaconNodeDuties + 'static, S: Signer + 'static, E: EthSpec> Service<B,
|
||||
return Err("Genesis time in the future".into());
|
||||
}
|
||||
// verify the node's chain id
|
||||
if eth2_config.spec.chain_id != info.chain_id as u8 {
|
||||
if eth2_config.spec.network_id != info.network_id as u8 {
|
||||
error!(
|
||||
log,
|
||||
"Beacon Node's genesis time is in the future. No work to do.\n Exiting"
|
||||
);
|
||||
return Err(format!("Beacon node has the wrong chain id. Expected chain id: {}, node's chain id: {}", eth2_config.spec.chain_id, info.chain_id).into());
|
||||
return Err(format!("Beacon node has the wrong chain id. Expected chain id: {}, node's chain id: {}", eth2_config.spec.network_id, info.network_id).into());
|
||||
}
|
||||
break info;
|
||||
}
|
||||
@ -123,7 +123,7 @@ impl<B: BeaconNodeDuties + 'static, S: Signer + 'static, E: EthSpec> Service<B,
|
||||
let genesis_time = node_info.get_genesis_time();
|
||||
let genesis_slot = Slot::from(node_info.get_genesis_slot());
|
||||
|
||||
info!(log,"Beacon node connected"; "Node Version" => 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];
|
||||
|
Loading…
Reference in New Issue
Block a user