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

Schema definitions redesign #8592

Draft
wants to merge 3 commits into
base: master
Choose a base branch
from
Draft
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 @@ -48,7 +48,8 @@ public Attestation(
final tech.pegasys.teku.spec.datastructures.operations.Attestation attestation) {
this.aggregation_bits = attestation.getAggregationBits().sszSerialize();
this.data = new AttestationData(attestation.getData());
this.committee_bits = attestation.getCommitteeBits().map(SszData::sszSerialize).orElse(null);
this.committee_bits =
attestation.getCommitteeBitsOptional().map(SszData::sszSerialize).orElse(null);
this.signature = new BLSSignature(attestation.getAggregateSignature());
}

Expand Down Expand Up @@ -78,7 +79,7 @@ public tech.pegasys.teku.spec.datastructures.operations.Attestation asInternalAt
data.asInternalAttestationData(),
signature.asInternalBLSSignature(),
attestationSchema
.getCommitteeBitsSchema()
.getCommitteeBitsSchemaOptional()
.map(
committeeBits ->
(Supplier<SszBitvector>) () -> committeeBits.sszDeserialize(committee_bits))
Expand Down
5 changes: 5 additions & 0 deletions ethereum/spec/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ dependencies {
implementation 'org.apache.tuweni:tuweni-bytes'
implementation 'org.apache.tuweni:tuweni-ssz'
implementation 'org.apache.tuweni:tuweni-units'
implementation 'org.javassist:javassist'
implementation 'org.apache.commons:commons-text'
implementation project(':ethereum:performance-trackers')
implementation project(':ethereum:execution-types')
implementation project(':ethereum:pow:api')
Expand All @@ -25,12 +27,14 @@ dependencies {
implementation project(':infrastructure:kzg')
implementation project(':infrastructure:logging')
implementation project(':infrastructure:ssz')
implementation project(':infrastructure:ssz:generator')
implementation project(':infrastructure:time')

testFixturesApi 'com.google.guava:guava'
testFixturesApi 'org.apache.tuweni:tuweni-bytes'
testFixturesApi project(':ethereum:pow:api')
testFixturesApi project(':infrastructure:ssz')
testFixturesApi project(':infrastructure:ssz:generator')
testFixturesApi project(':infrastructure:unsigned')

testFixturesImplementation 'com.fasterxml.jackson.core:jackson-databind'
Expand Down Expand Up @@ -65,6 +69,7 @@ dependencies {
testImplementation 'org.junit.jupiter:junit-jupiter-api'
testImplementation 'org.junit.jupiter:junit-jupiter-params'
testImplementation 'org.mockito:mockito-core'
testImplementation project(':infrastructure:ssz:generator')
testImplementation testFixtures(project(':ethereum:statetransition'))
testImplementation testFixtures(project(':infrastructure:async'))
testImplementation testFixtures(project(':infrastructure:bls'))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,14 @@ public boolean isGreaterThanOrEqualTo(final SpecMilestone other) {
return compareTo(other) >= 0;
}

public boolean isGreaterThan(final SpecMilestone other) {
return compareTo(other) > 0;
}

public boolean isLessThanOrEqualTo(final SpecMilestone other) {
return compareTo(other) <= 0;
}

/** Returns the milestone prior to this milestone */
public SpecMilestone getPreviousMilestone() {
if (equals(PHASE0)) {
Expand Down
75 changes: 57 additions & 18 deletions ethereum/spec/src/main/java/tech/pegasys/teku/spec/SpecVersion.java
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,8 @@
import tech.pegasys.teku.spec.schemas.SchemaDefinitionsDeneb;
import tech.pegasys.teku.spec.schemas.SchemaDefinitionsElectra;
import tech.pegasys.teku.spec.schemas.SchemaDefinitionsPhase0;
import tech.pegasys.teku.spec.schemas.SchemaRegistry;
import tech.pegasys.teku.spec.schemas.SchemaRegistryBuilder;

public class SpecVersion extends DelegatingSpecLogic {
private final SpecMilestone milestone;
Expand All @@ -56,53 +58,90 @@ private SpecVersion(

public static Optional<SpecVersion> create(
final SpecMilestone milestone, final SpecConfig specConfig) {
final SchemaRegistryBuilder schemaRegistryBuilder = SchemaRegistryBuilder.create();
return switch (milestone) {
case PHASE0 -> Optional.of(createPhase0(specConfig));
case ALTAIR -> specConfig.toVersionAltair().map(SpecVersion::createAltair);
case BELLATRIX -> specConfig.toVersionBellatrix().map(SpecVersion::createBellatrix);
case CAPELLA -> specConfig.toVersionCapella().map(SpecVersion::createCapella);
case DENEB -> specConfig.toVersionDeneb().map(SpecVersion::createDeneb);
case ELECTRA -> specConfig.toVersionElectra().map(SpecVersion::createElectra);
case PHASE0 -> Optional.of(createPhase0(specConfig, schemaRegistryBuilder));
case ALTAIR ->
specConfig
.toVersionAltair()
.map(specConfigAltair -> createAltair(specConfigAltair, schemaRegistryBuilder));
case BELLATRIX ->
specConfig
.toVersionBellatrix()
.map(
specConfigBellatrix ->
createBellatrix(specConfigBellatrix, schemaRegistryBuilder));
case CAPELLA ->
specConfig
.toVersionCapella()
.map(specConfigCapella -> createCapella(specConfigCapella, schemaRegistryBuilder));
case DENEB ->
specConfig
.toVersionDeneb()
.map(specConfigDeneb -> createDeneb(specConfigDeneb, schemaRegistryBuilder));
case ELECTRA ->
specConfig
.toVersionElectra()
.map(specConfigElectra -> createElectra(specConfigElectra, schemaRegistryBuilder));
};
}

static SpecVersion createPhase0(final SpecConfig specConfig) {
final SchemaDefinitions schemaDefinitions = new SchemaDefinitionsPhase0(specConfig);
static SpecVersion createPhase0(
final SpecConfig specConfig, final SchemaRegistryBuilder schemaRegistryBuilder) {
final SchemaRegistry schemaRegistry =
schemaRegistryBuilder.build(SpecMilestone.PHASE0, specConfig);
final SchemaDefinitions schemaDefinitions = new SchemaDefinitionsPhase0(schemaRegistry);
final SpecLogic specLogic =
SpecLogicPhase0.create(specConfig, schemaDefinitions, SYSTEM_TIME_PROVIDER);
return new SpecVersion(SpecMilestone.PHASE0, specConfig, schemaDefinitions, specLogic);
}

static SpecVersion createAltair(final SpecConfigAltair specConfig) {
final SchemaDefinitionsAltair schemaDefinitions = new SchemaDefinitionsAltair(specConfig);
static SpecVersion createAltair(
final SpecConfigAltair specConfig, final SchemaRegistryBuilder schemaRegistryBuilder) {
final SchemaRegistry schemaRegistry =
schemaRegistryBuilder.build(SpecMilestone.ALTAIR, specConfig);
final SchemaDefinitionsAltair schemaDefinitions = new SchemaDefinitionsAltair(schemaRegistry);
final SpecLogic specLogic =
SpecLogicAltair.create(specConfig, schemaDefinitions, SYSTEM_TIME_PROVIDER);
return new SpecVersion(SpecMilestone.ALTAIR, specConfig, schemaDefinitions, specLogic);
}

static SpecVersion createBellatrix(final SpecConfigBellatrix specConfig) {
final SchemaDefinitionsBellatrix schemaDefinitions = new SchemaDefinitionsBellatrix(specConfig);
static SpecVersion createBellatrix(
final SpecConfigBellatrix specConfig, final SchemaRegistryBuilder schemaRegistryBuilder) {
final SchemaRegistry schemaRegistry =
schemaRegistryBuilder.build(SpecMilestone.BELLATRIX, specConfig);
final SchemaDefinitionsBellatrix schemaDefinitions =
new SchemaDefinitionsBellatrix(schemaRegistry);
final SpecLogic specLogic =
SpecLogicBellatrix.create(specConfig, schemaDefinitions, SYSTEM_TIME_PROVIDER);
return new SpecVersion(SpecMilestone.BELLATRIX, specConfig, schemaDefinitions, specLogic);
}

static SpecVersion createCapella(final SpecConfigCapella specConfig) {
final SchemaDefinitionsCapella schemaDefinitions = new SchemaDefinitionsCapella(specConfig);
static SpecVersion createCapella(
final SpecConfigCapella specConfig, final SchemaRegistryBuilder schemaRegistryBuilder) {
final SchemaRegistry schemaRegistry =
schemaRegistryBuilder.build(SpecMilestone.CAPELLA, specConfig);
final SchemaDefinitionsCapella schemaDefinitions = new SchemaDefinitionsCapella(schemaRegistry);
final SpecLogicCapella specLogic =
SpecLogicCapella.create(specConfig, schemaDefinitions, SYSTEM_TIME_PROVIDER);
return new SpecVersion(SpecMilestone.CAPELLA, specConfig, schemaDefinitions, specLogic);
}

static SpecVersion createDeneb(final SpecConfigDeneb specConfig) {
final SchemaDefinitionsDeneb schemaDefinitions = new SchemaDefinitionsDeneb(specConfig);
static SpecVersion createDeneb(
final SpecConfigDeneb specConfig, final SchemaRegistryBuilder schemaRegistryBuilder) {
final SchemaRegistry schemaRegistry =
schemaRegistryBuilder.build(SpecMilestone.DENEB, specConfig);
final SchemaDefinitionsDeneb schemaDefinitions = new SchemaDefinitionsDeneb(schemaRegistry);
final SpecLogicDeneb specLogic =
SpecLogicDeneb.create(specConfig, schemaDefinitions, SYSTEM_TIME_PROVIDER);
return new SpecVersion(SpecMilestone.DENEB, specConfig, schemaDefinitions, specLogic);
}

static SpecVersion createElectra(final SpecConfigElectra specConfig) {
final SchemaDefinitionsElectra schemaDefinitions = new SchemaDefinitionsElectra(specConfig);
static SpecVersion createElectra(
final SpecConfigElectra specConfig, final SchemaRegistryBuilder schemaRegistryBuilder) {
final SchemaRegistry schemaRegistry =
schemaRegistryBuilder.build(SpecMilestone.ELECTRA, specConfig);
final SchemaDefinitionsElectra schemaDefinitions = new SchemaDefinitionsElectra(schemaRegistry);
final SpecLogicElectra specLogic =
SpecLogicElectra.create(specConfig, schemaDefinitions, SYSTEM_TIME_PROVIDER);
return new SpecVersion(SpecMilestone.ELECTRA, specConfig, schemaDefinitions, specLogic);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,9 @@

package tech.pegasys.teku.spec.datastructures.blocks.blockbody.versions.altair;

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

import it.unimi.dsi.fastutil.longs.LongList;
import java.util.function.Function;
import tech.pegasys.teku.infrastructure.async.SafeFuture;
Expand All @@ -32,11 +35,9 @@
import tech.pegasys.teku.spec.datastructures.operations.Deposit;
import tech.pegasys.teku.spec.datastructures.operations.ProposerSlashing;
import tech.pegasys.teku.spec.datastructures.operations.SignedVoluntaryExit;
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.type.SszSignature;
import tech.pegasys.teku.spec.datastructures.type.SszSignatureSchema;
import tech.pegasys.teku.spec.schemas.SchemaRegistry;

public class BeaconBlockBodySchemaAltairImpl
extends ContainerSchema9<
Expand Down Expand Up @@ -78,7 +79,7 @@ private BeaconBlockBodySchemaAltairImpl(

public static BeaconBlockBodySchemaAltairImpl create(
final SpecConfig specConfig,
final long maxValidatorsPerAttestation,
final SchemaRegistry schemaRegistry,
final String containerName) {
return new BeaconBlockBodySchemaAltairImpl(
containerName,
Expand All @@ -92,17 +93,12 @@ public static BeaconBlockBodySchemaAltairImpl create(
namedSchema(
BlockBodyFields.ATTESTER_SLASHINGS,
SszListSchema.create(
new AttesterSlashingPhase0Schema(
new IndexedAttestationPhase0Schema(maxValidatorsPerAttestation)
.castTypeToIndexedAttestationSchema())
.castTypeToAttesterSlashingSchema(),
schemaRegistry.get(ATTESTER_SLASHING_SCHEMA),
specConfig.getMaxAttesterSlashings())),
namedSchema(
BlockBodyFields.ATTESTATIONS,
SszListSchema.create(
new AttestationPhase0Schema(maxValidatorsPerAttestation)
.castTypeToAttestationSchema(),
specConfig.getMaxAttestations())),
schemaRegistry.get(ATTESTATION_SCHEMA), specConfig.getMaxAttestations())),
namedSchema(
BlockBodyFields.DEPOSITS,
SszListSchema.create(Deposit.SSZ_SCHEMA, specConfig.getMaxDeposits())),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,10 @@

package tech.pegasys.teku.spec.datastructures.blocks.blockbody.versions.bellatrix;

import static tech.pegasys.teku.spec.schemas.SchemaTypes.ATTESTATION_SCHEMA;
import static tech.pegasys.teku.spec.schemas.SchemaTypes.ATTESTER_SLASHING_SCHEMA;
import static tech.pegasys.teku.spec.schemas.SchemaTypes.EXECUTION_PAYLOAD_SCHEMA;

import it.unimi.dsi.fastutil.longs.LongList;
import java.util.function.Function;
import tech.pegasys.teku.infrastructure.async.SafeFuture;
Expand All @@ -38,11 +42,9 @@
import tech.pegasys.teku.spec.datastructures.operations.Deposit;
import tech.pegasys.teku.spec.datastructures.operations.ProposerSlashing;
import tech.pegasys.teku.spec.datastructures.operations.SignedVoluntaryExit;
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.type.SszSignature;
import tech.pegasys.teku.spec.datastructures.type.SszSignatureSchema;
import tech.pegasys.teku.spec.schemas.SchemaRegistry;

public class BeaconBlockBodySchemaBellatrixImpl
extends ContainerSchema10<
Expand Down Expand Up @@ -87,10 +89,8 @@ private BeaconBlockBodySchemaBellatrixImpl(

public static BeaconBlockBodySchemaBellatrixImpl create(
final SpecConfigBellatrix specConfig,
final long maxValidatorsPerAttestation,
final SchemaRegistry schemaRegistry,
final String containerName) {
final ExecutionPayloadSchemaBellatrix executionPayloadSchemaBellatrix =
new ExecutionPayloadSchemaBellatrix(specConfig);
return new BeaconBlockBodySchemaBellatrixImpl(
containerName,
namedSchema(BlockBodyFields.RANDAO_REVEAL, SszSignatureSchema.INSTANCE),
Expand All @@ -103,17 +103,12 @@ public static BeaconBlockBodySchemaBellatrixImpl create(
namedSchema(
BlockBodyFields.ATTESTER_SLASHINGS,
SszListSchema.create(
new AttesterSlashingPhase0Schema(
new IndexedAttestationPhase0Schema(maxValidatorsPerAttestation)
.castTypeToIndexedAttestationSchema())
.castTypeToAttesterSlashingSchema(),
schemaRegistry.get(ATTESTER_SLASHING_SCHEMA),
specConfig.getMaxAttesterSlashings())),
namedSchema(
BlockBodyFields.ATTESTATIONS,
SszListSchema.create(
new AttestationPhase0Schema(maxValidatorsPerAttestation)
.castTypeToAttestationSchema(),
specConfig.getMaxAttestations())),
schemaRegistry.get(ATTESTATION_SCHEMA), specConfig.getMaxAttestations())),
namedSchema(
BlockBodyFields.DEPOSITS,
SszListSchema.create(Deposit.SSZ_SCHEMA, specConfig.getMaxDeposits())),
Expand All @@ -124,7 +119,9 @@ public static BeaconBlockBodySchemaBellatrixImpl create(
namedSchema(
BlockBodyFields.SYNC_AGGREGATE,
SyncAggregateSchema.create(specConfig.getSyncCommitteeSize())),
namedSchema(BlockBodyFields.EXECUTION_PAYLOAD, executionPayloadSchemaBellatrix));
namedSchema(
BlockBodyFields.EXECUTION_PAYLOAD,
(ExecutionPayloadSchemaBellatrix) schemaRegistry.get(EXECUTION_PAYLOAD_SCHEMA)));
}

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

package tech.pegasys.teku.spec.datastructures.blocks.blockbody.versions.bellatrix;

import static tech.pegasys.teku.spec.schemas.SchemaTypes.ATTESTATION_SCHEMA;
import static tech.pegasys.teku.spec.schemas.SchemaTypes.ATTESTER_SLASHING_SCHEMA;
import static tech.pegasys.teku.spec.schemas.SchemaTypes.EXECUTION_PAYLOAD_HEADER_SCHEMA;

import it.unimi.dsi.fastutil.longs.LongList;
import java.util.function.Function;
import tech.pegasys.teku.infrastructure.async.SafeFuture;
Expand All @@ -37,11 +41,9 @@
import tech.pegasys.teku.spec.datastructures.operations.Deposit;
import tech.pegasys.teku.spec.datastructures.operations.ProposerSlashing;
import tech.pegasys.teku.spec.datastructures.operations.SignedVoluntaryExit;
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.type.SszSignature;
import tech.pegasys.teku.spec.datastructures.type.SszSignatureSchema;
import tech.pegasys.teku.spec.schemas.SchemaRegistry;

public class BlindedBeaconBlockBodySchemaBellatrixImpl
extends ContainerSchema10<
Expand Down Expand Up @@ -86,9 +88,8 @@ private BlindedBeaconBlockBodySchemaBellatrixImpl(

public static BlindedBeaconBlockBodySchemaBellatrixImpl create(
final SpecConfigBellatrix specConfig,
final long maxValidatorsPerAttestation,
final String containerName,
final ExecutionPayloadHeaderSchemaBellatrix executionPayloadHeaderSchema) {
final SchemaRegistry schemaRegistry,
final String containerName) {
return new BlindedBeaconBlockBodySchemaBellatrixImpl(
containerName,
namedSchema(BlockBodyFields.RANDAO_REVEAL, SszSignatureSchema.INSTANCE),
Expand All @@ -101,17 +102,12 @@ public static BlindedBeaconBlockBodySchemaBellatrixImpl create(
namedSchema(
BlockBodyFields.ATTESTER_SLASHINGS,
SszListSchema.create(
new AttesterSlashingPhase0Schema(
new IndexedAttestationPhase0Schema(maxValidatorsPerAttestation)
.castTypeToIndexedAttestationSchema())
.castTypeToAttesterSlashingSchema(),
schemaRegistry.get(ATTESTER_SLASHING_SCHEMA),
specConfig.getMaxAttesterSlashings())),
namedSchema(
BlockBodyFields.ATTESTATIONS,
SszListSchema.create(
new AttestationPhase0Schema(maxValidatorsPerAttestation)
.castTypeToAttestationSchema(),
specConfig.getMaxAttestations())),
schemaRegistry.get(ATTESTATION_SCHEMA), specConfig.getMaxAttestations())),
namedSchema(
BlockBodyFields.DEPOSITS,
SszListSchema.create(Deposit.SSZ_SCHEMA, specConfig.getMaxDeposits())),
Expand All @@ -122,7 +118,10 @@ public static BlindedBeaconBlockBodySchemaBellatrixImpl create(
namedSchema(
BlockBodyFields.SYNC_AGGREGATE,
SyncAggregateSchema.create(specConfig.getSyncCommitteeSize())),
namedSchema(BlockBodyFields.EXECUTION_PAYLOAD_HEADER, executionPayloadHeaderSchema));
namedSchema(
BlockBodyFields.EXECUTION_PAYLOAD_HEADER,
(ExecutionPayloadHeaderSchemaBellatrix)
schemaRegistry.get(EXECUTION_PAYLOAD_HEADER_SCHEMA)));
}

@Override
Expand Down
Loading