diff --git a/ethereum/spec/src/main/java/tech/pegasys/teku/spec/datastructures/operations/AggregateAndProof.java b/ethereum/spec/src/main/java/tech/pegasys/teku/spec/datastructures/operations/AggregateAndProof.java index 6894978a128..f826573b161 100644 --- a/ethereum/spec/src/main/java/tech/pegasys/teku/spec/datastructures/operations/AggregateAndProof.java +++ b/ethereum/spec/src/main/java/tech/pegasys/teku/spec/datastructures/operations/AggregateAndProof.java @@ -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 { @@ -32,13 +34,11 @@ public static class AggregateAndProofSchema extends ContainerSchema3 { public AggregateAndProofSchema( - final AttestationSchema 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)); } diff --git a/ethereum/spec/src/main/java/tech/pegasys/teku/spec/datastructures/operations/SignedAggregateAndProof.java b/ethereum/spec/src/main/java/tech/pegasys/teku/spec/datastructures/operations/SignedAggregateAndProof.java index 0e5c5435bb3..6c62014b238 100644 --- a/ethereum/spec/src/main/java/tech/pegasys/teku/spec/datastructures/operations/SignedAggregateAndProof.java +++ b/ethereum/spec/src/main/java/tech/pegasys/teku/spec/datastructures/operations/SignedAggregateAndProof.java @@ -13,6 +13,8 @@ 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; @@ -20,6 +22,7 @@ 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 { @@ -27,12 +30,11 @@ public class SignedAggregateAndProof public static class SignedAggregateAndProofSchema extends ContainerSchema2 { - 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)); } diff --git a/ethereum/spec/src/main/java/tech/pegasys/teku/spec/schemas/SchemaDefinitionsAltair.java b/ethereum/spec/src/main/java/tech/pegasys/teku/spec/schemas/SchemaDefinitionsAltair.java index 8e932b11a93..ce63e9585e5 100644 --- a/ethereum/spec/src/main/java/tech/pegasys/teku/spec/schemas/SchemaDefinitionsAltair.java +++ b/ethereum/spec/src/main/java/tech/pegasys/teku/spec/schemas/SchemaDefinitionsAltair.java @@ -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; @@ -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; @@ -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( diff --git a/ethereum/spec/src/main/java/tech/pegasys/teku/spec/schemas/SchemaDefinitionsElectra.java b/ethereum/spec/src/main/java/tech/pegasys/teku/spec/schemas/SchemaDefinitionsElectra.java index bcd78684b51..e843ba1d95b 100644 --- a/ethereum/spec/src/main/java/tech/pegasys/teku/spec/schemas/SchemaDefinitionsElectra.java +++ b/ethereum/spec/src/main/java/tech/pegasys/teku/spec/schemas/SchemaDefinitionsElectra.java @@ -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; @@ -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 attestationSchema; - private final SignedAggregateAndProofSchema signedAggregateAndProofSchema; - private final AggregateAndProofSchema aggregateAndProofSchema; - private final BeaconStateSchemaElectra beaconStateSchema; private final BeaconBlockBodySchemaElectraImpl beaconBlockBodySchema; @@ -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 = @@ -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 getAttestationSchema() { - return attestationSchema; - } - @Override public BeaconStateSchema getBeaconStateSchema() { diff --git a/ethereum/spec/src/main/java/tech/pegasys/teku/spec/schemas/SchemaDefinitionsPhase0.java b/ethereum/spec/src/main/java/tech/pegasys/teku/spec/schemas/SchemaDefinitionsPhase0.java index 3352cef3609..ef38dd68cbb 100644 --- a/ethereum/spec/src/main/java/tech/pegasys/teku/spec/schemas/SchemaDefinitionsPhase0.java +++ b/ethereum/spec/src/main/java/tech/pegasys/teku/spec/schemas/SchemaDefinitionsPhase0.java @@ -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; @@ -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( diff --git a/ethereum/spec/src/main/java/tech/pegasys/teku/spec/schemas/registry/SchemaRegistryBuilder.java b/ethereum/spec/src/main/java/tech/pegasys/teku/spec/schemas/registry/SchemaRegistryBuilder.java index 6d17881ffe7..3024a6b50c1 100644 --- a/ethereum/spec/src/main/java/tech/pegasys/teku/spec/schemas/registry/SchemaRegistryBuilder.java +++ b/ethereum/spec/src/main/java/tech/pegasys/teku/spec/schemas/registry/SchemaRegistryBuilder.java @@ -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; @@ -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; @@ -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() { @@ -125,7 +129,7 @@ private static SchemaProvider createIndexedAttestationSchemaProvider() { .build(); } - private static SchemaProvider> createAttestationSchemaProvider() { + private static SchemaProvider createAttestationSchemaProvider() { return constantProviderBuilder(ATTESTATION_SCHEMA) .withCreator( PHASE0, @@ -133,7 +137,7 @@ private static SchemaProvider> createAttestationS new AttestationPhase0Schema(getMaxValidatorPerAttestationPhase0(specConfig)) .castTypeToAttestationSchema()) .withCreator( - SpecMilestone.DENEB, + ELECTRA, (registry, specConfig) -> new AttestationElectraSchema( getMaxValidatorPerAttestationElectra(specConfig), @@ -142,6 +146,38 @@ private static SchemaProvider> 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(); } diff --git a/ethereum/spec/src/main/java/tech/pegasys/teku/spec/schemas/registry/SchemaTypes.java b/ethereum/spec/src/main/java/tech/pegasys/teku/spec/schemas/registry/SchemaTypes.java index 1062b0c6d63..94c92f6d541 100644 --- a/ethereum/spec/src/main/java/tech/pegasys/teku/spec/schemas/registry/SchemaTypes.java +++ b/ethereum/spec/src/main/java/tech/pegasys/teku/spec/schemas/registry/SchemaTypes.java @@ -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; @@ -52,6 +54,11 @@ public class SchemaTypes { public static final SchemaId> ATTESTATION_SCHEMA = create("ATTESTATION_SCHEMA"); + public static final SchemaId AGGREGATE_AND_PROOF_SCHEMA = + create("AGGREGATE_AND_PROOF_SCHEMA"); + public static final SchemaId SIGNED_AGGREGATE_AND_PROOF_SCHEMA = + create("SIGNED_AGGREGATE_AND_PROOF_SCHEMA"); + public static final SchemaId> EXECUTION_PAYLOAD_HEADER_SCHEMA = create("EXECUTION_PAYLOAD_HEADER_SCHEMA");