Skip to content

Commit

Permalink
[Merge] Make Teku interop standalone node running with stubbed Execut…
Browse files Browse the repository at this point in the history
…ion Engine (#4424)

* Pass the target slot to the `BlockFactory.prepareExecutionPayload` to correctly cache by slot and calculate payload timestamp
* Support --Xnetwork-altair/merge-fork-epoch CLI options in the `genesis mock` command
* Fix log string
* Fix ExecutePayloadResponse construction
* Delegate `SpecLogicMerge.getSyncCommitteeUtil()` to the `SpecLogicAltair` instance
* Even if the Merge milestone is set to the slot 0 the Spec instance should still contain all the previous milestones
* Adjust the ExecutionEngineClient.Stub for created `ExecutionPayload` to pass all the validations
  • Loading branch information
Nashatyrev authored Sep 28, 2021
1 parent 2ed3fa3 commit 0ea4b31
Show file tree
Hide file tree
Showing 8 changed files with 42 additions and 17 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -65,9 +65,6 @@ public static Spec create(final SpecConfig config) {
.filter(epoch -> !epoch.equals(FAR_FUTURE_EPOCH));
// Merge takes precedence in the prototype
if (mergeForkEpoch.isPresent()) {
if (mergeForkEpoch.get().equals(UInt64.ZERO)) {
return Spec.createSinceGenesis(config, SpecMilestone.MERGE);
}
return Spec.create(config, SpecMilestone.MERGE);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
import tech.pegasys.teku.spec.logic.common.util.ForkChoiceUtil;
import tech.pegasys.teku.spec.logic.common.util.SyncCommitteeUtil;
import tech.pegasys.teku.spec.logic.common.util.ValidatorsUtil;
import tech.pegasys.teku.spec.logic.versions.altair.SpecLogicAltair;
import tech.pegasys.teku.spec.logic.versions.altair.helpers.BeaconStateMutatorsAltair;
import tech.pegasys.teku.spec.logic.versions.altair.statetransition.epoch.EpochProcessorAltair;
import tech.pegasys.teku.spec.logic.versions.altair.statetransition.epoch.ValidatorStatusFactoryAltair;
Expand All @@ -41,6 +42,8 @@ public class SpecLogicMerge extends AbstractSpecLogic {
private final ExecutionPayloadUtil executionPayloadUtil;
private final MergeTransitionHelpers mergeTransitionHelpers;

private final SpecLogicAltair specLogicAltair;

private SpecLogicMerge(
final Predicates predicates,
final MiscHelpersMerge miscHelpers,
Expand All @@ -58,7 +61,8 @@ private SpecLogicMerge(
final BlockProposalUtil blockProposalUtil,
final ExecutionPayloadUtil executionPayloadUtil,
final MergeTransitionHelpers mergeTransitionHelpers,
final MergeStateUpgrade stateUpgrade) {
final MergeStateUpgrade stateUpgrade,
final SpecLogicAltair specLogicAltair) {
super(
predicates,
miscHelpers,
Expand All @@ -77,6 +81,7 @@ private SpecLogicMerge(
Optional.of(stateUpgrade));
this.executionPayloadUtil = executionPayloadUtil;
this.mergeTransitionHelpers = mergeTransitionHelpers;
this.specLogicAltair = specLogicAltair;
}

public static SpecLogicMerge create(
Expand Down Expand Up @@ -151,6 +156,8 @@ public static SpecLogicMerge create(
final MergeStateUpgrade stateUpgrade =
new MergeStateUpgrade(config, schemaDefinitions, beaconStateAccessors);

final SpecLogicAltair specLogicAltair = SpecLogicAltair.create(config, schemaDefinitions);

return new SpecLogicMerge(
predicates,
miscHelpers,
Expand All @@ -168,12 +175,13 @@ public static SpecLogicMerge create(
blockProposalUtil,
executionPayloadUtil,
mergeTransitionHelpers,
stateUpgrade);
stateUpgrade,
specLogicAltair);
}

@Override
public Optional<SyncCommitteeUtil> getSyncCommitteeUtil() {
return Optional.empty();
return specLogicAltair.getSyncCommitteeUtil();
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ public SafeFuture<ExecutionPayloadStatus> executePayload(
.thenPeek(
res ->
printConsole(
"Failed consensus_newBlock(execution_payload=%s), reason: %s",
"engine_executePayload(execution_payload=%s), result: %s",
executionPayload, res));
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -78,9 +78,9 @@ public SafeFuture<Response<ExecutionPayload>> getPayload(UInt64 payloadId) {
Bytes32.ZERO,
Bytes32.ZERO,
ZERO_LOGS_BLOOM,
Bytes32.ZERO,
preparePayloadRequest.random,
number,
UInt64.ZERO,
UInt64.valueOf(30_000_000),
UInt64.ZERO,
preparePayloadRequest.timestamp,
ZERO_EXTRA_DATA,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ public class ExecutePayloadResponse {

public ExecutePayloadResponse(@JsonProperty("status") String status) {
try {
ExecutionPayloadStatus.valueOf(status);
this.status = ExecutionPayloadStatus.valueOf(status);
} catch (IllegalArgumentException e) {
throw new RuntimeException("Invalid status field received: " + status);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@

import picocli.CommandLine.Option;
import tech.pegasys.teku.config.TekuConfiguration;
import tech.pegasys.teku.infrastructure.unsigned.UInt64;
import tech.pegasys.teku.networks.Eth2NetworkConfiguration;
import tech.pegasys.teku.spec.Spec;

Expand All @@ -27,6 +28,20 @@ public class MinimalEth2NetworkOptions {
arity = "1")
private String network = "mainnet";

@Option(
names = {"--Xnetwork-altair-fork-epoch"},
paramLabel = "<EPOCH>",
description = "Altair fork first epoch",
arity = "1")
private long altairForkEpoch = -1;

@Option(
names = {"--Xnetwork-merge-fork-epoch"},
paramLabel = "<EPOCH>",
description = "Merge fork first epoch",
arity = "1")
private long mergeForkEpoch = -1;

public void configure(final TekuConfiguration.Builder builder) {
builder.eth2NetworkConfig(b -> b.applyNetworkDefaults(network));
}
Expand All @@ -36,6 +51,9 @@ public Spec getSpec() {
}

private Eth2NetworkConfiguration getConfig() {
return Eth2NetworkConfiguration.builder(network).build();
return Eth2NetworkConfiguration.builder(network)
.mergeForkEpoch(UInt64.fromLongBits(mergeForkEpoch))
.altairForkEpoch(UInt64.fromLongBits(altairForkEpoch))
.build();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -101,16 +101,18 @@ public BlockFactory(
10); // TODO check if makes sense to remember payloadId for the latest 10 slots
}

public void prepareExecutionPayload(final Optional<BeaconState> maybeCurrentSlotState) {
public void prepareExecutionPayload(
final Optional<BeaconState> maybeCurrentSlotState, UInt64 targetSlot) {
maybeCurrentSlotState.ifPresent(
currentSlotState -> {
Optional<PreparePayloadReference> maybeRef = prepareExecutionPayloadRef(currentSlotState);
slotToPayloadIdMap.invalidateWithNewValue(currentSlotState.getSlot(), maybeRef);
Optional<PreparePayloadReference> maybeRef =
prepareExecutionPayloadRef(currentSlotState, targetSlot);
slotToPayloadIdMap.invalidateWithNewValue(targetSlot, maybeRef);
});
}

private Optional<PreparePayloadReference> prepareExecutionPayloadRef(
final BeaconState currentSlotState) {
final BeaconState currentSlotState, UInt64 targetSlot) {
final Optional<BeaconStateMerge> maybeCurrentMergeState = currentSlotState.toVersionMerge();

if (maybeCurrentMergeState.isEmpty()) {
Expand All @@ -121,7 +123,7 @@ private Optional<PreparePayloadReference> prepareExecutionPayloadRef(

final UInt64 slot = currentMergeState.getSlot();
final UInt64 epoch = spec.computeEpochAtSlot(slot);
final UInt64 timestamp = spec.computeTimeAtSlot(currentMergeState, slot);
final UInt64 timestamp = spec.computeTimeAtSlot(currentMergeState, targetSlot);
final Bytes32 random =
spec.atEpoch(epoch).beaconStateAccessors().getRandaoMix(currentMergeState, epoch);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -268,7 +268,7 @@ public SafeFuture<Void> prepareExecutionPayload(UInt64 preparingSlot) {

return currentSlotStateFuture.thenApply(
preState -> {
blockFactory.prepareExecutionPayload(preState);
blockFactory.prepareExecutionPayload(preState, preparingSlot);
return null;
});
}
Expand Down

0 comments on commit 0ea4b31

Please sign in to comment.