From 63580460d1801f86aa9996f85250e1942f67bca9 Mon Sep 17 00:00:00 2001 From: Enrico Del Fante Date: Wed, 6 Nov 2024 15:33:47 +0100 Subject: [PATCH] migrate capella schemas --- .../SignedBlsToExecutionChangeSchema.java | 7 +++- .../schemas/SchemaDefinitionsCapella.java | 14 ++++--- .../registry/SchemaRegistryBuilder.java | 42 ++++++++++++++++++- .../spec/schemas/registry/SchemaTypes.java | 17 ++++++-- .../versions/capella/WithdrawalTest.java | 9 ++-- .../operations/BlsToExecutionChangeTest.java | 11 +++-- .../SignedBlsToExecutionChangeTest.java | 11 +++-- 7 files changed, 88 insertions(+), 23 deletions(-) diff --git a/ethereum/spec/src/main/java/tech/pegasys/teku/spec/datastructures/operations/SignedBlsToExecutionChangeSchema.java b/ethereum/spec/src/main/java/tech/pegasys/teku/spec/datastructures/operations/SignedBlsToExecutionChangeSchema.java index 43c01f24754..f003d122d9e 100644 --- a/ethereum/spec/src/main/java/tech/pegasys/teku/spec/datastructures/operations/SignedBlsToExecutionChangeSchema.java +++ b/ethereum/spec/src/main/java/tech/pegasys/teku/spec/datastructures/operations/SignedBlsToExecutionChangeSchema.java @@ -13,19 +13,22 @@ package tech.pegasys.teku.spec.datastructures.operations; +import static tech.pegasys.teku.spec.schemas.registry.SchemaTypes.BLS_TO_EXECUTION_CHANGE_SCHEMA; + import tech.pegasys.teku.bls.BLSSignature; import tech.pegasys.teku.infrastructure.ssz.containers.ContainerSchema2; import tech.pegasys.teku.infrastructure.ssz.tree.TreeNode; 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 SignedBlsToExecutionChangeSchema extends ContainerSchema2 { - public SignedBlsToExecutionChangeSchema() { + public SignedBlsToExecutionChangeSchema(final SchemaRegistry schemaRegistry) { super( "SignedBLSToExecutionChange", - namedSchema("message", new BlsToExecutionChangeSchema()), + namedSchema("message", schemaRegistry.get(BLS_TO_EXECUTION_CHANGE_SCHEMA)), namedSchema("signature", SszSignatureSchema.INSTANCE)); } diff --git a/ethereum/spec/src/main/java/tech/pegasys/teku/spec/schemas/SchemaDefinitionsCapella.java b/ethereum/spec/src/main/java/tech/pegasys/teku/spec/schemas/SchemaDefinitionsCapella.java index 2e364d0b0e6..b256f056394 100644 --- a/ethereum/spec/src/main/java/tech/pegasys/teku/spec/schemas/SchemaDefinitionsCapella.java +++ b/ethereum/spec/src/main/java/tech/pegasys/teku/spec/schemas/SchemaDefinitionsCapella.java @@ -14,6 +14,10 @@ package tech.pegasys.teku.spec.schemas; import static com.google.common.base.Preconditions.checkArgument; +import static tech.pegasys.teku.spec.schemas.registry.SchemaTypes.BLS_TO_EXECUTION_CHANGE_SCHEMA; +import static tech.pegasys.teku.spec.schemas.registry.SchemaTypes.HISTORICAL_SUMMARY_SCHEMA; +import static tech.pegasys.teku.spec.schemas.registry.SchemaTypes.SIGNED_BLS_TO_EXECUTION_CHANGE_SCHEMA; +import static tech.pegasys.teku.spec.schemas.registry.SchemaTypes.WITHDRAWAL_SCHEMA; import java.util.Optional; import tech.pegasys.teku.spec.config.SpecConfigCapella; @@ -35,7 +39,6 @@ import tech.pegasys.teku.spec.datastructures.execution.ExecutionPayloadSchema; import tech.pegasys.teku.spec.datastructures.execution.versions.capella.ExecutionPayloadHeaderSchemaCapella; import tech.pegasys.teku.spec.datastructures.execution.versions.capella.ExecutionPayloadSchemaCapella; -import tech.pegasys.teku.spec.datastructures.execution.versions.capella.Withdrawal; import tech.pegasys.teku.spec.datastructures.execution.versions.capella.WithdrawalSchema; import tech.pegasys.teku.spec.datastructures.operations.BlsToExecutionChangeSchema; import tech.pegasys.teku.spec.datastructures.operations.SignedBlsToExecutionChangeSchema; @@ -74,10 +77,12 @@ public class SchemaDefinitionsCapella extends SchemaDefinitionsBellatrix { public SchemaDefinitionsCapella(final SchemaRegistry schemaRegistry) { super(schemaRegistry); final SpecConfigCapella specConfig = SpecConfigCapella.required(schemaRegistry.getSpecConfig()); + this.historicalSummarySchema = schemaRegistry.get(HISTORICAL_SUMMARY_SCHEMA); this.executionPayloadSchemaCapella = new ExecutionPayloadSchemaCapella(specConfig); - this.blsToExecutionChangeSchema = new BlsToExecutionChangeSchema(); - this.signedBlsToExecutionChangeSchema = new SignedBlsToExecutionChangeSchema(); - this.withdrawalSchema = Withdrawal.SSZ_SCHEMA; + this.blsToExecutionChangeSchema = schemaRegistry.get(BLS_TO_EXECUTION_CHANGE_SCHEMA); + this.signedBlsToExecutionChangeSchema = + schemaRegistry.get(SIGNED_BLS_TO_EXECUTION_CHANGE_SCHEMA); + this.withdrawalSchema = schemaRegistry.get(WITHDRAWAL_SCHEMA); this.beaconStateSchema = BeaconStateSchemaCapella.create(specConfig); this.executionPayloadHeaderSchemaCapella = @@ -107,7 +112,6 @@ public SchemaDefinitionsCapella(final SchemaRegistry schemaRegistry) { new BuilderBidSchemaBellatrix("BuilderBidCapella", executionPayloadHeaderSchemaCapella); this.signedBuilderBidSchemaCapella = new SignedBuilderBidSchema("SignedBuilderBidCapella", builderBidSchemaCapella); - this.historicalSummarySchema = new HistoricalSummary.HistoricalSummarySchema(); } public static SchemaDefinitionsCapella required(final SchemaDefinitions schemaDefinitions) { 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 56d05612432..0d67122e301 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 @@ -13,6 +13,7 @@ package tech.pegasys.teku.spec.schemas.registry; +import static tech.pegasys.teku.spec.SpecMilestone.CAPELLA; 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; @@ -21,10 +22,14 @@ 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.BLS_TO_EXECUTION_CHANGE_SCHEMA; import static tech.pegasys.teku.spec.schemas.registry.SchemaTypes.HISTORICAL_BATCH_SCHEMA; +import static tech.pegasys.teku.spec.schemas.registry.SchemaTypes.HISTORICAL_SUMMARY_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.SIGNED_BLS_TO_EXECUTION_CHANGE_SCHEMA; import static tech.pegasys.teku.spec.schemas.registry.SchemaTypes.SYNCNETS_ENR_FIELD_SCHEMA; +import static tech.pegasys.teku.spec.schemas.registry.SchemaTypes.WITHDRAWAL_SCHEMA; import com.google.common.annotations.VisibleForTesting; import java.util.HashSet; @@ -33,14 +38,18 @@ import tech.pegasys.teku.spec.SpecMilestone; import tech.pegasys.teku.spec.config.SpecConfig; import tech.pegasys.teku.spec.constants.NetworkConstants; +import tech.pegasys.teku.spec.datastructures.execution.versions.capella.WithdrawalSchema; 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.AttesterSlashingSchema; +import tech.pegasys.teku.spec.datastructures.operations.BlsToExecutionChangeSchema; import tech.pegasys.teku.spec.datastructures.operations.IndexedAttestationSchema; import tech.pegasys.teku.spec.datastructures.operations.SignedAggregateAndProof.SignedAggregateAndProofSchema; +import tech.pegasys.teku.spec.datastructures.operations.SignedBlsToExecutionChangeSchema; 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; +import tech.pegasys.teku.spec.datastructures.state.versions.capella.HistoricalSummary.HistoricalSummarySchema; import tech.pegasys.teku.spec.schemas.registry.SchemaTypes.SchemaId; public class SchemaRegistryBuilder { @@ -59,7 +68,38 @@ public static SchemaRegistryBuilder create() { .addProvider(createAttesterSlashingSchemaProvider()) .addProvider(createAttestationSchemaProvider()) .addProvider(createAggregateAndProofSchemaProvider()) - .addProvider(createSignedAggregateAndProofSchemaProvider()); + .addProvider(createSignedAggregateAndProofSchemaProvider()) + + // CAPELLA + .addProvider(createWithdrawalSchemaProvider()) + .addProvider(createBlsToExecutionChangeSchemaProvider()) + .addProvider(createSignedBlsToExecutionChangeSchemaProvider()) + .addProvider(createHistoricalSummarySchemaProvider()); + } + + private static SchemaProvider createHistoricalSummarySchemaProvider() { + return constantProviderBuilder(HISTORICAL_SUMMARY_SCHEMA) + .withCreator(CAPELLA, (registry, specConfig) -> new HistoricalSummarySchema()) + .build(); + } + + private static SchemaProvider createSignedBlsToExecutionChangeSchemaProvider() { + return constantProviderBuilder(SIGNED_BLS_TO_EXECUTION_CHANGE_SCHEMA) + .withCreator( + CAPELLA, (registry, specConfig) -> new SignedBlsToExecutionChangeSchema(registry)) + .build(); + } + + private static SchemaProvider createBlsToExecutionChangeSchemaProvider() { + return constantProviderBuilder(BLS_TO_EXECUTION_CHANGE_SCHEMA) + .withCreator(CAPELLA, (registry, specConfig) -> new BlsToExecutionChangeSchema()) + .build(); + } + + private static SchemaProvider createWithdrawalSchemaProvider() { + return constantProviderBuilder(WITHDRAWAL_SCHEMA) + .withCreator(CAPELLA, (registry, specConfig) -> new WithdrawalSchema()) + .build(); } private static SchemaProvider createAttnetsENRFieldSchemaProvider() { 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 94c92f6d541..74119855a12 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 @@ -23,17 +23,21 @@ import tech.pegasys.teku.spec.SpecMilestone; import tech.pegasys.teku.spec.datastructures.execution.ExecutionPayloadHeader; import tech.pegasys.teku.spec.datastructures.execution.ExecutionPayloadHeaderSchema; +import tech.pegasys.teku.spec.datastructures.execution.versions.capella.WithdrawalSchema; 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.BlsToExecutionChangeSchema; import tech.pegasys.teku.spec.datastructures.operations.IndexedAttestationSchema; import tech.pegasys.teku.spec.datastructures.operations.SignedAggregateAndProof.SignedAggregateAndProofSchema; +import tech.pegasys.teku.spec.datastructures.operations.SignedBlsToExecutionChangeSchema; 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; import tech.pegasys.teku.spec.datastructures.state.beaconstate.MutableBeaconState; +import tech.pegasys.teku.spec.datastructures.state.versions.capella.HistoricalSummary.HistoricalSummarySchema; public class SchemaTypes { // PHASE0 @@ -59,9 +63,6 @@ public class SchemaTypes { 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"); - public static final SchemaId> BEACON_STATE_SCHEMA = create("BEACON_STATE_SCHEMA"); @@ -69,7 +70,17 @@ public class SchemaTypes { // Bellatrix + public static final SchemaId> + EXECUTION_PAYLOAD_HEADER_SCHEMA = create("EXECUTION_PAYLOAD_HEADER_SCHEMA"); + // Capella + public static final SchemaId WITHDRAWAL_SCHEMA = create("WITHDRAWAL_SCHEMA"); + public static final SchemaId BLS_TO_EXECUTION_CHANGE_SCHEMA = + create("BLS_TO_EXECUTION_CHANGE_SCHEMA"); + public static final SchemaId + SIGNED_BLS_TO_EXECUTION_CHANGE_SCHEMA = create("SIGNED_BLS_TO_EXECUTION_CHANGE_SCHEMA"); + public static final SchemaId HISTORICAL_SUMMARY_SCHEMA = + create("HISTORICAL_SUMMARY_SCHEMA"); // Deneb diff --git a/ethereum/spec/src/test/java/tech/pegasys/teku/spec/datastructures/execution/versions/capella/WithdrawalTest.java b/ethereum/spec/src/test/java/tech/pegasys/teku/spec/datastructures/execution/versions/capella/WithdrawalTest.java index 9c81825fead..d80a78d3f0d 100644 --- a/ethereum/spec/src/test/java/tech/pegasys/teku/spec/datastructures/execution/versions/capella/WithdrawalTest.java +++ b/ethereum/spec/src/test/java/tech/pegasys/teku/spec/datastructures/execution/versions/capella/WithdrawalTest.java @@ -19,15 +19,16 @@ import org.junit.jupiter.api.Test; import tech.pegasys.teku.infrastructure.bytes.Bytes20; import tech.pegasys.teku.infrastructure.unsigned.UInt64; +import tech.pegasys.teku.spec.Spec; import tech.pegasys.teku.spec.SpecMilestone; import tech.pegasys.teku.spec.TestSpecFactory; import tech.pegasys.teku.spec.util.DataStructureUtil; class WithdrawalTest { - - private final DataStructureUtil dataStructureUtil = - new DataStructureUtil(TestSpecFactory.createMinimal(SpecMilestone.CAPELLA)); - private final WithdrawalSchema withdrawalSchema = Withdrawal.SSZ_SCHEMA; + private final Spec spec = TestSpecFactory.createMinimal(SpecMilestone.CAPELLA); + private final DataStructureUtil dataStructureUtil = new DataStructureUtil(spec); + private final WithdrawalSchema withdrawalSchema = + spec.getGenesisSchemaDefinitions().toVersionCapella().orElseThrow().getWithdrawalSchema(); private final UInt64 index = dataStructureUtil.randomUInt64(); private final UInt64 validatorIndex = dataStructureUtil.randomUInt64(); diff --git a/ethereum/spec/src/test/java/tech/pegasys/teku/spec/datastructures/operations/BlsToExecutionChangeTest.java b/ethereum/spec/src/test/java/tech/pegasys/teku/spec/datastructures/operations/BlsToExecutionChangeTest.java index 99ef89e13a5..0a3a983a164 100644 --- a/ethereum/spec/src/test/java/tech/pegasys/teku/spec/datastructures/operations/BlsToExecutionChangeTest.java +++ b/ethereum/spec/src/test/java/tech/pegasys/teku/spec/datastructures/operations/BlsToExecutionChangeTest.java @@ -20,17 +20,20 @@ import tech.pegasys.teku.bls.BLSPublicKey; import tech.pegasys.teku.infrastructure.bytes.Bytes20; import tech.pegasys.teku.infrastructure.unsigned.UInt64; +import tech.pegasys.teku.spec.Spec; import tech.pegasys.teku.spec.SpecMilestone; import tech.pegasys.teku.spec.TestSpecFactory; import tech.pegasys.teku.spec.util.DataStructureUtil; class BlsToExecutionChangeTest { - - private final DataStructureUtil dataStructureUtil = - new DataStructureUtil(TestSpecFactory.createMinimal(SpecMilestone.CAPELLA)); + private final Spec spec = TestSpecFactory.createMinimal(SpecMilestone.CAPELLA); + private final DataStructureUtil dataStructureUtil = new DataStructureUtil(spec); private final BlsToExecutionChangeSchema blsToExecutionChangeSchema = - new BlsToExecutionChangeSchema(); + spec.getGenesisSchemaDefinitions() + .toVersionCapella() + .orElseThrow() + .getBlsToExecutionChangeSchema(); private final UInt64 validatorIndex = dataStructureUtil.randomUInt64(); private final BLSPublicKey fromBlsPubkey = dataStructureUtil.randomPublicKey(); diff --git a/ethereum/spec/src/test/java/tech/pegasys/teku/spec/datastructures/operations/SignedBlsToExecutionChangeTest.java b/ethereum/spec/src/test/java/tech/pegasys/teku/spec/datastructures/operations/SignedBlsToExecutionChangeTest.java index cb79569fee2..ca60de0e76a 100644 --- a/ethereum/spec/src/test/java/tech/pegasys/teku/spec/datastructures/operations/SignedBlsToExecutionChangeTest.java +++ b/ethereum/spec/src/test/java/tech/pegasys/teku/spec/datastructures/operations/SignedBlsToExecutionChangeTest.java @@ -18,17 +18,20 @@ import org.apache.tuweni.bytes.Bytes; import org.junit.jupiter.api.Test; import tech.pegasys.teku.bls.BLSSignature; +import tech.pegasys.teku.spec.Spec; import tech.pegasys.teku.spec.SpecMilestone; import tech.pegasys.teku.spec.TestSpecFactory; import tech.pegasys.teku.spec.util.DataStructureUtil; class SignedBlsToExecutionChangeTest { - - private final DataStructureUtil dataStructureUtil = - new DataStructureUtil(TestSpecFactory.createMinimal(SpecMilestone.CAPELLA)); + private final Spec spec = TestSpecFactory.createMinimal(SpecMilestone.CAPELLA); + private final DataStructureUtil dataStructureUtil = new DataStructureUtil(spec); private final SignedBlsToExecutionChangeSchema signedBlsToExecutionChangeSchema = - new SignedBlsToExecutionChangeSchema(); + spec.getGenesisSchemaDefinitions() + .toVersionCapella() + .orElseThrow() + .getSignedBlsToExecutionChangeSchema(); private final BlsToExecutionChange message = dataStructureUtil.randomBlsToExecutionChange();