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

Aggregate and proof in schema registry #8770

Merged
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,17 +13,19 @@

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

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

import tech.pegasys.teku.bls.BLSSignature;
import tech.pegasys.teku.infrastructure.ssz.containers.Container3;
import tech.pegasys.teku.infrastructure.ssz.containers.ContainerSchema3;
import tech.pegasys.teku.infrastructure.ssz.primitive.SszUInt64;
import tech.pegasys.teku.infrastructure.ssz.schema.SszPrimitiveSchemas;
import tech.pegasys.teku.infrastructure.ssz.schema.SszSchema;
import tech.pegasys.teku.infrastructure.ssz.tree.TreeNode;
import tech.pegasys.teku.infrastructure.unsigned.UInt64;
import tech.pegasys.teku.spec.datastructures.operations.versions.phase0.AttestationPhase0;
import tech.pegasys.teku.spec.datastructures.type.SszSignature;
import tech.pegasys.teku.spec.datastructures.type.SszSignatureSchema;
import tech.pegasys.teku.spec.schemas.registry.SchemaRegistry;

public class AggregateAndProof
extends Container3<AggregateAndProof, SszUInt64, Attestation, SszSignature> {
Expand All @@ -32,13 +34,11 @@ public static class AggregateAndProofSchema
extends ContainerSchema3<AggregateAndProof, SszUInt64, Attestation, SszSignature> {

public AggregateAndProofSchema(
final AttestationSchema<? extends Attestation> attestationSchema) {
final String containerName, final SchemaRegistry schemaRegistry) {
super(
attestationSchema.requiresCommitteeBits()
? "AggregateAndProofElectra"
: "AggregateAndProofPhase0",
containerName,
namedSchema("aggregator_index", SszPrimitiveSchemas.UINT64_SCHEMA),
namedSchema("aggregate", SszSchema.as(Attestation.class, attestationSchema)),
namedSchema("aggregate", schemaRegistry.get(ATTESTATION_SCHEMA)),
namedSchema("selection_proof", SszSignatureSchema.INSTANCE));
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,26 +13,28 @@

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

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

import tech.pegasys.teku.bls.BLSSignature;
import tech.pegasys.teku.infrastructure.ssz.containers.Container2;
import tech.pegasys.teku.infrastructure.ssz.containers.ContainerSchema2;
import tech.pegasys.teku.infrastructure.ssz.tree.TreeNode;
import tech.pegasys.teku.spec.datastructures.operations.AggregateAndProof.AggregateAndProofSchema;
import tech.pegasys.teku.spec.datastructures.type.SszSignature;
import tech.pegasys.teku.spec.datastructures.type.SszSignatureSchema;
import tech.pegasys.teku.spec.schemas.registry.SchemaRegistry;

public class SignedAggregateAndProof
extends Container2<SignedAggregateAndProof, AggregateAndProof, SszSignature> {

public static class SignedAggregateAndProofSchema
extends ContainerSchema2<SignedAggregateAndProof, AggregateAndProof, SszSignature> {

public SignedAggregateAndProofSchema(final AggregateAndProofSchema aggregateAndProofSchema) {
public SignedAggregateAndProofSchema(
final String containerName, final SchemaRegistry schemaRegistry) {
super(
aggregateAndProofSchema.getAttestationSchema().requiresCommitteeBits()
? "SignedAggregateAndProofElectra"
: "SignedAggregateAndProofPhase0",
namedSchema("message", aggregateAndProofSchema),
containerName,
namedSchema("message", schemaRegistry.get(AGGREGATE_AND_PROOF_SCHEMA)),
namedSchema("signature", SszSignatureSchema.INSTANCE));
}

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

package tech.pegasys.teku.spec.schemas;

import static tech.pegasys.teku.spec.schemas.registry.SchemaTypes.AGGREGATE_AND_PROOF_SCHEMA;
import static tech.pegasys.teku.spec.schemas.registry.SchemaTypes.SIGNED_AGGREGATE_AND_PROOF_SCHEMA;

import com.google.common.base.Preconditions;
import java.util.Optional;
import tech.pegasys.teku.spec.config.SpecConfig;
Expand Down Expand Up @@ -43,7 +46,6 @@
import tech.pegasys.teku.spec.datastructures.operations.versions.altair.SyncAggregatorSelectionDataSchema;
import tech.pegasys.teku.spec.datastructures.operations.versions.altair.SyncCommitteeContributionSchema;
import tech.pegasys.teku.spec.datastructures.operations.versions.altair.SyncCommitteeMessageSchema;
import tech.pegasys.teku.spec.datastructures.operations.versions.phase0.AttestationPhase0Schema;
import tech.pegasys.teku.spec.datastructures.state.beaconstate.BeaconStateSchema;
import tech.pegasys.teku.spec.datastructures.state.beaconstate.versions.altair.BeaconStateAltair;
import tech.pegasys.teku.spec.datastructures.state.beaconstate.versions.altair.BeaconStateSchemaAltair;
Expand Down Expand Up @@ -75,11 +77,9 @@ public SchemaDefinitionsAltair(final SchemaRegistry schemaRegistry) {
final SpecConfigAltair specConfig = SpecConfigAltair.required(schemaRegistry.getSpecConfig());
this.indexedAttestationSchema = schemaRegistry.get(SchemaTypes.INDEXED_ATTESTATION_SCHEMA);
this.attesterSlashingSchema = schemaRegistry.get(SchemaTypes.ATTESTER_SLASHING_SCHEMA);
this.attestationSchema =
new AttestationPhase0Schema(getMaxValidatorPerAttestation(specConfig))
.castTypeToAttestationSchema();
this.aggregateAndProofSchema = new AggregateAndProofSchema(attestationSchema);
this.signedAggregateAndProofSchema = new SignedAggregateAndProofSchema(aggregateAndProofSchema);
this.attestationSchema = schemaRegistry.get(SchemaTypes.ATTESTATION_SCHEMA);
this.aggregateAndProofSchema = schemaRegistry.get(AGGREGATE_AND_PROOF_SCHEMA);
this.signedAggregateAndProofSchema = schemaRegistry.get(SIGNED_AGGREGATE_AND_PROOF_SCHEMA);
this.beaconStateSchema = BeaconStateSchemaAltair.create(specConfig);
this.beaconBlockBodySchema =
BeaconBlockBodySchemaAltairImpl.create(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,10 +45,6 @@
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.operations.AggregateAndProof.AggregateAndProofSchema;
import tech.pegasys.teku.spec.datastructures.operations.Attestation;
import tech.pegasys.teku.spec.datastructures.operations.AttestationSchema;
import tech.pegasys.teku.spec.datastructures.operations.SignedAggregateAndProof.SignedAggregateAndProofSchema;
import tech.pegasys.teku.spec.datastructures.state.beaconstate.BeaconStateSchema;
import tech.pegasys.teku.spec.datastructures.state.beaconstate.versions.electra.BeaconStateElectra;
import tech.pegasys.teku.spec.datastructures.state.beaconstate.versions.electra.BeaconStateSchemaElectra;
Expand All @@ -57,13 +53,8 @@
import tech.pegasys.teku.spec.datastructures.state.versions.electra.PendingDeposit;
import tech.pegasys.teku.spec.datastructures.state.versions.electra.PendingPartialWithdrawal;
import tech.pegasys.teku.spec.schemas.registry.SchemaRegistry;
import tech.pegasys.teku.spec.schemas.registry.SchemaTypes;

public class SchemaDefinitionsElectra extends SchemaDefinitionsDeneb {
private final AttestationSchema<Attestation> attestationSchema;
private final SignedAggregateAndProofSchema signedAggregateAndProofSchema;
private final AggregateAndProofSchema aggregateAndProofSchema;

private final BeaconStateSchemaElectra beaconStateSchema;

private final BeaconBlockBodySchemaElectraImpl beaconBlockBodySchema;
Expand Down Expand Up @@ -99,10 +90,6 @@ public SchemaDefinitionsElectra(final SchemaRegistry schemaRegistry) {

final long maxValidatorsPerAttestation = getMaxValidatorPerAttestation(specConfig);

this.attestationSchema = schemaRegistry.get(SchemaTypes.ATTESTATION_SCHEMA);
this.aggregateAndProofSchema = new AggregateAndProofSchema(attestationSchema);
this.signedAggregateAndProofSchema = new SignedAggregateAndProofSchema(aggregateAndProofSchema);

this.executionRequestsSchema = new ExecutionRequestsSchema(specConfig);
this.beaconStateSchema = BeaconStateSchemaElectra.create(specConfig);
this.beaconBlockBodySchema =
Expand Down Expand Up @@ -169,21 +156,6 @@ public static SchemaDefinitionsElectra required(final SchemaDefinitions schemaDe
return (SchemaDefinitionsElectra) schemaDefinitions;
}

@Override
public SignedAggregateAndProofSchema getSignedAggregateAndProofSchema() {
return signedAggregateAndProofSchema;
}

@Override
public AggregateAndProofSchema getAggregateAndProofSchema() {
return aggregateAndProofSchema;
}

@Override
public AttestationSchema<Attestation> getAttestationSchema() {
return attestationSchema;
}

@Override
public BeaconStateSchema<? extends BeaconStateElectra, ? extends MutableBeaconStateElectra>
getBeaconStateSchema() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,9 @@

package tech.pegasys.teku.spec.schemas;

import static tech.pegasys.teku.spec.schemas.registry.SchemaTypes.AGGREGATE_AND_PROOF_SCHEMA;
import static tech.pegasys.teku.spec.schemas.registry.SchemaTypes.SIGNED_AGGREGATE_AND_PROOF_SCHEMA;

import java.util.Optional;
import tech.pegasys.teku.spec.config.SpecConfig;
import tech.pegasys.teku.spec.datastructures.blocks.BeaconBlockSchema;
Expand Down Expand Up @@ -56,8 +59,8 @@ public SchemaDefinitionsPhase0(final SchemaRegistry schemaRegistry) {
this.attesterSlashingSchema = schemaRegistry.get(SchemaTypes.ATTESTER_SLASHING_SCHEMA);

this.attestationSchema = schemaRegistry.get(SchemaTypes.ATTESTATION_SCHEMA);
this.aggregateAndProofSchema = new AggregateAndProofSchema(attestationSchema);
this.signedAggregateAndProofSchema = new SignedAggregateAndProofSchema(aggregateAndProofSchema);
this.aggregateAndProofSchema = schemaRegistry.get(AGGREGATE_AND_PROOF_SCHEMA);
this.signedAggregateAndProofSchema = schemaRegistry.get(SIGNED_AGGREGATE_AND_PROOF_SCHEMA);
this.beaconStateSchema = BeaconStateSchemaPhase0.create(specConfig);
this.beaconBlockBodySchema =
BeaconBlockBodySchemaPhase0.create(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,14 @@
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.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;
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.HISTORICAL_BATCH_SCHEMA;
import static tech.pegasys.teku.spec.schemas.registry.SchemaTypes.INDEXED_ATTESTATION_SCHEMA;
import static tech.pegasys.teku.spec.schemas.registry.SchemaTypes.SIGNED_AGGREGATE_AND_PROOF_SCHEMA;
import static tech.pegasys.teku.spec.schemas.registry.SchemaTypes.SYNCNETS_ENR_FIELD_SCHEMA;

import com.google.common.annotations.VisibleForTesting;
Expand All @@ -32,10 +34,10 @@
import tech.pegasys.teku.spec.config.SpecConfig;
import tech.pegasys.teku.spec.constants.NetworkConstants;
import tech.pegasys.teku.spec.datastructures.networking.libp2p.rpc.BeaconBlocksByRootRequestMessage.BeaconBlocksByRootRequestMessageSchema;
import tech.pegasys.teku.spec.datastructures.operations.Attestation;
import tech.pegasys.teku.spec.datastructures.operations.AttestationSchema;
import tech.pegasys.teku.spec.datastructures.operations.AggregateAndProof.AggregateAndProofSchema;
import tech.pegasys.teku.spec.datastructures.operations.AttesterSlashingSchema;
import tech.pegasys.teku.spec.datastructures.operations.IndexedAttestationSchema;
import tech.pegasys.teku.spec.datastructures.operations.SignedAggregateAndProof.SignedAggregateAndProofSchema;
import tech.pegasys.teku.spec.datastructures.operations.versions.electra.AttestationElectraSchema;
import tech.pegasys.teku.spec.datastructures.operations.versions.phase0.AttestationPhase0Schema;
import tech.pegasys.teku.spec.datastructures.state.HistoricalBatch.HistoricalBatchSchema;
Expand All @@ -55,7 +57,9 @@ public static SchemaRegistryBuilder create() {
.addProvider(createHistoricalBatchSchemaProvider())
.addProvider(createIndexedAttestationSchemaProvider())
.addProvider(createAttesterSlashingSchemaProvider())
.addProvider(createAttestationSchemaProvider());
.addProvider(createAttestationSchemaProvider())
.addProvider(createAggregateAndProofSchemaProvider())
.addProvider(createSignedAggregateAndProofSchemaProvider());
}

private static SchemaProvider<?> createAttnetsENRFieldSchemaProvider() {
Expand Down Expand Up @@ -125,15 +129,15 @@ private static SchemaProvider<?> createIndexedAttestationSchemaProvider() {
.build();
}

private static SchemaProvider<AttestationSchema<Attestation>> createAttestationSchemaProvider() {
private static SchemaProvider<?> createAttestationSchemaProvider() {
return constantProviderBuilder(ATTESTATION_SCHEMA)
.withCreator(
PHASE0,
(registry, specConfig) ->
new AttestationPhase0Schema(getMaxValidatorPerAttestationPhase0(specConfig))
.castTypeToAttestationSchema())
.withCreator(
SpecMilestone.DENEB,
ELECTRA,
(registry, specConfig) ->
new AttestationElectraSchema(
getMaxValidatorPerAttestationElectra(specConfig),
Expand All @@ -142,6 +146,38 @@ private static SchemaProvider<AttestationSchema<Attestation>> createAttestationS
.build();
}

private static SchemaProvider<?> createAggregateAndProofSchemaProvider() {
return constantProviderBuilder(AGGREGATE_AND_PROOF_SCHEMA)
.withCreator(
PHASE0,
(registry, specConfig) ->
new AggregateAndProofSchema(
AGGREGATE_AND_PROOF_SCHEMA.getContainerName(registry.getMilestone()), registry))
.withCreator(
ELECTRA,
(registry, specConfig) ->
new AggregateAndProofSchema(
AGGREGATE_AND_PROOF_SCHEMA.getContainerName(registry.getMilestone()), registry))
.build();
}

private static SchemaProvider<?> createSignedAggregateAndProofSchemaProvider() {
return constantProviderBuilder(SIGNED_AGGREGATE_AND_PROOF_SCHEMA)
.withCreator(
PHASE0,
(registry, specConfig) ->
new SignedAggregateAndProofSchema(
SIGNED_AGGREGATE_AND_PROOF_SCHEMA.getContainerName(registry.getMilestone()),
registry))
.withCreator(
ELECTRA,
(registry, specConfig) ->
new SignedAggregateAndProofSchema(
SIGNED_AGGREGATE_AND_PROOF_SCHEMA.getContainerName(registry.getMilestone()),
registry))
.build();
}

private static long getMaxValidatorPerAttestationPhase0(final SpecConfig specConfig) {
return specConfig.getMaxValidatorsPerCommittee();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,12 @@
import tech.pegasys.teku.spec.datastructures.execution.ExecutionPayloadHeader;
import tech.pegasys.teku.spec.datastructures.execution.ExecutionPayloadHeaderSchema;
import tech.pegasys.teku.spec.datastructures.networking.libp2p.rpc.BeaconBlocksByRootRequestMessage.BeaconBlocksByRootRequestMessageSchema;
import tech.pegasys.teku.spec.datastructures.operations.AggregateAndProof.AggregateAndProofSchema;
import tech.pegasys.teku.spec.datastructures.operations.Attestation;
import tech.pegasys.teku.spec.datastructures.operations.AttestationSchema;
import tech.pegasys.teku.spec.datastructures.operations.AttesterSlashingSchema;
import tech.pegasys.teku.spec.datastructures.operations.IndexedAttestationSchema;
import tech.pegasys.teku.spec.datastructures.operations.SignedAggregateAndProof.SignedAggregateAndProofSchema;
import tech.pegasys.teku.spec.datastructures.state.HistoricalBatch.HistoricalBatchSchema;
import tech.pegasys.teku.spec.datastructures.state.beaconstate.BeaconState;
import tech.pegasys.teku.spec.datastructures.state.beaconstate.BeaconStateSchema;
Expand All @@ -52,6 +54,11 @@ public class SchemaTypes {
public static final SchemaId<AttestationSchema<Attestation>> ATTESTATION_SCHEMA =
create("ATTESTATION_SCHEMA");

public static final SchemaId<AggregateAndProofSchema> AGGREGATE_AND_PROOF_SCHEMA =
create("AGGREGATE_AND_PROOF_SCHEMA");
public static final SchemaId<SignedAggregateAndProofSchema> SIGNED_AGGREGATE_AND_PROOF_SCHEMA =
create("SIGNED_AGGREGATE_AND_PROOF_SCHEMA");

public static final SchemaId<ExecutionPayloadHeaderSchema<? extends ExecutionPayloadHeader>>
EXECUTION_PAYLOAD_HEADER_SCHEMA = create("EXECUTION_PAYLOAD_HEADER_SCHEMA");

Expand Down