Skip to content

Commit 5afb156

Browse files
Added electra ref tests for deposit_receipt and execution_layer_exit (Consensys#8176)
1 parent a11e4c5 commit 5afb156

File tree

10 files changed

+118
-12
lines changed

10 files changed

+118
-12
lines changed

Diff for: eth-reference-tests/src/referenceTest/java/tech/pegasys/teku/reference/common/operations/DefaultOperationProcessor.java

+37
Original file line numberDiff line numberDiff line change
@@ -14,25 +14,32 @@
1414
package tech.pegasys.teku.reference.common.operations;
1515

1616
import java.util.Optional;
17+
import java.util.function.Supplier;
1718
import tech.pegasys.teku.bls.BLSSignatureVerifier;
19+
import tech.pegasys.teku.infrastructure.ssz.SszList;
1820
import tech.pegasys.teku.spec.Spec;
1921
import tech.pegasys.teku.spec.datastructures.blocks.BeaconBlockSummary;
2022
import tech.pegasys.teku.spec.datastructures.blocks.blockbody.BeaconBlockBody;
2123
import tech.pegasys.teku.spec.datastructures.blocks.blockbody.BeaconBlockBodySchema;
2224
import tech.pegasys.teku.spec.datastructures.blocks.blockbody.versions.altair.SyncAggregate;
2325
import tech.pegasys.teku.spec.datastructures.blocks.blockbody.versions.capella.BeaconBlockBodySchemaCapella;
26+
import tech.pegasys.teku.spec.datastructures.blocks.blockbody.versions.electra.BeaconBlockBodySchemaElectra;
2427
import tech.pegasys.teku.spec.datastructures.execution.ExecutionPayloadSummary;
28+
import tech.pegasys.teku.spec.datastructures.execution.versions.electra.DepositReceipt;
29+
import tech.pegasys.teku.spec.datastructures.execution.versions.electra.ExecutionLayerExit;
2530
import tech.pegasys.teku.spec.datastructures.operations.Attestation;
2631
import tech.pegasys.teku.spec.datastructures.operations.AttesterSlashing;
2732
import tech.pegasys.teku.spec.datastructures.operations.Deposit;
2833
import tech.pegasys.teku.spec.datastructures.operations.ProposerSlashing;
2934
import tech.pegasys.teku.spec.datastructures.operations.SignedBlsToExecutionChange;
3035
import tech.pegasys.teku.spec.datastructures.operations.SignedVoluntaryExit;
3136
import tech.pegasys.teku.spec.datastructures.state.beaconstate.MutableBeaconState;
37+
import tech.pegasys.teku.spec.logic.common.helpers.BeaconStateMutators.ValidatorExitContext;
3238
import tech.pegasys.teku.spec.logic.common.statetransition.exceptions.BlockProcessingException;
3339
import tech.pegasys.teku.spec.logic.versions.bellatrix.block.OptimisticExecutionPayloadExecutor;
3440

3541
public class DefaultOperationProcessor implements OperationProcessor {
42+
3643
private final Spec spec;
3744
private final BeaconBlockBodySchema<?> beaconBlockBodySchema;
3845

@@ -132,4 +139,34 @@ public void processWithdrawals(
132139
throws BlockProcessingException {
133140
spec.getBlockProcessor(state.getSlot()).processWithdrawals(state, payloadSummary);
134141
}
142+
143+
@Override
144+
public void processDepositReceipt(
145+
final MutableBeaconState state, final DepositReceipt depositReceipt)
146+
throws BlockProcessingException {
147+
final SszList<DepositReceipt> depositReceiptList =
148+
BeaconBlockBodySchemaElectra.required(beaconBlockBodySchema)
149+
.getExecutionPayloadSchema()
150+
.getDepositReceiptsSchemaRequired()
151+
.of(depositReceipt);
152+
153+
spec.getBlockProcessor(state.getSlot()).processDepositReceipts(state, depositReceiptList);
154+
}
155+
156+
@Override
157+
public void processExecutionLayerExit(
158+
final MutableBeaconState state, final ExecutionLayerExit executionLayerExit)
159+
throws BlockProcessingException {
160+
final SszList<ExecutionLayerExit> exits =
161+
BeaconBlockBodySchemaElectra.required(beaconBlockBodySchema)
162+
.getExecutionPayloadSchema()
163+
.getExecutionLayerExitsSchemaRequired()
164+
.of(executionLayerExit);
165+
final Supplier<ValidatorExitContext> validatorExitContextSupplier =
166+
spec.atSlot(state.getSlot())
167+
.beaconStateMutators()
168+
.createValidatorExitContextSupplier(state);
169+
spec.getBlockProcessor(state.getSlot())
170+
.processExecutionLayerExits(state, exits, validatorExitContextSupplier);
171+
}
135172
}

Diff for: eth-reference-tests/src/referenceTest/java/tech/pegasys/teku/reference/common/operations/OperationProcessor.java

+8
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,8 @@
1818
import tech.pegasys.teku.spec.datastructures.blocks.blockbody.BeaconBlockBody;
1919
import tech.pegasys.teku.spec.datastructures.blocks.blockbody.versions.altair.SyncAggregate;
2020
import tech.pegasys.teku.spec.datastructures.execution.ExecutionPayloadSummary;
21+
import tech.pegasys.teku.spec.datastructures.execution.versions.electra.DepositReceipt;
22+
import tech.pegasys.teku.spec.datastructures.execution.versions.electra.ExecutionLayerExit;
2123
import tech.pegasys.teku.spec.datastructures.operations.Attestation;
2224
import tech.pegasys.teku.spec.datastructures.operations.AttesterSlashing;
2325
import tech.pegasys.teku.spec.datastructures.operations.Deposit;
@@ -62,4 +64,10 @@ void processBlsToExecutionChange(
6264

6365
void processWithdrawals(MutableBeaconState state, ExecutionPayloadSummary payloadSummary)
6466
throws BlockProcessingException;
67+
68+
void processDepositReceipt(final MutableBeaconState state, final DepositReceipt depositReceipt)
69+
throws BlockProcessingException;
70+
71+
void processExecutionLayerExit(MutableBeaconState state, ExecutionLayerExit executionLayerExit)
72+
throws BlockProcessingException;
6573
}

Diff for: eth-reference-tests/src/referenceTest/java/tech/pegasys/teku/reference/common/operations/OperationsTestExecutor.java

+37-2
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,8 @@
3434
import tech.pegasys.teku.spec.datastructures.blocks.blockbody.versions.altair.BeaconBlockBodySchemaAltair;
3535
import tech.pegasys.teku.spec.datastructures.blocks.blockbody.versions.altair.SyncAggregate;
3636
import tech.pegasys.teku.spec.datastructures.execution.ExecutionPayload;
37+
import tech.pegasys.teku.spec.datastructures.execution.versions.electra.DepositReceipt;
38+
import tech.pegasys.teku.spec.datastructures.execution.versions.electra.ExecutionLayerExit;
3739
import tech.pegasys.teku.spec.datastructures.operations.Attestation;
3840
import tech.pegasys.teku.spec.datastructures.operations.AttesterSlashing;
3941
import tech.pegasys.teku.spec.datastructures.operations.Deposit;
@@ -71,7 +73,9 @@ private enum Operation {
7173
SYNC_AGGREGATE,
7274
EXECUTION_PAYLOAD,
7375
BLS_TO_EXECUTION_CHANGE,
74-
WITHDRAWAL
76+
WITHDRAWAL,
77+
DEPOSIT_RECEIPT,
78+
EXECUTION_LAYER_EXIT
7579
}
7680

7781
public static final ImmutableMap<String, TestExecutor> OPERATIONS_TEST_TYPES =
@@ -112,6 +116,13 @@ private enum Operation {
112116
.put(
113117
"operations/withdrawals",
114118
new OperationsTestExecutor<>("execution_payload.ssz_snappy", Operation.WITHDRAWAL))
119+
.put(
120+
"operations/deposit_receipt",
121+
new OperationsTestExecutor<>("deposit_receipt.ssz_snappy", Operation.DEPOSIT_RECEIPT))
122+
.put(
123+
"operations/execution_layer_exit",
124+
new OperationsTestExecutor<>(
125+
"execution_layer_exit.ssz_snappy", Operation.EXECUTION_LAYER_EXIT))
115126
.build();
116127

117128
private final String dataFileName;
@@ -298,6 +309,8 @@ private void processOperation(
298309
}
299310
case BLS_TO_EXECUTION_CHANGE -> processBlsToExecutionChange(testDefinition, state, processor);
300311
case WITHDRAWAL -> processWithdrawal(testDefinition, state, processor);
312+
case DEPOSIT_RECEIPT -> processDepositReceipt(testDefinition, state, processor);
313+
case EXECUTION_LAYER_EXIT -> processExecutionLayerExit(testDefinition, state, processor);
301314
default -> throw new UnsupportedOperationException(
302315
"Operation " + operation + " not implemented in OperationTestExecutor");
303316
}
@@ -325,6 +338,26 @@ private void processBlsToExecutionChange(
325338
processor.processBlsToExecutionChange(state, blsToExecutionChange);
326339
}
327340

341+
private void processDepositReceipt(
342+
final TestDefinition testDefinition,
343+
final MutableBeaconState state,
344+
final OperationProcessor processor)
345+
throws BlockProcessingException {
346+
final DepositReceipt depositReceipt =
347+
loadSsz(testDefinition, dataFileName, DepositReceipt.SSZ_SCHEMA);
348+
processor.processDepositReceipt(state, depositReceipt);
349+
}
350+
351+
private void processExecutionLayerExit(
352+
final TestDefinition testDefinition,
353+
final MutableBeaconState state,
354+
final OperationProcessor processor)
355+
throws BlockProcessingException {
356+
final ExecutionLayerExit executionLayerExit =
357+
loadSsz(testDefinition, dataFileName, ExecutionLayerExit.SSZ_SCHEMA);
358+
processor.processExecutionLayerExit(state, executionLayerExit);
359+
}
360+
328361
private SignedVoluntaryExit loadVoluntaryExit(final TestDefinition testDefinition) {
329362
return loadSsz(testDefinition, dataFileName, SignedVoluntaryExit.SSZ_SCHEMA);
330363
}
@@ -387,7 +420,9 @@ public void checkBlockInclusionValidation(
387420
ATTESTATION,
388421
SYNC_AGGREGATE,
389422
EXECUTION_PAYLOAD,
390-
WITHDRAWAL -> {}
423+
WITHDRAWAL,
424+
DEPOSIT_RECEIPT,
425+
EXECUTION_LAYER_EXIT -> {}
391426
}
392427
}
393428

Diff for: eth-tests/src/main/java/tech/pegasys/teku/ethtests/TestFork.java

+1
Original file line numberDiff line numberDiff line change
@@ -19,4 +19,5 @@ public class TestFork {
1919
public static final String BELLATRIX = "bellatrix";
2020
public static final String CAPELLA = "capella";
2121
public static final String DENEB = "deneb";
22+
public static final String ELECTRA = "electra";
2223
}

Diff for: eth-tests/src/main/java/tech/pegasys/teku/ethtests/finder/ReferenceTestFinder.java

+6-1
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,12 @@ public class ReferenceTestFinder {
3131
Path.of("src", "referenceTest", "resources", "consensus-spec-tests", "tests");
3232
private static final List<String> SUPPORTED_FORKS =
3333
List.of(
34-
TestFork.PHASE0, TestFork.ALTAIR, TestFork.BELLATRIX, TestFork.CAPELLA, TestFork.DENEB);
34+
TestFork.PHASE0,
35+
TestFork.ALTAIR,
36+
TestFork.BELLATRIX,
37+
TestFork.CAPELLA,
38+
TestFork.DENEB,
39+
TestFork.ELECTRA);
3540

3641
@MustBeClosed
3742
public static Stream<TestDefinition> findReferenceTests() throws IOException {

Diff for: eth-tests/src/main/java/tech/pegasys/teku/ethtests/finder/TestDefinition.java

+1
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,7 @@ private void createSpec() {
7272
case TestFork.BELLATRIX -> SpecMilestone.BELLATRIX;
7373
case TestFork.CAPELLA -> SpecMilestone.CAPELLA;
7474
case TestFork.DENEB -> SpecMilestone.DENEB;
75+
case TestFork.ELECTRA -> SpecMilestone.ELECTRA;
7576
default -> throw new IllegalArgumentException("Unknown fork: " + fork);
7677
};
7778
spec = TestSpecFactory.create(milestone, network);

Diff for: ethereum/spec/src/main/java/tech/pegasys/teku/spec/logic/common/block/AbstractBlockProcessor.java

+10-1
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@
4747
import tech.pegasys.teku.spec.datastructures.blocks.SignedBeaconBlock;
4848
import tech.pegasys.teku.spec.datastructures.blocks.blockbody.BeaconBlockBody;
4949
import tech.pegasys.teku.spec.datastructures.execution.ExecutionPayload;
50+
import tech.pegasys.teku.spec.datastructures.execution.versions.electra.DepositReceipt;
5051
import tech.pegasys.teku.spec.datastructures.execution.versions.electra.ExecutionLayerExit;
5152
import tech.pegasys.teku.spec.datastructures.operations.Attestation;
5253
import tech.pegasys.teku.spec.datastructures.operations.AttestationData;
@@ -884,11 +885,19 @@ protected void processExecutionLayerExits(
884885
// No ExecutionLayer exits until Electra
885886
}
886887

888+
@Override
889+
public void processDepositReceipts(
890+
final MutableBeaconState state, final SszList<DepositReceipt> depositReceipts)
891+
throws BlockProcessingException {
892+
// No DepositReceipts until Electra
893+
}
894+
887895
@Override
888896
public void processExecutionLayerExits(
889897
final MutableBeaconState state,
890898
final SszList<ExecutionLayerExit> exits,
891-
final Supplier<ValidatorExitContext> validatorExitContextSupplier) {
899+
final Supplier<ValidatorExitContext> validatorExitContextSupplier)
900+
throws BlockProcessingException {
892901
// No ExecutionLayer exits until Electra
893902
}
894903

Diff for: ethereum/spec/src/main/java/tech/pegasys/teku/spec/logic/common/block/BlockProcessor.java

+7-1
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@
3232
import tech.pegasys.teku.spec.datastructures.execution.ExecutionPayloadSummary;
3333
import tech.pegasys.teku.spec.datastructures.execution.NewPayloadRequest;
3434
import tech.pegasys.teku.spec.datastructures.execution.versions.capella.Withdrawal;
35+
import tech.pegasys.teku.spec.datastructures.execution.versions.electra.DepositReceipt;
3536
import tech.pegasys.teku.spec.datastructures.execution.versions.electra.ExecutionLayerExit;
3637
import tech.pegasys.teku.spec.datastructures.operations.Attestation;
3738
import tech.pegasys.teku.spec.datastructures.operations.AttestationData;
@@ -167,10 +168,15 @@ void processBlsToExecutionChanges(
167168
void processWithdrawals(MutableBeaconState state, ExecutionPayloadSummary payloadSummary)
168169
throws BlockProcessingException;
169170

171+
void processDepositReceipts(
172+
final MutableBeaconState state, final SszList<DepositReceipt> depositReceipts)
173+
throws BlockProcessingException;
174+
170175
void processExecutionLayerExits(
171176
final MutableBeaconState state,
172177
final SszList<ExecutionLayerExit> exits,
173-
final Supplier<ValidatorExitContext> validatorExitContextSupplier);
178+
final Supplier<ValidatorExitContext> validatorExitContextSupplier)
179+
throws BlockProcessingException;
174180

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

Diff for: ethereum/spec/src/main/java/tech/pegasys/teku/spec/logic/versions/electra/block/BlockProcessorElectra.java

+8-4
Original file line numberDiff line numberDiff line change
@@ -142,7 +142,8 @@ protected void processExecutionLayerExits(
142142
public void processExecutionLayerExits(
143143
final MutableBeaconState state,
144144
final SszList<ExecutionLayerExit> exits,
145-
final Supplier<ValidatorExitContext> validatorExitContextSupplier) {
145+
final Supplier<ValidatorExitContext> validatorExitContextSupplier)
146+
throws BlockProcessingException {
146147
final UInt64 currentEpoch = miscHelpers.computeEpochAtSlot(state.getSlot());
147148

148149
exits.forEach(
@@ -210,14 +211,17 @@ private SszList<ExecutionLayerExit> getExecutionLayerExitsFromBlock(
210211
/*
211212
Implements process_deposit_receipt from consensus-specs (EIP-6110)
212213
*/
214+
@Override
213215
public void processDepositReceipts(
214-
final MutableBeaconStateElectra state, final SszList<DepositReceipt> depositReceipts) {
216+
final MutableBeaconState state, final SszList<DepositReceipt> depositReceipts)
217+
throws BlockProcessingException {
218+
final MutableBeaconStateElectra electraState = MutableBeaconStateElectra.required(state);
215219
for (DepositReceipt depositReceipt : depositReceipts) {
216220
// process_deposit_receipt
217-
if (state
221+
if (electraState
218222
.getDepositReceiptsStartIndex()
219223
.equals(SpecConfigElectra.UNSET_DEPOSIT_RECEIPTS_START_INDEX)) {
220-
state.setDepositReceiptsStartIndex(depositReceipt.getIndex());
224+
electraState.setDepositReceiptsStartIndex(depositReceipt.getIndex());
221225
}
222226
applyDeposit(
223227
state,

Diff for: ethereum/spec/src/test/java/tech/pegasys/teku/spec/logic/versions/electra/block/BlockProcessorElectraTest.java

+3-3
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,7 @@ public void verifiesOutstandingEth1DepositsAreProcessed() {
105105
}
106106

107107
@Test
108-
public void processesDepositReceipts() {
108+
public void processesDepositReceipts() throws BlockProcessingException {
109109
final BeaconStateElectra preState =
110110
BeaconStateElectra.required(
111111
createBeaconState()
@@ -129,7 +129,7 @@ public void processesDepositReceipts() {
129129
UInt64.valueOf(firstElectraDepositReceiptIndex + i)))
130130
.toList();
131131

132-
final BeaconStateElectra state =
132+
final BeaconState state =
133133
BeaconStateElectra.required(
134134
preState.updated(
135135
mutableState ->
@@ -139,7 +139,7 @@ public void processesDepositReceipts() {
139139
depositReceiptsSchema.createFromElements(depositReceipts))));
140140

141141
// verify deposit_receipts_start_index has been set
142-
assertThat(state.getDepositReceiptsStartIndex())
142+
assertThat(BeaconStateElectra.required(state).getDepositReceiptsStartIndex())
143143
.isEqualTo(UInt64.valueOf(firstElectraDepositReceiptIndex));
144144
// verify validators have been added to the state
145145
assertThat(state.getValidators().size())

0 commit comments

Comments
 (0)