Skip to content

Commit

Permalink
Added the capability to run capella reference tests
Browse files Browse the repository at this point in the history
 - added the `operations/bls_to_execution_change` group to operations that are supported
 - added capella fork support

 partially addresses Consensys#5680

Signed-off-by: Paul Harris <[email protected]>
  • Loading branch information
rolfyone committed Nov 9, 2022
1 parent e2df22b commit a1dfcfe
Show file tree
Hide file tree
Showing 11 changed files with 91 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,14 @@ public abstract class Eth2ReferenceTestCase {
.putAll(RewardsTestExecutorBellatrix.REWARDS_TEST_TYPES)
.build();

private static final ImmutableMap<String, TestExecutor> CAPELLA_TEST_TYPES =
ImmutableMap.<String, TestExecutor>builder()
.putAll(TransitionTestExecutor.TRANSITION_TEST_TYPES)
.putAll(ForkUpgradeTestExecutor.FORK_UPGRADE_TEST_TYPES)
.putAll(RewardsTestExecutorBellatrix.REWARDS_TEST_TYPES)
.putAll(OperationsTestExecutor.OPERATIONS_TEST_TYPES)
.build();

protected void runReferenceTest(final TestDefinition testDefinition) throws Throwable {
getExecutorFor(testDefinition).runTest(testDefinition);
}
Expand All @@ -78,12 +86,22 @@ private TestExecutor getExecutorFor(final TestDefinition testDefinition) {
TestExecutor testExecutor = null;

// Look for fork-specific tests first
if (testDefinition.getFork().equals(TestFork.PHASE0)) {
testExecutor = PHASE_0_TEST_TYPES.get(testDefinition.getTestType());
} else if (testDefinition.getFork().equals(TestFork.ALTAIR)) {
testExecutor = ALTAIR_TEST_TYPES.get(testDefinition.getTestType());
} else if (testDefinition.getFork().equals(TestFork.BELLATRIX)) {
testExecutor = BELLATRIX_TEST_TYPES.get(testDefinition.getTestType());
switch (testDefinition.getFork()) {
case TestFork.PHASE0:
testExecutor = PHASE_0_TEST_TYPES.get(testDefinition.getTestType());
break;
case TestFork.ALTAIR:
testExecutor = ALTAIR_TEST_TYPES.get(testDefinition.getTestType());
break;
case TestFork.BELLATRIX:
testExecutor = BELLATRIX_TEST_TYPES.get(testDefinition.getTestType());
break;
case TestFork.CAPELLA:
testExecutor = CAPELLA_TEST_TYPES.get(testDefinition.getTestType());
break;
default:
throw new UnsupportedOperationException(
"Fork " + testDefinition.getFork() + " not implemented");
}

// Look for a common test type if no specific override present
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
import tech.pegasys.teku.spec.datastructures.operations.AttesterSlashing;
import tech.pegasys.teku.spec.datastructures.operations.Deposit;
import tech.pegasys.teku.spec.datastructures.operations.ProposerSlashing;
import tech.pegasys.teku.spec.datastructures.operations.SignedBlsToExecutionChange;
import tech.pegasys.teku.spec.datastructures.operations.SignedVoluntaryExit;
import tech.pegasys.teku.spec.datastructures.state.beaconstate.MutableBeaconState;
import tech.pegasys.teku.spec.logic.common.statetransition.exceptions.BlockProcessingException;
Expand Down Expand Up @@ -112,4 +113,12 @@ public void processExecutionPayload(
spec.getBlockProcessor(state.getSlot())
.processExecutionPayload(state, executionPayloadHeader, executionPayload, payloadExecutor);
}

@Override
public void processBlsToExecutionChange(
final MutableBeaconState state, final SignedBlsToExecutionChange blsToExecutionChange)
throws BlockProcessingException {
spec.getBlockProcessor(state.getSlot())
.processBlsToExecutionChange(state, blsToExecutionChange);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
import tech.pegasys.teku.spec.datastructures.operations.AttesterSlashing;
import tech.pegasys.teku.spec.datastructures.operations.Deposit;
import tech.pegasys.teku.spec.datastructures.operations.ProposerSlashing;
import tech.pegasys.teku.spec.datastructures.operations.SignedBlsToExecutionChange;
import tech.pegasys.teku.spec.datastructures.operations.SignedVoluntaryExit;
import tech.pegasys.teku.spec.datastructures.state.beaconstate.MutableBeaconState;
import tech.pegasys.teku.spec.logic.common.statetransition.exceptions.BlockProcessingException;
Expand Down Expand Up @@ -55,4 +56,9 @@ void processExecutionPayload(
Optional<ExecutionPayload> payload,
Optional<? extends OptimisticExecutionPayloadExecutor> payloadExecutor)
throws BlockProcessingException;

void processBlsToExecutionChange(
MutableBeaconState state, SignedBlsToExecutionChange blsToExecutionChange)
throws BlockProcessingException;
;
}
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@
import tech.pegasys.teku.spec.datastructures.operations.AttesterSlashing;
import tech.pegasys.teku.spec.datastructures.operations.Deposit;
import tech.pegasys.teku.spec.datastructures.operations.ProposerSlashing;
import tech.pegasys.teku.spec.datastructures.operations.SignedBlsToExecutionChange;
import tech.pegasys.teku.spec.datastructures.operations.SignedVoluntaryExit;
import tech.pegasys.teku.spec.datastructures.state.beaconstate.BeaconState;
import tech.pegasys.teku.spec.datastructures.state.beaconstate.BeaconStateCache;
Expand All @@ -47,6 +48,7 @@
import tech.pegasys.teku.spec.logic.common.statetransition.exceptions.EpochProcessingException;
import tech.pegasys.teku.spec.logic.common.statetransition.exceptions.SlotProcessingException;
import tech.pegasys.teku.spec.schemas.SchemaDefinitionsBellatrix;
import tech.pegasys.teku.spec.schemas.SchemaDefinitionsCapella;
import tech.pegasys.teku.statetransition.validation.AttesterSlashingValidator;
import tech.pegasys.teku.statetransition.validation.OperationValidator;
import tech.pegasys.teku.statetransition.validation.ProposerSlashingValidator;
Expand All @@ -64,7 +66,8 @@ private enum Operation {
VOLUNTARY_EXIT,
ATTESTATION,
SYNC_AGGREGATE,
EXECUTION_PAYLOAD
EXECUTION_PAYLOAD,
BLS_TO_EXECUTION_CHANGE
}

public static final ImmutableMap<String, TestExecutor> OPERATIONS_TEST_TYPES =
Expand Down Expand Up @@ -99,6 +102,10 @@ private enum Operation {
"operations/execution_payload",
new OperationsTestExecutor<>(
"execution_payload.ssz_snappy", Operation.EXECUTION_PAYLOAD))
.put(
"operations/bls_to_execution_change",
new OperationsTestExecutor<>(
"address_change.ssz_snappy", Operation.EXECUTION_PAYLOAD))
.build();

private final String dataFileName;
Expand Down Expand Up @@ -289,6 +296,19 @@ private void processOperation(
Optional.of(
(latestExecutionPayloadHeader, payloadToExecute) -> executionMeta.executionValid));
break;
case BLS_TO_EXECUTION_CHANGE:
final SchemaDefinitionsCapella schemaDefinitionsCapella =
testDefinition.getSpec().getGenesisSchemaDefinitions().toVersionCapella().orElseThrow();
final SignedBlsToExecutionChange blsToExecutionChange =
loadSsz(
testDefinition,
dataFileName,
schemaDefinitionsCapella.getSignedBlsToExecutionChangeSchema());
processor.processBlsToExecutionChange(state, blsToExecutionChange);
break;
default:
throw new UnsupportedOperationException(
"Operation " + operation + " not implemented in OperationTestExecutor");
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,4 +17,6 @@ public class TestFork {
public static final String PHASE0 = "phase0";
public static final String ALTAIR = "altair";
public static final String BELLATRIX = "bellatrix";

public static final String CAPELLA = "capella";
}
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ public class ReferenceTestFinder {
private static final Path TEST_PATH_FROM_MODULE =
Path.of("src", "referenceTest", "resources", "eth2.0-spec-tests", "tests");
private static final List<String> SUPPORTED_FORKS =
List.of(TestFork.PHASE0, TestFork.ALTAIR, TestFork.BELLATRIX);
List.of(TestFork.PHASE0, TestFork.ALTAIR, TestFork.BELLATRIX, TestFork.CAPELLA);

@MustBeClosed
public static Stream<TestDefinition> findReferenceTests() throws IOException {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,9 @@ private void createSpec() {
case TestFork.BELLATRIX:
highestSupportedMilestone = SpecMilestone.BELLATRIX;
break;
case TestFork.CAPELLA:
highestSupportedMilestone = SpecMilestone.CAPELLA;
break;
default:
throw new IllegalArgumentException("Unknown fork: " + fork);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
import tech.pegasys.teku.spec.datastructures.operations.AttesterSlashing;
import tech.pegasys.teku.spec.datastructures.operations.Deposit;
import tech.pegasys.teku.spec.datastructures.operations.ProposerSlashing;
import tech.pegasys.teku.spec.datastructures.operations.SignedBlsToExecutionChange;
import tech.pegasys.teku.spec.datastructures.operations.SignedVoluntaryExit;
import tech.pegasys.teku.spec.datastructures.state.beaconstate.BeaconState;
import tech.pegasys.teku.spec.datastructures.state.beaconstate.MutableBeaconState;
Expand Down Expand Up @@ -135,4 +136,7 @@ void validateExecutionPayload(
throws BlockProcessingException;

boolean isOptimistic();

void processBlsToExecutionChange(
MutableBeaconState state, SignedBlsToExecutionChange blsToExecutionChange);
}
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@
import tech.pegasys.teku.spec.datastructures.operations.Attestation;
import tech.pegasys.teku.spec.datastructures.operations.AttestationData;
import tech.pegasys.teku.spec.datastructures.operations.Deposit;
import tech.pegasys.teku.spec.datastructures.operations.SignedBlsToExecutionChange;
import tech.pegasys.teku.spec.datastructures.state.beaconstate.BeaconState;
import tech.pegasys.teku.spec.datastructures.state.beaconstate.BeaconStateCache;
import tech.pegasys.teku.spec.datastructures.state.beaconstate.MutableBeaconState;
Expand Down Expand Up @@ -292,6 +293,12 @@ public boolean isOptimistic() {
return false;
}

@Override
public void processBlsToExecutionChange(
final MutableBeaconState state, final SignedBlsToExecutionChange blsToExecutionChange) {
throw new UnsupportedOperationException("No BlsToExecutionChange in Altair.");
}

public static boolean eth2FastAggregateVerify(
final BLSSignatureVerifier signatureVerifier,
List<BLSPublicKey> pubkeys,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
import tech.pegasys.teku.spec.datastructures.blocks.blockbody.versions.bellatrix.BlindedBeaconBlockBodyBellatrix;
import tech.pegasys.teku.spec.datastructures.execution.ExecutionPayload;
import tech.pegasys.teku.spec.datastructures.execution.ExecutionPayloadHeader;
import tech.pegasys.teku.spec.datastructures.operations.SignedBlsToExecutionChange;
import tech.pegasys.teku.spec.datastructures.state.beaconstate.BeaconState;
import tech.pegasys.teku.spec.datastructures.state.beaconstate.MutableBeaconState;
import tech.pegasys.teku.spec.datastructures.state.beaconstate.versions.bellatrix.BeaconStateBellatrix;
Expand Down Expand Up @@ -177,4 +178,10 @@ public void validateExecutionPayload(
public boolean isOptimistic() {
return true;
}

@Override
public void processBlsToExecutionChange(
final MutableBeaconState state, final SignedBlsToExecutionChange blsToExecutionChange) {
throw new UnsupportedOperationException("No BlsToExecutionChange in Bellatrix.");
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
import tech.pegasys.teku.spec.datastructures.execution.ExecutionPayloadHeader;
import tech.pegasys.teku.spec.datastructures.operations.Attestation;
import tech.pegasys.teku.spec.datastructures.operations.AttestationData;
import tech.pegasys.teku.spec.datastructures.operations.SignedBlsToExecutionChange;
import tech.pegasys.teku.spec.datastructures.state.PendingAttestation;
import tech.pegasys.teku.spec.datastructures.state.beaconstate.BeaconState;
import tech.pegasys.teku.spec.datastructures.state.beaconstate.MutableBeaconState;
Expand Down Expand Up @@ -123,4 +124,10 @@ public void validateExecutionPayload(
public boolean isOptimistic() {
return false;
}

@Override
public void processBlsToExecutionChange(
final MutableBeaconState state, final SignedBlsToExecutionChange blsToExecutionChange) {
throw new UnsupportedOperationException("No BlsToExecutionChange in phase0");
}
}

0 comments on commit a1dfcfe

Please sign in to comment.