mirror of
https://github.com/sigp/lighthouse.git
synced 2026-03-18 04:13:00 +00:00
Remove genesis_epoch from ChainSpec
This commit is contained in:
@@ -162,7 +162,7 @@ impl<T: EthSpec> BeaconState<T> {
|
||||
spec: &ChainSpec,
|
||||
) -> BeaconState<T> {
|
||||
let initial_crosslink = Crosslink {
|
||||
epoch: spec.genesis_epoch,
|
||||
epoch: T::genesis_epoch(),
|
||||
previous_crosslink_root: spec.zero_hash,
|
||||
crosslink_data_root: spec.zero_hash,
|
||||
};
|
||||
@@ -171,7 +171,7 @@ impl<T: EthSpec> BeaconState<T> {
|
||||
// Misc
|
||||
slot: spec.genesis_slot,
|
||||
genesis_time,
|
||||
fork: Fork::genesis(spec),
|
||||
fork: Fork::genesis(T::genesis_epoch()),
|
||||
|
||||
// Validator registry
|
||||
validator_registry: vec![], // Set later in the function.
|
||||
@@ -187,12 +187,12 @@ impl<T: EthSpec> BeaconState<T> {
|
||||
// Finality
|
||||
previous_epoch_attestations: vec![],
|
||||
current_epoch_attestations: vec![],
|
||||
previous_justified_epoch: spec.genesis_epoch,
|
||||
current_justified_epoch: spec.genesis_epoch,
|
||||
previous_justified_epoch: T::genesis_epoch(),
|
||||
current_justified_epoch: T::genesis_epoch(),
|
||||
previous_justified_root: spec.zero_hash,
|
||||
current_justified_root: spec.zero_hash,
|
||||
justification_bitfield: 0,
|
||||
finalized_epoch: spec.genesis_epoch,
|
||||
finalized_epoch: T::genesis_epoch(),
|
||||
finalized_root: spec.zero_hash,
|
||||
|
||||
// Recent state
|
||||
|
||||
@@ -127,7 +127,7 @@ impl EthSpec for FewValidatorsEthSpec {
|
||||
type GenesisEpoch = U0;
|
||||
|
||||
fn default_spec() -> ChainSpec {
|
||||
ChainSpec::few_validators(Self::slots_per_epoch())
|
||||
ChainSpec::few_validators()
|
||||
}
|
||||
}
|
||||
|
||||
@@ -147,7 +147,7 @@ impl EthSpec for LighthouseTestnetEthSpec {
|
||||
type GenesisEpoch = U0;
|
||||
|
||||
fn default_spec() -> ChainSpec {
|
||||
ChainSpec::lighthouse_testnet(Self::slots_per_epoch())
|
||||
ChainSpec::lighthouse_testnet()
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -154,7 +154,7 @@ impl EthSpec for ExcessShardsEthSpec {
|
||||
type GenesisEpoch = U0;
|
||||
|
||||
fn default_spec() -> ChainSpec {
|
||||
ChainSpec::few_validators(Self::slots_per_epoch())
|
||||
ChainSpec::few_validators()
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -172,7 +172,8 @@ fn cache_initialization() {
|
||||
TestingBeaconStateBuilder::from_default_keypairs_file_if_exists(16, &spec);
|
||||
let (mut state, _keypairs) = builder.build();
|
||||
|
||||
state.slot = (spec.genesis_epoch + 1).start_slot(FewValidatorsEthSpec::slots_per_epoch());
|
||||
state.slot = (FewValidatorsEthSpec::genesis_epoch() + 1)
|
||||
.start_slot(FewValidatorsEthSpec::slots_per_epoch());
|
||||
|
||||
test_cache_initialization(&mut state, RelativeEpoch::Previous, &spec);
|
||||
test_cache_initialization(&mut state, RelativeEpoch::Current, &spec);
|
||||
@@ -333,13 +334,13 @@ mod committees {
|
||||
|
||||
committee_consistency_test::<T>(
|
||||
validator_count as usize,
|
||||
spec.genesis_epoch + 4,
|
||||
T::genesis_epoch() + 4,
|
||||
cached_epoch,
|
||||
);
|
||||
|
||||
committee_consistency_test::<T>(
|
||||
validator_count as usize,
|
||||
spec.genesis_epoch + T::slots_per_historical_root() as u64 * T::slots_per_epoch() * 4,
|
||||
T::genesis_epoch() + T::slots_per_historical_root() as u64 * T::slots_per_epoch() * 4,
|
||||
cached_epoch,
|
||||
);
|
||||
}
|
||||
|
||||
@@ -48,7 +48,6 @@ pub struct ChainSpec {
|
||||
* Initial Values
|
||||
*/
|
||||
pub genesis_slot: Slot,
|
||||
pub genesis_epoch: Epoch,
|
||||
pub far_future_epoch: Epoch,
|
||||
pub zero_hash: Hash256,
|
||||
#[serde(deserialize_with = "u8_from_hex_str")]
|
||||
@@ -166,7 +165,6 @@ impl ChainSpec {
|
||||
* Initial Values
|
||||
*/
|
||||
genesis_slot: Slot::new(0),
|
||||
genesis_epoch: Epoch::new(0),
|
||||
far_future_epoch: Epoch::new(u64::max_value()),
|
||||
zero_hash: Hash256::zero(),
|
||||
bls_withdrawal_prefix_byte: 0,
|
||||
@@ -226,7 +224,7 @@ impl ChainSpec {
|
||||
/// Returns a `ChainSpec` compatible with the Lighthouse testnet specification.
|
||||
///
|
||||
/// Spec v0.4.0
|
||||
pub fn lighthouse_testnet(slots_per_epoch: u64) -> Self {
|
||||
pub fn lighthouse_testnet() -> Self {
|
||||
/*
|
||||
* Lighthouse testnet bootnodes
|
||||
*/
|
||||
@@ -237,19 +235,17 @@ impl ChainSpec {
|
||||
Self {
|
||||
boot_nodes,
|
||||
chain_id: 2, // lighthouse testnet chain id
|
||||
..ChainSpec::few_validators(slots_per_epoch)
|
||||
..ChainSpec::few_validators()
|
||||
}
|
||||
}
|
||||
|
||||
/// Returns a `ChainSpec` compatible with the specification suitable for 8 validators.
|
||||
pub fn few_validators(slots_per_epoch: u64) -> Self {
|
||||
pub fn few_validators() -> Self {
|
||||
let genesis_slot = Slot::new(0);
|
||||
let genesis_epoch = genesis_slot.epoch(slots_per_epoch);
|
||||
|
||||
Self {
|
||||
target_committee_size: 1,
|
||||
genesis_slot,
|
||||
genesis_epoch,
|
||||
..ChainSpec::foundation()
|
||||
}
|
||||
}
|
||||
@@ -272,7 +268,7 @@ mod tests {
|
||||
}
|
||||
|
||||
fn test_domain(domain_type: Domain, raw_domain: u32, spec: &ChainSpec) {
|
||||
let fork = Fork::genesis(&spec);
|
||||
let fork = Fork::genesis(Epoch::new(0));
|
||||
let epoch = Epoch::new(0);
|
||||
|
||||
let domain = spec.get_domain(epoch, domain_type, &fork);
|
||||
|
||||
@@ -36,11 +36,11 @@ impl Fork {
|
||||
/// Initialize the `Fork` from the genesis parameters in the `spec`.
|
||||
///
|
||||
/// Spec v0.6.1
|
||||
pub fn genesis(spec: &ChainSpec) -> Self {
|
||||
pub fn genesis(genesis_epoch: Epoch) -> Self {
|
||||
Self {
|
||||
previous_version: [0; 4],
|
||||
current_version: [0; 4],
|
||||
epoch: spec.genesis_epoch,
|
||||
epoch: genesis_epoch,
|
||||
}
|
||||
}
|
||||
|
||||
@@ -65,11 +65,9 @@ mod tests {
|
||||
fn test_genesis(epoch: Epoch) {
|
||||
let mut spec = ChainSpec::foundation();
|
||||
|
||||
spec.genesis_epoch = epoch;
|
||||
let fork = Fork::genesis(epoch);
|
||||
|
||||
let fork = Fork::genesis(&spec);
|
||||
|
||||
assert_eq!(fork.epoch, spec.genesis_epoch, "epoch incorrect");
|
||||
assert_eq!(fork.epoch, epoch, "epoch incorrect");
|
||||
assert_eq!(
|
||||
fork.previous_version, fork.current_version,
|
||||
"previous and current are not identical"
|
||||
|
||||
@@ -113,8 +113,8 @@ impl<T: EthSpec> TestingBeaconStateBuilder<T> {
|
||||
pubkey: keypair.pk.clone(),
|
||||
withdrawal_credentials,
|
||||
// All validators start active.
|
||||
activation_eligibility_epoch: spec.genesis_epoch,
|
||||
activation_epoch: spec.genesis_epoch,
|
||||
activation_eligibility_epoch: T::genesis_epoch(),
|
||||
activation_epoch: T::genesis_epoch(),
|
||||
exit_epoch: spec.far_future_epoch,
|
||||
withdrawable_epoch: spec.far_future_epoch,
|
||||
slashed: false,
|
||||
|
||||
Reference in New Issue
Block a user