Skip to content

Commit

Permalink
Increase max attestation inclusion slot (beacon chain changes)
Browse files Browse the repository at this point in the history
  • Loading branch information
StefanBratanov committed Jun 29, 2023
1 parent 0b5ef8a commit 88117a0
Show file tree
Hide file tree
Showing 17 changed files with 196 additions and 58 deletions.
2 changes: 1 addition & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -295,7 +295,7 @@ allprojects {
}
}

def refTestVersion = 'v1.4.0-alpha.3' // Arbitrary change to refresh cache number: 1
def refTestVersion = 'v1.4.0-beta.0' // Arbitrary change to refresh cache number: 1
def blsRefTestVersion = 'v0.1.2'
def refTestBaseUrl = 'https://github.com/ethereum/consensus-spec-tests/releases/download'
def blsRefTestBaseUrl = 'https://github.com/ethereum/bls12-381-tests/releases/download'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -214,7 +214,7 @@ public NetworkingSpecConfig getNetworkingConfig() {
public Optional<NetworkingSpecConfigDeneb> getNetworkingConfigDeneb() {
return Optional.ofNullable(forMilestone(DENEB))
.map(SpecVersion::getConfig)
.map(specConfig -> (SpecConfigDeneb) specConfig.getNetworkingConfig());
.map(specConfig -> (NetworkingSpecConfigDeneb) specConfig.getNetworkingConfig());
}

public SchemaDefinitions getGenesisSchemaDefinitions() {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
/*
* Copyright ConsenSys Software Inc., 2023
*
* Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on
* an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the
* specific language governing permissions and limitations under the License.
*/

package tech.pegasys.teku.spec.logic.common.operations.validation;

import tech.pegasys.teku.spec.datastructures.operations.AttestationData;

public interface AttestationDataValidator
extends OperationStateTransitionValidator<AttestationData> {

enum AttestationInvalidReason implements OperationInvalidReason {
COMMITTEE_INDEX_TOO_HIGH("CommitteeIndex too high"),
NOT_FROM_CURRENT_OR_PREVIOUS_EPOCH("Attestation not from current or previous epoch"),
SLOT_NOT_IN_EPOCH("Attestation slot not in specified epoch"),
SUBMITTED_TOO_QUICKLY("Attestation submitted too quickly"),
SUBMITTED_TOO_LATE("Attestation submitted too late"),
INCORRECT_CURRENT_JUSTIFIED_CHECKPOINT(
"Attestation source does not match current justified checkpoint"),
INCORRECT_PREVIOUS_JUSTIFIED_CHECKPOINT(
"Attestation source does not match previous justified checkpoint");

private final String description;

AttestationInvalidReason(final String description) {
this.description = description;
}

@Override
public String describe() {
return description;
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
import tech.pegasys.teku.spec.logic.common.helpers.BeaconStateMutators;
import tech.pegasys.teku.spec.logic.common.helpers.Predicates;
import tech.pegasys.teku.spec.logic.common.operations.OperationSignatureVerifier;
import tech.pegasys.teku.spec.logic.common.operations.validation.AttestationDataValidator;
import tech.pegasys.teku.spec.logic.common.operations.validation.OperationValidator;
import tech.pegasys.teku.spec.logic.common.util.AttestationUtil;
import tech.pegasys.teku.spec.logic.common.util.BeaconStateUtil;
Expand All @@ -36,6 +37,7 @@
import tech.pegasys.teku.spec.logic.versions.altair.statetransition.epoch.ValidatorStatusFactoryAltair;
import tech.pegasys.teku.spec.logic.versions.altair.util.AttestationUtilAltair;
import tech.pegasys.teku.spec.logic.versions.bellatrix.helpers.BellatrixTransitionHelpers;
import tech.pegasys.teku.spec.logic.versions.phase0.operations.validation.AttestationDataValidatorPhase0;
import tech.pegasys.teku.spec.logic.versions.phase0.operations.validation.OperationValidatorPhase0;
import tech.pegasys.teku.spec.schemas.SchemaDefinitionsAltair;

Expand Down Expand Up @@ -106,9 +108,11 @@ public static SpecLogicAltair create(
new AttestationUtilAltair(config, schemaDefinitions, beaconStateAccessors, miscHelpers);
// specific operation validator from spec so that things can hapepn like rejecting bls to
// execution change
final AttestationDataValidator attestationDataValidator =
new AttestationDataValidatorPhase0(config, miscHelpers, beaconStateAccessors);
final OperationValidator operationValidator =
new OperationValidatorPhase0(
config, predicates, miscHelpers, beaconStateAccessors, attestationUtil);
config, predicates, beaconStateAccessors, attestationDataValidator, attestationUtil);
final ValidatorStatusFactoryAltair validatorStatusFactory =
new ValidatorStatusFactoryAltair(
config,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -196,7 +196,7 @@ public List<Integer> getAttestationParticipationFlagIndices(
&& inclusionDelay.isLessThanOrEqualTo(config.getSquareRootSlotsPerEpoch())) {
participationFlagIndices.add(ParticipationFlags.TIMELY_SOURCE_FLAG_INDEX);
}
if (isMatchingTarget && inclusionDelay.isLessThanOrEqualTo(config.getSlotsPerEpoch())) {
if (shouldSetTargetTimelinessFlag(isMatchingTarget, inclusionDelay)) {
participationFlagIndices.add(ParticipationFlags.TIMELY_TARGET_FLAG_INDEX);
}
if (isMatchingHead
Expand All @@ -206,6 +206,11 @@ public List<Integer> getAttestationParticipationFlagIndices(
return participationFlagIndices;
}

protected boolean shouldSetTargetTimelinessFlag(
final boolean isMatchingTarget, final UInt64 inclusionDelay) {
return isMatchingTarget && inclusionDelay.isLessThanOrEqualTo(config.getSlotsPerEpoch());
}

public static BeaconStateAccessorsAltair required(
final BeaconStateAccessors beaconStateAccessors) {
checkArgument(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
import tech.pegasys.teku.spec.logic.common.AbstractSpecLogic;
import tech.pegasys.teku.spec.logic.common.helpers.Predicates;
import tech.pegasys.teku.spec.logic.common.operations.OperationSignatureVerifier;
import tech.pegasys.teku.spec.logic.common.operations.validation.AttestationDataValidator;
import tech.pegasys.teku.spec.logic.common.operations.validation.OperationValidator;
import tech.pegasys.teku.spec.logic.common.util.AttestationUtil;
import tech.pegasys.teku.spec.logic.common.util.BeaconStateUtil;
Expand All @@ -37,6 +38,7 @@
import tech.pegasys.teku.spec.logic.versions.bellatrix.helpers.MiscHelpersBellatrix;
import tech.pegasys.teku.spec.logic.versions.bellatrix.statetransition.epoch.EpochProcessorBellatrix;
import tech.pegasys.teku.spec.logic.versions.bellatrix.util.BlindBlockUtilBellatrix;
import tech.pegasys.teku.spec.logic.versions.phase0.operations.validation.AttestationDataValidatorPhase0;
import tech.pegasys.teku.spec.logic.versions.phase0.operations.validation.OperationValidatorPhase0;
import tech.pegasys.teku.spec.schemas.SchemaDefinitionsBellatrix;

Expand Down Expand Up @@ -110,9 +112,11 @@ public static SpecLogicBellatrix create(
config, schemaDefinitions, predicates, miscHelpers, beaconStateAccessors);
final AttestationUtil attestationUtil =
new AttestationUtilAltair(config, schemaDefinitions, beaconStateAccessors, miscHelpers);
final AttestationDataValidator attestationDataValidator =
new AttestationDataValidatorPhase0(config, miscHelpers, beaconStateAccessors);
final OperationValidator operationValidator =
new OperationValidatorPhase0(
config, predicates, miscHelpers, beaconStateAccessors, attestationUtil);
config, predicates, beaconStateAccessors, attestationDataValidator, attestationUtil);
final ValidatorStatusFactoryAltair validatorStatusFactory =
new ValidatorStatusFactoryAltair(
config,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
import tech.pegasys.teku.spec.logic.common.AbstractSpecLogic;
import tech.pegasys.teku.spec.logic.common.helpers.Predicates;
import tech.pegasys.teku.spec.logic.common.operations.OperationSignatureVerifier;
import tech.pegasys.teku.spec.logic.common.operations.validation.AttestationDataValidator;
import tech.pegasys.teku.spec.logic.common.operations.validation.OperationValidator;
import tech.pegasys.teku.spec.logic.common.util.AttestationUtil;
import tech.pegasys.teku.spec.logic.common.util.BeaconStateUtil;
Expand All @@ -39,6 +40,7 @@
import tech.pegasys.teku.spec.logic.versions.capella.helpers.MiscHelpersCapella;
import tech.pegasys.teku.spec.logic.versions.capella.operations.validation.OperationValidatorCapella;
import tech.pegasys.teku.spec.logic.versions.capella.statetransition.epoch.EpochProcessorCapella;
import tech.pegasys.teku.spec.logic.versions.phase0.operations.validation.AttestationDataValidatorPhase0;
import tech.pegasys.teku.spec.schemas.SchemaDefinitionsCapella;

public class SpecLogicCapella extends AbstractSpecLogic {
Expand Down Expand Up @@ -110,9 +112,11 @@ public static SpecLogicCapella create(
config, schemaDefinitions, predicates, miscHelpers, beaconStateAccessors);
final AttestationUtil attestationUtil =
new AttestationUtilAltair(config, schemaDefinitions, beaconStateAccessors, miscHelpers);
final AttestationDataValidator attestationDataValidator =
new AttestationDataValidatorPhase0(config, miscHelpers, beaconStateAccessors);
final OperationValidator operationValidator =
new OperationValidatorCapella(
config, predicates, miscHelpers, beaconStateAccessors, attestationUtil);
config, predicates, beaconStateAccessors, attestationDataValidator, attestationUtil);
final ValidatorStatusFactoryAltair validatorStatusFactory =
new ValidatorStatusFactoryAltair(
config,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,8 @@
import tech.pegasys.teku.spec.datastructures.state.Fork;
import tech.pegasys.teku.spec.datastructures.state.beaconstate.BeaconState;
import tech.pegasys.teku.spec.logic.common.helpers.BeaconStateAccessors;
import tech.pegasys.teku.spec.logic.common.helpers.MiscHelpers;
import tech.pegasys.teku.spec.logic.common.helpers.Predicates;
import tech.pegasys.teku.spec.logic.common.operations.validation.AttestationDataValidator;
import tech.pegasys.teku.spec.logic.common.operations.validation.OperationInvalidReason;
import tech.pegasys.teku.spec.logic.common.util.AttestationUtil;
import tech.pegasys.teku.spec.logic.versions.phase0.operations.validation.OperationValidatorPhase0;
Expand All @@ -33,10 +33,10 @@ public class OperationValidatorCapella extends OperationValidatorPhase0 {
public OperationValidatorCapella(
final SpecConfig specConfig,
final Predicates predicates,
final MiscHelpers miscHelpers,
final BeaconStateAccessors beaconStateAccessors,
final AttestationDataValidator attestationDataValidator,
final AttestationUtil attestationUtil) {
super(specConfig, predicates, miscHelpers, beaconStateAccessors, attestationUtil);
super(specConfig, predicates, beaconStateAccessors, attestationDataValidator, attestationUtil);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
import tech.pegasys.teku.spec.logic.common.AbstractSpecLogic;
import tech.pegasys.teku.spec.logic.common.helpers.Predicates;
import tech.pegasys.teku.spec.logic.common.operations.OperationSignatureVerifier;
import tech.pegasys.teku.spec.logic.common.operations.validation.AttestationDataValidator;
import tech.pegasys.teku.spec.logic.common.operations.validation.OperationValidator;
import tech.pegasys.teku.spec.logic.common.util.AttestationUtil;
import tech.pegasys.teku.spec.logic.common.util.BeaconStateUtil;
Expand All @@ -37,7 +38,9 @@
import tech.pegasys.teku.spec.logic.versions.capella.statetransition.epoch.EpochProcessorCapella;
import tech.pegasys.teku.spec.logic.versions.deneb.block.BlockProcessorDeneb;
import tech.pegasys.teku.spec.logic.versions.deneb.forktransition.DenebStateUpgrade;
import tech.pegasys.teku.spec.logic.versions.deneb.helpers.BeaconStateAccessorsDeneb;
import tech.pegasys.teku.spec.logic.versions.deneb.helpers.MiscHelpersDeneb;
import tech.pegasys.teku.spec.logic.versions.deneb.operations.validation.AttestationDataValidatorDeneb;
import tech.pegasys.teku.spec.logic.versions.deneb.util.BlindBlockUtilDeneb;
import tech.pegasys.teku.spec.logic.versions.deneb.util.ForkChoiceUtilDeneb;
import tech.pegasys.teku.spec.schemas.SchemaDefinitionsDeneb;
Expand Down Expand Up @@ -91,8 +94,8 @@ public static SpecLogicDeneb create(
// Helpers
final Predicates predicates = new Predicates(config);
final MiscHelpersDeneb miscHelpers = new MiscHelpersDeneb(config);
final BeaconStateAccessorsAltair beaconStateAccessors =
new BeaconStateAccessorsAltair(config, predicates, miscHelpers);
final BeaconStateAccessorsDeneb beaconStateAccessors =
new BeaconStateAccessorsDeneb(config, predicates, miscHelpers);
final BeaconStateMutatorsBellatrix beaconStateMutators =
new BeaconStateMutatorsBellatrix(config, miscHelpers, beaconStateAccessors);

Expand All @@ -108,9 +111,11 @@ public static SpecLogicDeneb create(
config, schemaDefinitions, predicates, miscHelpers, beaconStateAccessors);
final AttestationUtil attestationUtil =
new AttestationUtilAltair(config, schemaDefinitions, beaconStateAccessors, miscHelpers);
final AttestationDataValidator attestationDataValidator =
new AttestationDataValidatorDeneb(config, miscHelpers, beaconStateAccessors);
final OperationValidator operationValidator =
new OperationValidatorCapella(
config, predicates, miscHelpers, beaconStateAccessors, attestationUtil);
config, predicates, beaconStateAccessors, attestationDataValidator, attestationUtil);
final ValidatorStatusFactoryAltair validatorStatusFactory =
new ValidatorStatusFactoryAltair(
config,
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
/*
* Copyright ConsenSys Software Inc., 2023
*
* Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on
* an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the
* specific language governing permissions and limitations under the License.
*/

package tech.pegasys.teku.spec.logic.versions.deneb.helpers;

import tech.pegasys.teku.infrastructure.unsigned.UInt64;
import tech.pegasys.teku.spec.config.SpecConfigDeneb;
import tech.pegasys.teku.spec.logic.common.helpers.Predicates;
import tech.pegasys.teku.spec.logic.versions.altair.helpers.BeaconStateAccessorsAltair;

public class BeaconStateAccessorsDeneb extends BeaconStateAccessorsAltair {

public BeaconStateAccessorsDeneb(
final SpecConfigDeneb config,
final Predicates predicates,
final MiscHelpersDeneb miscHelpers) {
super(config, predicates, miscHelpers);
}

/**
* <a
* href="https://github.com/ethereum/consensus-specs/blob/dev/specs/deneb/beacon-chain.md#modified-get_attestation_participation_flag_indices">Modified
* get_attestation_participation_flag_indices</a>
*/
@Override
protected boolean shouldSetTargetTimelinessFlag(
final boolean isMatchingTarget, final UInt64 inclusionDelay) {
return isMatchingTarget;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
/*
* Copyright ConsenSys Software Inc., 2023
*
* Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on
* an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the
* specific language governing permissions and limitations under the License.
*/

package tech.pegasys.teku.spec.logic.versions.deneb.operations.validation;

import java.util.Optional;
import tech.pegasys.teku.spec.config.SpecConfig;
import tech.pegasys.teku.spec.datastructures.operations.AttestationData;
import tech.pegasys.teku.spec.datastructures.state.beaconstate.BeaconState;
import tech.pegasys.teku.spec.logic.common.helpers.BeaconStateAccessors;
import tech.pegasys.teku.spec.logic.common.helpers.MiscHelpers;
import tech.pegasys.teku.spec.logic.common.operations.validation.OperationInvalidReason;
import tech.pegasys.teku.spec.logic.versions.phase0.operations.validation.AttestationDataValidatorPhase0;

public class AttestationDataValidatorDeneb extends AttestationDataValidatorPhase0 {

public AttestationDataValidatorDeneb(
final SpecConfig specConfig,
final MiscHelpers miscHelpers,
final BeaconStateAccessors beaconStateAccessors) {
super(specConfig, miscHelpers, beaconStateAccessors);
}

/**
* <a
* href="https://github.com/ethereum/consensus-specs/blob/dev/specs/deneb/beacon-chain.md#modified-process_attestation">Modified
* process_attestation</a>
*/
@Override
protected Optional<OperationInvalidReason> isSubmittedTooLate(
final BeaconState state, final AttestationData data) {
return Optional.empty();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
import tech.pegasys.teku.spec.logic.common.helpers.MiscHelpers;
import tech.pegasys.teku.spec.logic.common.helpers.Predicates;
import tech.pegasys.teku.spec.logic.common.operations.OperationSignatureVerifier;
import tech.pegasys.teku.spec.logic.common.operations.validation.AttestationDataValidator;
import tech.pegasys.teku.spec.logic.common.operations.validation.OperationValidator;
import tech.pegasys.teku.spec.logic.common.util.AttestationUtil;
import tech.pegasys.teku.spec.logic.common.util.BeaconStateUtil;
Expand All @@ -32,6 +33,7 @@
import tech.pegasys.teku.spec.logic.versions.bellatrix.helpers.BellatrixTransitionHelpers;
import tech.pegasys.teku.spec.logic.versions.phase0.block.BlockProcessorPhase0;
import tech.pegasys.teku.spec.logic.versions.phase0.helpers.BeaconStateAccessorsPhase0;
import tech.pegasys.teku.spec.logic.versions.phase0.operations.validation.AttestationDataValidatorPhase0;
import tech.pegasys.teku.spec.logic.versions.phase0.operations.validation.OperationValidatorPhase0;
import tech.pegasys.teku.spec.logic.versions.phase0.statetransition.epoch.EpochProcessorPhase0;
import tech.pegasys.teku.spec.logic.versions.phase0.statetransition.epoch.ValidatorStatusFactoryPhase0;
Expand Down Expand Up @@ -96,9 +98,11 @@ public static SpecLogicPhase0 create(
config, schemaDefinitions, predicates, miscHelpers, beaconStateAccessors);
final AttestationUtil attestationUtil =
new AttestationUtilPhase0(config, schemaDefinitions, beaconStateAccessors, miscHelpers);
final AttestationDataValidator attestationDataValidator =
new AttestationDataValidatorPhase0(config, miscHelpers, beaconStateAccessors);
final OperationValidator operationValidator =
new OperationValidatorPhase0(
config, predicates, miscHelpers, beaconStateAccessors, attestationUtil);
config, predicates, beaconStateAccessors, attestationDataValidator, attestationUtil);
final ValidatorStatusFactoryPhase0 validatorStatusFactory =
new ValidatorStatusFactoryPhase0(
config, beaconStateUtil, attestationUtil, beaconStateAccessors, predicates);
Expand Down
Loading

0 comments on commit 88117a0

Please sign in to comment.