Remove genesis_epoch
from ChainSpec
This commit is contained in:
parent
e74d49fc8a
commit
caddeba81b
@ -31,7 +31,7 @@ impl Default for ClientConfig {
|
||||
network: NetworkConfig::new(vec![]),
|
||||
rpc: rpc::RPCConfig::default(),
|
||||
http: HttpServerConfig::default(),
|
||||
spec: ChainSpec::lighthouse_testnet(8),
|
||||
spec: ChainSpec::lighthouse_testnet(),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -680,7 +680,7 @@ mod tests {
|
||||
|
||||
let mut state = BeaconState::random_for_test(rng);
|
||||
|
||||
state.fork = Fork::genesis(&spec);
|
||||
state.fork = Fork::genesis(FoundationEthSpec::genesis_epoch());
|
||||
|
||||
(spec, state)
|
||||
}
|
||||
|
@ -23,7 +23,7 @@ pub fn bench_epoch_processing_n_validators(c: &mut Criterion, validator_count: u
|
||||
TestingBeaconStateBuilder::from_default_keypairs_file_if_exists(validator_count, &spec);
|
||||
|
||||
// Set the state to be just before an epoch transition.
|
||||
let target_slot = (spec.genesis_epoch + 4).end_slot(T::slots_per_epoch());
|
||||
let target_slot = (T::genesis_epoch() + 4).end_slot(T::slots_per_epoch());
|
||||
builder.teleport_to_slot(target_slot, &spec);
|
||||
|
||||
// Builds all caches; benches will not contain shuffling/committee building times.
|
||||
|
@ -34,7 +34,7 @@ pub fn block_processing_worst_case(c: &mut Criterion) {
|
||||
bench_builder.maximize_block_operations(&spec);
|
||||
|
||||
// Set the state and block to be in the last slot of the 4th epoch.
|
||||
let last_slot_of_epoch = (spec.genesis_epoch + 4).end_slot(T::slots_per_epoch());
|
||||
let last_slot_of_epoch = (T::genesis_epoch() + 4).end_slot(T::slots_per_epoch());
|
||||
bench_builder.set_slot(last_slot_of_epoch, &spec);
|
||||
|
||||
// Build all the state caches so the build times aren't included in the benches.
|
||||
@ -73,7 +73,7 @@ pub fn block_processing_reasonable_case(c: &mut Criterion) {
|
||||
bench_builder.num_transfers = 2;
|
||||
|
||||
// Set the state and block to be in the last slot of the 4th epoch.
|
||||
let last_slot_of_epoch = (spec.genesis_epoch + 4).end_slot(T::slots_per_epoch());
|
||||
let last_slot_of_epoch = (T::genesis_epoch() + 4).end_slot(T::slots_per_epoch());
|
||||
bench_builder.set_slot(last_slot_of_epoch, &spec);
|
||||
|
||||
// Build all the state caches so the build times aren't included in the benches.
|
||||
|
@ -25,8 +25,8 @@ pub fn get_genesis_beacon_state<T: EthSpec>(
|
||||
// Process genesis activations.
|
||||
for validator in &mut state.validator_registry {
|
||||
if validator.effective_balance >= spec.max_effective_balance {
|
||||
validator.activation_eligibility_epoch = spec.genesis_epoch;
|
||||
validator.activation_epoch = spec.genesis_epoch;
|
||||
validator.activation_eligibility_epoch = T::genesis_epoch();
|
||||
validator.activation_epoch = T::genesis_epoch();
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -105,7 +105,7 @@ fn get_builder(spec: &ChainSpec) -> (BlockProcessingBuilder<FoundationEthSpec>)
|
||||
|
||||
// Set the state and block to be in the last slot of the 4th epoch.
|
||||
let last_slot_of_epoch =
|
||||
(spec.genesis_epoch + 4).end_slot(FoundationEthSpec::slots_per_epoch());
|
||||
(FoundationEthSpec::genesis_epoch() + 4).end_slot(FoundationEthSpec::slots_per_epoch());
|
||||
builder.set_slot(last_slot_of_epoch, &spec);
|
||||
builder.build_caches(&spec);
|
||||
|
||||
|
@ -86,7 +86,7 @@ pub fn process_justification_and_finalization<T: EthSpec>(
|
||||
total_balances: &TotalBalances,
|
||||
spec: &ChainSpec,
|
||||
) -> Result<(), Error> {
|
||||
if state.current_epoch() == spec.genesis_epoch {
|
||||
if state.current_epoch() == T::genesis_epoch() {
|
||||
return Ok(());
|
||||
}
|
||||
|
||||
|
@ -39,7 +39,7 @@ pub fn process_rewards_and_penalties<T: EthSpec>(
|
||||
winning_root_for_shards: &WinningRootHashSet,
|
||||
spec: &ChainSpec,
|
||||
) -> Result<(), Error> {
|
||||
if state.current_epoch() == spec.genesis_epoch {
|
||||
if state.current_epoch() == T::genesis_epoch() {
|
||||
return Ok(());
|
||||
}
|
||||
|
||||
|
@ -13,7 +13,8 @@ fn runs_without_error() {
|
||||
let mut builder: TestingBeaconStateBuilder<FewValidatorsEthSpec> =
|
||||
TestingBeaconStateBuilder::from_deterministic_keypairs(8, &spec);
|
||||
|
||||
let target_slot = (spec.genesis_epoch + 4).end_slot(FewValidatorsEthSpec::slots_per_epoch());
|
||||
let target_slot = (FewValidatorsEthSpec::genesis_epoch() + 4)
|
||||
.end_slot(FewValidatorsEthSpec::slots_per_epoch());
|
||||
builder.teleport_to_slot(target_slot, &spec);
|
||||
|
||||
let (mut state, _keypairs) = builder.build();
|
||||
|
@ -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,
|
||||
|
Loading…
Reference in New Issue
Block a user