Skip to content

Commit

Permalink
few more fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
StefanBratanov committed Sep 10, 2024
1 parent 3df5ee0 commit 85e774e
Show file tree
Hide file tree
Showing 19 changed files with 252 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,12 @@ private static TekuNodeConfigBuilder createTekuNodeBuilderForMilestone(
tekuNodeConfigBuilder.withDenebEpoch(UInt64.ZERO);
tekuNodeConfigBuilder.withElectraEpoch(UInt64.ZERO);
break;
case EIP7732:
tekuNodeConfigBuilder.withCapellaEpoch(UInt64.ZERO);
tekuNodeConfigBuilder.withDenebEpoch(UInt64.ZERO);
tekuNodeConfigBuilder.withElectraEpoch(UInt64.ZERO);
tekuNodeConfigBuilder.withEip7732Epoch(UInt64.ZERO);
break;
default:
// Test will reach this whenever a new milestone is added and isn't mapped on the switch.
// This is a way to force us to always remember to validate that a new milestone can start
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -170,6 +170,18 @@ public TekuNodeConfigBuilder withElectraEpoch(final UInt64 electraForkEpoch) {
return this;
}

public TekuNodeConfigBuilder withEip7732Epoch(final UInt64 eip7732ForkEpoch) {
mustBe(NodeType.BEACON_NODE);
LOG.debug("Xnetwork-eip7732-fork-epoch={}", eip7732ForkEpoch);
configMap.put("Xnetwork-eip7732-fork-epoch", eip7732ForkEpoch.toString());
specConfigModifier =
specConfigModifier.andThen(
specConfigBuilder ->
specConfigBuilder.eip7732Builder(
eip7732Builder -> eip7732Builder.eip7732ForkEpoch(eip7732ForkEpoch)));
return this;
}

public TekuNodeConfigBuilder withTrustedSetupFromClasspath(final String trustedSetup)
throws Exception {
mustBe(NodeType.BEACON_NODE);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@
import tech.pegasys.teku.spec.schemas.SchemaDefinitions;
import tech.pegasys.teku.spec.schemas.SchemaDefinitionsBellatrix;
import tech.pegasys.teku.spec.schemas.SchemaDefinitionsDeneb;
import tech.pegasys.teku.spec.schemas.SchemaDefinitionsEip7732;
import tech.pegasys.teku.statetransition.OperationPool;
import tech.pegasys.teku.statetransition.attestation.AggregatingAttestationPool;
import tech.pegasys.teku.statetransition.attestation.AttestationForkChecker;
Expand Down Expand Up @@ -180,6 +181,7 @@ public Function<BeaconBlockBodyBuilder, SafeFuture<Void>> createSelector(
// In `setExecutionData` the following fields are set:
// Post-Bellatrix: Execution Payload / Execution Payload Header
// Post-Deneb: KZG Commitments
// Post-ePBS: Signed Execution Payload Header
if (bodyBuilder.supportsExecutionPayload()) {
blockProductionComplete =
forkChoiceNotifier
Expand Down Expand Up @@ -224,6 +226,35 @@ private SafeFuture<Void> setExecutionData(
return SafeFuture.COMPLETE;
}

// ePBS (TODO: placeholder) also the whole flow requires refactor
if (bodyBuilder.supportsSignedExecutionPayloadHeader()) {
final SchemaDefinitionsEip7732 schemaDefinitionsEip7732 =
SchemaDefinitionsEip7732.required(schemaDefinitions);
final ExecutionPayloadHeader emptyHeader =
schemaDefinitions
.getExecutionPayloadHeaderSchema()
.createExecutionPayloadHeader(
builder ->
builder
.parentBlockHash(() -> Bytes32.ZERO)
.parentBlockRoot(() -> Bytes32.ZERO)
.blockHash(Bytes32.ZERO)
.gasLimit(UInt64.ZERO)
.builderIndex(() -> UInt64.ZERO)
.slot(() -> UInt64.ZERO)
.value(() -> UInt64.ZERO)
.blobKzgCommitmentsRoot(() -> Bytes32.ZERO));
// empty signed header
bodyBuilder.signedExecutionPayloadHeader(
schemaDefinitionsEip7732
.getSignedExecutionPayloadHeaderSchema()
.create(emptyHeader, BLSSignature.empty()));
// empty list
bodyBuilder.payloadAttestations(
schemaDefinitionsEip7732.getPayloadAttestationsSchema().createFromElements(List.of()));
return SafeFuture.COMPLETE;
}

// We should run Builder flow (blinded) only if we have a validator registration
final boolean shouldTryBuilderFlow =
executionPayloadContext
Expand Down Expand Up @@ -296,6 +327,10 @@ private SafeFuture<Void> setKzgCommitments(
if (!bodyBuilder.supportsKzgCommitments()) {
return SafeFuture.COMPLETE;
}
// ePBS (no blob kzg commitments in block)
if (bodyBuilder.supportsSignedExecutionPayloadHeader()) {
return SafeFuture.COMPLETE;
}
final BlobKzgCommitmentsSchema blobKzgCommitmentsSchema =
SchemaDefinitionsDeneb.required(schemaDefinitions).getBlobKzgCommitmentsSchema();
final SafeFuture<SszList<SszKZGCommitment>> blobKzgCommitments;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -78,8 +78,15 @@ void shouldHandleBlindedBeaconBlocks() throws Exception {
assertThat(request.getResponseBody()).isEqualTo(blockContainerAndMetaData);
assertThat(request.getResponseHeaders(HEADER_CONSENSUS_VERSION))
.isEqualTo(Version.fromMilestone(blockContainerAndMetaData.specMilestone()).name());
final boolean expectedHeaderExecutionPayloadBlinded;
if (specMilestone.isGreaterThanOrEqualTo(SpecMilestone.EIP7732)) {
// no blind/unblind concept in ePBS
expectedHeaderExecutionPayloadBlinded = false;
} else {
expectedHeaderExecutionPayloadBlinded = true;
}
assertThat(request.getResponseHeaders(HEADER_EXECUTION_PAYLOAD_BLINDED))
.isEqualTo(Boolean.toString(true));
.isEqualTo(Boolean.toString(expectedHeaderExecutionPayloadBlinded));
assertThat(request.getResponseHeaders(HEADER_EXECUTION_PAYLOAD_VALUE))
.isEqualTo(blockContainerAndMetaData.executionPayloadValue().toDecimalString());
assertThat(request.getResponseHeaders(HEADER_CONSENSUS_BLOCK_VALUE))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,8 @@ public ExecutionPayloadHeaderEip7732(
}

public ExecutionPayloadHeaderEip7732(
tech.pegasys.teku.spec.datastructures.execution.versions.eip7732.ExecutionPayloadHeaderEip7732
final tech.pegasys.teku.spec.datastructures.execution.versions.eip7732
.ExecutionPayloadHeaderEip7732
executionPayloadHeader) {
this(
executionPayloadHeader.getParentBlockHash(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,16 @@ public BeaconBlockBodyBuilderEip7732(
super(schema, null);
}

@Override
public Boolean supportsExecutionPayload() {
return false;
}

@Override
public Boolean supportsKzgCommitments() {
return false;
}

@Override
public Boolean supportsSignedExecutionPayloadHeader() {
return true;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
import tech.pegasys.teku.infrastructure.ssz.SszList;
import tech.pegasys.teku.spec.datastructures.blocks.blockbody.BeaconBlockBody;
import tech.pegasys.teku.spec.datastructures.blocks.blockbody.versions.electra.BeaconBlockBodyElectra;
import tech.pegasys.teku.spec.datastructures.execution.ExecutionPayload;
import tech.pegasys.teku.spec.datastructures.execution.SignedExecutionPayloadHeader;
import tech.pegasys.teku.spec.datastructures.execution.versions.electra.ExecutionPayloadElectra;
import tech.pegasys.teku.spec.datastructures.operations.PayloadAttestation;
Expand All @@ -38,6 +39,16 @@ static BeaconBlockBodyEip7732 required(final BeaconBlockBody body) {

SszList<PayloadAttestation> getPayloadAttestations();

@Override
default Optional<ExecutionPayload> getOptionalExecutionPayload() {
return Optional.empty();
}

@Override
default Optional<SszList<SszKZGCommitment>> getOptionalBlobKzgCommitments() {
return Optional.empty();
}

@Override
default Optional<SignedExecutionPayloadHeader> getOptionalSignedExecutionPayloadHeader() {
return Optional.of(getSignedExecutionPayloadHeader());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -269,7 +269,10 @@ public void processWithdrawals(
final SszList<Withdrawal> expectedWithdrawals =
getExpectedWithdrawalsSszList(schemaDefinitionsCapella);

assertWithdrawalsInExecutionPayloadMatchExpected(payloadSummary, expectedWithdrawals);
// EIP7732 TODO: hacky (requires refactor)
if (genericState.toVersionEip7732().isEmpty()) {
assertWithdrawalsInExecutionPayloadMatchExpected(payloadSummary, expectedWithdrawals);
}

processWithdrawalsUnchecked(
genericState, schemaDefinitionsCapella, beaconStateMutators, specConfigCapella);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
import tech.pegasys.teku.spec.datastructures.blocks.blockbody.BeaconBlockBody;
import tech.pegasys.teku.spec.datastructures.blocks.blockbody.versions.eip7732.BeaconBlockBodyEip7732;
import tech.pegasys.teku.spec.datastructures.execution.ExecutionPayload;
import tech.pegasys.teku.spec.datastructures.execution.ExecutionPayloadHeader;
import tech.pegasys.teku.spec.datastructures.execution.SignedExecutionPayloadHeader;
import tech.pegasys.teku.spec.datastructures.execution.versions.eip7732.ExecutionPayloadHeaderEip7732;
import tech.pegasys.teku.spec.datastructures.operations.IndexedPayloadAttestation;
Expand Down Expand Up @@ -284,6 +285,13 @@ public void processExecutionPayload(
// Removed in EIP-7732
}

@Override
public ExecutionPayloadHeader extractExecutionPayloadHeader(final BeaconBlockBody beaconBlockBody)
throws BlockProcessingException {
// Removed in EIP-7732 (only required for withdrawals validation against the state)
return null;
}

@Override
protected void processDepositRequests(
final MutableBeaconState state, final Optional<ExecutionPayload> executionPayload)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
import static com.google.common.base.Preconditions.checkArgument;

import java.util.Optional;
import tech.pegasys.teku.infrastructure.ssz.schema.SszListSchema;
import tech.pegasys.teku.spec.config.SpecConfigEip7732;
import tech.pegasys.teku.spec.datastructures.blobs.versions.deneb.BlobSidecarSchema;
import tech.pegasys.teku.spec.datastructures.blocks.BeaconBlockSchema;
Expand Down Expand Up @@ -48,6 +49,7 @@
import tech.pegasys.teku.spec.datastructures.operations.AggregateAndProof.AggregateAndProofSchema;
import tech.pegasys.teku.spec.datastructures.operations.AttestationSchema;
import tech.pegasys.teku.spec.datastructures.operations.IndexedPayloadAttestationSchema;
import tech.pegasys.teku.spec.datastructures.operations.PayloadAttestation;
import tech.pegasys.teku.spec.datastructures.operations.PayloadAttestationMessageSchema;
import tech.pegasys.teku.spec.datastructures.operations.PayloadAttestationSchema;
import tech.pegasys.teku.spec.datastructures.operations.SignedAggregateAndProof.SignedAggregateAndProofSchema;
Expand Down Expand Up @@ -322,6 +324,10 @@ public PayloadAttestationMessageSchema getPayloadAttestationMessageSchema() {
return payloadAttestationMessageSchema;
}

public SszListSchema<PayloadAttestation, ?> getPayloadAttestationsSchema() {
return beaconBlockBodySchema.getPayloadAttestationsSchema();
}

@Override
public Optional<SchemaDefinitionsEip7732> toVersionEip7732() {
return Optional.of(this);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
import tech.pegasys.teku.infrastructure.unsigned.UInt64;
import tech.pegasys.teku.spec.datastructures.blocks.BeaconBlock;
import tech.pegasys.teku.spec.datastructures.builder.ValidatorRegistration;
import tech.pegasys.teku.spec.datastructures.execution.ExecutionPayloadHeader;
import tech.pegasys.teku.spec.datastructures.operations.AggregateAndProof;
import tech.pegasys.teku.spec.datastructures.operations.AttestationData;
import tech.pegasys.teku.spec.datastructures.operations.PayloadAttestationData;
Expand Down Expand Up @@ -117,6 +118,12 @@ public SafeFuture<BLSSignature> signValidatorRegistration(
return sign(() -> delegate.signValidatorRegistration(validatorRegistration));
}

@Override
public SafeFuture<BLSSignature> signExecutionPayloadHeader(
final ExecutionPayloadHeader executionPayloadHeader, final ForkInfo forkInfo) {
return sign(() -> delegate.signExecutionPayloadHeader(executionPayloadHeader, forkInfo));
}

@Override
public Optional<URL> getSigningServiceUrl() {
return delegate.getSigningServiceUrl();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
import tech.pegasys.teku.spec.Spec;
import tech.pegasys.teku.spec.datastructures.blocks.BeaconBlock;
import tech.pegasys.teku.spec.datastructures.builder.ValidatorRegistration;
import tech.pegasys.teku.spec.datastructures.execution.ExecutionPayloadHeader;
import tech.pegasys.teku.spec.datastructures.operations.AggregateAndProof;
import tech.pegasys.teku.spec.datastructures.operations.AttestationData;
import tech.pegasys.teku.spec.datastructures.operations.PayloadAttestationData;
Expand Down Expand Up @@ -130,6 +131,13 @@ public SafeFuture<BLSSignature> signValidatorRegistration(
return sign(signingRootUtil.signingRootForValidatorRegistration(validatorRegistration));
}

@Override
public SafeFuture<BLSSignature> signExecutionPayloadHeader(
final ExecutionPayloadHeader executionPayloadHeader, final ForkInfo forkInfo) {
return sign(
signingRootUtil.signingRootForExecutionPayloadHeader(executionPayloadHeader, forkInfo));
}

private SafeFuture<Bytes> signingRootFromSyncCommitteeUtils(
final UInt64 slot, final Function<SyncCommitteeUtil, Bytes> createSigningRoot) {
return SafeFuture.of(() -> createSigningRoot.apply(spec.getSyncCommitteeUtilRequired(slot)));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
import tech.pegasys.teku.infrastructure.unsigned.UInt64;
import tech.pegasys.teku.spec.datastructures.blocks.BeaconBlock;
import tech.pegasys.teku.spec.datastructures.builder.ValidatorRegistration;
import tech.pegasys.teku.spec.datastructures.execution.ExecutionPayloadHeader;
import tech.pegasys.teku.spec.datastructures.operations.AggregateAndProof;
import tech.pegasys.teku.spec.datastructures.operations.AttestationData;
import tech.pegasys.teku.spec.datastructures.operations.PayloadAttestationData;
Expand Down Expand Up @@ -60,6 +61,9 @@ SafeFuture<BLSSignature> signContributionAndProof(

SafeFuture<BLSSignature> signValidatorRegistration(ValidatorRegistration validatorRegistration);

SafeFuture<BLSSignature> signExecutionPayloadHeader(
ExecutionPayloadHeader executionPayloadHeader, ForkInfo forkInfo);

default boolean isLocal() {
return getSigningServiceUrl().isEmpty();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@
import tech.pegasys.teku.spec.datastructures.blocks.BeaconBlock;
import tech.pegasys.teku.spec.datastructures.blocks.BeaconBlockHeader;
import tech.pegasys.teku.spec.datastructures.builder.ValidatorRegistration;
import tech.pegasys.teku.spec.datastructures.execution.ExecutionPayloadHeader;
import tech.pegasys.teku.spec.datastructures.execution.versions.eip7732.ExecutionPayloadHeaderEip7732;
import tech.pegasys.teku.spec.datastructures.operations.AggregateAndProof;
import tech.pegasys.teku.spec.datastructures.operations.AttestationData;
import tech.pegasys.teku.spec.datastructures.operations.PayloadAttestationData;
Expand Down Expand Up @@ -125,4 +127,17 @@ public Bytes signingRootForValidatorRegistration(
final Bytes32 domain = miscHelpers.computeDomain(Domain.APPLICATION_BUILDER);
return miscHelpers.computeSigningRoot(validatorRegistration, domain);
}

public Bytes signingRootForExecutionPayloadHeader(
final ExecutionPayloadHeader executionPayloadHeader, final ForkInfo forkInfo) {
final UInt64 slot = ExecutionPayloadHeaderEip7732.required(executionPayloadHeader).getSlot();
final SpecVersion specVersion = spec.atSlot(slot);
final Bytes32 domain =
spec.getDomain(
Domain.BEACON_BUILDER,
spec.computeEpochAtSlot(slot),
forkInfo.getFork(),
forkInfo.getGenesisValidatorsRoot());
return specVersion.miscHelpers().computeSigningRoot(executionPayloadHeader, domain);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
import tech.pegasys.teku.infrastructure.unsigned.UInt64;
import tech.pegasys.teku.spec.datastructures.blocks.BeaconBlock;
import tech.pegasys.teku.spec.datastructures.builder.ValidatorRegistration;
import tech.pegasys.teku.spec.datastructures.execution.ExecutionPayloadHeader;
import tech.pegasys.teku.spec.datastructures.operations.AggregateAndProof;
import tech.pegasys.teku.spec.datastructures.operations.AttestationData;
import tech.pegasys.teku.spec.datastructures.operations.PayloadAttestationData;
Expand Down Expand Up @@ -155,6 +156,12 @@ public SafeFuture<BLSSignature> signValidatorRegistration(
return delegate.signValidatorRegistration(validatorRegistration);
}

@Override
public SafeFuture<BLSSignature> signExecutionPayloadHeader(
final ExecutionPayloadHeader executionPayloadHeader, final ForkInfo forkInfo) {
return delegate.signExecutionPayloadHeader(executionPayloadHeader, forkInfo);
}

@Override
public Optional<URL> getSigningServiceUrl() {
return delegate.getSigningServiceUrl();
Expand Down
Loading

0 comments on commit 85e774e

Please sign in to comment.