diff --git a/ethereum/spec/src/main/java/tech/pegasys/teku/spec/schemas/AbstractSchemaDefinitions.java b/ethereum/spec/src/main/java/tech/pegasys/teku/spec/schemas/AbstractSchemaDefinitions.java index 086f6587cc1..91145d621d4 100644 --- a/ethereum/spec/src/main/java/tech/pegasys/teku/spec/schemas/AbstractSchemaDefinitions.java +++ b/ethereum/spec/src/main/java/tech/pegasys/teku/spec/schemas/AbstractSchemaDefinitions.java @@ -20,6 +20,7 @@ import tech.pegasys.teku.spec.datastructures.networking.libp2p.rpc.BeaconBlocksByRootRequestMessage; import tech.pegasys.teku.spec.datastructures.state.HistoricalBatch.HistoricalBatchSchema; import tech.pegasys.teku.spec.schemas.registry.SchemaRegistry; +import tech.pegasys.teku.spec.schemas.registry.SchemaTypes; public abstract class AbstractSchemaDefinitions implements SchemaDefinitions { protected SchemaRegistry schemaRegistry; @@ -39,8 +40,7 @@ public AbstractSchemaDefinitions(final SchemaRegistry schemaRegistry) { this.beaconBlocksByRootRequestMessageSchema = new BeaconBlocksByRootRequestMessage.BeaconBlocksByRootRequestMessageSchema( schemaRegistry.getSpecConfig()); - this.attnetsENRFieldSchema = - SszBitvectorSchema.create(schemaRegistry.getSpecConfig().getAttestationSubnetCount()); + this.attnetsENRFieldSchema = schemaRegistry.get(SchemaTypes.ATTNETS_ENR_FIELD_SCHEMA); } abstract long getMaxValidatorPerAttestation(SpecConfig specConfig); 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 1f730bfad8a..6c858851a1e 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 @@ -53,7 +53,6 @@ import tech.pegasys.teku.spec.datastructures.operations.IndexedAttestation; 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.electra.AttesterSlashingElectraSchema; import tech.pegasys.teku.spec.datastructures.operations.versions.electra.IndexedAttestationElectraSchema; import tech.pegasys.teku.spec.datastructures.state.beaconstate.BeaconStateSchema; @@ -64,6 +63,7 @@ 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 { @@ -114,10 +114,7 @@ public SchemaDefinitionsElectra(final SchemaRegistry schemaRegistry) { new AttesterSlashingElectraSchema(indexedAttestationSchema) .castTypeToAttesterSlashingSchema(); - this.attestationSchema = - new AttestationElectraSchema( - maxValidatorsPerAttestation, specConfig.getMaxCommitteesPerSlot()) - .castTypeToAttestationSchema(); + this.attestationSchema = schemaRegistry.get(SchemaTypes.ATTESTATION_SCHEMA); this.aggregateAndProofSchema = new AggregateAndProofSchema(attestationSchema); this.signedAggregateAndProofSchema = new SignedAggregateAndProofSchema(aggregateAndProofSchema); 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 08387f63345..6176c070e32 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 @@ -34,12 +34,12 @@ import tech.pegasys.teku.spec.datastructures.operations.IndexedAttestation; 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.phase0.AttestationPhase0Schema; import tech.pegasys.teku.spec.datastructures.operations.versions.phase0.AttesterSlashingPhase0Schema; import tech.pegasys.teku.spec.datastructures.operations.versions.phase0.IndexedAttestationPhase0Schema; import tech.pegasys.teku.spec.datastructures.state.beaconstate.BeaconStateSchema; import tech.pegasys.teku.spec.datastructures.state.beaconstate.versions.phase0.BeaconStateSchemaPhase0; import tech.pegasys.teku.spec.schemas.registry.SchemaRegistry; +import tech.pegasys.teku.spec.schemas.registry.SchemaTypes; public class SchemaDefinitionsPhase0 extends AbstractSchemaDefinitions { private final IndexedAttestationSchema indexedAttestationSchema; @@ -63,10 +63,8 @@ public SchemaDefinitionsPhase0(final SchemaRegistry schemaRegistry) { new AttesterSlashingPhase0Schema(indexedAttestationSchema) .castTypeToAttesterSlashingSchema(); - this.aggregateAndProofSchema = - new AggregateAndProofSchema( - new AttestationPhase0Schema(getMaxValidatorPerAttestation(specConfig))); - this.attestationSchema = this.aggregateAndProofSchema.getAttestationSchema(); + this.attestationSchema = schemaRegistry.get(SchemaTypes.ATTESTATION_SCHEMA); + this.aggregateAndProofSchema = new AggregateAndProofSchema(attestationSchema); this.signedAggregateAndProofSchema = new SignedAggregateAndProofSchema(aggregateAndProofSchema); this.beaconStateSchema = BeaconStateSchemaPhase0.create(specConfig); this.beaconBlockBodySchema = diff --git a/ethereum/spec/src/main/java/tech/pegasys/teku/spec/schemas/registry/AbstractSchemaProvider.java b/ethereum/spec/src/main/java/tech/pegasys/teku/spec/schemas/registry/AbstractSchemaProvider.java index c1addf4d779..d7e023b76d5 100644 --- a/ethereum/spec/src/main/java/tech/pegasys/teku/spec/schemas/registry/AbstractSchemaProvider.java +++ b/ethereum/spec/src/main/java/tech/pegasys/teku/spec/schemas/registry/AbstractSchemaProvider.java @@ -34,8 +34,8 @@ protected AbstractSchemaProvider(final SchemaId schemaId) { protected void addMilestoneMapping( final SpecMilestone milestone, final SpecMilestone untilMilestone) { checkArgument( - untilMilestone.isGreaterThan(milestone), - "%s must be earlier than %s", + untilMilestone.isGreaterThanOrEqualTo(milestone), + "%s must be earlier then or equal to %s", milestone, untilMilestone); diff --git a/ethereum/spec/src/main/java/tech/pegasys/teku/spec/schemas/registry/AttestationSchemaProvider.java b/ethereum/spec/src/main/java/tech/pegasys/teku/spec/schemas/registry/AttestationSchemaProvider.java new file mode 100644 index 00000000000..120d9d5ecbd --- /dev/null +++ b/ethereum/spec/src/main/java/tech/pegasys/teku/spec/schemas/registry/AttestationSchemaProvider.java @@ -0,0 +1,63 @@ +/* + * Copyright Consensys Software Inc., 2024 + * + * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on + * an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the + * specific language governing permissions and limitations under the License. + */ + +package tech.pegasys.teku.spec.schemas.registry; + +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.SchemaTypes.ATTESTATION_SCHEMA; + +import java.util.Set; +import tech.pegasys.teku.spec.SpecMilestone; +import tech.pegasys.teku.spec.config.SpecConfig; +import tech.pegasys.teku.spec.datastructures.operations.Attestation; +import tech.pegasys.teku.spec.datastructures.operations.AttestationSchema; +import tech.pegasys.teku.spec.datastructures.operations.versions.electra.AttestationElectraSchema; +import tech.pegasys.teku.spec.datastructures.operations.versions.phase0.AttestationPhase0Schema; + +public class AttestationSchemaProvider + extends AbstractSchemaProvider> { + + public AttestationSchemaProvider() { + super(ATTESTATION_SCHEMA); + addMilestoneMapping(PHASE0, DENEB); + addMilestoneMapping(ELECTRA, SpecMilestone.getHighestMilestone()); + } + + @Override + protected AttestationSchema createSchema( + final SchemaRegistry registry, + final SpecMilestone effectiveMilestone, + final SpecConfig specConfig) { + return switch (effectiveMilestone) { + case PHASE0 -> + new AttestationPhase0Schema(specConfig.getMaxValidatorsPerCommittee()) + .castTypeToAttestationSchema(); + case ELECTRA -> + new AttestationElectraSchema( + (long) specConfig.getMaxValidatorsPerCommittee() + * specConfig.getMaxCommitteesPerSlot(), + specConfig.getMaxCommitteesPerSlot()) + .castTypeToAttestationSchema(); + default -> + throw new IllegalArgumentException( + "It is not supposed to create a specific version for " + effectiveMilestone); + }; + } + + @Override + public Set getSupportedMilestones() { + return ALL_MILESTONES; + } +} diff --git a/ethereum/spec/src/main/java/tech/pegasys/teku/spec/schemas/registry/AttnetsENRFieldSchemaProvider.java b/ethereum/spec/src/main/java/tech/pegasys/teku/spec/schemas/registry/AttnetsENRFieldSchemaProvider.java new file mode 100644 index 00000000000..bd01161eec4 --- /dev/null +++ b/ethereum/spec/src/main/java/tech/pegasys/teku/spec/schemas/registry/AttnetsENRFieldSchemaProvider.java @@ -0,0 +1,44 @@ +/* + * Copyright Consensys Software Inc., 2024 + * + * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on + * an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the + * specific language governing permissions and limitations under the License. + */ + +package tech.pegasys.teku.spec.schemas.registry; + +import static tech.pegasys.teku.spec.SpecMilestone.PHASE0; +import static tech.pegasys.teku.spec.schemas.registry.SchemaTypes.ATTNETS_ENR_FIELD_SCHEMA; + +import java.util.Set; +import tech.pegasys.teku.infrastructure.ssz.collections.SszBitvector; +import tech.pegasys.teku.infrastructure.ssz.schema.collections.SszBitvectorSchema; +import tech.pegasys.teku.spec.SpecMilestone; +import tech.pegasys.teku.spec.config.SpecConfig; + +public class AttnetsENRFieldSchemaProvider + extends AbstractSchemaProvider> { + public AttnetsENRFieldSchemaProvider() { + super(ATTNETS_ENR_FIELD_SCHEMA); + addMilestoneMapping(PHASE0, SpecMilestone.getHighestMilestone()); + } + + @Override + protected SszBitvectorSchema createSchema( + final SchemaRegistry registry, + final SpecMilestone effectiveMilestone, + final SpecConfig specConfig) { + return SszBitvectorSchema.create(specConfig.getAttestationSubnetCount()); + } + + @Override + public Set getSupportedMilestones() { + return ALL_MILESTONES; + } +} 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 e11bb1f6678..81788ca7d99 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 @@ -26,7 +26,9 @@ public class SchemaRegistryBuilder { private final SchemaCache cache; public static SchemaRegistryBuilder create() { - return new SchemaRegistryBuilder(); + return new SchemaRegistryBuilder() + .addProvider(new AttnetsENRFieldSchemaProvider()) + .addProvider(new AttestationSchemaProvider()); } public SchemaRegistryBuilder() { 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 68a82c8d4a9..69e783dd28f 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 @@ -21,12 +21,17 @@ import tech.pegasys.teku.infrastructure.ssz.collections.SszBitvector; import tech.pegasys.teku.infrastructure.ssz.schema.collections.SszBitvectorSchema; import tech.pegasys.teku.spec.SpecMilestone; +import tech.pegasys.teku.spec.datastructures.operations.Attestation; +import tech.pegasys.teku.spec.datastructures.operations.AttestationSchema; public class SchemaTypes { // PHASE0 public static final SchemaId> ATTNETS_ENR_FIELD_SCHEMA = create("ATTNETS_ENR_FIELD_SCHEMA"); + public static final SchemaId> ATTESTATION_SCHEMA = + create("ATTESTATION_SCHEMA"); + // Altair // Bellatrix