Skip to content

Commit

Permalink
migrate other electra schemas (#8845)
Browse files Browse the repository at this point in the history
  • Loading branch information
tbenr authored Nov 21, 2024
1 parent 769f53a commit b0dad8a
Show file tree
Hide file tree
Showing 15 changed files with 112 additions and 64 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@
}
},
"execution_requests" : {
"$ref" : "#/components/schemas/ExecutionRequests"
"$ref" : "#/components/schemas/ExecutionRequestsElectra"
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@
}
},
"execution_requests" : {
"$ref" : "#/components/schemas/ExecutionRequests"
"$ref" : "#/components/schemas/ExecutionRequestsElectra"
}
}
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"title" : "ExecutionRequests",
"title" : "ExecutionRequestsElectra",
"type" : "object",
"required" : [ "deposits", "withdrawals", "consolidations" ],
"properties" : {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,24 +13,26 @@

package tech.pegasys.teku.spec.datastructures.builder;

import static tech.pegasys.teku.spec.schemas.registry.SchemaTypes.BLOBS_BUNDLE_SCHEMA;
import static tech.pegasys.teku.spec.schemas.registry.SchemaTypes.EXECUTION_PAYLOAD_SCHEMA;

import tech.pegasys.teku.infrastructure.ssz.containers.ContainerSchema2;
import tech.pegasys.teku.infrastructure.ssz.schema.SszSchema;
import tech.pegasys.teku.infrastructure.ssz.tree.TreeNode;
import tech.pegasys.teku.spec.datastructures.execution.ExecutionPayload;
import tech.pegasys.teku.spec.datastructures.execution.ExecutionPayloadSchema;
import tech.pegasys.teku.spec.schemas.registry.SchemaRegistry;

public class ExecutionPayloadAndBlobsBundleSchema
extends ContainerSchema2<ExecutionPayloadAndBlobsBundle, ExecutionPayload, BlobsBundle>
implements BuilderPayloadSchema<ExecutionPayloadAndBlobsBundle> {

public ExecutionPayloadAndBlobsBundleSchema(
final ExecutionPayloadSchema<? extends ExecutionPayload> executionPayloadSchema,
final BlobsBundleSchema blobsBundleSchema) {
public ExecutionPayloadAndBlobsBundleSchema(final SchemaRegistry schemaRegistry) {
super(
"ExecutionPayloadAndBlobsBundle",
namedSchema(
"execution_payload", SszSchema.as(ExecutionPayload.class, executionPayloadSchema)),
namedSchema("blobs_bundle", blobsBundleSchema));
"execution_payload",
SszSchema.as(ExecutionPayload.class, schemaRegistry.get(EXECUTION_PAYLOAD_SCHEMA))),
namedSchema("blobs_bundle", schemaRegistry.get(BLOBS_BUNDLE_SCHEMA)));
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,6 @@ public class ConsolidationRequest

public static final byte REQUEST_TYPE = 0x2;

public static final ConsolidationRequestSchema SSZ_SCHEMA = new ConsolidationRequestSchema();

protected ConsolidationRequest(
final ConsolidationRequestSchema schema,
final Bytes20 sourceAddress,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,8 +47,6 @@ public class DepositRequest
SszUInt64.of(index));
}

public static final DepositRequestSchema SSZ_SCHEMA = new DepositRequestSchema();

DepositRequest(final DepositRequestSchema type, final TreeNode backingNode) {
super(type, backingNode);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,12 @@

package tech.pegasys.teku.spec.datastructures.execution.versions.electra;

import static tech.pegasys.teku.spec.schemas.registry.SchemaTypes.EXECUTION_REQUESTS_SCHEMA;

import com.google.common.annotations.VisibleForTesting;
import java.util.List;
import tech.pegasys.teku.spec.config.SpecConfigElectra;
import tech.pegasys.teku.spec.datastructures.execution.ExecutionRequestsBuilder;
import tech.pegasys.teku.spec.schemas.registry.SchemaRegistry;

public class ExecutionRequestsBuilderElectra implements ExecutionRequestsBuilder {

Expand All @@ -26,8 +28,8 @@ public class ExecutionRequestsBuilderElectra implements ExecutionRequestsBuilder
private List<ConsolidationRequest> consolidations = List.of();

@VisibleForTesting
public ExecutionRequestsBuilderElectra(final SpecConfigElectra specConfig) {
this(new ExecutionRequestsSchema(specConfig));
public ExecutionRequestsBuilderElectra(final SchemaRegistry schemaRegistry) {
this(schemaRegistry.get(EXECUTION_REQUESTS_SCHEMA));
}

public ExecutionRequestsBuilderElectra(final ExecutionRequestsSchema executionRequestsSchema) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,17 @@
import static tech.pegasys.teku.spec.datastructures.execution.versions.electra.ExecutionRequestsFields.CONSOLIDATIONS;
import static tech.pegasys.teku.spec.datastructures.execution.versions.electra.ExecutionRequestsFields.DEPOSITS;
import static tech.pegasys.teku.spec.datastructures.execution.versions.electra.ExecutionRequestsFields.WITHDRAWALS;
import static tech.pegasys.teku.spec.schemas.registry.SchemaTypes.CONSOLIDATION_REQUEST_SCHEMA;
import static tech.pegasys.teku.spec.schemas.registry.SchemaTypes.DEPOSIT_REQUEST_SCHEMA;
import static tech.pegasys.teku.spec.schemas.registry.SchemaTypes.WITHDRAWAL_REQUEST_SCHEMA;

import java.util.List;
import tech.pegasys.teku.infrastructure.ssz.SszList;
import tech.pegasys.teku.infrastructure.ssz.containers.ContainerSchema3;
import tech.pegasys.teku.infrastructure.ssz.schema.SszListSchema;
import tech.pegasys.teku.infrastructure.ssz.tree.TreeNode;
import tech.pegasys.teku.spec.config.SpecConfigElectra;
import tech.pegasys.teku.spec.schemas.registry.SchemaRegistry;

public class ExecutionRequestsSchema
extends ContainerSchema3<
Expand All @@ -31,21 +35,26 @@ public class ExecutionRequestsSchema
SszList<WithdrawalRequest>,
SszList<ConsolidationRequest>> {

public ExecutionRequestsSchema(final SpecConfigElectra specConfig) {
public ExecutionRequestsSchema(
final SpecConfigElectra specConfig,
final SchemaRegistry schemaRegistry,
final String containerName) {
super(
"ExecutionRequests",
containerName,
namedSchema(
DEPOSITS,
SszListSchema.create(
DepositRequest.SSZ_SCHEMA, specConfig.getMaxDepositRequestsPerPayload())),
schemaRegistry.get(DEPOSIT_REQUEST_SCHEMA),
specConfig.getMaxDepositRequestsPerPayload())),
namedSchema(
WITHDRAWALS,
SszListSchema.create(
WithdrawalRequest.SSZ_SCHEMA, specConfig.getMaxWithdrawalRequestsPerPayload())),
schemaRegistry.get(WITHDRAWAL_REQUEST_SCHEMA),
specConfig.getMaxWithdrawalRequestsPerPayload())),
namedSchema(
CONSOLIDATIONS,
SszListSchema.create(
ConsolidationRequest.SSZ_SCHEMA,
schemaRegistry.get(CONSOLIDATION_REQUEST_SCHEMA),
specConfig.getMaxConsolidationRequestsPerPayload())));
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,6 @@ public class WithdrawalRequest

public static final byte REQUEST_TYPE = 0x1;

public static final WithdrawalRequestSchema SSZ_SCHEMA = new WithdrawalRequestSchema();

protected WithdrawalRequest(
final WithdrawalRequestSchema schema,
final Bytes20 sourceAddress,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
import static tech.pegasys.teku.spec.schemas.registry.SchemaTypes.BLOB_SIDECARS_BY_ROOT_REQUEST_MESSAGE_SCHEMA;
import static tech.pegasys.teku.spec.schemas.registry.SchemaTypes.BLOB_SIDECAR_SCHEMA;
import static tech.pegasys.teku.spec.schemas.registry.SchemaTypes.BLOCK_CONTENTS_SCHEMA;
import static tech.pegasys.teku.spec.schemas.registry.SchemaTypes.EXECUTION_PAYLOAD_AND_BLOBS_BUNDLE_SCHEMA;
import static tech.pegasys.teku.spec.schemas.registry.SchemaTypes.SIGNED_BLOCK_CONTENTS_SCHEMA;

import java.util.Optional;
Expand Down Expand Up @@ -67,7 +68,7 @@ public SchemaDefinitionsDeneb(final SchemaRegistry schemaRegistry) {
this.signedBlockContentsSchema = schemaRegistry.get(SIGNED_BLOCK_CONTENTS_SCHEMA);
this.blobsBundleSchema = schemaRegistry.get(BLOBS_BUNDLE_SCHEMA);
this.executionPayloadAndBlobsBundleSchema =
new ExecutionPayloadAndBlobsBundleSchema(getExecutionPayloadSchema(), blobsBundleSchema);
schemaRegistry.get(EXECUTION_PAYLOAD_AND_BLOBS_BUNDLE_SCHEMA);
this.blobSidecarsByRootRequestMessageSchema =
schemaRegistry.get(BLOB_SIDECARS_BY_ROOT_REQUEST_MESSAGE_SCHEMA);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,47 +14,44 @@
package tech.pegasys.teku.spec.schemas;

import static com.google.common.base.Preconditions.checkArgument;
import static tech.pegasys.teku.spec.schemas.registry.SchemaTypes.BLOBS_BUNDLE_SCHEMA;
import static tech.pegasys.teku.spec.schemas.registry.SchemaTypes.CONSOLIDATION_REQUEST_SCHEMA;
import static tech.pegasys.teku.spec.schemas.registry.SchemaTypes.DEPOSIT_REQUEST_SCHEMA;
import static tech.pegasys.teku.spec.schemas.registry.SchemaTypes.EXECUTION_REQUESTS_SCHEMA;
import static tech.pegasys.teku.spec.schemas.registry.SchemaTypes.PENDING_CONSOLIDATIONS_SCHEMA;
import static tech.pegasys.teku.spec.schemas.registry.SchemaTypes.PENDING_DEPOSITS_SCHEMA;
import static tech.pegasys.teku.spec.schemas.registry.SchemaTypes.PENDING_PARTIAL_WITHDRAWALS_SCHEMA;
import static tech.pegasys.teku.spec.schemas.registry.SchemaTypes.WITHDRAWAL_REQUEST_SCHEMA;

import java.util.Optional;
import tech.pegasys.teku.infrastructure.ssz.schema.SszListSchema;
import tech.pegasys.teku.spec.config.SpecConfig;
import tech.pegasys.teku.spec.datastructures.blocks.blockbody.BeaconBlockBodyBuilder;
import tech.pegasys.teku.spec.datastructures.blocks.blockbody.versions.electra.BeaconBlockBodyBuilderElectra;
import tech.pegasys.teku.spec.datastructures.builder.BuilderPayloadSchema;
import tech.pegasys.teku.spec.datastructures.builder.ExecutionPayloadAndBlobsBundleSchema;
import tech.pegasys.teku.spec.datastructures.execution.versions.electra.ConsolidationRequest;
import tech.pegasys.teku.spec.datastructures.execution.versions.electra.ConsolidationRequestSchema;
import tech.pegasys.teku.spec.datastructures.execution.versions.electra.DepositRequest;
import tech.pegasys.teku.spec.datastructures.execution.versions.electra.DepositRequestSchema;
import tech.pegasys.teku.spec.datastructures.execution.versions.electra.ExecutionRequestsSchema;
import tech.pegasys.teku.spec.datastructures.execution.versions.electra.WithdrawalRequest;
import tech.pegasys.teku.spec.datastructures.execution.versions.electra.WithdrawalRequestSchema;
import tech.pegasys.teku.spec.datastructures.state.versions.electra.PendingConsolidation;
import tech.pegasys.teku.spec.datastructures.state.versions.electra.PendingConsolidation.PendingConsolidationSchema;
import tech.pegasys.teku.spec.datastructures.state.versions.electra.PendingDeposit;
import tech.pegasys.teku.spec.datastructures.state.versions.electra.PendingDeposit.PendingDepositSchema;
import tech.pegasys.teku.spec.datastructures.state.versions.electra.PendingPartialWithdrawal;
import tech.pegasys.teku.spec.datastructures.state.versions.electra.PendingPartialWithdrawal.PendingPartialWithdrawalSchema;
import tech.pegasys.teku.spec.schemas.registry.SchemaRegistry;

public class SchemaDefinitionsElectra extends SchemaDefinitionsDeneb {
private final ExecutionPayloadAndBlobsBundleSchema executionPayloadAndBlobsBundleSchema;

private final ExecutionRequestsSchema executionRequestsSchema;
private final DepositRequestSchema depositRequestSchema;
private final WithdrawalRequestSchema withdrawalRequestSchema;
private final ConsolidationRequestSchema consolidationRequestSchema;
private final PendingDeposit.PendingDepositSchema pendingDepositSchema;

private final SszListSchema<PendingDeposit, ?> pendingDepositsSchema;
private final SszListSchema<PendingPartialWithdrawal, ?> pendingPartialWithdrawalsSchema;
private final SszListSchema<PendingConsolidation, ?> pendingConsolidationsSchema;

private final PendingPartialWithdrawal.PendingPartialWithdrawalSchema
pendingPartialWithdrawalSchema;
private final PendingConsolidation.PendingConsolidationSchema pendingConsolidationSchema;
private final PendingDepositSchema pendingDepositSchema;
private final PendingPartialWithdrawalSchema pendingPartialWithdrawalSchema;
private final PendingConsolidationSchema pendingConsolidationSchema;

public SchemaDefinitionsElectra(final SchemaRegistry schemaRegistry) {
super(schemaRegistry);
Expand All @@ -63,17 +60,17 @@ public SchemaDefinitionsElectra(final SchemaRegistry schemaRegistry) {
this.pendingPartialWithdrawalsSchema = schemaRegistry.get(PENDING_PARTIAL_WITHDRAWALS_SCHEMA);
this.pendingConsolidationsSchema = schemaRegistry.get(PENDING_CONSOLIDATIONS_SCHEMA);

this.executionPayloadAndBlobsBundleSchema =
new ExecutionPayloadAndBlobsBundleSchema(
getExecutionPayloadSchema(), schemaRegistry.get(BLOBS_BUNDLE_SCHEMA));

this.depositRequestSchema = DepositRequest.SSZ_SCHEMA;
this.withdrawalRequestSchema = WithdrawalRequest.SSZ_SCHEMA;
this.consolidationRequestSchema = ConsolidationRequest.SSZ_SCHEMA;
this.pendingDepositSchema = new PendingDeposit.PendingDepositSchema();
this.depositRequestSchema = schemaRegistry.get(DEPOSIT_REQUEST_SCHEMA);
this.withdrawalRequestSchema = schemaRegistry.get(WITHDRAWAL_REQUEST_SCHEMA);
this.consolidationRequestSchema = schemaRegistry.get(CONSOLIDATION_REQUEST_SCHEMA);
this.pendingDepositSchema =
(PendingDepositSchema) schemaRegistry.get(PENDING_DEPOSITS_SCHEMA).getElementSchema();
this.pendingPartialWithdrawalSchema =
new PendingPartialWithdrawal.PendingPartialWithdrawalSchema();
this.pendingConsolidationSchema = new PendingConsolidation.PendingConsolidationSchema();
(PendingPartialWithdrawalSchema)
schemaRegistry.get(PENDING_PARTIAL_WITHDRAWALS_SCHEMA).getElementSchema();
this.pendingConsolidationSchema =
(PendingConsolidationSchema)
schemaRegistry.get(PENDING_CONSOLIDATIONS_SCHEMA).getElementSchema();
}

public static SchemaDefinitionsElectra required(final SchemaDefinitions schemaDefinitions) {
Expand All @@ -85,23 +82,13 @@ public static SchemaDefinitionsElectra required(final SchemaDefinitions schemaDe
return (SchemaDefinitionsElectra) schemaDefinitions;
}

@Override
public BuilderPayloadSchema<?> getBuilderPayloadSchema() {
return getExecutionPayloadAndBlobsBundleSchema();
}

@Override
public BeaconBlockBodyBuilder createBeaconBlockBodyBuilder() {
return new BeaconBlockBodyBuilderElectra(
getBeaconBlockBodySchema().toVersionElectra().orElseThrow(),
getBlindedBeaconBlockBodySchema().toBlindedVersionElectra().orElseThrow());
}

@Override
public ExecutionPayloadAndBlobsBundleSchema getExecutionPayloadAndBlobsBundleSchema() {
return executionPayloadAndBlobsBundleSchema;
}

public ExecutionRequestsSchema getExecutionRequestsSchema() {
return executionRequestsSchema;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,9 @@
import static tech.pegasys.teku.spec.schemas.registry.SchemaTypes.BLOCK_CONTENTS_SCHEMA;
import static tech.pegasys.teku.spec.schemas.registry.SchemaTypes.BLS_TO_EXECUTION_CHANGE_SCHEMA;
import static tech.pegasys.teku.spec.schemas.registry.SchemaTypes.BUILDER_BID_SCHEMA;
import static tech.pegasys.teku.spec.schemas.registry.SchemaTypes.CONSOLIDATION_REQUEST_SCHEMA;
import static tech.pegasys.teku.spec.schemas.registry.SchemaTypes.DEPOSIT_REQUEST_SCHEMA;
import static tech.pegasys.teku.spec.schemas.registry.SchemaTypes.EXECUTION_PAYLOAD_AND_BLOBS_BUNDLE_SCHEMA;
import static tech.pegasys.teku.spec.schemas.registry.SchemaTypes.EXECUTION_PAYLOAD_HEADER_SCHEMA;
import static tech.pegasys.teku.spec.schemas.registry.SchemaTypes.EXECUTION_PAYLOAD_SCHEMA;
import static tech.pegasys.teku.spec.schemas.registry.SchemaTypes.EXECUTION_REQUESTS_SCHEMA;
Expand All @@ -56,6 +59,7 @@
import static tech.pegasys.teku.spec.schemas.registry.SchemaTypes.SIGNED_BLS_TO_EXECUTION_CHANGE_SCHEMA;
import static tech.pegasys.teku.spec.schemas.registry.SchemaTypes.SIGNED_BUILDER_BID_SCHEMA;
import static tech.pegasys.teku.spec.schemas.registry.SchemaTypes.SYNCNETS_ENR_FIELD_SCHEMA;
import static tech.pegasys.teku.spec.schemas.registry.SchemaTypes.WITHDRAWAL_REQUEST_SCHEMA;
import static tech.pegasys.teku.spec.schemas.registry.SchemaTypes.WITHDRAWAL_SCHEMA;

import com.google.common.annotations.VisibleForTesting;
Expand Down Expand Up @@ -89,6 +93,7 @@
import tech.pegasys.teku.spec.datastructures.blocks.versions.deneb.BlockContentsSchema;
import tech.pegasys.teku.spec.datastructures.blocks.versions.deneb.SignedBlockContentsSchema;
import tech.pegasys.teku.spec.datastructures.builder.BlobsBundleSchema;
import tech.pegasys.teku.spec.datastructures.builder.ExecutionPayloadAndBlobsBundleSchema;
import tech.pegasys.teku.spec.datastructures.builder.SignedBuilderBidSchema;
import tech.pegasys.teku.spec.datastructures.builder.versions.bellatrix.BuilderBidSchemaBellatrix;
import tech.pegasys.teku.spec.datastructures.builder.versions.deneb.BuilderBidSchemaDeneb;
Expand All @@ -100,7 +105,10 @@
import tech.pegasys.teku.spec.datastructures.execution.versions.capella.WithdrawalSchema;
import tech.pegasys.teku.spec.datastructures.execution.versions.deneb.ExecutionPayloadHeaderSchemaDeneb;
import tech.pegasys.teku.spec.datastructures.execution.versions.deneb.ExecutionPayloadSchemaDeneb;
import tech.pegasys.teku.spec.datastructures.execution.versions.electra.ConsolidationRequestSchema;
import tech.pegasys.teku.spec.datastructures.execution.versions.electra.DepositRequestSchema;
import tech.pegasys.teku.spec.datastructures.execution.versions.electra.ExecutionRequestsSchema;
import tech.pegasys.teku.spec.datastructures.execution.versions.electra.WithdrawalRequestSchema;
import tech.pegasys.teku.spec.datastructures.networking.libp2p.rpc.BeaconBlocksByRootRequestMessage.BeaconBlocksByRootRequestMessageSchema;
import tech.pegasys.teku.spec.datastructures.networking.libp2p.rpc.BlobSidecarsByRootRequestMessageSchema;
import tech.pegasys.teku.spec.datastructures.operations.AggregateAndProof.AggregateAndProofSchema;
Expand Down Expand Up @@ -171,14 +179,37 @@ public static SchemaRegistryBuilder create() {
.addProvider(createBlobsBundleSchemaProvider())
.addProvider(createBlockContentsSchema())
.addProvider(createSignedBlockContentsSchema())
.addProvider(createExecutionPayloadAndBlobsBundleSchemaProvider())

// ELECTRA
.addProvider(createPendingConsolidationsSchemaProvider())
.addProvider(createPendingPartialWithdrawalsSchemaProvider())
.addProvider(createPendingDepositsSchemaProvider())
.addProvider(createDepositRequestSchemaProvider())
.addProvider(createWithdrawalRequestSchemaProvider())
.addProvider(createConsolidationRequestSchemaProvider())
.addProvider(createExecutionRequestsSchemaProvider());
}

private static SchemaProvider<?> createDepositRequestSchemaProvider() {
return providerBuilder(DEPOSIT_REQUEST_SCHEMA)
.withCreator(ELECTRA, (registry, specConfig, schemaName) -> new DepositRequestSchema())
.build();
}

private static SchemaProvider<?> createWithdrawalRequestSchemaProvider() {
return providerBuilder(WITHDRAWAL_REQUEST_SCHEMA)
.withCreator(ELECTRA, (registry, specConfig, schemaName) -> new WithdrawalRequestSchema())
.build();
}

private static SchemaProvider<?> createConsolidationRequestSchemaProvider() {
return providerBuilder(CONSOLIDATION_REQUEST_SCHEMA)
.withCreator(
ELECTRA, (registry, specConfig, schemaName) -> new ConsolidationRequestSchema())
.build();
}

private static SchemaProvider<?> createBlockContentsSchema() {
return providerBuilder(BLOCK_CONTENTS_SCHEMA)
.withCreator(
Expand Down Expand Up @@ -255,6 +286,15 @@ private static SchemaProvider<?> createPendingConsolidationsSchemaProvider() {
.build();
}

private static SchemaProvider<?> createExecutionPayloadAndBlobsBundleSchemaProvider() {
return providerBuilder(EXECUTION_PAYLOAD_AND_BLOBS_BUNDLE_SCHEMA)
.withCreator(
DENEB,
(registry, specConfig, schemaName) ->
new ExecutionPayloadAndBlobsBundleSchema(registry))
.build();
}

private static SchemaProvider<?> createBeaconStateSchemaProvider() {
return providerBuilder(BEACON_STATE_SCHEMA)
.withCreator(
Expand Down Expand Up @@ -323,7 +363,8 @@ private static SchemaProvider<?> createExecutionRequestsSchemaProvider() {
.withCreator(
ELECTRA,
(registry, specConfig, schemaName) ->
new ExecutionRequestsSchema(SpecConfigElectra.required(specConfig)))
new ExecutionRequestsSchema(
SpecConfigElectra.required(specConfig), registry, schemaName))
.build();
}

Expand Down
Loading

0 comments on commit b0dad8a

Please sign in to comment.