mirror of
https://github.com/sigp/lighthouse.git
synced 2026-05-30 04:37:13 +00:00
Remove dupe info between ChainSpec and EthSpec
This commit is contained in:
@@ -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(spec.slots_per_epoch);
|
||||
let target_slot = (spec.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.
|
||||
@@ -38,10 +38,10 @@ pub fn bench_epoch_processing_n_validators(c: &mut Criterion, validator_count: u
|
||||
// Assert that the state has an attestations for each committee that is able to include an
|
||||
// attestation in the state.
|
||||
let committees_per_epoch = spec.get_epoch_committee_count(validator_count);
|
||||
let committees_per_slot = committees_per_epoch / spec.slots_per_epoch;
|
||||
let committees_per_slot = committees_per_epoch / T::slots_per_epoch();
|
||||
let previous_epoch_attestations = committees_per_epoch;
|
||||
let current_epoch_attestations =
|
||||
committees_per_slot * (spec.slots_per_epoch - spec.min_attestation_inclusion_delay);
|
||||
committees_per_slot * (T::slots_per_epoch() - spec.min_attestation_inclusion_delay);
|
||||
assert_eq!(
|
||||
state.latest_attestations.len() as u64,
|
||||
previous_epoch_attestations + current_epoch_attestations,
|
||||
|
||||
@@ -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(spec.slots_per_epoch);
|
||||
let last_slot_of_epoch = (spec.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.
|
||||
@@ -67,13 +67,13 @@ pub fn block_processing_reasonable_case(c: &mut Criterion) {
|
||||
// Set the number of included operations to what we might expect normally.
|
||||
bench_builder.num_proposer_slashings = 0;
|
||||
bench_builder.num_attester_slashings = 0;
|
||||
bench_builder.num_attestations = (spec.shard_count / spec.slots_per_epoch) as usize;
|
||||
bench_builder.num_attestations = (spec.shard_count / T::slots_per_epoch()) as usize;
|
||||
bench_builder.num_deposits = 2;
|
||||
bench_builder.num_exits = 2;
|
||||
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(spec.slots_per_epoch);
|
||||
let last_slot_of_epoch = (spec.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.
|
||||
|
||||
@@ -140,7 +140,7 @@ pub fn verify_block_signature<T: EthSpec>(
|
||||
[state.get_beacon_proposer_index(block.slot, RelativeEpoch::Current, spec)?];
|
||||
|
||||
let domain = spec.get_domain(
|
||||
block.slot.epoch(spec.slots_per_epoch),
|
||||
block.slot.epoch(T::slots_per_epoch()),
|
||||
Domain::BeaconProposer,
|
||||
&state.fork,
|
||||
);
|
||||
@@ -172,7 +172,7 @@ pub fn process_randao<T: EthSpec>(
|
||||
block.body.randao_reveal.verify(
|
||||
&state.current_epoch().tree_hash_root()[..],
|
||||
spec.get_domain(
|
||||
block.slot.epoch(spec.slots_per_epoch),
|
||||
block.slot.epoch(T::slots_per_epoch()),
|
||||
Domain::Randao,
|
||||
&state.fork
|
||||
),
|
||||
|
||||
@@ -55,11 +55,13 @@ impl<T: EthSpec> BlockProcessingBuilder<T> {
|
||||
let keypair = &keypairs[proposer_index];
|
||||
|
||||
match randao_sk {
|
||||
Some(sk) => builder.set_randao_reveal(&sk, &state.fork, spec),
|
||||
None => builder.set_randao_reveal(&keypair.sk, &state.fork, spec),
|
||||
Some(sk) => builder.set_randao_reveal::<T>(&sk, &state.fork, spec),
|
||||
None => builder.set_randao_reveal::<T>(&keypair.sk, &state.fork, spec),
|
||||
}
|
||||
|
||||
let block = self.block_builder.build(&keypair.sk, &state.fork, spec);
|
||||
let block = self
|
||||
.block_builder
|
||||
.build::<T>(&keypair.sk, &state.fork, spec);
|
||||
|
||||
(block, state)
|
||||
}
|
||||
|
||||
@@ -9,7 +9,7 @@ pub const VALIDATOR_COUNT: usize = 10;
|
||||
|
||||
#[test]
|
||||
fn valid_block_ok() {
|
||||
let spec = FoundationEthSpec::spec();
|
||||
let spec = FoundationEthSpec::default_spec();
|
||||
let builder = get_builder(&spec);
|
||||
let (block, mut state) = builder.build(None, None, &spec);
|
||||
|
||||
@@ -20,7 +20,7 @@ fn valid_block_ok() {
|
||||
|
||||
#[test]
|
||||
fn invalid_block_header_state_slot() {
|
||||
let spec = FoundationEthSpec::spec();
|
||||
let spec = FoundationEthSpec::default_spec();
|
||||
let builder = get_builder(&spec);
|
||||
let (mut block, mut state) = builder.build(None, None, &spec);
|
||||
|
||||
@@ -39,7 +39,7 @@ fn invalid_block_header_state_slot() {
|
||||
|
||||
#[test]
|
||||
fn invalid_parent_block_root() {
|
||||
let spec = FoundationEthSpec::spec();
|
||||
let spec = FoundationEthSpec::default_spec();
|
||||
let builder = get_builder(&spec);
|
||||
let invalid_parent_root = Hash256::from([0xAA; 32]);
|
||||
let (block, mut state) = builder.build(None, Some(invalid_parent_root), &spec);
|
||||
@@ -59,14 +59,14 @@ fn invalid_parent_block_root() {
|
||||
|
||||
#[test]
|
||||
fn invalid_block_signature() {
|
||||
let spec = FoundationEthSpec::spec();
|
||||
let spec = FoundationEthSpec::default_spec();
|
||||
let builder = get_builder(&spec);
|
||||
let (mut block, mut state) = builder.build(None, None, &spec);
|
||||
|
||||
// sign the block with a keypair that is not the expected proposer
|
||||
let keypair = Keypair::random();
|
||||
let message = block.signed_root();
|
||||
let epoch = block.slot.epoch(spec.slots_per_epoch);
|
||||
let epoch = block.slot.epoch(FoundationEthSpec::slots_per_epoch());
|
||||
let domain = spec.get_domain(epoch, Domain::BeaconProposer, &state.fork);
|
||||
block.signature = Signature::new(&message, domain, &keypair.sk);
|
||||
|
||||
@@ -82,7 +82,7 @@ fn invalid_block_signature() {
|
||||
|
||||
#[test]
|
||||
fn invalid_randao_reveal_signature() {
|
||||
let spec = FoundationEthSpec::spec();
|
||||
let spec = FoundationEthSpec::default_spec();
|
||||
let builder = get_builder(&spec);
|
||||
|
||||
// sign randao reveal with random keypair
|
||||
@@ -104,7 +104,8 @@ fn get_builder(spec: &ChainSpec) -> (BlockProcessingBuilder<FoundationEthSpec>)
|
||||
let mut builder = BlockProcessingBuilder::new(VALIDATOR_COUNT, &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(spec.slots_per_epoch);
|
||||
let last_slot_of_epoch =
|
||||
(spec.genesis_epoch + 4).end_slot(FoundationEthSpec::slots_per_epoch());
|
||||
builder.set_slot(last_slot_of_epoch, &spec);
|
||||
builder.build_caches(&spec);
|
||||
|
||||
|
||||
@@ -68,7 +68,7 @@ fn validate_attestation_parametric<T: EthSpec>(
|
||||
}
|
||||
);
|
||||
verify!(
|
||||
state.slot <= attestation_slot + spec.slots_per_epoch,
|
||||
state.slot <= attestation_slot + T::slots_per_epoch(),
|
||||
Invalid::IncludedTooLate {
|
||||
state: state.slot,
|
||||
attestation: attestation_slot
|
||||
|
||||
@@ -21,8 +21,8 @@ pub fn verify_proposer_slashing<T: EthSpec>(
|
||||
})?;
|
||||
|
||||
verify!(
|
||||
proposer_slashing.header_1.slot.epoch(spec.slots_per_epoch)
|
||||
== proposer_slashing.header_2.slot.epoch(spec.slots_per_epoch),
|
||||
proposer_slashing.header_1.slot.epoch(T::slots_per_epoch())
|
||||
== proposer_slashing.header_2.slot.epoch(T::slots_per_epoch()),
|
||||
Invalid::ProposalEpochMismatch(
|
||||
proposer_slashing.header_1.slot,
|
||||
proposer_slashing.header_2.slot
|
||||
@@ -40,7 +40,7 @@ pub fn verify_proposer_slashing<T: EthSpec>(
|
||||
);
|
||||
|
||||
verify!(
|
||||
verify_header_signature(
|
||||
verify_header_signature::<T>(
|
||||
&proposer_slashing.header_1,
|
||||
&proposer.pubkey,
|
||||
&state.fork,
|
||||
@@ -49,7 +49,7 @@ pub fn verify_proposer_slashing<T: EthSpec>(
|
||||
Invalid::BadProposal1Signature
|
||||
);
|
||||
verify!(
|
||||
verify_header_signature(
|
||||
verify_header_signature::<T>(
|
||||
&proposer_slashing.header_2,
|
||||
&proposer.pubkey,
|
||||
&state.fork,
|
||||
@@ -66,7 +66,7 @@ pub fn verify_proposer_slashing<T: EthSpec>(
|
||||
/// Returns `true` if the signature is valid.
|
||||
///
|
||||
/// Spec v0.6.1
|
||||
fn verify_header_signature(
|
||||
fn verify_header_signature<T: EthSpec>(
|
||||
header: &BeaconBlockHeader,
|
||||
pubkey: &PublicKey,
|
||||
fork: &Fork,
|
||||
@@ -74,7 +74,7 @@ fn verify_header_signature(
|
||||
) -> bool {
|
||||
let message = header.signed_root();
|
||||
let domain = spec.get_domain(
|
||||
header.slot.epoch(spec.slots_per_epoch),
|
||||
header.slot.epoch(T::slots_per_epoch()),
|
||||
Domain::BeaconProposer,
|
||||
fork,
|
||||
);
|
||||
|
||||
@@ -101,7 +101,7 @@ fn verify_transfer_parametric<T: EthSpec>(
|
||||
.get(transfer.sender as usize)
|
||||
.ok_or_else(|| Error::Invalid(Invalid::FromValidatorUnknown(transfer.sender)))?;
|
||||
|
||||
let epoch = state.slot.epoch(spec.slots_per_epoch);
|
||||
let epoch = state.slot.epoch(T::slots_per_epoch());
|
||||
|
||||
// Ensure one of the following is met:
|
||||
//
|
||||
@@ -136,7 +136,7 @@ fn verify_transfer_parametric<T: EthSpec>(
|
||||
// Verify the transfer signature.
|
||||
let message = transfer.signed_root();
|
||||
let domain = spec.get_domain(
|
||||
transfer.slot.epoch(spec.slots_per_epoch),
|
||||
transfer.slot.epoch(T::slots_per_epoch()),
|
||||
Domain::Transfer,
|
||||
&state.fork,
|
||||
);
|
||||
|
||||
@@ -237,7 +237,7 @@ pub fn process_final_updates<T: EthSpec>(
|
||||
state.slot -= 1;
|
||||
}
|
||||
|
||||
if next_epoch.as_u64() % (T::SlotsPerHistoricalRoot::to_u64() / spec.slots_per_epoch) == 0 {
|
||||
if next_epoch.as_u64() % (T::SlotsPerHistoricalRoot::to_u64() / T::slots_per_epoch()) == 0 {
|
||||
let historical_batch = state.historical_batch();
|
||||
state
|
||||
.historical_roots
|
||||
|
||||
@@ -8,12 +8,12 @@ use types::*;
|
||||
fn runs_without_error() {
|
||||
Builder::from_env(Env::default().default_filter_or("error")).init();
|
||||
|
||||
let spec = FewValidatorsEthSpec::spec();
|
||||
let spec = FewValidatorsEthSpec::default_spec();
|
||||
|
||||
let mut builder: TestingBeaconStateBuilder<FewValidatorsEthSpec> =
|
||||
TestingBeaconStateBuilder::from_deterministic_keypairs(8, &spec);
|
||||
|
||||
let target_slot = (spec.genesis_epoch + 4).end_slot(spec.slots_per_epoch);
|
||||
let target_slot = (spec.genesis_epoch + 4).end_slot(FewValidatorsEthSpec::slots_per_epoch());
|
||||
builder.teleport_to_slot(target_slot, &spec);
|
||||
|
||||
let (mut state, _keypairs) = builder.build();
|
||||
|
||||
@@ -233,7 +233,7 @@ impl ValidatorStatuses {
|
||||
let attestation_slot = state.get_attestation_slot(&a.data)?;
|
||||
let inclusion_slot = attestation_slot + a.inclusion_delay;
|
||||
let relative_epoch =
|
||||
RelativeEpoch::from_slot(state.slot, inclusion_slot, spec.slots_per_epoch)?;
|
||||
RelativeEpoch::from_slot(state.slot, inclusion_slot, T::slots_per_epoch())?;
|
||||
status.inclusion_info = Some(InclusionInfo {
|
||||
slot: inclusion_slot,
|
||||
distance: a.inclusion_delay,
|
||||
@@ -297,7 +297,7 @@ impl ValidatorStatuses {
|
||||
spec: &ChainSpec,
|
||||
) -> Result<(), BeaconStateError> {
|
||||
// Loop through each slot in the previous epoch.
|
||||
for slot in state.previous_epoch().slot_iter(spec.slots_per_epoch) {
|
||||
for slot in state.previous_epoch().slot_iter(T::slots_per_epoch()) {
|
||||
let crosslink_committees_at_slot = state.get_crosslink_committees_at_slot(slot)?;
|
||||
|
||||
// Loop through each committee in the slot.
|
||||
@@ -338,7 +338,7 @@ fn target_matches_epoch_start_block<T: EthSpec>(
|
||||
epoch: Epoch,
|
||||
spec: &ChainSpec,
|
||||
) -> Result<bool, BeaconStateError> {
|
||||
let slot = epoch.start_slot(spec.slots_per_epoch);
|
||||
let slot = epoch.start_slot(T::slots_per_epoch());
|
||||
let state_boundary_root = *state.get_block_root(slot)?;
|
||||
|
||||
Ok(a.data.target_root == state_boundary_root)
|
||||
|
||||
@@ -16,7 +16,7 @@ pub fn per_slot_processing<T: EthSpec>(
|
||||
) -> Result<(), Error> {
|
||||
cache_state(state, spec)?;
|
||||
|
||||
if (state.slot > spec.genesis_slot) && ((state.slot + 1) % spec.slots_per_epoch == 0) {
|
||||
if (state.slot > spec.genesis_slot) && ((state.slot + 1) % T::slots_per_epoch() == 0) {
|
||||
per_epoch_processing(state, spec)?;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user