Skip to content

Commit

Permalink
improve requires
Browse files Browse the repository at this point in the history
  • Loading branch information
tbenr committed Nov 14, 2024
1 parent 6d4e224 commit 7e1da2b
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 16 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 @@ -137,7 +137,9 @@ static Spec create(

for (SpecMilestone milestone : SpecMilestone.getMilestonesUpTo(highestMilestoneSupported)) {
SpecVersion.create(
milestone, specConfigAndParent.forMilestone(milestone), schemaRegistryBuilder)
milestone,
specConfigAndParent.forMilestone(milestone).specConfig(),
schemaRegistryBuilder)
.ifPresent(
milestoneSpec -> {
forkScheduleBuilder.addNextMilestone(milestoneSpec);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,12 @@

package tech.pegasys.teku.spec.config;

import static com.google.common.base.Preconditions.checkArgument;
import static tech.pegasys.teku.spec.SpecMilestone.ALTAIR;
import static tech.pegasys.teku.spec.SpecMilestone.BELLATRIX;
import static tech.pegasys.teku.spec.SpecMilestone.CAPELLA;
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 java.util.Optional;
import tech.pegasys.teku.spec.SpecMilestone;
Expand All @@ -31,9 +36,9 @@ public static <TConfig extends SpecConfig> SpecConfigAndParent<TConfig> of(final
return new SpecConfigAndParent<>(spec, Optional.empty());
}

public SpecConfig forMilestone(final SpecMilestone milestone) {
public SpecConfigAndParent<? extends SpecConfig> forMilestone(final SpecMilestone milestone) {
if (specConfig.getMilestone() == milestone) {
return specConfig;
return this;
}
if (parentSpecConfig.isEmpty()) {
throw new IllegalArgumentException("No config available for milestone " + milestone);
Expand All @@ -44,41 +49,36 @@ public SpecConfig forMilestone(final SpecMilestone milestone) {
@SuppressWarnings("unchecked")
public static SpecConfigAndParent<SpecConfigPhase0> requirePhase0(
final SpecConfigAndParent<? extends SpecConfig> specConfigAndParent) {
return (SpecConfigAndParent<SpecConfigPhase0>) specConfigAndParent;
return (SpecConfigAndParent<SpecConfigPhase0>) specConfigAndParent.forMilestone(PHASE0);
}

@SuppressWarnings("unchecked")
public static SpecConfigAndParent<SpecConfigAltair> requireAltair(
final SpecConfigAndParent<? extends SpecConfig> specConfigAndParent) {
checkArgument(specConfigAndParent.specConfig.toVersionAltair().isPresent());
return (SpecConfigAndParent<SpecConfigAltair>) specConfigAndParent;
return (SpecConfigAndParent<SpecConfigAltair>) specConfigAndParent.forMilestone(ALTAIR);
}

@SuppressWarnings("unchecked")
public static SpecConfigAndParent<SpecConfigBellatrix> requireBellatrix(
final SpecConfigAndParent<? extends SpecConfig> specConfigAndParent) {
checkArgument(specConfigAndParent.specConfig.toVersionBellatrix().isPresent());
return (SpecConfigAndParent<SpecConfigBellatrix>) specConfigAndParent;
return (SpecConfigAndParent<SpecConfigBellatrix>) specConfigAndParent.forMilestone(BELLATRIX);
}

@SuppressWarnings("unchecked")
public static SpecConfigAndParent<SpecConfigCapella> requireCapella(
final SpecConfigAndParent<? extends SpecConfig> specConfigAndParent) {
checkArgument(specConfigAndParent.specConfig.toVersionCapella().isPresent());
return (SpecConfigAndParent<SpecConfigCapella>) specConfigAndParent;
return (SpecConfigAndParent<SpecConfigCapella>) specConfigAndParent.forMilestone(CAPELLA);
}

@SuppressWarnings("unchecked")
public static SpecConfigAndParent<SpecConfigDeneb> requireDeneb(
final SpecConfigAndParent<? extends SpecConfig> specConfigAndParent) {
checkArgument(specConfigAndParent.specConfig.toVersionDeneb().isPresent());
return (SpecConfigAndParent<SpecConfigDeneb>) specConfigAndParent;
return (SpecConfigAndParent<SpecConfigDeneb>) specConfigAndParent.forMilestone(DENEB);
}

@SuppressWarnings("unchecked")
public static SpecConfigAndParent<SpecConfigElectra> requireElectra(
final SpecConfigAndParent<? extends SpecConfig> specConfigAndParent) {
checkArgument(specConfigAndParent.specConfig.toVersionElectra().isPresent());
return (SpecConfigAndParent<SpecConfigElectra>) specConfigAndParent;
return (SpecConfigAndParent<SpecConfigElectra>) specConfigAndParent.forMilestone(ELECTRA);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ private SchemaDefinitions createSchemaDefinition(final SpecMilestone milestone)
}
return SpecVersion.create(
milestone,
spec.getSpecConfigAndParent().forMilestone(milestone),
spec.getSpecConfigAndParent().forMilestone(milestone).specConfig(),
SchemaRegistryBuilder.create())
.orElseThrow(
() ->
Expand Down

0 comments on commit 7e1da2b

Please sign in to comment.