Skip to content

Commit 4a20310

Browse files
Modified withdrawals and proposer slashings for Gloas (Consensys#9940)
1 parent e476211 commit 4a20310

File tree

5 files changed

+53
-0
lines changed

5 files changed

+53
-0
lines changed

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,8 @@ private static Stream<TestDefinition> findTestTypes(final Path specDirectory) th
7575
"fork/fork",
7676
"networking/",
7777
"rewards/",
78+
"operations/withdrawals",
79+
"operations/proposer_slashing",
7880
"operations/execution_payload_bid"))
7981
.flatMap(unchecked(finder -> finder.findTests(fork, spec, testsPath)));
8082
}

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

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -498,6 +498,8 @@ protected void processProposerSlashingsNoValidation(
498498
"process_proposer_slashings: %s",
499499
invalidReason.map(OperationInvalidReason::describe).orElse(""));
500500

501+
removeBuilderPendingPayment(proposerSlashing, state);
502+
501503
beaconStateMutators.slashValidator(
502504
state,
503505
proposerSlashing.getHeader1().getMessage().getProposerIndex().intValue(),
@@ -506,6 +508,11 @@ protected void processProposerSlashingsNoValidation(
506508
});
507509
}
508510

511+
protected void removeBuilderPendingPayment(
512+
final ProposerSlashing proposerSlashing, final MutableBeaconState state) {
513+
// NO-OP until Gloas
514+
}
515+
509516
protected BlockValidationResult verifyProposerSlashings(
510517
final BeaconState state,
511518
final SszList<ProposerSlashing> proposerSlashings,

ethereum/spec/src/main/java/tech/pegasys/teku/spec/logic/versions/capella/withdrawals/WithdrawalsHelpersCapella.java

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -195,6 +195,8 @@ private void processWithdrawalsUnchecked(
195195
final int processedPartialWithdrawalsCount,
196196
final int processedBuilderWithdrawalsCount) {
197197

198+
setLatestWithdrawalsRoot(expectedWithdrawals, state);
199+
198200
for (final Withdrawal withdrawal : expectedWithdrawals) {
199201
beaconStateMutators.decreaseBalance(
200202
state, withdrawal.getValidatorIndex().intValue(), withdrawal.getAmount());
@@ -234,6 +236,10 @@ private void processWithdrawalsUnchecked(
234236
}
235237
}
236238

239+
// NO-OP
240+
protected void setLatestWithdrawalsRoot(
241+
final List<Withdrawal> expectedWithdrawals, final MutableBeaconState state) {}
242+
237243
// NO-OP
238244
protected void updatePendingBuilderWithdrawals(
239245
final MutableBeaconState state, final int processedBuilderWithdrawalsCount) {}

ethereum/spec/src/main/java/tech/pegasys/teku/spec/logic/versions/gloas/block/BlockProcessorGloas.java

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
package tech.pegasys.teku.spec.logic.versions.gloas.block;
1515

1616
import java.util.Optional;
17+
import java.util.OptionalInt;
1718
import java.util.function.Supplier;
1819
import tech.pegasys.teku.bls.BLSSignatureVerifier;
1920
import tech.pegasys.teku.infrastructure.unsigned.UInt64;
@@ -27,6 +28,7 @@
2728
import tech.pegasys.teku.spec.datastructures.epbs.versions.gloas.SignedExecutionPayloadBid;
2829
import tech.pegasys.teku.spec.datastructures.execution.ExecutionPayloadSummary;
2930
import tech.pegasys.teku.spec.datastructures.execution.versions.electra.ExecutionRequestsDataCodec;
31+
import tech.pegasys.teku.spec.datastructures.operations.ProposerSlashing;
3032
import tech.pegasys.teku.spec.datastructures.state.Validator;
3133
import tech.pegasys.teku.spec.datastructures.state.beaconstate.MutableBeaconState;
3234
import tech.pegasys.teku.spec.datastructures.state.beaconstate.versions.gloas.MutableBeaconStateGloas;
@@ -227,6 +229,28 @@ public void processExecutionPayload(
227229
throw new UnsupportedOperationException("process_execution_payload has been removed in Gloas");
228230
}
229231

232+
// Remove the BuilderPendingPayment corresponding to this proposal if it is still in the 2-epoch
233+
// window.
234+
@Override
235+
protected void removeBuilderPendingPayment(
236+
final ProposerSlashing proposerSlashing, final MutableBeaconState state) {
237+
final UInt64 slot = proposerSlashing.getHeader1().getMessage().getSlot();
238+
final UInt64 proposalEpoch = miscHelpers.computeEpochAtSlot(slot);
239+
OptionalInt paymentIndex = OptionalInt.empty();
240+
if (proposalEpoch.equals(beaconStateAccessors.getCurrentEpoch(state))) {
241+
paymentIndex =
242+
OptionalInt.of(
243+
specConfig.getSlotsPerEpoch() + slot.mod(specConfig.getSlotsPerEpoch()).intValue());
244+
} else if (proposalEpoch.equals(beaconStateAccessors.getPreviousEpoch(state))) {
245+
paymentIndex = OptionalInt.of(slot.mod(specConfig.getSlotsPerEpoch()).intValue());
246+
}
247+
paymentIndex.ifPresent(
248+
index ->
249+
MutableBeaconStateGloas.required(state)
250+
.getBuilderPendingPayments()
251+
.set(index, schemaDefinitionsGloas.getBuilderPendingPaymentSchema().getDefault()));
252+
}
253+
230254
@Override
231255
public void processExecutionRequests(
232256
final MutableBeaconState state,

ethereum/spec/src/main/java/tech/pegasys/teku/spec/logic/versions/gloas/withdrawals/WithdrawalsHelpersGloas.java

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@
3535
public class WithdrawalsHelpersGloas extends WithdrawalsHelpersElectra {
3636

3737
private final PredicatesGloas predicatesGloas;
38+
private final SchemaDefinitionsGloas schemaDefinitionsGloas;
3839

3940
public WithdrawalsHelpersGloas(
4041
final SchemaDefinitionsGloas schemaDefinitions,
@@ -44,6 +45,7 @@ public WithdrawalsHelpersGloas(
4445
final BeaconStateMutatorsElectra beaconStateMutators) {
4546
super(schemaDefinitions, miscHelpers, specConfig, predicates, beaconStateMutators);
4647
this.predicatesGloas = predicates;
48+
this.schemaDefinitionsGloas = schemaDefinitions;
4749
}
4850

4951
@Override
@@ -54,6 +56,18 @@ public void processWithdrawals(final MutableBeaconState state) {
5456
super.processWithdrawals(state);
5557
}
5658

59+
@Override
60+
protected void setLatestWithdrawalsRoot(
61+
final List<Withdrawal> expectedWithdrawals, final MutableBeaconState state) {
62+
MutableBeaconStateGloas.required(state)
63+
.setLatestWithdrawalsRoot(
64+
schemaDefinitionsGloas
65+
.getExecutionPayloadSchema()
66+
.getWithdrawalsSchemaRequired()
67+
.createFromElements(expectedWithdrawals)
68+
.hashTreeRoot());
69+
}
70+
5771
@Override
5872
protected int sweepForBuilderPayments(
5973
final List<Withdrawal> withdrawals, final BeaconState state) {

0 commit comments

Comments
 (0)