Skip to content

Commit

Permalink
make SchemaRegistryBuilder cross-milestone when possible
Browse files Browse the repository at this point in the history
  • Loading branch information
tbenr committed Sep 24, 2024
1 parent bd1f60c commit a6642c1
Show file tree
Hide file tree
Showing 5 changed files with 20 additions and 11 deletions.
4 changes: 3 additions & 1 deletion ethereum/spec/src/main/java/tech/pegasys/teku/spec/Spec.java
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,7 @@
import tech.pegasys.teku.spec.logic.common.util.SyncCommitteeUtil;
import tech.pegasys.teku.spec.logic.versions.bellatrix.block.OptimisticExecutionPayloadExecutor;
import tech.pegasys.teku.spec.schemas.SchemaDefinitions;
import tech.pegasys.teku.spec.schemas.registry.SchemaRegistryBuilder;

public class Spec {
private final Map<SpecMilestone, SpecVersion> specVersions;
Expand All @@ -122,9 +123,10 @@ private Spec(
static Spec create(final SpecConfig config, final SpecMilestone highestMilestoneSupported) {
final Map<SpecMilestone, SpecVersion> specVersions = new EnumMap<>(SpecMilestone.class);
final ForkSchedule.Builder forkScheduleBuilder = ForkSchedule.builder();
final SchemaRegistryBuilder schemaRegistryBuilder = SchemaRegistryBuilder.create();

for (SpecMilestone milestone : SpecMilestone.getMilestonesUpTo(highestMilestoneSupported)) {
SpecVersion.create(milestone, config)
SpecVersion.create(milestone, config, schemaRegistryBuilder)
.ifPresent(
milestoneSpec -> {
forkScheduleBuilder.addNextMilestone(milestoneSpec);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,8 +57,10 @@ private SpecVersion(
}

public static Optional<SpecVersion> create(
final SpecMilestone milestone, final SpecConfig specConfig) {
final SchemaRegistryBuilder schemaRegistryBuilder = SchemaRegistryBuilder.create();
final SpecMilestone milestone,
final SpecConfig specConfig,
final SchemaRegistryBuilder schemaRegistryBuilder) {

return switch (milestone) {
case PHASE0 -> Optional.of(createPhase0(specConfig, schemaRegistryBuilder));
case ALTAIR ->
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
import tech.pegasys.teku.spec.Spec;
import tech.pegasys.teku.spec.SpecMilestone;
import tech.pegasys.teku.spec.SpecVersion;
import tech.pegasys.teku.spec.schemas.registry.SchemaRegistryBuilder;

public class SchemaDefinitionCache {
private final Spec spec;
Expand All @@ -46,7 +47,8 @@ private SchemaDefinitions createSchemaDefinition(final SpecMilestone milestone)
if (specVersion != null) {
return specVersion.getSchemaDefinitions();
}
return SpecVersion.create(milestone, spec.getGenesisSpecConfig())
return SpecVersion.create(
milestone, spec.getGenesisSpecConfig(), SchemaRegistryBuilder.create())
.orElseThrow(
() ->
new IllegalArgumentException(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ void shouldCreatePhase0Spec() {
final SpecVersion expectedVersion =
SpecVersion.createPhase0(minimalConfig, schemaRegistryBuilder);
final Optional<SpecVersion> actualVersion =
SpecVersion.create(SpecMilestone.PHASE0, minimalConfig);
SpecVersion.create(SpecMilestone.PHASE0, minimalConfig, schemaRegistryBuilder);
assertThat(actualVersion).isPresent();
assertThat(actualVersion.get().getMilestone()).isEqualTo(SpecMilestone.PHASE0);
assertThat(actualVersion.get().getSchemaDefinitions())
Expand All @@ -49,7 +49,7 @@ void shouldCreateAltairSpec() {
final SpecVersion expectedVersion =
SpecVersion.createAltair(altairSpecConfig, schemaRegistryBuilder);
final Optional<SpecVersion> actualVersion =
SpecVersion.create(SpecMilestone.ALTAIR, minimalConfig);
SpecVersion.create(SpecMilestone.ALTAIR, minimalConfig, schemaRegistryBuilder);
assertThat(actualVersion).isPresent();
assertThat(actualVersion.get().getMilestone()).isEqualTo(SpecMilestone.ALTAIR);
assertThat(actualVersion.get().getSchemaDefinitions())
Expand All @@ -62,7 +62,7 @@ void shouldCreateBellatrixSpec() {
final SpecVersion expectedVersion =
SpecVersion.createBellatrix(bellatrixSpecConfig, schemaRegistryBuilder);
final Optional<SpecVersion> actualVersion =
SpecVersion.create(SpecMilestone.BELLATRIX, minimalConfig);
SpecVersion.create(SpecMilestone.BELLATRIX, minimalConfig, schemaRegistryBuilder);
assertThat(actualVersion).isPresent();
assertThat(actualVersion.get().getMilestone()).isEqualTo(SpecMilestone.BELLATRIX);
assertThat(actualVersion.get().getSchemaDefinitions())
Expand All @@ -75,7 +75,7 @@ void shouldCreateCapellaSpec() {
final SpecVersion expectedVersion =
SpecVersion.createCapella(capellaSpecConfig, schemaRegistryBuilder);
final Optional<SpecVersion> actualVersion =
SpecVersion.create(SpecMilestone.CAPELLA, minimalConfig);
SpecVersion.create(SpecMilestone.CAPELLA, minimalConfig, schemaRegistryBuilder);
assertThat(actualVersion).isPresent();
assertThat(actualVersion.get().getMilestone()).isEqualTo(SpecMilestone.CAPELLA);
assertThat(actualVersion.get().getSchemaDefinitions())
Expand All @@ -88,7 +88,7 @@ void shouldCreateDenebSpec() {
final SpecVersion expectedVersion =
SpecVersion.createDeneb(denebSpecConfig, schemaRegistryBuilder);
final Optional<SpecVersion> actualVersion =
SpecVersion.create(SpecMilestone.DENEB, minimalConfig);
SpecVersion.create(SpecMilestone.DENEB, minimalConfig, schemaRegistryBuilder);
assertThat(actualVersion).isPresent();
assertThat(actualVersion.get().getMilestone()).isEqualTo(SpecMilestone.DENEB);
assertThat(actualVersion.get().getSchemaDefinitions())
Expand All @@ -101,7 +101,7 @@ void shouldCreateElectraSpec() {
final SpecVersion expectedVersion =
SpecVersion.createElectra(electraSpecConfig, schemaRegistryBuilder);
final Optional<SpecVersion> actualVersion =
SpecVersion.create(SpecMilestone.ELECTRA, minimalConfig);
SpecVersion.create(SpecMilestone.ELECTRA, minimalConfig, schemaRegistryBuilder);
assertThat(actualVersion).isPresent();
assertThat(actualVersion.get().getMilestone()).isEqualTo(SpecMilestone.ELECTRA);
assertThat(actualVersion.get().getSchemaDefinitions())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@
import tech.pegasys.teku.spec.SpecMilestone;
import tech.pegasys.teku.spec.SpecVersion;
import tech.pegasys.teku.spec.config.SpecConfigLoader;
import tech.pegasys.teku.spec.schemas.registry.SchemaRegistryBuilder;

@Command(
name = "pretty-print",
Expand Down Expand Up @@ -95,7 +96,9 @@ public class PrettyPrintCommand implements Callable<Integer> {
@Override
public Integer call() throws IOException {
final SpecVersion spec =
SpecVersion.create(milestone, SpecConfigLoader.loadConfig(network)).orElseThrow();
SpecVersion.create(
milestone, SpecConfigLoader.loadConfig(network), SchemaRegistryBuilder.create())
.orElseThrow();
final Bytes inputData;
try (final InputStream in = openStream()) {
inputData = Bytes.wrap(IOUtils.toByteArray(in));
Expand Down

0 comments on commit a6642c1

Please sign in to comment.