Skip to content

Commit

Permalink
update blobs bundle schema
Browse files Browse the repository at this point in the history
adds javadoc
  • Loading branch information
tbenr committed Nov 7, 2024
1 parent d37407c commit 22c8f6e
Show file tree
Hide file tree
Showing 4 changed files with 51 additions and 20 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -13,36 +13,39 @@

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 SchemaRegistry schemaRegistry,
final SpecConfigDeneb specConfig) {
super(
containerName,
namedSchema("commitments", blobKzgCommitmentsSchema),
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,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 @@ -18,6 +18,7 @@
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;
import static tech.pegasys.teku.spec.schemas.registry.BaseSchemaProvider.variableProviderBuilder;
import static tech.pegasys.teku.spec.schemas.registry.SchemaTypes.AGGREGATE_AND_PROOF_SCHEMA;
import static tech.pegasys.teku.spec.schemas.registry.SchemaTypes.ATTESTATION_SCHEMA;
import static tech.pegasys.teku.spec.schemas.registry.SchemaTypes.ATTESTER_SLASHING_SCHEMA;
Expand Down Expand Up @@ -101,14 +102,13 @@ public static SchemaRegistryBuilder create() {
}

private static SchemaProvider<?> createBlobsBundleSchemaProvider() {
return constantProviderBuilder(BLOBS_BUNDLE_SCHEMA)
return variableProviderBuilder(BLOBS_BUNDLE_SCHEMA)
.withCreator(
DENEB,
(registry, specConfig) ->
new BlobsBundleSchema(
BLOBS_BUNDLE_SCHEMA.getContainerName(registry),
registry.get(BLOB_SCHEMA),
registry.get(BLOB_KZG_COMMITMENTS_SCHEMA),
registry,
SpecConfigDeneb.required(specConfig)))
.build();
}
Expand Down

0 comments on commit 22c8f6e

Please sign in to comment.