Skip to content

Commit

Permalink
Added electra ref tests for deposit_receipt and execution_layer_exit
Browse files Browse the repository at this point in the history
  • Loading branch information
lucassaldanha committed Apr 7, 2024
1 parent a11e4c5 commit 5e0bd21
Show file tree
Hide file tree
Showing 10 changed files with 115 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -14,25 +14,32 @@
package tech.pegasys.teku.reference.common.operations;

import java.util.Optional;
import java.util.function.Supplier;
import tech.pegasys.teku.bls.BLSSignatureVerifier;
import tech.pegasys.teku.infrastructure.ssz.SszList;
import tech.pegasys.teku.spec.Spec;
import tech.pegasys.teku.spec.datastructures.blocks.BeaconBlockSummary;
import tech.pegasys.teku.spec.datastructures.blocks.blockbody.BeaconBlockBody;
import tech.pegasys.teku.spec.datastructures.blocks.blockbody.BeaconBlockBodySchema;
import tech.pegasys.teku.spec.datastructures.blocks.blockbody.versions.altair.SyncAggregate;
import tech.pegasys.teku.spec.datastructures.blocks.blockbody.versions.capella.BeaconBlockBodySchemaCapella;
import tech.pegasys.teku.spec.datastructures.blocks.blockbody.versions.electra.BeaconBlockBodySchemaElectra;
import tech.pegasys.teku.spec.datastructures.execution.ExecutionPayloadSummary;
import tech.pegasys.teku.spec.datastructures.execution.versions.electra.DepositReceipt;
import tech.pegasys.teku.spec.datastructures.execution.versions.electra.ExecutionLayerExit;
import tech.pegasys.teku.spec.datastructures.operations.Attestation;
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.helpers.BeaconStateMutators.ValidatorExitContext;
import tech.pegasys.teku.spec.logic.common.statetransition.exceptions.BlockProcessingException;
import tech.pegasys.teku.spec.logic.versions.bellatrix.block.OptimisticExecutionPayloadExecutor;

public class DefaultOperationProcessor implements OperationProcessor {

private final Spec spec;
private final BeaconBlockBodySchema<?> beaconBlockBodySchema;

Expand Down Expand Up @@ -132,4 +139,34 @@ public void processWithdrawals(
throws BlockProcessingException {
spec.getBlockProcessor(state.getSlot()).processWithdrawals(state, payloadSummary);
}

@Override
public void processDepositReceipt(
final MutableBeaconState state, final DepositReceipt depositReceipt)
throws BlockProcessingException {
final SszList<DepositReceipt> depositReceiptList =
BeaconBlockBodySchemaElectra.required(beaconBlockBodySchema)
.getExecutionPayloadSchema()
.getDepositReceiptsSchemaRequired()
.of(depositReceipt);

spec.getBlockProcessor(state.getSlot()).processDepositReceipts(state, depositReceiptList);
}

@Override
public void processExecutionLayerExit(
final MutableBeaconState state, final ExecutionLayerExit executionLayerExit)
throws BlockProcessingException {
final SszList<ExecutionLayerExit> exits =
BeaconBlockBodySchemaElectra.required(beaconBlockBodySchema)
.getExecutionPayloadSchema()
.getExecutionLayerExitsSchemaRequired()
.of(executionLayerExit);
final Supplier<ValidatorExitContext> validatorExitContextSupplier =
spec.atSlot(state.getSlot())
.beaconStateMutators()
.createValidatorExitContextSupplier(state);
spec.getBlockProcessor(state.getSlot())
.processExecutionLayerExits(state, exits, validatorExitContextSupplier);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@
import tech.pegasys.teku.spec.datastructures.blocks.blockbody.BeaconBlockBody;
import tech.pegasys.teku.spec.datastructures.blocks.blockbody.versions.altair.SyncAggregate;
import tech.pegasys.teku.spec.datastructures.execution.ExecutionPayloadSummary;
import tech.pegasys.teku.spec.datastructures.execution.versions.electra.DepositReceipt;
import tech.pegasys.teku.spec.datastructures.execution.versions.electra.ExecutionLayerExit;
import tech.pegasys.teku.spec.datastructures.operations.Attestation;
import tech.pegasys.teku.spec.datastructures.operations.AttesterSlashing;
import tech.pegasys.teku.spec.datastructures.operations.Deposit;
Expand Down Expand Up @@ -62,4 +64,10 @@ void processBlsToExecutionChange(

void processWithdrawals(MutableBeaconState state, ExecutionPayloadSummary payloadSummary)
throws BlockProcessingException;

void processDepositReceipt(final MutableBeaconState state, final DepositReceipt depositReceipt)
throws BlockProcessingException;

void processExecutionLayerExit(MutableBeaconState state, ExecutionLayerExit executionLayerExit)
throws BlockProcessingException;
}
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,8 @@
import tech.pegasys.teku.spec.datastructures.blocks.blockbody.versions.altair.BeaconBlockBodySchemaAltair;
import tech.pegasys.teku.spec.datastructures.blocks.blockbody.versions.altair.SyncAggregate;
import tech.pegasys.teku.spec.datastructures.execution.ExecutionPayload;
import tech.pegasys.teku.spec.datastructures.execution.versions.electra.DepositReceipt;
import tech.pegasys.teku.spec.datastructures.execution.versions.electra.ExecutionLayerExit;
import tech.pegasys.teku.spec.datastructures.operations.Attestation;
import tech.pegasys.teku.spec.datastructures.operations.AttesterSlashing;
import tech.pegasys.teku.spec.datastructures.operations.Deposit;
Expand Down Expand Up @@ -71,7 +73,9 @@ private enum Operation {
SYNC_AGGREGATE,
EXECUTION_PAYLOAD,
BLS_TO_EXECUTION_CHANGE,
WITHDRAWAL
WITHDRAWAL,
DEPOSIT_RECEIPT,
EXECUTION_LAYER_EXIT
}

public static final ImmutableMap<String, TestExecutor> OPERATIONS_TEST_TYPES =
Expand Down Expand Up @@ -112,6 +116,13 @@ private enum Operation {
.put(
"operations/withdrawals",
new OperationsTestExecutor<>("execution_payload.ssz_snappy", Operation.WITHDRAWAL))
.put(
"operations/deposit_receipt",
new OperationsTestExecutor<>("deposit_receipt.ssz_snappy", Operation.DEPOSIT_RECEIPT))
.put(
"operations/execution_layer_exit",
new OperationsTestExecutor<>(
"execution_layer_exit.ssz_snappy", Operation.EXECUTION_LAYER_EXIT))
.build();

private final String dataFileName;
Expand Down Expand Up @@ -298,6 +309,8 @@ private void processOperation(
}
case BLS_TO_EXECUTION_CHANGE -> processBlsToExecutionChange(testDefinition, state, processor);
case WITHDRAWAL -> processWithdrawal(testDefinition, state, processor);
case DEPOSIT_RECEIPT -> processDepositReceipt(testDefinition, state, processor);
case EXECUTION_LAYER_EXIT -> processExecutionLayerExit(testDefinition, state, processor);
default -> throw new UnsupportedOperationException(
"Operation " + operation + " not implemented in OperationTestExecutor");
}
Expand Down Expand Up @@ -325,6 +338,26 @@ private void processBlsToExecutionChange(
processor.processBlsToExecutionChange(state, blsToExecutionChange);
}

private void processDepositReceipt(
final TestDefinition testDefinition,
final MutableBeaconState state,
final OperationProcessor processor)
throws BlockProcessingException {
final DepositReceipt depositReceipt =
loadSsz(testDefinition, dataFileName, DepositReceipt.SSZ_SCHEMA);
processor.processDepositReceipt(state, depositReceipt);
}

private void processExecutionLayerExit(
final TestDefinition testDefinition,
final MutableBeaconState state,
final OperationProcessor processor)
throws BlockProcessingException {
final ExecutionLayerExit executionLayerExit =
loadSsz(testDefinition, dataFileName, ExecutionLayerExit.SSZ_SCHEMA);
processor.processExecutionLayerExit(state, executionLayerExit);
}

private SignedVoluntaryExit loadVoluntaryExit(final TestDefinition testDefinition) {
return loadSsz(testDefinition, dataFileName, SignedVoluntaryExit.SSZ_SCHEMA);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,4 +19,5 @@ public class TestFork {
public static final String BELLATRIX = "bellatrix";
public static final String CAPELLA = "capella";
public static final String DENEB = "deneb";
public static final String ELECTRA = "electra";
}
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,12 @@ public class ReferenceTestFinder {
Path.of("src", "referenceTest", "resources", "consensus-spec-tests", "tests");
private static final List<String> SUPPORTED_FORKS =
List.of(
TestFork.PHASE0, TestFork.ALTAIR, TestFork.BELLATRIX, TestFork.CAPELLA, TestFork.DENEB);
TestFork.PHASE0,
TestFork.ALTAIR,
TestFork.BELLATRIX,
TestFork.CAPELLA,
TestFork.DENEB,
TestFork.ELECTRA);

@MustBeClosed
public static Stream<TestDefinition> findReferenceTests() throws IOException {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@ private void createSpec() {
case TestFork.BELLATRIX -> SpecMilestone.BELLATRIX;
case TestFork.CAPELLA -> SpecMilestone.CAPELLA;
case TestFork.DENEB -> SpecMilestone.DENEB;
case TestFork.ELECTRA -> SpecMilestone.ELECTRA;
default -> throw new IllegalArgumentException("Unknown fork: " + fork);
};
spec = TestSpecFactory.create(milestone, network);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@
import tech.pegasys.teku.spec.datastructures.blocks.SignedBeaconBlock;
import tech.pegasys.teku.spec.datastructures.blocks.blockbody.BeaconBlockBody;
import tech.pegasys.teku.spec.datastructures.execution.ExecutionPayload;
import tech.pegasys.teku.spec.datastructures.execution.versions.electra.DepositReceipt;
import tech.pegasys.teku.spec.datastructures.execution.versions.electra.ExecutionLayerExit;
import tech.pegasys.teku.spec.datastructures.operations.Attestation;
import tech.pegasys.teku.spec.datastructures.operations.AttestationData;
Expand Down Expand Up @@ -884,11 +885,19 @@ protected void processExecutionLayerExits(
// No ExecutionLayer exits until Electra
}

@Override
public void processDepositReceipts(
final MutableBeaconState state, final SszList<DepositReceipt> depositReceipts)
throws BlockProcessingException {
// No DepositReceipts until Electra
}

@Override
public void processExecutionLayerExits(
final MutableBeaconState state,
final SszList<ExecutionLayerExit> exits,
final Supplier<ValidatorExitContext> validatorExitContextSupplier) {
final Supplier<ValidatorExitContext> validatorExitContextSupplier)
throws BlockProcessingException {
// No ExecutionLayer exits until Electra
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
import tech.pegasys.teku.spec.datastructures.execution.ExecutionPayloadSummary;
import tech.pegasys.teku.spec.datastructures.execution.NewPayloadRequest;
import tech.pegasys.teku.spec.datastructures.execution.versions.capella.Withdrawal;
import tech.pegasys.teku.spec.datastructures.execution.versions.electra.DepositReceipt;
import tech.pegasys.teku.spec.datastructures.execution.versions.electra.ExecutionLayerExit;
import tech.pegasys.teku.spec.datastructures.operations.Attestation;
import tech.pegasys.teku.spec.datastructures.operations.AttestationData;
Expand Down Expand Up @@ -167,10 +168,15 @@ void processBlsToExecutionChanges(
void processWithdrawals(MutableBeaconState state, ExecutionPayloadSummary payloadSummary)
throws BlockProcessingException;

void processDepositReceipts(
final MutableBeaconState state, final SszList<DepositReceipt> depositReceipts)
throws BlockProcessingException;

void processExecutionLayerExits(
final MutableBeaconState state,
final SszList<ExecutionLayerExit> exits,
final Supplier<ValidatorExitContext> validatorExitContextSupplier);
final Supplier<ValidatorExitContext> validatorExitContextSupplier)
throws BlockProcessingException;

Optional<List<Withdrawal>> getExpectedWithdrawals(BeaconState preState);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,8 @@ protected void processExecutionLayerExits(
public void processExecutionLayerExits(
final MutableBeaconState state,
final SszList<ExecutionLayerExit> exits,
final Supplier<ValidatorExitContext> validatorExitContextSupplier) {
final Supplier<ValidatorExitContext> validatorExitContextSupplier)
throws BlockProcessingException {
final UInt64 currentEpoch = miscHelpers.computeEpochAtSlot(state.getSlot());

exits.forEach(
Expand Down Expand Up @@ -210,14 +211,17 @@ private SszList<ExecutionLayerExit> getExecutionLayerExitsFromBlock(
/*
Implements process_deposit_receipt from consensus-specs (EIP-6110)
*/
@Override
public void processDepositReceipts(
final MutableBeaconStateElectra state, final SszList<DepositReceipt> depositReceipts) {
final MutableBeaconState state, final SszList<DepositReceipt> depositReceipts)
throws BlockProcessingException {
final MutableBeaconStateElectra electraState = MutableBeaconStateElectra.required(state);
for (DepositReceipt depositReceipt : depositReceipts) {
// process_deposit_receipt
if (state
if (electraState
.getDepositReceiptsStartIndex()
.equals(SpecConfigElectra.UNSET_DEPOSIT_RECEIPTS_START_INDEX)) {
state.setDepositReceiptsStartIndex(depositReceipt.getIndex());
electraState.setDepositReceiptsStartIndex(depositReceipt.getIndex());
}
applyDeposit(
state,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ public void verifiesOutstandingEth1DepositsAreProcessed() {
}

@Test
public void processesDepositReceipts() {
public void processesDepositReceipts() throws BlockProcessingException {
final BeaconStateElectra preState =
BeaconStateElectra.required(
createBeaconState()
Expand All @@ -129,7 +129,7 @@ public void processesDepositReceipts() {
UInt64.valueOf(firstElectraDepositReceiptIndex + i)))
.toList();

final BeaconStateElectra state =
final BeaconState state =
BeaconStateElectra.required(
preState.updated(
mutableState ->
Expand All @@ -139,7 +139,7 @@ public void processesDepositReceipts() {
depositReceiptsSchema.createFromElements(depositReceipts))));

// verify deposit_receipts_start_index has been set
assertThat(state.getDepositReceiptsStartIndex())
assertThat(BeaconStateElectra.required(state).getDepositReceiptsStartIndex())
.isEqualTo(UInt64.valueOf(firstElectraDepositReceiptIndex));
// verify validators have been added to the state
assertThat(state.getValidators().size())
Expand Down

0 comments on commit 5e0bd21

Please sign in to comment.