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

Migrate block content schemas #8843

Merged
merged 3 commits into from
Nov 21, 2024
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 @@ -13,6 +13,9 @@

package tech.pegasys.teku.spec.datastructures.blocks.versions.deneb;

import static tech.pegasys.teku.spec.schemas.registry.SchemaTypes.BEACON_BLOCK_SCHEMA;
import static tech.pegasys.teku.spec.schemas.registry.SchemaTypes.BLOB_SCHEMA;

import java.util.List;
import tech.pegasys.teku.infrastructure.ssz.SszList;
import tech.pegasys.teku.infrastructure.ssz.containers.ContainerSchema3;
Expand All @@ -22,12 +25,11 @@
import tech.pegasys.teku.kzg.KZGProof;
import tech.pegasys.teku.spec.config.SpecConfigDeneb;
import tech.pegasys.teku.spec.datastructures.blobs.versions.deneb.Blob;
import tech.pegasys.teku.spec.datastructures.blobs.versions.deneb.BlobSchema;
import tech.pegasys.teku.spec.datastructures.blocks.BeaconBlock;
import tech.pegasys.teku.spec.datastructures.blocks.BeaconBlockSchema;
import tech.pegasys.teku.spec.datastructures.blocks.BlockContainerSchema;
import tech.pegasys.teku.spec.datastructures.type.SszKZGProof;
import tech.pegasys.teku.spec.datastructures.type.SszKZGProofSchema;
import tech.pegasys.teku.spec.schemas.registry.SchemaRegistry;

public class BlockContentsSchema
extends ContainerSchema3<BlockContents, BeaconBlock, SszList<SszKZGProof>, SszList<Blob>>
Expand All @@ -36,27 +38,20 @@ public class BlockContentsSchema
static final SszFieldName FIELD_KZG_PROOFS = () -> "kzg_proofs";
static final SszFieldName FIELD_BLOBS = () -> "blobs";

BlockContentsSchema(
public BlockContentsSchema(
final String containerName,
final SpecConfigDeneb specConfig,
final BeaconBlockSchema beaconBlockSchema,
final BlobSchema blobSchema) {
final SchemaRegistry schemaRegistry) {
super(
containerName,
namedSchema("block", beaconBlockSchema),
namedSchema("block", schemaRegistry.get(BEACON_BLOCK_SCHEMA)),
namedSchema(
FIELD_KZG_PROOFS,
SszListSchema.create(SszKZGProofSchema.INSTANCE, specConfig.getMaxBlobsPerBlock())),
namedSchema(
FIELD_BLOBS, SszListSchema.create(blobSchema, specConfig.getMaxBlobsPerBlock())));
}

public static BlockContentsSchema create(
final SpecConfigDeneb specConfig,
final BeaconBlockSchema beaconBlockSchema,
final BlobSchema blobSchema,
final String containerName) {
return new BlockContentsSchema(containerName, specConfig, beaconBlockSchema, blobSchema);
FIELD_BLOBS,
SszListSchema.create(
schemaRegistry.get(BLOB_SCHEMA), specConfig.getMaxBlobsPerBlock())));
}

public BlockContents create(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,9 @@

package tech.pegasys.teku.spec.datastructures.blocks.versions.deneb;

import static tech.pegasys.teku.spec.schemas.registry.SchemaTypes.BLOB_SCHEMA;
import static tech.pegasys.teku.spec.schemas.registry.SchemaTypes.SIGNED_BEACON_BLOCK_SCHEMA;

import java.util.List;
import tech.pegasys.teku.infrastructure.ssz.SszList;
import tech.pegasys.teku.infrastructure.ssz.containers.ContainerSchema3;
Expand All @@ -22,12 +25,12 @@
import tech.pegasys.teku.kzg.KZGProof;
import tech.pegasys.teku.spec.config.SpecConfigDeneb;
import tech.pegasys.teku.spec.datastructures.blobs.versions.deneb.Blob;
import tech.pegasys.teku.spec.datastructures.blobs.versions.deneb.BlobSchema;
import tech.pegasys.teku.spec.datastructures.blocks.SignedBeaconBlock;
import tech.pegasys.teku.spec.datastructures.blocks.SignedBeaconBlockSchema;
import tech.pegasys.teku.spec.datastructures.blocks.SignedBlockContainerSchema;
import tech.pegasys.teku.spec.datastructures.type.SszKZGProof;
import tech.pegasys.teku.spec.datastructures.type.SszKZGProofSchema;
import tech.pegasys.teku.spec.schemas.registry.SchemaRegistry;

public class SignedBlockContentsSchema
extends ContainerSchema3<
Expand All @@ -37,28 +40,20 @@ public class SignedBlockContentsSchema
static final SszFieldName FIELD_KZG_PROOFS = () -> "kzg_proofs";
static final SszFieldName FIELD_BLOBS = () -> "blobs";

SignedBlockContentsSchema(
public SignedBlockContentsSchema(
final String containerName,
final SpecConfigDeneb specConfig,
final SignedBeaconBlockSchema signedBeaconBlockSchema,
final BlobSchema blobSchema) {
final SchemaRegistry schemaRegistry) {
super(
containerName,
namedSchema("signed_block", signedBeaconBlockSchema),
namedSchema("signed_block", schemaRegistry.get(SIGNED_BEACON_BLOCK_SCHEMA)),
namedSchema(
FIELD_KZG_PROOFS,
SszListSchema.create(SszKZGProofSchema.INSTANCE, specConfig.getMaxBlobsPerBlock())),
namedSchema(
FIELD_BLOBS, SszListSchema.create(blobSchema, specConfig.getMaxBlobsPerBlock())));
}

public static SignedBlockContentsSchema create(
final SpecConfigDeneb specConfig,
final SignedBeaconBlockSchema signedBeaconBlockSchema,
final BlobSchema blobSchema,
final String containerName) {
return new SignedBlockContentsSchema(
containerName, specConfig, signedBeaconBlockSchema, blobSchema);
FIELD_BLOBS,
SszListSchema.create(
schemaRegistry.get(BLOB_SCHEMA), specConfig.getMaxBlobsPerBlock())));
}

public SignedBlockContents create(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,12 @@
import static tech.pegasys.teku.spec.schemas.registry.SchemaTypes.BLOB_SCHEMA;
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.SIGNED_BLOCK_CONTENTS_SCHEMA;

import java.util.Optional;
import tech.pegasys.teku.infrastructure.ssz.SszList;
import tech.pegasys.teku.infrastructure.ssz.schema.SszListSchema;
import tech.pegasys.teku.spec.config.SpecConfigDeneb;
import tech.pegasys.teku.spec.datastructures.blobs.versions.deneb.Blob;
import tech.pegasys.teku.spec.datastructures.blobs.versions.deneb.BlobKzgCommitmentsSchema;
import tech.pegasys.teku.spec.datastructures.blobs.versions.deneb.BlobSchema;
Expand Down Expand Up @@ -57,18 +58,13 @@ public class SchemaDefinitionsDeneb extends SchemaDefinitionsCapella {

public SchemaDefinitionsDeneb(final SchemaRegistry schemaRegistry) {
super(schemaRegistry);
final SpecConfigDeneb specConfig = SpecConfigDeneb.required(schemaRegistry.getSpecConfig());
this.blobKzgCommitmentsSchema = schemaRegistry.get(BLOB_KZG_COMMITMENTS_SCHEMA);

this.blobKzgCommitmentsSchema = schemaRegistry.get(BLOB_KZG_COMMITMENTS_SCHEMA);
this.blobSchema = schemaRegistry.get(BLOB_SCHEMA);
this.blobsInBlockSchema = schemaRegistry.get(BLOBS_IN_BLOCK_SCHEMA);
this.blobSidecarSchema = schemaRegistry.get(BLOB_SIDECAR_SCHEMA);
this.blockContentsSchema =
BlockContentsSchema.create(
specConfig, getBeaconBlockSchema(), blobSchema, "BlockContentsDeneb");
this.signedBlockContentsSchema =
SignedBlockContentsSchema.create(
specConfig, getSignedBeaconBlockSchema(), blobSchema, "SignedBlockContentsDeneb");
this.blockContentsSchema = schemaRegistry.get(BLOCK_CONTENTS_SCHEMA);
this.signedBlockContentsSchema = schemaRegistry.get(SIGNED_BLOCK_CONTENTS_SCHEMA);
this.blobsBundleSchema = schemaRegistry.get(BLOBS_BUNDLE_SCHEMA);
this.executionPayloadAndBlobsBundleSchema =
new ExecutionPayloadAndBlobsBundleSchema(getExecutionPayloadSchema(), blobsBundleSchema);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,15 +23,8 @@
import java.util.Optional;
import tech.pegasys.teku.infrastructure.ssz.schema.SszListSchema;
import tech.pegasys.teku.spec.config.SpecConfig;
import tech.pegasys.teku.spec.config.SpecConfigElectra;
import tech.pegasys.teku.spec.datastructures.blocks.BlockContainer;
import tech.pegasys.teku.spec.datastructures.blocks.BlockContainerSchema;
import tech.pegasys.teku.spec.datastructures.blocks.SignedBlockContainer;
import tech.pegasys.teku.spec.datastructures.blocks.SignedBlockContainerSchema;
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.blocks.versions.deneb.BlockContentsSchema;
import tech.pegasys.teku.spec.datastructures.blocks.versions.deneb.SignedBlockContentsSchema;
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;
Expand All @@ -47,8 +40,6 @@
import tech.pegasys.teku.spec.schemas.registry.SchemaRegistry;

public class SchemaDefinitionsElectra extends SchemaDefinitionsDeneb {
private final BlockContentsSchema blockContentsSchema;
private final SignedBlockContentsSchema signedBlockContentsSchema;
private final ExecutionPayloadAndBlobsBundleSchema executionPayloadAndBlobsBundleSchema;

private final ExecutionRequestsSchema executionRequestsSchema;
Expand All @@ -67,22 +58,11 @@ public class SchemaDefinitionsElectra extends SchemaDefinitionsDeneb {

public SchemaDefinitionsElectra(final SchemaRegistry schemaRegistry) {
super(schemaRegistry);
final SpecConfigElectra specConfig = SpecConfigElectra.required(schemaRegistry.getSpecConfig());

this.executionRequestsSchema = schemaRegistry.get(EXECUTION_REQUESTS_SCHEMA);
this.pendingDepositsSchema = schemaRegistry.get(PENDING_DEPOSITS_SCHEMA);
this.pendingPartialWithdrawalsSchema = schemaRegistry.get(PENDING_PARTIAL_WITHDRAWALS_SCHEMA);
this.pendingConsolidationsSchema = schemaRegistry.get(PENDING_CONSOLIDATIONS_SCHEMA);

this.blockContentsSchema =
BlockContentsSchema.create(
specConfig, getBeaconBlockSchema(), getBlobSchema(), "BlockContentsElectra");
this.signedBlockContentsSchema =
SignedBlockContentsSchema.create(
specConfig,
getSignedBeaconBlockSchema(),
getBlobSchema(),
"SignedBlockContentsElectra");
this.executionPayloadAndBlobsBundleSchema =
new ExecutionPayloadAndBlobsBundleSchema(
getExecutionPayloadSchema(), schemaRegistry.get(BLOBS_BUNDLE_SCHEMA));
Expand All @@ -105,16 +85,6 @@ public static SchemaDefinitionsElectra required(final SchemaDefinitions schemaDe
return (SchemaDefinitionsElectra) schemaDefinitions;
}

@Override
public BlockContainerSchema<BlockContainer> getBlockContainerSchema() {
return getBlockContentsSchema().castTypeToBlockContainer();
}

@Override
public SignedBlockContainerSchema<SignedBlockContainer> getSignedBlockContainerSchema() {
return getSignedBlockContentsSchema().castTypeToSignedBlockContainer();
}

@Override
public BuilderPayloadSchema<?> getBuilderPayloadSchema() {
return getExecutionPayloadAndBlobsBundleSchema();
Expand All @@ -127,16 +97,6 @@ public BeaconBlockBodyBuilder createBeaconBlockBodyBuilder() {
getBlindedBeaconBlockBodySchema().toBlindedVersionElectra().orElseThrow());
}

@Override
public BlockContentsSchema getBlockContentsSchema() {
return blockContentsSchema;
}

@Override
public SignedBlockContentsSchema getSignedBlockContentsSchema() {
return signedBlockContentsSchema;
}

@Override
public ExecutionPayloadAndBlobsBundleSchema getExecutionPayloadAndBlobsBundleSchema() {
return executionPayloadAndBlobsBundleSchema;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,11 @@ boolean isProviderRegistered(final SchemaProvider<?> provider) {

@SuppressWarnings("unchecked")
public <T> T get(final SchemaId<T> schemaId) {
final T schema = cache.get(milestone, schemaId);
if (schema != null) {
return schema;
}

final SchemaProvider<T> provider = (SchemaProvider<T>) providers.get(schemaId);
if (provider == null) {
throw new IllegalArgumentException(
Expand All @@ -75,10 +80,6 @@ public <T> T get(final SchemaId<T> schemaId) {
+ " or it does not support milestone "
+ milestone);
}
final T schema = cache.get(milestone, schemaId);
if (schema != null) {
return schema;
}

// The schema was not found.
// we reach this point only during priming when we actually ask providers to generate schemas
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@
import static tech.pegasys.teku.spec.schemas.registry.SchemaTypes.BLOB_SCHEMA;
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.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.EXECUTION_PAYLOAD_HEADER_SCHEMA;
Expand All @@ -51,6 +52,7 @@
import static tech.pegasys.teku.spec.schemas.registry.SchemaTypes.SIGNED_AGGREGATE_AND_PROOF_SCHEMA;
import static tech.pegasys.teku.spec.schemas.registry.SchemaTypes.SIGNED_BEACON_BLOCK_SCHEMA;
import static tech.pegasys.teku.spec.schemas.registry.SchemaTypes.SIGNED_BLINDED_BEACON_BLOCK_SCHEMA;
import static tech.pegasys.teku.spec.schemas.registry.SchemaTypes.SIGNED_BLOCK_CONTENTS_SCHEMA;
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;
Expand Down Expand Up @@ -84,6 +86,8 @@
import tech.pegasys.teku.spec.datastructures.blocks.blockbody.versions.electra.BeaconBlockBodySchemaElectraImpl;
import tech.pegasys.teku.spec.datastructures.blocks.blockbody.versions.electra.BlindedBeaconBlockBodySchemaElectraImpl;
import tech.pegasys.teku.spec.datastructures.blocks.blockbody.versions.phase0.BeaconBlockBodySchemaPhase0;
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.SignedBuilderBidSchema;
import tech.pegasys.teku.spec.datastructures.builder.versions.bellatrix.BuilderBidSchemaBellatrix;
Expand Down Expand Up @@ -165,6 +169,8 @@ public static SchemaRegistryBuilder create() {
.addProvider(createBlobSidecarSchemaProvider())
.addProvider(createBlobSidecarsByRootRequestMessageSchemaProvider())
.addProvider(createBlobsBundleSchemaProvider())
.addProvider(createBlockContentsSchema())
.addProvider(createSignedBlockContentsSchema())

// ELECTRA
.addProvider(createPendingConsolidationsSchemaProvider())
Expand All @@ -173,6 +179,25 @@ public static SchemaRegistryBuilder create() {
.addProvider(createExecutionRequestsSchemaProvider());
}

private static SchemaProvider<?> createBlockContentsSchema() {
return providerBuilder(BLOCK_CONTENTS_SCHEMA)
.withCreator(
DENEB,
(registry, specConfig, schemaName) ->
new BlockContentsSchema(schemaName, SpecConfigDeneb.required(specConfig), registry))
.build();
}

private static SchemaProvider<?> createSignedBlockContentsSchema() {
return providerBuilder(SIGNED_BLOCK_CONTENTS_SCHEMA)
.withCreator(
DENEB,
(registry, specConfig, schemaName) ->
new SignedBlockContentsSchema(
schemaName, SpecConfigDeneb.required(specConfig), registry))
.build();
}

private static SchemaProvider<?> createSignedBuilderBidSchemaProvider() {
return providerBuilder(SIGNED_BUILDER_BID_SCHEMA)
.withCreator(
Expand Down