Skip to content

Commit cedae8a

Browse files
authored
migrate capella schemas (#8825)
1 parent da8f449 commit cedae8a

File tree

7 files changed

+88
-23
lines changed

7 files changed

+88
-23
lines changed

ethereum/spec/src/main/java/tech/pegasys/teku/spec/datastructures/operations/SignedBlsToExecutionChangeSchema.java

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,19 +13,22 @@
1313

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

16+
import static tech.pegasys.teku.spec.schemas.registry.SchemaTypes.BLS_TO_EXECUTION_CHANGE_SCHEMA;
17+
1618
import tech.pegasys.teku.bls.BLSSignature;
1719
import tech.pegasys.teku.infrastructure.ssz.containers.ContainerSchema2;
1820
import tech.pegasys.teku.infrastructure.ssz.tree.TreeNode;
1921
import tech.pegasys.teku.spec.datastructures.type.SszSignature;
2022
import tech.pegasys.teku.spec.datastructures.type.SszSignatureSchema;
23+
import tech.pegasys.teku.spec.schemas.registry.SchemaRegistry;
2124

2225
public class SignedBlsToExecutionChangeSchema
2326
extends ContainerSchema2<SignedBlsToExecutionChange, BlsToExecutionChange, SszSignature> {
2427

25-
public SignedBlsToExecutionChangeSchema() {
28+
public SignedBlsToExecutionChangeSchema(final SchemaRegistry schemaRegistry) {
2629
super(
2730
"SignedBLSToExecutionChange",
28-
namedSchema("message", new BlsToExecutionChangeSchema()),
31+
namedSchema("message", schemaRegistry.get(BLS_TO_EXECUTION_CHANGE_SCHEMA)),
2932
namedSchema("signature", SszSignatureSchema.INSTANCE));
3033
}
3134

ethereum/spec/src/main/java/tech/pegasys/teku/spec/schemas/SchemaDefinitionsCapella.java

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,10 @@
1414
package tech.pegasys.teku.spec.schemas;
1515

1616
import static com.google.common.base.Preconditions.checkArgument;
17+
import static tech.pegasys.teku.spec.schemas.registry.SchemaTypes.BLS_TO_EXECUTION_CHANGE_SCHEMA;
18+
import static tech.pegasys.teku.spec.schemas.registry.SchemaTypes.HISTORICAL_SUMMARY_SCHEMA;
19+
import static tech.pegasys.teku.spec.schemas.registry.SchemaTypes.SIGNED_BLS_TO_EXECUTION_CHANGE_SCHEMA;
20+
import static tech.pegasys.teku.spec.schemas.registry.SchemaTypes.WITHDRAWAL_SCHEMA;
1721

1822
import java.util.Optional;
1923
import tech.pegasys.teku.spec.config.SpecConfigCapella;
@@ -35,7 +39,6 @@
3539
import tech.pegasys.teku.spec.datastructures.execution.ExecutionPayloadSchema;
3640
import tech.pegasys.teku.spec.datastructures.execution.versions.capella.ExecutionPayloadHeaderSchemaCapella;
3741
import tech.pegasys.teku.spec.datastructures.execution.versions.capella.ExecutionPayloadSchemaCapella;
38-
import tech.pegasys.teku.spec.datastructures.execution.versions.capella.Withdrawal;
3942
import tech.pegasys.teku.spec.datastructures.execution.versions.capella.WithdrawalSchema;
4043
import tech.pegasys.teku.spec.datastructures.operations.BlsToExecutionChangeSchema;
4144
import tech.pegasys.teku.spec.datastructures.operations.SignedBlsToExecutionChangeSchema;
@@ -74,10 +77,12 @@ public class SchemaDefinitionsCapella extends SchemaDefinitionsBellatrix {
7477
public SchemaDefinitionsCapella(final SchemaRegistry schemaRegistry) {
7578
super(schemaRegistry);
7679
final SpecConfigCapella specConfig = SpecConfigCapella.required(schemaRegistry.getSpecConfig());
80+
this.historicalSummarySchema = schemaRegistry.get(HISTORICAL_SUMMARY_SCHEMA);
7781
this.executionPayloadSchemaCapella = new ExecutionPayloadSchemaCapella(specConfig);
78-
this.blsToExecutionChangeSchema = new BlsToExecutionChangeSchema();
79-
this.signedBlsToExecutionChangeSchema = new SignedBlsToExecutionChangeSchema();
80-
this.withdrawalSchema = Withdrawal.SSZ_SCHEMA;
82+
this.blsToExecutionChangeSchema = schemaRegistry.get(BLS_TO_EXECUTION_CHANGE_SCHEMA);
83+
this.signedBlsToExecutionChangeSchema =
84+
schemaRegistry.get(SIGNED_BLS_TO_EXECUTION_CHANGE_SCHEMA);
85+
this.withdrawalSchema = schemaRegistry.get(WITHDRAWAL_SCHEMA);
8186

8287
this.beaconStateSchema = BeaconStateSchemaCapella.create(specConfig);
8388
this.executionPayloadHeaderSchemaCapella =
@@ -107,7 +112,6 @@ public SchemaDefinitionsCapella(final SchemaRegistry schemaRegistry) {
107112
new BuilderBidSchemaBellatrix("BuilderBidCapella", executionPayloadHeaderSchemaCapella);
108113
this.signedBuilderBidSchemaCapella =
109114
new SignedBuilderBidSchema("SignedBuilderBidCapella", builderBidSchemaCapella);
110-
this.historicalSummarySchema = new HistoricalSummary.HistoricalSummarySchema();
111115
}
112116

113117
public static SchemaDefinitionsCapella required(final SchemaDefinitions schemaDefinitions) {

ethereum/spec/src/main/java/tech/pegasys/teku/spec/schemas/registry/SchemaRegistryBuilder.java

Lines changed: 41 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313

1414
package tech.pegasys.teku.spec.schemas.registry;
1515

16+
import static tech.pegasys.teku.spec.SpecMilestone.CAPELLA;
1617
import static tech.pegasys.teku.spec.SpecMilestone.ELECTRA;
1718
import static tech.pegasys.teku.spec.SpecMilestone.PHASE0;
1819
import static tech.pegasys.teku.spec.schemas.registry.BaseSchemaProvider.constantProviderBuilder;
@@ -21,10 +22,14 @@
2122
import static tech.pegasys.teku.spec.schemas.registry.SchemaTypes.ATTESTER_SLASHING_SCHEMA;
2223
import static tech.pegasys.teku.spec.schemas.registry.SchemaTypes.ATTNETS_ENR_FIELD_SCHEMA;
2324
import static tech.pegasys.teku.spec.schemas.registry.SchemaTypes.BEACON_BLOCKS_BY_ROOT_REQUEST_MESSAGE_SCHEMA;
25+
import static tech.pegasys.teku.spec.schemas.registry.SchemaTypes.BLS_TO_EXECUTION_CHANGE_SCHEMA;
2426
import static tech.pegasys.teku.spec.schemas.registry.SchemaTypes.HISTORICAL_BATCH_SCHEMA;
27+
import static tech.pegasys.teku.spec.schemas.registry.SchemaTypes.HISTORICAL_SUMMARY_SCHEMA;
2528
import static tech.pegasys.teku.spec.schemas.registry.SchemaTypes.INDEXED_ATTESTATION_SCHEMA;
2629
import static tech.pegasys.teku.spec.schemas.registry.SchemaTypes.SIGNED_AGGREGATE_AND_PROOF_SCHEMA;
30+
import static tech.pegasys.teku.spec.schemas.registry.SchemaTypes.SIGNED_BLS_TO_EXECUTION_CHANGE_SCHEMA;
2731
import static tech.pegasys.teku.spec.schemas.registry.SchemaTypes.SYNCNETS_ENR_FIELD_SCHEMA;
32+
import static tech.pegasys.teku.spec.schemas.registry.SchemaTypes.WITHDRAWAL_SCHEMA;
2833

2934
import com.google.common.annotations.VisibleForTesting;
3035
import java.util.HashSet;
@@ -33,14 +38,18 @@
3338
import tech.pegasys.teku.spec.SpecMilestone;
3439
import tech.pegasys.teku.spec.config.SpecConfig;
3540
import tech.pegasys.teku.spec.constants.NetworkConstants;
41+
import tech.pegasys.teku.spec.datastructures.execution.versions.capella.WithdrawalSchema;
3642
import tech.pegasys.teku.spec.datastructures.networking.libp2p.rpc.BeaconBlocksByRootRequestMessage.BeaconBlocksByRootRequestMessageSchema;
3743
import tech.pegasys.teku.spec.datastructures.operations.AggregateAndProof.AggregateAndProofSchema;
3844
import tech.pegasys.teku.spec.datastructures.operations.AttesterSlashingSchema;
45+
import tech.pegasys.teku.spec.datastructures.operations.BlsToExecutionChangeSchema;
3946
import tech.pegasys.teku.spec.datastructures.operations.IndexedAttestationSchema;
4047
import tech.pegasys.teku.spec.datastructures.operations.SignedAggregateAndProof.SignedAggregateAndProofSchema;
48+
import tech.pegasys.teku.spec.datastructures.operations.SignedBlsToExecutionChangeSchema;
4149
import tech.pegasys.teku.spec.datastructures.operations.versions.electra.AttestationElectraSchema;
4250
import tech.pegasys.teku.spec.datastructures.operations.versions.phase0.AttestationPhase0Schema;
4351
import tech.pegasys.teku.spec.datastructures.state.HistoricalBatch.HistoricalBatchSchema;
52+
import tech.pegasys.teku.spec.datastructures.state.versions.capella.HistoricalSummary.HistoricalSummarySchema;
4453
import tech.pegasys.teku.spec.schemas.registry.SchemaTypes.SchemaId;
4554

4655
public class SchemaRegistryBuilder {
@@ -59,7 +68,38 @@ public static SchemaRegistryBuilder create() {
5968
.addProvider(createAttesterSlashingSchemaProvider())
6069
.addProvider(createAttestationSchemaProvider())
6170
.addProvider(createAggregateAndProofSchemaProvider())
62-
.addProvider(createSignedAggregateAndProofSchemaProvider());
71+
.addProvider(createSignedAggregateAndProofSchemaProvider())
72+
73+
// CAPELLA
74+
.addProvider(createWithdrawalSchemaProvider())
75+
.addProvider(createBlsToExecutionChangeSchemaProvider())
76+
.addProvider(createSignedBlsToExecutionChangeSchemaProvider())
77+
.addProvider(createHistoricalSummarySchemaProvider());
78+
}
79+
80+
private static SchemaProvider<?> createHistoricalSummarySchemaProvider() {
81+
return constantProviderBuilder(HISTORICAL_SUMMARY_SCHEMA)
82+
.withCreator(CAPELLA, (registry, specConfig) -> new HistoricalSummarySchema())
83+
.build();
84+
}
85+
86+
private static SchemaProvider<?> createSignedBlsToExecutionChangeSchemaProvider() {
87+
return constantProviderBuilder(SIGNED_BLS_TO_EXECUTION_CHANGE_SCHEMA)
88+
.withCreator(
89+
CAPELLA, (registry, specConfig) -> new SignedBlsToExecutionChangeSchema(registry))
90+
.build();
91+
}
92+
93+
private static SchemaProvider<?> createBlsToExecutionChangeSchemaProvider() {
94+
return constantProviderBuilder(BLS_TO_EXECUTION_CHANGE_SCHEMA)
95+
.withCreator(CAPELLA, (registry, specConfig) -> new BlsToExecutionChangeSchema())
96+
.build();
97+
}
98+
99+
private static SchemaProvider<?> createWithdrawalSchemaProvider() {
100+
return constantProviderBuilder(WITHDRAWAL_SCHEMA)
101+
.withCreator(CAPELLA, (registry, specConfig) -> new WithdrawalSchema())
102+
.build();
63103
}
64104

65105
private static SchemaProvider<?> createAttnetsENRFieldSchemaProvider() {

ethereum/spec/src/main/java/tech/pegasys/teku/spec/schemas/registry/SchemaTypes.java

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,17 +23,21 @@
2323
import tech.pegasys.teku.spec.SpecMilestone;
2424
import tech.pegasys.teku.spec.datastructures.execution.ExecutionPayloadHeader;
2525
import tech.pegasys.teku.spec.datastructures.execution.ExecutionPayloadHeaderSchema;
26+
import tech.pegasys.teku.spec.datastructures.execution.versions.capella.WithdrawalSchema;
2627
import tech.pegasys.teku.spec.datastructures.networking.libp2p.rpc.BeaconBlocksByRootRequestMessage.BeaconBlocksByRootRequestMessageSchema;
2728
import tech.pegasys.teku.spec.datastructures.operations.AggregateAndProof.AggregateAndProofSchema;
2829
import tech.pegasys.teku.spec.datastructures.operations.Attestation;
2930
import tech.pegasys.teku.spec.datastructures.operations.AttestationSchema;
3031
import tech.pegasys.teku.spec.datastructures.operations.AttesterSlashingSchema;
32+
import tech.pegasys.teku.spec.datastructures.operations.BlsToExecutionChangeSchema;
3133
import tech.pegasys.teku.spec.datastructures.operations.IndexedAttestationSchema;
3234
import tech.pegasys.teku.spec.datastructures.operations.SignedAggregateAndProof.SignedAggregateAndProofSchema;
35+
import tech.pegasys.teku.spec.datastructures.operations.SignedBlsToExecutionChangeSchema;
3336
import tech.pegasys.teku.spec.datastructures.state.HistoricalBatch.HistoricalBatchSchema;
3437
import tech.pegasys.teku.spec.datastructures.state.beaconstate.BeaconState;
3538
import tech.pegasys.teku.spec.datastructures.state.beaconstate.BeaconStateSchema;
3639
import tech.pegasys.teku.spec.datastructures.state.beaconstate.MutableBeaconState;
40+
import tech.pegasys.teku.spec.datastructures.state.versions.capella.HistoricalSummary.HistoricalSummarySchema;
3741

3842
public class SchemaTypes {
3943
// PHASE0
@@ -59,17 +63,24 @@ public class SchemaTypes {
5963
public static final SchemaId<SignedAggregateAndProofSchema> SIGNED_AGGREGATE_AND_PROOF_SCHEMA =
6064
create("SIGNED_AGGREGATE_AND_PROOF_SCHEMA");
6165

62-
public static final SchemaId<ExecutionPayloadHeaderSchema<? extends ExecutionPayloadHeader>>
63-
EXECUTION_PAYLOAD_HEADER_SCHEMA = create("EXECUTION_PAYLOAD_HEADER_SCHEMA");
64-
6566
public static final SchemaId<BeaconStateSchema<BeaconState, MutableBeaconState>>
6667
BEACON_STATE_SCHEMA = create("BEACON_STATE_SCHEMA");
6768

6869
// Altair
6970

7071
// Bellatrix
7172

73+
public static final SchemaId<ExecutionPayloadHeaderSchema<? extends ExecutionPayloadHeader>>
74+
EXECUTION_PAYLOAD_HEADER_SCHEMA = create("EXECUTION_PAYLOAD_HEADER_SCHEMA");
75+
7276
// Capella
77+
public static final SchemaId<WithdrawalSchema> WITHDRAWAL_SCHEMA = create("WITHDRAWAL_SCHEMA");
78+
public static final SchemaId<BlsToExecutionChangeSchema> BLS_TO_EXECUTION_CHANGE_SCHEMA =
79+
create("BLS_TO_EXECUTION_CHANGE_SCHEMA");
80+
public static final SchemaId<SignedBlsToExecutionChangeSchema>
81+
SIGNED_BLS_TO_EXECUTION_CHANGE_SCHEMA = create("SIGNED_BLS_TO_EXECUTION_CHANGE_SCHEMA");
82+
public static final SchemaId<HistoricalSummarySchema> HISTORICAL_SUMMARY_SCHEMA =
83+
create("HISTORICAL_SUMMARY_SCHEMA");
7384

7485
// Deneb
7586

ethereum/spec/src/test/java/tech/pegasys/teku/spec/datastructures/execution/versions/capella/WithdrawalTest.java

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,15 +19,16 @@
1919
import org.junit.jupiter.api.Test;
2020
import tech.pegasys.teku.infrastructure.bytes.Bytes20;
2121
import tech.pegasys.teku.infrastructure.unsigned.UInt64;
22+
import tech.pegasys.teku.spec.Spec;
2223
import tech.pegasys.teku.spec.SpecMilestone;
2324
import tech.pegasys.teku.spec.TestSpecFactory;
2425
import tech.pegasys.teku.spec.util.DataStructureUtil;
2526

2627
class WithdrawalTest {
27-
28-
private final DataStructureUtil dataStructureUtil =
29-
new DataStructureUtil(TestSpecFactory.createMinimal(SpecMilestone.CAPELLA));
30-
private final WithdrawalSchema withdrawalSchema = Withdrawal.SSZ_SCHEMA;
28+
private final Spec spec = TestSpecFactory.createMinimal(SpecMilestone.CAPELLA);
29+
private final DataStructureUtil dataStructureUtil = new DataStructureUtil(spec);
30+
private final WithdrawalSchema withdrawalSchema =
31+
spec.getGenesisSchemaDefinitions().toVersionCapella().orElseThrow().getWithdrawalSchema();
3132

3233
private final UInt64 index = dataStructureUtil.randomUInt64();
3334
private final UInt64 validatorIndex = dataStructureUtil.randomUInt64();

ethereum/spec/src/test/java/tech/pegasys/teku/spec/datastructures/operations/BlsToExecutionChangeTest.java

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -20,17 +20,20 @@
2020
import tech.pegasys.teku.bls.BLSPublicKey;
2121
import tech.pegasys.teku.infrastructure.bytes.Bytes20;
2222
import tech.pegasys.teku.infrastructure.unsigned.UInt64;
23+
import tech.pegasys.teku.spec.Spec;
2324
import tech.pegasys.teku.spec.SpecMilestone;
2425
import tech.pegasys.teku.spec.TestSpecFactory;
2526
import tech.pegasys.teku.spec.util.DataStructureUtil;
2627

2728
class BlsToExecutionChangeTest {
28-
29-
private final DataStructureUtil dataStructureUtil =
30-
new DataStructureUtil(TestSpecFactory.createMinimal(SpecMilestone.CAPELLA));
29+
private final Spec spec = TestSpecFactory.createMinimal(SpecMilestone.CAPELLA);
30+
private final DataStructureUtil dataStructureUtil = new DataStructureUtil(spec);
3131

3232
private final BlsToExecutionChangeSchema blsToExecutionChangeSchema =
33-
new BlsToExecutionChangeSchema();
33+
spec.getGenesisSchemaDefinitions()
34+
.toVersionCapella()
35+
.orElseThrow()
36+
.getBlsToExecutionChangeSchema();
3437

3538
private final UInt64 validatorIndex = dataStructureUtil.randomUInt64();
3639
private final BLSPublicKey fromBlsPubkey = dataStructureUtil.randomPublicKey();

ethereum/spec/src/test/java/tech/pegasys/teku/spec/datastructures/operations/SignedBlsToExecutionChangeTest.java

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -18,17 +18,20 @@
1818
import org.apache.tuweni.bytes.Bytes;
1919
import org.junit.jupiter.api.Test;
2020
import tech.pegasys.teku.bls.BLSSignature;
21+
import tech.pegasys.teku.spec.Spec;
2122
import tech.pegasys.teku.spec.SpecMilestone;
2223
import tech.pegasys.teku.spec.TestSpecFactory;
2324
import tech.pegasys.teku.spec.util.DataStructureUtil;
2425

2526
class SignedBlsToExecutionChangeTest {
26-
27-
private final DataStructureUtil dataStructureUtil =
28-
new DataStructureUtil(TestSpecFactory.createMinimal(SpecMilestone.CAPELLA));
27+
private final Spec spec = TestSpecFactory.createMinimal(SpecMilestone.CAPELLA);
28+
private final DataStructureUtil dataStructureUtil = new DataStructureUtil(spec);
2929

3030
private final SignedBlsToExecutionChangeSchema signedBlsToExecutionChangeSchema =
31-
new SignedBlsToExecutionChangeSchema();
31+
spec.getGenesisSchemaDefinitions()
32+
.toVersionCapella()
33+
.orElseThrow()
34+
.getSignedBlsToExecutionChangeSchema();
3235

3336
private final BlsToExecutionChange message = dataStructureUtil.randomBlsToExecutionChange();
3437

0 commit comments

Comments
 (0)