Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added block production restrictions for electra #9017

Merged
merged 4 commits into from
Jan 21, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@
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;
import tech.pegasys.teku.spec.datastructures.state.versions.electra.PendingPartialWithdrawal;
import tech.pegasys.teku.spec.datastructures.type.SszKZGCommitment;
import tech.pegasys.teku.spec.datastructures.type.SszKZGProof;
import tech.pegasys.teku.spec.executionlayer.ExecutionLayerBlockProductionManager;
Expand Down Expand Up @@ -146,7 +147,7 @@ public Function<BeaconBlockBodyBuilder, SafeFuture<Void>> createSelector(
final SszList<SignedVoluntaryExit> voluntaryExits =
voluntaryExitPool.getItemsForBlock(
blockSlotState,
exit -> !exitedValidators.contains(exit.getMessage().getValidatorIndex()),
exit -> voluntaryExitPredicate(blockSlotState, exitedValidators, exit),
exit -> exitedValidators.add(exit.getMessage().getValidatorIndex()));

bodyBuilder
Expand Down Expand Up @@ -204,6 +205,25 @@ public Function<BeaconBlockBodyBuilder, SafeFuture<Void>> createSelector(
};
}

private boolean voluntaryExitPredicate(
final BeaconState blockSlotState,
final Set<UInt64> exitedValidators,
final SignedVoluntaryExit exit) {
final UInt64 validatorIndex = exit.getMessage().getValidatorIndex();
if (exitedValidators.contains(validatorIndex)) {
return false;
}
// if there is a pending withdrawal, the exit is not valid for inclusion in a block.
return blockSlotState
.toVersionElectra()
.map(
beaconStateElectra ->
beaconStateElectra.getPendingPartialWithdrawals().stream()
.map(PendingPartialWithdrawal::getValidatorIndex)
.noneMatch(index -> index == validatorIndex.intValue()))
.orElse(true);
}

private SafeFuture<Void> setExecutionData(
final Optional<ExecutionPayloadContext> executionPayloadContext,
final BeaconBlockBodyBuilder bodyBuilder,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,7 @@
import tech.pegasys.teku.spec.datastructures.operations.versions.altair.SignedContributionAndProof;
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.versions.electra.MutableBeaconStateElectra;
import tech.pegasys.teku.spec.datastructures.type.SszKZGCommitment;
import tech.pegasys.teku.spec.datastructures.type.SszKZGProof;
import tech.pegasys.teku.spec.executionlayer.ExecutionLayerBlockProductionManager;
Expand Down Expand Up @@ -264,6 +265,39 @@ void shouldNotSelectOperationsWhenNoneAreAvailable() {
assertThat(bodyBuilder.blsToExecutionChanges).isEmpty();
}

@Test
void shouldNotSelectVoluntaryExitWhenValidatorHasPendingWithdrawal() {
final UInt64 slot = UInt64.ONE;
final MutableBeaconStateElectra blockSlotState =
dataStructureUtil.randomBeaconState(slot).toVersionElectra().get().createWritableCopy();
blockSlotState
.getPendingPartialWithdrawals()
.append(dataStructureUtil.randomPendingPartialWithdrawal(1));
final SignedVoluntaryExit voluntaryExit =
dataStructureUtil.randomSignedVoluntaryExit(UInt64.valueOf(1));
final ExecutionPayload randomExecutionPayload = dataStructureUtil.randomExecutionPayload();
final UInt256 blockExecutionValue = dataStructureUtil.randomUInt256();

addToPool(voluntaryExitPool, voluntaryExit);
prepareBlockProductionWithPayload(
randomExecutionPayload,
executionPayloadContext,
blockSlotState,
Optional.of(blockExecutionValue));

safeJoin(
factory
.createSelector(
parentRoot,
blockSlotState,
randaoReveal,
Optional.of(defaultGraffiti),
Optional.empty(),
BlockProductionPerformance.NOOP)
.apply(bodyBuilder));
assertThat(bodyBuilder.voluntaryExits).isEmpty();
}

@Test
void shouldIncludeValidOperations() {
final UInt64 slot = UInt64.valueOf(2);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,8 @@ public class ReferenceTestFinder {
TestFork.ALTAIR,
TestFork.BELLATRIX,
TestFork.CAPELLA,
TestFork.DENEB); // TODO: Add Electra fork tests back
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 @@ -2641,6 +2641,15 @@ public PendingPartialWithdrawal randomPendingPartialWithdrawal() {
SszUInt64.of(randomUInt64()));
}

public PendingPartialWithdrawal randomPendingPartialWithdrawal(final long validatorIndex) {
return getElectraSchemaDefinitions(randomSlot())
.getPendingPartialWithdrawalSchema()
.create(
SszUInt64.of(UInt64.valueOf(validatorIndex)),
SszUInt64.of(randomUInt64()),
SszUInt64.of(randomUInt64()));
}

public UInt64 randomBlobSidecarIndex() {
return randomUInt64(
spec.forMilestone(spec.getForkSchedule().getHighestSupportedMilestone())
Expand Down
Loading