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 some deneb schemas to registry #8828

Merged
merged 3 commits into from
Nov 7, 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,36 +13,36 @@

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

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

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.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;
import tech.pegasys.teku.spec.datastructures.type.SszKZGCommitment;
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 BlobsBundleSchema
extends ContainerSchema3<
BlobsBundle, SszList<SszKZGCommitment>, SszList<SszKZGProof>, SszList<Blob>> {

public BlobsBundleSchema(
final String containerName,
final BlobSchema blobSchema,
final BlobKzgCommitmentsSchema blobKzgCommitmentsSchema,
final SpecConfigDeneb specConfig) {
public BlobsBundleSchema(final SchemaRegistry schemaRegistry, final SpecConfigDeneb specConfig) {
super(
containerName,
namedSchema("commitments", blobKzgCommitmentsSchema),
"BlobsBundle",
namedSchema("commitments", schemaRegistry.get(BLOB_KZG_COMMITMENTS_SCHEMA)),
namedSchema(
"proofs",
SszListSchema.create(
SszKZGProofSchema.INSTANCE, specConfig.getMaxBlobCommitmentsPerBlock())),
namedSchema(
"blobs", SszListSchema.create(blobSchema, specConfig.getMaxBlobCommitmentsPerBlock())));
"blobs",
SszListSchema.create(
schemaRegistry.get(BLOB_SCHEMA), specConfig.getMaxBlobCommitmentsPerBlock())));
}

@SuppressWarnings("unchecked")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,12 @@
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.BLOBS_IN_BLOCK_SCHEMA;
import static tech.pegasys.teku.spec.schemas.registry.SchemaTypes.BLOB_KZG_COMMITMENTS_SCHEMA;
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 java.util.Optional;
import tech.pegasys.teku.infrastructure.ssz.SszList;
Expand All @@ -26,7 +32,6 @@
import tech.pegasys.teku.spec.datastructures.blocks.BeaconBlockSchema;
import tech.pegasys.teku.spec.datastructures.blocks.BlockContainer;
import tech.pegasys.teku.spec.datastructures.blocks.BlockContainerSchema;
import tech.pegasys.teku.spec.datastructures.blocks.SignedBeaconBlockHeader;
import tech.pegasys.teku.spec.datastructures.blocks.SignedBeaconBlockSchema;
import tech.pegasys.teku.spec.datastructures.blocks.SignedBlockContainer;
import tech.pegasys.teku.spec.datastructures.blocks.SignedBlockContainerSchema;
Expand Down Expand Up @@ -91,7 +96,7 @@ public SchemaDefinitionsDeneb(final SchemaRegistry schemaRegistry) {
this.beaconStateSchema = BeaconStateSchemaDeneb.create(specConfig);
this.executionPayloadHeaderSchemaDeneb =
beaconStateSchema.getLastExecutionPayloadHeaderSchema();
this.blobKzgCommitmentsSchema = new BlobKzgCommitmentsSchema(specConfig);
this.blobKzgCommitmentsSchema = schemaRegistry.get(BLOB_KZG_COMMITMENTS_SCHEMA);
this.beaconBlockBodySchema =
BeaconBlockBodySchemaDenebImpl.create(
specConfig,
Expand Down Expand Up @@ -121,24 +126,19 @@ public SchemaDefinitionsDeneb(final SchemaRegistry schemaRegistry) {
this.signedBuilderBidSchemaDeneb =
new SignedBuilderBidSchema("SignedBuilderBidDeneb", builderBidSchemaDeneb);

this.blobSchema = new BlobSchema(specConfig);
this.blobsInBlockSchema = SszListSchema.create(blobSchema, specConfig.getMaxBlobsPerBlock());
this.blobSidecarSchema =
BlobSidecarSchema.create(
SignedBeaconBlockHeader.SSZ_SCHEMA,
blobSchema,
specConfig.getKzgCommitmentInclusionProofDepth());
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, beaconBlockSchema, blobSchema, "BlockContentsDeneb");
this.signedBlockContentsSchema =
SignedBlockContentsSchema.create(
specConfig, signedBeaconBlockSchema, blobSchema, "SignedBlockContentsDeneb");
this.blobsBundleSchema =
new BlobsBundleSchema("BlobsBundleDeneb", blobSchema, blobKzgCommitmentsSchema, specConfig);
this.blobsBundleSchema = schemaRegistry.get(BLOBS_BUNDLE_SCHEMA);
this.executionPayloadAndBlobsBundleSchema =
new ExecutionPayloadAndBlobsBundleSchema(executionPayloadSchemaDeneb, blobsBundleSchema);
this.blobSidecarsByRootRequestMessageSchema =
new BlobSidecarsByRootRequestMessageSchema(specConfig);
schemaRegistry.get(BLOB_SIDECARS_BY_ROOT_REQUEST_MESSAGE_SCHEMA);
}

public static SchemaDefinitionsDeneb required(final SchemaDefinitions schemaDefinitions) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
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 java.util.Optional;
import tech.pegasys.teku.infrastructure.ssz.schema.SszListSchema;
Expand All @@ -32,7 +33,6 @@
import tech.pegasys.teku.spec.datastructures.blocks.blockbody.versions.electra.BlindedBeaconBlockBodySchemaElectraImpl;
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.BuilderBidSchema;
import tech.pegasys.teku.spec.datastructures.builder.BuilderPayloadSchema;
import tech.pegasys.teku.spec.datastructures.builder.ExecutionPayloadAndBlobsBundleSchema;
Expand Down Expand Up @@ -70,7 +70,6 @@ public class SchemaDefinitionsElectra extends SchemaDefinitionsDeneb {

private final BlockContentsSchema blockContentsSchema;
private final SignedBlockContentsSchema signedBlockContentsSchema;
private final BlobsBundleSchema blobsBundleSchema;
private final ExecutionPayloadAndBlobsBundleSchema executionPayloadAndBlobsBundleSchema;

private final ExecutionRequestsSchema executionRequestsSchema;
Expand Down Expand Up @@ -132,11 +131,9 @@ public SchemaDefinitionsElectra(final SchemaRegistry schemaRegistry) {
this.signedBlockContentsSchema =
SignedBlockContentsSchema.create(
specConfig, signedBeaconBlockSchema, getBlobSchema(), "SignedBlockContentsElectra");
this.blobsBundleSchema =
new BlobsBundleSchema(
"BlobsBundleElectra", getBlobSchema(), getBlobKzgCommitmentsSchema(), specConfig);
this.executionPayloadAndBlobsBundleSchema =
new ExecutionPayloadAndBlobsBundleSchema(getExecutionPayloadSchema(), blobsBundleSchema);
new ExecutionPayloadAndBlobsBundleSchema(
getExecutionPayloadSchema(), schemaRegistry.get(BLOBS_BUNDLE_SCHEMA));

this.depositRequestSchema = DepositRequest.SSZ_SCHEMA;
this.withdrawalRequestSchema = WithdrawalRequest.SSZ_SCHEMA;
Expand Down Expand Up @@ -242,11 +239,6 @@ public SignedBlockContentsSchema getSignedBlockContentsSchema() {
return signedBlockContentsSchema;
}

@Override
public BlobsBundleSchema getBlobsBundleSchema() {
return blobsBundleSchema;
}

@Override
public ExecutionPayloadAndBlobsBundleSchema getExecutionPayloadAndBlobsBundleSchema() {
return executionPayloadAndBlobsBundleSchema;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -102,10 +102,46 @@ public String toString() {
}
}

/**
* Creates a builder for a constant schema provider.<br>
* This can be used when schema remains the same across multiple milestones. <br>
* Example usage:
*
* <pre>{@code
* constantProviderBuilder(EXAMPLE_SCHEMA)
* .withCreator(ALTAIR, (registry, config) -> new ExampleSchemaAltair())
* .withCreator(ELECTRA, (registry, config) -> new ExampleSchemaElectra())
* .build();
*
* }</pre>
*
* this will create a schema provider that will generate: <br>
* - only one ExampleSchemaAltair instance which will be reused from ALTAIR to BELLATRIX <br>
* - only one ExampleSchemaElectra instance which will be reused from ELECTRA to last known
* milestone <br>
*/
static <T> Builder<T> constantProviderBuilder(final SchemaId<T> schemaId) {
return new Builder<>(schemaId, true);
}

/**
* Creates a builder for a variable schema provider.<br>
* This can be used when schema changes across multiple milestones (i.e. depends on changing
* schemas) <br>
* Example usage:
*
* <pre>{@code
* variableProviderBuilder(EXAMPLE_SCHEMA)
* .withCreator(ALTAIR, (registry, config) -> new ExampleSchema1(registry, config))
* .withCreator(ELECTRA, (registry, config) -> new ExampleSchema2(registry, config))
* .build();
*
* }</pre>
*
* this will create a schema provider that will generate: <br>
* - a new instance of ExampleSchema1 for each milestone from ALTAIR to ELECTRA <br>
* - a new instance of ExampleSchema2 for each milestone from ELECTRA to last known milestone <br>
*/
static <T> Builder<T> variableProviderBuilder(final SchemaId<T> schemaId) {
return new Builder<>(schemaId, false);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
package tech.pegasys.teku.spec.schemas.registry;

import static tech.pegasys.teku.spec.SpecMilestone.CAPELLA;
import static tech.pegasys.teku.spec.SpecMilestone.DENEB;
import static tech.pegasys.teku.spec.SpecMilestone.ELECTRA;
import static tech.pegasys.teku.spec.SpecMilestone.PHASE0;
import static tech.pegasys.teku.spec.schemas.registry.BaseSchemaProvider.constantProviderBuilder;
Expand All @@ -22,6 +23,12 @@
import static tech.pegasys.teku.spec.schemas.registry.SchemaTypes.ATTESTER_SLASHING_SCHEMA;
import static tech.pegasys.teku.spec.schemas.registry.SchemaTypes.ATTNETS_ENR_FIELD_SCHEMA;
import static tech.pegasys.teku.spec.schemas.registry.SchemaTypes.BEACON_BLOCKS_BY_ROOT_REQUEST_MESSAGE_SCHEMA;
import static tech.pegasys.teku.spec.schemas.registry.SchemaTypes.BLOBS_BUNDLE_SCHEMA;
import static tech.pegasys.teku.spec.schemas.registry.SchemaTypes.BLOBS_IN_BLOCK_SCHEMA;
import static tech.pegasys.teku.spec.schemas.registry.SchemaTypes.BLOB_KZG_COMMITMENTS_SCHEMA;
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.BLS_TO_EXECUTION_CHANGE_SCHEMA;
import static tech.pegasys.teku.spec.schemas.registry.SchemaTypes.HISTORICAL_BATCH_SCHEMA;
import static tech.pegasys.teku.spec.schemas.registry.SchemaTypes.HISTORICAL_SUMMARY_SCHEMA;
Expand All @@ -34,12 +41,20 @@
import com.google.common.annotations.VisibleForTesting;
import java.util.HashSet;
import java.util.Set;
import tech.pegasys.teku.infrastructure.ssz.schema.SszListSchema;
import tech.pegasys.teku.infrastructure.ssz.schema.collections.SszBitvectorSchema;
import tech.pegasys.teku.spec.SpecMilestone;
import tech.pegasys.teku.spec.config.SpecConfig;
import tech.pegasys.teku.spec.config.SpecConfigDeneb;
import tech.pegasys.teku.spec.constants.NetworkConstants;
import tech.pegasys.teku.spec.datastructures.blobs.versions.deneb.BlobKzgCommitmentsSchema;
import tech.pegasys.teku.spec.datastructures.blobs.versions.deneb.BlobSchema;
import tech.pegasys.teku.spec.datastructures.blobs.versions.deneb.BlobSidecarSchema;
import tech.pegasys.teku.spec.datastructures.blocks.SignedBeaconBlockHeader;
import tech.pegasys.teku.spec.datastructures.builder.BlobsBundleSchema;
import tech.pegasys.teku.spec.datastructures.execution.versions.capella.WithdrawalSchema;
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;
import tech.pegasys.teku.spec.datastructures.operations.AttesterSlashingSchema;
import tech.pegasys.teku.spec.datastructures.operations.BlsToExecutionChangeSchema;
Expand Down Expand Up @@ -74,7 +89,76 @@ public static SchemaRegistryBuilder create() {
.addProvider(createWithdrawalSchemaProvider())
.addProvider(createBlsToExecutionChangeSchemaProvider())
.addProvider(createSignedBlsToExecutionChangeSchemaProvider())
.addProvider(createHistoricalSummarySchemaProvider());
.addProvider(createHistoricalSummarySchemaProvider())

// DENEB
.addProvider(createBlobKzgCommitmentsSchemaProvider())
.addProvider(createBlobSchemaProvider())
.addProvider(createBlobsInBlockSchemaProvider())
.addProvider(createBlobSidecarSchemaProvider())
.addProvider(createBlobSidecarsByRootRequestMessageSchemaProvider())
.addProvider(createBlobsBundleSchemaProvider());
}

private static SchemaProvider<?> createBlobsBundleSchemaProvider() {
// we can keep this to be constant because the blob list max length is
// getMaxBlobCommitmentsPerBlock
return constantProviderBuilder(BLOBS_BUNDLE_SCHEMA)
.withCreator(
DENEB,
(registry, specConfig) ->
new BlobsBundleSchema(registry, SpecConfigDeneb.required(specConfig)))
.build();
}

private static SchemaProvider<?> createBlobKzgCommitmentsSchemaProvider() {
// we can keep this to be constant because the kzg commitment list max length is
// getMaxBlobCommitmentsPerBlock
return constantProviderBuilder(BLOB_KZG_COMMITMENTS_SCHEMA)
.withCreator(
DENEB,
(registry, specConfig) ->
new BlobKzgCommitmentsSchema(SpecConfigDeneb.required(specConfig)))
.build();
}

private static SchemaProvider<?> createBlobSchemaProvider() {
return constantProviderBuilder(BLOB_SCHEMA)
.withCreator(
DENEB, (registry, specConfig) -> new BlobSchema(SpecConfigDeneb.required(specConfig)))
.build();
}

private static SchemaProvider<?> createBlobsInBlockSchemaProvider() {
return constantProviderBuilder(BLOBS_IN_BLOCK_SCHEMA)
.withCreator(
DENEB,
(registry, specConfig) ->
SszListSchema.create(
registry.get(BLOB_SCHEMA),
SpecConfigDeneb.required(specConfig).getMaxBlobsPerBlock()))
.build();
}

private static SchemaProvider<?> createBlobSidecarSchemaProvider() {
return constantProviderBuilder(BLOB_SIDECAR_SCHEMA)
.withCreator(
DENEB,
(registry, specConfig) ->
BlobSidecarSchema.create(
SignedBeaconBlockHeader.SSZ_SCHEMA,
registry.get(BLOB_SCHEMA),
SpecConfigDeneb.required(specConfig).getKzgCommitmentInclusionProofDepth()))
.build();
}

private static SchemaProvider<?> createBlobSidecarsByRootRequestMessageSchemaProvider() {
return constantProviderBuilder(BLOB_SIDECARS_BY_ROOT_REQUEST_MESSAGE_SCHEMA)
.withCreator(
DENEB,
(registry, specConfig) ->
new BlobSidecarsByRootRequestMessageSchema(SpecConfigDeneb.required(specConfig)))
.build();
}

private static SchemaProvider<?> createHistoricalSummarySchemaProvider() {
Expand Down Expand Up @@ -143,12 +227,12 @@ private static SchemaProvider<?> createAttesterSlashingSchemaProvider() {
PHASE0,
(registry, specConfig) ->
new AttesterSlashingSchema(
ATTESTER_SLASHING_SCHEMA.getContainerName(registry.getMilestone()), registry))
ATTESTER_SLASHING_SCHEMA.getContainerName(registry), registry))
.withCreator(
ELECTRA,
(registry, specConfig) ->
new AttesterSlashingSchema(
ATTESTER_SLASHING_SCHEMA.getContainerName(registry.getMilestone()), registry))
ATTESTER_SLASHING_SCHEMA.getContainerName(registry), registry))
.build();
}

Expand All @@ -158,13 +242,13 @@ private static SchemaProvider<?> createIndexedAttestationSchemaProvider() {
PHASE0,
(registry, specConfig) ->
new IndexedAttestationSchema(
INDEXED_ATTESTATION_SCHEMA.getContainerName(registry.getMilestone()),
INDEXED_ATTESTATION_SCHEMA.getContainerName(registry),
getMaxValidatorsPerAttestationPhase0(specConfig)))
.withCreator(
ELECTRA,
(registry, specConfig) ->
new IndexedAttestationSchema(
INDEXED_ATTESTATION_SCHEMA.getContainerName(registry.getMilestone()),
INDEXED_ATTESTATION_SCHEMA.getContainerName(registry),
getMaxValidatorsPerAttestationElectra(specConfig)))
.build();
}
Expand Down Expand Up @@ -192,12 +276,12 @@ private static SchemaProvider<?> createAggregateAndProofSchemaProvider() {
PHASE0,
(registry, specConfig) ->
new AggregateAndProofSchema(
AGGREGATE_AND_PROOF_SCHEMA.getContainerName(registry.getMilestone()), registry))
AGGREGATE_AND_PROOF_SCHEMA.getContainerName(registry), registry))
.withCreator(
ELECTRA,
(registry, specConfig) ->
new AggregateAndProofSchema(
AGGREGATE_AND_PROOF_SCHEMA.getContainerName(registry.getMilestone()), registry))
AGGREGATE_AND_PROOF_SCHEMA.getContainerName(registry), registry))
.build();
}

Expand All @@ -207,14 +291,12 @@ private static SchemaProvider<?> createSignedAggregateAndProofSchemaProvider() {
PHASE0,
(registry, specConfig) ->
new SignedAggregateAndProofSchema(
SIGNED_AGGREGATE_AND_PROOF_SCHEMA.getContainerName(registry.getMilestone()),
registry))
SIGNED_AGGREGATE_AND_PROOF_SCHEMA.getContainerName(registry), registry))
.withCreator(
ELECTRA,
(registry, specConfig) ->
new SignedAggregateAndProofSchema(
SIGNED_AGGREGATE_AND_PROOF_SCHEMA.getContainerName(registry.getMilestone()),
registry))
SIGNED_AGGREGATE_AND_PROOF_SCHEMA.getContainerName(registry), registry))
.build();
}

Expand Down
Loading