diff --git a/beacon/pow/src/test/java/tech/pegasys/teku/beacon/pow/DepositProcessingControllerTest.java b/beacon/pow/src/test/java/tech/pegasys/teku/beacon/pow/DepositProcessingControllerTest.java index ab51e6f0f15..e6b458ede93 100644 --- a/beacon/pow/src/test/java/tech/pegasys/teku/beacon/pow/DepositProcessingControllerTest.java +++ b/beacon/pow/src/test/java/tech/pegasys/teku/beacon/pow/DepositProcessingControllerTest.java @@ -53,7 +53,7 @@ public class DepositProcessingControllerTest { private DepositProcessingController depositProcessingController; private void createDepositProcessingController(final Consumer configModifier) { - final SpecConfig config = SpecConfigLoader.loadConfig("minimal", configModifier); + final SpecConfig config = SpecConfigLoader.loadConfig("minimal", configModifier).specConfig(); depositProcessingController = new DepositProcessingController( config, diff --git a/beacon/pow/src/test/java/tech/pegasys/teku/beacon/pow/Eth1DepositManagerTest.java b/beacon/pow/src/test/java/tech/pegasys/teku/beacon/pow/Eth1DepositManagerTest.java index 51665e1ea3b..8ef46c440de 100644 --- a/beacon/pow/src/test/java/tech/pegasys/teku/beacon/pow/Eth1DepositManagerTest.java +++ b/beacon/pow/src/test/java/tech/pegasys/teku/beacon/pow/Eth1DepositManagerTest.java @@ -56,9 +56,10 @@ class Eth1DepositManagerTest { private static final int MIN_GENESIS_BLOCK_TIMESTAMP = 10_000; private final SpecConfig config = SpecConfigLoader.loadConfig( - "minimal", - builder -> - builder.minGenesisTime(UInt64.valueOf(10_300)).genesisDelay(UInt64.valueOf(300))); + "minimal", + builder -> + builder.minGenesisTime(UInt64.valueOf(10_300)).genesisDelay(UInt64.valueOf(300))) + .specConfig(); private final Spec spec = TestSpecFactory.createMinimalBellatrix(); private final DataStructureUtil dataStructureUtil = new DataStructureUtil(spec); diff --git a/beacon/pow/src/test/java/tech/pegasys/teku/beacon/pow/MinimumGenesisTimeBlockFinderTest.java b/beacon/pow/src/test/java/tech/pegasys/teku/beacon/pow/MinimumGenesisTimeBlockFinderTest.java index babb31aac61..c772925166c 100644 --- a/beacon/pow/src/test/java/tech/pegasys/teku/beacon/pow/MinimumGenesisTimeBlockFinderTest.java +++ b/beacon/pow/src/test/java/tech/pegasys/teku/beacon/pow/MinimumGenesisTimeBlockFinderTest.java @@ -38,7 +38,8 @@ public class MinimumGenesisTimeBlockFinderTest { // Setup so genesis time for a block will be blockTime + 2 private final SpecConfig config = - SpecConfigLoader.loadConfig("minimal", builder -> builder.genesisDelay(UInt64.valueOf(2))); + SpecConfigLoader.loadConfig("minimal", builder -> builder.genesisDelay(UInt64.valueOf(2))) + .specConfig(); private final Eth1Provider eth1Provider = mock(Eth1Provider.class); private final StubAsyncRunner asyncRunner = new StubAsyncRunner(); @@ -303,7 +304,8 @@ private void withMinGenesisTime( final long minGenesisTime, final Optional eth1DepositContractDeployBlock) { final SpecConfig config = SpecConfigLoader.loadConfig( - "minimal", builder -> builder.minGenesisTime(UInt64.valueOf(minGenesisTime))); + "minimal", builder -> builder.minGenesisTime(UInt64.valueOf(minGenesisTime))) + .specConfig(); minimumGenesisTimeBlockFinder = new MinimumGenesisTimeBlockFinder(config, eth1Provider, eth1DepositContractDeployBlock); } diff --git a/beacon/pow/src/test/java/tech/pegasys/teku/beacon/pow/api/Eth1DataCachePeriodCalculatorTest.java b/beacon/pow/src/test/java/tech/pegasys/teku/beacon/pow/api/Eth1DataCachePeriodCalculatorTest.java index 3fda54f1c23..fec0393b382 100644 --- a/beacon/pow/src/test/java/tech/pegasys/teku/beacon/pow/api/Eth1DataCachePeriodCalculatorTest.java +++ b/beacon/pow/src/test/java/tech/pegasys/teku/beacon/pow/api/Eth1DataCachePeriodCalculatorTest.java @@ -21,7 +21,7 @@ import tech.pegasys.teku.spec.config.SpecConfigLoader; class Eth1DataCachePeriodCalculatorTest { - private final SpecConfig config = SpecConfigLoader.loadConfig("minimal"); + private final SpecConfig config = SpecConfigLoader.loadConfig("minimal").specConfig(); @Test void shouldCalculateCachePeriodForMinimalConstantsFromFollowDistance() { diff --git a/beacon/validator/src/test/java/tech/pegasys/teku/validator/coordinator/Eth1VotingPeriodTest.java b/beacon/validator/src/test/java/tech/pegasys/teku/validator/coordinator/Eth1VotingPeriodTest.java index 0a1bc722d67..4c47ab83127 100644 --- a/beacon/validator/src/test/java/tech/pegasys/teku/validator/coordinator/Eth1VotingPeriodTest.java +++ b/beacon/validator/src/test/java/tech/pegasys/teku/validator/coordinator/Eth1VotingPeriodTest.java @@ -22,11 +22,12 @@ import tech.pegasys.teku.spec.Spec; import tech.pegasys.teku.spec.TestSpecFactory; import tech.pegasys.teku.spec.config.SpecConfig; +import tech.pegasys.teku.spec.config.SpecConfigAndParent; import tech.pegasys.teku.spec.config.SpecConfigLoader; class Eth1VotingPeriodTest { - final SpecConfig specConfig = + final SpecConfigAndParent specConfig = SpecConfigLoader.loadConfig( "minimal", b -> diff --git a/eth-reference-tests/src/referenceTest/java/tech/pegasys/teku/reference/altair/fork/TransitionTestExecutor.java b/eth-reference-tests/src/referenceTest/java/tech/pegasys/teku/reference/altair/fork/TransitionTestExecutor.java index ae3380c490e..94bfc6711ed 100644 --- a/eth-reference-tests/src/referenceTest/java/tech/pegasys/teku/reference/altair/fork/TransitionTestExecutor.java +++ b/eth-reference-tests/src/referenceTest/java/tech/pegasys/teku/reference/altair/fork/TransitionTestExecutor.java @@ -28,6 +28,7 @@ import tech.pegasys.teku.spec.SpecFactory; import tech.pegasys.teku.spec.SpecMilestone; import tech.pegasys.teku.spec.config.SpecConfig; +import tech.pegasys.teku.spec.config.SpecConfigAndParent; import tech.pegasys.teku.spec.config.SpecConfigLoader; import tech.pegasys.teku.spec.datastructures.blocks.SignedBeaconBlock; import tech.pegasys.teku.spec.datastructures.state.beaconstate.BeaconState; @@ -47,7 +48,7 @@ public void runTest(final TestDefinition testDefinition) throws Throwable { private void processUpgrade(final TestDefinition testDefinition, final MetaData metadata) { final SpecMilestone milestone = SpecMilestone.forName(metadata.postFork); final UInt64 forkEpoch = UInt64.valueOf(metadata.forkEpoch); - final SpecConfig config = + final SpecConfigAndParent config = SpecConfigLoader.loadConfig( testDefinition.getConfigName(), builder -> { diff --git a/ethereum/networks/src/main/java/tech/pegasys/teku/networks/EphemeryNetwork.java b/ethereum/networks/src/main/java/tech/pegasys/teku/networks/EphemeryNetwork.java index fbc8f35635d..999e843a894 100644 --- a/ethereum/networks/src/main/java/tech/pegasys/teku/networks/EphemeryNetwork.java +++ b/ethereum/networks/src/main/java/tech/pegasys/teku/networks/EphemeryNetwork.java @@ -41,7 +41,7 @@ public static void updateConfig(final SpecConfigBuilder builder) { } static void updateConfig(final SpecConfigBuilder builder, final TimeProvider timeProvider) { - final SpecConfig config = SpecConfigLoader.loadConfig("ephemery"); + final SpecConfig config = SpecConfigLoader.loadConfig("ephemery").specConfig(); final SpecConfigBuilder rawConfigBuilder = builder.rawConfig(config.getRawConfig()); final long periodsSinceInitialGenesis = getPeriodsSinceGenesis(timeProvider); diff --git a/ethereum/networks/src/test/java/tech/pegasys/teku/networks/EphemeryNetworkTest.java b/ethereum/networks/src/test/java/tech/pegasys/teku/networks/EphemeryNetworkTest.java index adfcdd74575..4cf1a8d9bea 100644 --- a/ethereum/networks/src/test/java/tech/pegasys/teku/networks/EphemeryNetworkTest.java +++ b/ethereum/networks/src/test/java/tech/pegasys/teku/networks/EphemeryNetworkTest.java @@ -31,6 +31,7 @@ import tech.pegasys.teku.spec.Spec; import tech.pegasys.teku.spec.SpecFactory; import tech.pegasys.teku.spec.config.SpecConfig; +import tech.pegasys.teku.spec.config.SpecConfigAndParent; import tech.pegasys.teku.spec.config.SpecConfigLoader; import tech.pegasys.teku.spec.config.SpecConfigReader; import tech.pegasys.teku.spec.config.builder.SpecConfigBuilder; @@ -51,7 +52,7 @@ public class EphemeryNetworkTest { private long expectedChainId; private long periodSinceGenesis; private final SpecConfigReader reader = new SpecConfigReader(); - private SpecConfig configFile; + private SpecConfigAndParent configFile; private SpecConfig config; @BeforeEach @@ -66,7 +67,7 @@ void setUp() { @Test public void testUpdateConfig() { - when(config.getRawConfig()).thenReturn(configFile.getRawConfig()); + when(config.getRawConfig()).thenReturn(configFile.specConfig().getRawConfig()); when(builder.rawConfig(config.getRawConfig())).thenReturn(builder); when(builder.depositChainId(expectedChainId)).thenReturn(builder); when(builder.depositNetworkId(expectedChainId)).thenReturn(builder); @@ -143,7 +144,7 @@ public void shouldUpdateConfigAfterFirstPeriod() { final long expectedMinGenesisTime = MIN_GENESIS_TIME + (ONE_PERIOD * PERIOD_IN_SECONDS); - when(config.getRawConfig()).thenReturn(configFile.getRawConfig()); + when(config.getRawConfig()).thenReturn(configFile.specConfig().getRawConfig()); when(builder.rawConfig(config.getRawConfig())).thenReturn(builder); when(builder.depositChainId(genesisChainidAfterFirstPeriod)).thenReturn(builder); when(builder.depositNetworkId(genesisChainidAfterFirstPeriod)).thenReturn(builder); @@ -169,7 +170,7 @@ public void shouldUpdateConfigForManyPeriods() { final long expectedMinGenesisTime = MIN_GENESIS_TIME + MANY_PERIOD * PERIOD_IN_SECONDS; - when(config.getRawConfig()).thenReturn(configFile.getRawConfig()); + when(config.getRawConfig()).thenReturn(configFile.specConfig().getRawConfig()); when(builder.rawConfig(config.getRawConfig())).thenReturn(builder); when(builder.depositChainId(genesisChainIdAfter1000Period)).thenReturn(builder); when(builder.depositNetworkId(genesisChainIdAfter1000Period)).thenReturn(builder); @@ -255,7 +256,8 @@ private void readConfig(final InputStream preset) throws IOException { } private Spec getSpec(final Consumer consumer) { - final SpecConfig config = SpecConfigLoader.loadConfig("ephemery", consumer); + final SpecConfigAndParent config = + SpecConfigLoader.loadConfig("ephemery", consumer); return SpecFactory.create(config); } } diff --git a/ethereum/spec/src/main/java/tech/pegasys/teku/spec/Spec.java b/ethereum/spec/src/main/java/tech/pegasys/teku/spec/Spec.java index 29d1f68f6a3..a677306a623 100644 --- a/ethereum/spec/src/main/java/tech/pegasys/teku/spec/Spec.java +++ b/ethereum/spec/src/main/java/tech/pegasys/teku/spec/Spec.java @@ -52,6 +52,7 @@ import tech.pegasys.teku.spec.config.NetworkingSpecConfigElectra; import tech.pegasys.teku.spec.config.SpecConfig; import tech.pegasys.teku.spec.config.SpecConfigAltair; +import tech.pegasys.teku.spec.config.SpecConfigAndParent; import tech.pegasys.teku.spec.config.SpecConfigDeneb; import tech.pegasys.teku.spec.config.SpecConfigElectra; import tech.pegasys.teku.spec.constants.Domain; @@ -111,11 +112,15 @@ public class Spec { private final Map specVersions; private final ForkSchedule forkSchedule; private final StateTransition stateTransition; + private final SpecConfigAndParent specConfigAndParent; private Spec( - final Map specVersions, final ForkSchedule forkSchedule) { + final SpecConfigAndParent specConfigAndParent, + final Map specVersions, + final ForkSchedule forkSchedule) { Preconditions.checkArgument(specVersions != null && !specVersions.isEmpty()); Preconditions.checkArgument(forkSchedule != null); + this.specConfigAndParent = specConfigAndParent; this.specVersions = specVersions; this.forkSchedule = forkSchedule; @@ -123,13 +128,16 @@ private Spec( this.stateTransition = new StateTransition(this::atSlot); } - static Spec create(final SpecConfig config, final SpecMilestone highestMilestoneSupported) { + static Spec create( + final SpecConfigAndParent specConfigAndParent, + final SpecMilestone highestMilestoneSupported) { final Map 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, schemaRegistryBuilder) + SpecVersion.create( + milestone, specConfigAndParent.forMilestone(milestone), schemaRegistryBuilder) .ifPresent( milestoneSpec -> { forkScheduleBuilder.addNextMilestone(milestoneSpec); @@ -139,7 +147,7 @@ static Spec create(final SpecConfig config, final SpecMilestone highestMilestone final ForkSchedule forkSchedule = forkScheduleBuilder.build(); - return new Spec(specVersions, forkSchedule); + return new Spec(specConfigAndParent, specVersions, forkSchedule); } public SpecVersion forMilestone(final SpecMilestone milestone) { @@ -162,6 +170,10 @@ private SpecVersion atTimeMillis(final UInt64 genesisTimeMillis, final UInt64 cu return atTime(millisToSeconds(genesisTimeMillis), millisToSeconds(currentTimeMillis)); } + public SpecConfigAndParent getSpecConfigAndParent() { + return specConfigAndParent; + } + public SpecConfig getSpecConfig(final UInt64 epoch) { return atEpoch(epoch).getConfig(); } diff --git a/ethereum/spec/src/main/java/tech/pegasys/teku/spec/SpecFactory.java b/ethereum/spec/src/main/java/tech/pegasys/teku/spec/SpecFactory.java index 4c06267bcab..5a32aae7313 100644 --- a/ethereum/spec/src/main/java/tech/pegasys/teku/spec/SpecFactory.java +++ b/ethereum/spec/src/main/java/tech/pegasys/teku/spec/SpecFactory.java @@ -25,6 +25,7 @@ import tech.pegasys.teku.infrastructure.unsigned.UInt64; import tech.pegasys.teku.spec.config.SpecConfig; import tech.pegasys.teku.spec.config.SpecConfigAltair; +import tech.pegasys.teku.spec.config.SpecConfigAndParent; import tech.pegasys.teku.spec.config.SpecConfigBellatrix; import tech.pegasys.teku.spec.config.SpecConfigCapella; import tech.pegasys.teku.spec.config.SpecConfigDeneb; @@ -39,27 +40,39 @@ public static Spec create(final String configName) { } public static Spec create(final String configName, final Consumer modifier) { - final SpecConfig config = SpecConfigLoader.loadConfig(configName, modifier); + final SpecConfigAndParent config = + SpecConfigLoader.loadConfig(configName, modifier); return create(config); } - public static Spec create(final SpecConfig config) { + public static Spec create(final SpecConfigAndParent config) { final UInt64 altairForkEpoch = - config.toVersionAltair().map(SpecConfigAltair::getAltairForkEpoch).orElse(FAR_FUTURE_EPOCH); + config + .specConfig() + .toVersionAltair() + .map(SpecConfigAltair::getAltairForkEpoch) + .orElse(FAR_FUTURE_EPOCH); final UInt64 bellatrixForkEpoch = config + .specConfig() .toVersionBellatrix() .map(SpecConfigBellatrix::getBellatrixForkEpoch) .orElse(FAR_FUTURE_EPOCH); final UInt64 capellaForkEpoch = config + .specConfig() .toVersionCapella() .map(SpecConfigCapella::getCapellaForkEpoch) .orElse(FAR_FUTURE_EPOCH); final UInt64 denebForkEpoch = - config.toVersionDeneb().map(SpecConfigDeneb::getDenebForkEpoch).orElse(FAR_FUTURE_EPOCH); + config + .specConfig() + .toVersionDeneb() + .map(SpecConfigDeneb::getDenebForkEpoch) + .orElse(FAR_FUTURE_EPOCH); final UInt64 electraForkEpoch = config + .specConfig() .toVersionElectra() .map(SpecConfigElectra::getElectraForkEpoch) .orElse(FAR_FUTURE_EPOCH); diff --git a/ethereum/spec/src/main/java/tech/pegasys/teku/spec/config/DelegatingSpecConfig.java b/ethereum/spec/src/main/java/tech/pegasys/teku/spec/config/DelegatingSpecConfig.java index b5da8abbada..b513c9b16bf 100644 --- a/ethereum/spec/src/main/java/tech/pegasys/teku/spec/config/DelegatingSpecConfig.java +++ b/ethereum/spec/src/main/java/tech/pegasys/teku/spec/config/DelegatingSpecConfig.java @@ -18,6 +18,7 @@ import tech.pegasys.teku.ethereum.execution.types.Eth1Address; import tech.pegasys.teku.infrastructure.bytes.Bytes4; import tech.pegasys.teku.infrastructure.unsigned.UInt64; +import tech.pegasys.teku.spec.SpecMilestone; public class DelegatingSpecConfig implements SpecConfig { protected final SpecConfig specConfig; @@ -395,4 +396,9 @@ public int getAttestationSubnetPrefixBits() { public int getProposerScoreBoost() { return specConfig.getProposerScoreBoost(); } + + @Override + public SpecMilestone getMilestone() { + return specConfig.getMilestone(); + } } diff --git a/ethereum/spec/src/main/java/tech/pegasys/teku/spec/config/SpecConfig.java b/ethereum/spec/src/main/java/tech/pegasys/teku/spec/config/SpecConfig.java index 54802ae2332..c23b7ceed68 100644 --- a/ethereum/spec/src/main/java/tech/pegasys/teku/spec/config/SpecConfig.java +++ b/ethereum/spec/src/main/java/tech/pegasys/teku/spec/config/SpecConfig.java @@ -19,6 +19,7 @@ import tech.pegasys.teku.ethereum.execution.types.Eth1Address; import tech.pegasys.teku.infrastructure.bytes.Bytes4; import tech.pegasys.teku.infrastructure.unsigned.UInt64; +import tech.pegasys.teku.spec.SpecMilestone; import tech.pegasys.teku.spec.config.builder.SpecConfigBuilder; public interface SpecConfig extends NetworkingSpecConfig { @@ -188,4 +189,6 @@ default Optional toVersionDeneb() { default Optional toVersionElectra() { return Optional.empty(); } + + SpecMilestone getMilestone(); } diff --git a/ethereum/spec/src/main/java/tech/pegasys/teku/spec/config/SpecConfigAltairImpl.java b/ethereum/spec/src/main/java/tech/pegasys/teku/spec/config/SpecConfigAltairImpl.java index 0cbfd20f76f..9acadbec46a 100644 --- a/ethereum/spec/src/main/java/tech/pegasys/teku/spec/config/SpecConfigAltairImpl.java +++ b/ethereum/spec/src/main/java/tech/pegasys/teku/spec/config/SpecConfigAltairImpl.java @@ -17,6 +17,7 @@ import java.util.Optional; import tech.pegasys.teku.infrastructure.bytes.Bytes4; import tech.pegasys.teku.infrastructure.unsigned.UInt64; +import tech.pegasys.teku.spec.SpecMilestone; public class SpecConfigAltairImpl extends DelegatingSpecConfig implements SpecConfigAltair { @@ -156,6 +157,11 @@ public Optional toVersionAltair() { return Optional.of(this); } + @Override + public SpecMilestone getMilestone() { + return SpecMilestone.ALTAIR; + } + @Override public boolean equals(final Object o) { if (this == o) { diff --git a/ethereum/spec/src/main/java/tech/pegasys/teku/spec/config/SpecConfigAndParent.java b/ethereum/spec/src/main/java/tech/pegasys/teku/spec/config/SpecConfigAndParent.java new file mode 100644 index 00000000000..655eb6e7dc7 --- /dev/null +++ b/ethereum/spec/src/main/java/tech/pegasys/teku/spec/config/SpecConfigAndParent.java @@ -0,0 +1,84 @@ +/* + * Copyright Consensys Software Inc., 2024 + * + * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on + * an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the + * specific language governing permissions and limitations under the License. + */ + +package tech.pegasys.teku.spec.config; + +import static com.google.common.base.Preconditions.checkArgument; + +import java.util.Optional; +import tech.pegasys.teku.spec.SpecMilestone; + +public record SpecConfigAndParent( + TConfig specConfig, Optional> parentSpecConfig) { + + public static + SpecConfigAndParent of( + final TConfig spec, final SpecConfigAndParent parentSpec) { + return new SpecConfigAndParent<>(spec, Optional.of(parentSpec)); + } + + public static SpecConfigAndParent of(final TConfig spec) { + return new SpecConfigAndParent<>(spec, Optional.empty()); + } + + public SpecConfig forMilestone(final SpecMilestone milestone) { + if (specConfig.getMilestone() == milestone) { + return specConfig; + } + if (parentSpecConfig.isEmpty()) { + throw new IllegalArgumentException("No config available for milestone " + milestone); + } + return parentSpecConfig.get().forMilestone(milestone); + } + + @SuppressWarnings("unchecked") + public static SpecConfigAndParent requirePhase0( + final SpecConfigAndParent specConfigAndParent) { + return (SpecConfigAndParent) specConfigAndParent; + } + + @SuppressWarnings("unchecked") + public static SpecConfigAndParent requireAltair( + final SpecConfigAndParent specConfigAndParent) { + checkArgument(specConfigAndParent.specConfig.toVersionAltair().isPresent()); + return (SpecConfigAndParent) specConfigAndParent; + } + + @SuppressWarnings("unchecked") + public static SpecConfigAndParent requireBellatrix( + final SpecConfigAndParent specConfigAndParent) { + checkArgument(specConfigAndParent.specConfig.toVersionBellatrix().isPresent()); + return (SpecConfigAndParent) specConfigAndParent; + } + + @SuppressWarnings("unchecked") + public static SpecConfigAndParent requireCapella( + final SpecConfigAndParent specConfigAndParent) { + checkArgument(specConfigAndParent.specConfig.toVersionCapella().isPresent()); + return (SpecConfigAndParent) specConfigAndParent; + } + + @SuppressWarnings("unchecked") + public static SpecConfigAndParent requireDeneb( + final SpecConfigAndParent specConfigAndParent) { + checkArgument(specConfigAndParent.specConfig.toVersionDeneb().isPresent()); + return (SpecConfigAndParent) specConfigAndParent; + } + + @SuppressWarnings("unchecked") + public static SpecConfigAndParent requireElectra( + final SpecConfigAndParent specConfigAndParent) { + checkArgument(specConfigAndParent.specConfig.toVersionElectra().isPresent()); + return (SpecConfigAndParent) specConfigAndParent; + } +} diff --git a/ethereum/spec/src/main/java/tech/pegasys/teku/spec/config/SpecConfigBellatrixImpl.java b/ethereum/spec/src/main/java/tech/pegasys/teku/spec/config/SpecConfigBellatrixImpl.java index 199102da252..f06186aceb5 100644 --- a/ethereum/spec/src/main/java/tech/pegasys/teku/spec/config/SpecConfigBellatrixImpl.java +++ b/ethereum/spec/src/main/java/tech/pegasys/teku/spec/config/SpecConfigBellatrixImpl.java @@ -19,6 +19,7 @@ import org.apache.tuweni.units.bigints.UInt256; import tech.pegasys.teku.infrastructure.bytes.Bytes4; import tech.pegasys.teku.infrastructure.unsigned.UInt64; +import tech.pegasys.teku.spec.SpecMilestone; public class SpecConfigBellatrixImpl extends DelegatingSpecConfigAltair implements SpecConfigBellatrix { @@ -153,6 +154,11 @@ public Optional toVersionBellatrix() { return Optional.of(this); } + @Override + public SpecMilestone getMilestone() { + return SpecMilestone.BELLATRIX; + } + @Override public boolean equals(final Object o) { if (this == o) { diff --git a/ethereum/spec/src/main/java/tech/pegasys/teku/spec/config/SpecConfigCapellaImpl.java b/ethereum/spec/src/main/java/tech/pegasys/teku/spec/config/SpecConfigCapellaImpl.java index 53e42fa486f..ad4626f05e3 100644 --- a/ethereum/spec/src/main/java/tech/pegasys/teku/spec/config/SpecConfigCapellaImpl.java +++ b/ethereum/spec/src/main/java/tech/pegasys/teku/spec/config/SpecConfigCapellaImpl.java @@ -17,6 +17,7 @@ import java.util.Optional; import tech.pegasys.teku.infrastructure.bytes.Bytes4; import tech.pegasys.teku.infrastructure.unsigned.UInt64; +import tech.pegasys.teku.spec.SpecMilestone; public class SpecConfigCapellaImpl extends DelegatingSpecConfigBellatrix implements SpecConfigCapella { @@ -100,4 +101,9 @@ public int getMaxValidatorsPerWithdrawalSweep() { public Optional toVersionCapella() { return Optional.of(this); } + + @Override + public SpecMilestone getMilestone() { + return SpecMilestone.CAPELLA; + } } diff --git a/ethereum/spec/src/main/java/tech/pegasys/teku/spec/config/SpecConfigDenebImpl.java b/ethereum/spec/src/main/java/tech/pegasys/teku/spec/config/SpecConfigDenebImpl.java index 53ced36b5af..351906dc463 100644 --- a/ethereum/spec/src/main/java/tech/pegasys/teku/spec/config/SpecConfigDenebImpl.java +++ b/ethereum/spec/src/main/java/tech/pegasys/teku/spec/config/SpecConfigDenebImpl.java @@ -17,6 +17,7 @@ import java.util.Optional; import tech.pegasys.teku.infrastructure.bytes.Bytes4; import tech.pegasys.teku.infrastructure.unsigned.UInt64; +import tech.pegasys.teku.spec.SpecMilestone; public class SpecConfigDenebImpl extends DelegatingSpecConfigCapella implements SpecConfigDeneb { @@ -130,6 +131,11 @@ public Optional toVersionDeneb() { return Optional.of(this); } + @Override + public SpecMilestone getMilestone() { + return SpecMilestone.DENEB; + } + @Override public boolean equals(final Object o) { if (this == o) { diff --git a/ethereum/spec/src/main/java/tech/pegasys/teku/spec/config/SpecConfigElectraImpl.java b/ethereum/spec/src/main/java/tech/pegasys/teku/spec/config/SpecConfigElectraImpl.java index 499d52c0399..47052fc890f 100644 --- a/ethereum/spec/src/main/java/tech/pegasys/teku/spec/config/SpecConfigElectraImpl.java +++ b/ethereum/spec/src/main/java/tech/pegasys/teku/spec/config/SpecConfigElectraImpl.java @@ -17,6 +17,7 @@ import java.util.Optional; import tech.pegasys.teku.infrastructure.bytes.Bytes4; import tech.pegasys.teku.infrastructure.unsigned.UInt64; +import tech.pegasys.teku.spec.SpecMilestone; public class SpecConfigElectraImpl extends DelegatingSpecConfigDeneb implements SpecConfigElectra { @@ -201,6 +202,11 @@ public Optional toVersionElectra() { return Optional.of(this); } + @Override + public SpecMilestone getMilestone() { + return SpecMilestone.ELECTRA; + } + @Override public boolean equals(final Object o) { if (this == o) { diff --git a/ethereum/spec/src/main/java/tech/pegasys/teku/spec/config/SpecConfigLoader.java b/ethereum/spec/src/main/java/tech/pegasys/teku/spec/config/SpecConfigLoader.java index 683e6491302..b7aebebb946 100644 --- a/ethereum/spec/src/main/java/tech/pegasys/teku/spec/config/SpecConfigLoader.java +++ b/ethereum/spec/src/main/java/tech/pegasys/teku/spec/config/SpecConfigLoader.java @@ -36,20 +36,21 @@ public class SpecConfigLoader { private static final String CONFIG_PATH = "configs/"; private static final String PRESET_PATH = "presets/"; - public static SpecConfig loadConfigStrict(final String configName) { + public static SpecConfigAndParent loadConfigStrict( + final String configName) { return loadConfig(configName, false, __ -> {}); } - public static SpecConfig loadConfig(final String configName) { + public static SpecConfigAndParent loadConfig(final String configName) { return loadConfig(configName, __ -> {}); } - public static SpecConfig loadConfig( + public static SpecConfigAndParent loadConfig( final String configName, final Consumer modifier) { return loadConfig(configName, true, modifier); } - public static SpecConfig loadConfig( + public static SpecConfigAndParent loadConfig( final String configName, final boolean ignoreUnknownConfigItems, final Consumer modifier) { @@ -58,7 +59,8 @@ public static SpecConfig loadConfig( return reader.build(modifier); } - public static SpecConfig loadRemoteConfig(final Map config) { + public static SpecConfigAndParent loadRemoteConfig( + final Map config) { final SpecConfigReader reader = new SpecConfigReader(); if (config.containsKey(SpecConfigReader.PRESET_KEY)) { try { diff --git a/ethereum/spec/src/main/java/tech/pegasys/teku/spec/config/SpecConfigPhase0.java b/ethereum/spec/src/main/java/tech/pegasys/teku/spec/config/SpecConfigPhase0.java index e44266cd681..6d41969704c 100644 --- a/ethereum/spec/src/main/java/tech/pegasys/teku/spec/config/SpecConfigPhase0.java +++ b/ethereum/spec/src/main/java/tech/pegasys/teku/spec/config/SpecConfigPhase0.java @@ -19,6 +19,7 @@ import tech.pegasys.teku.ethereum.execution.types.Eth1Address; import tech.pegasys.teku.infrastructure.bytes.Bytes4; import tech.pegasys.teku.infrastructure.unsigned.UInt64; +import tech.pegasys.teku.spec.SpecMilestone; import tech.pegasys.teku.spec.constants.WithdrawalPrefixes; import tech.pegasys.teku.spec.logic.common.helpers.MathHelpers; @@ -634,6 +635,11 @@ public int getAttestationSubnetPrefixBits() { return attestationSubnetPrefixBits; } + @Override + public SpecMilestone getMilestone() { + return SpecMilestone.PHASE0; + } + @Override public boolean equals(final Object o) { if (this == o) { diff --git a/ethereum/spec/src/main/java/tech/pegasys/teku/spec/config/SpecConfigReader.java b/ethereum/spec/src/main/java/tech/pegasys/teku/spec/config/SpecConfigReader.java index 6bfb9297322..f48941998bd 100644 --- a/ethereum/spec/src/main/java/tech/pegasys/teku/spec/config/SpecConfigReader.java +++ b/ethereum/spec/src/main/java/tech/pegasys/teku/spec/config/SpecConfigReader.java @@ -110,11 +110,12 @@ public class SpecConfigReader { final SpecConfigBuilder configBuilder = SpecConfig.builder(); - public SpecConfig build() { + public SpecConfigAndParent build() { return configBuilder.build(); } - public SpecConfig build(final Consumer modifier) { + public SpecConfigAndParent build( + final Consumer modifier) { modifier.accept(configBuilder); return build(); } diff --git a/ethereum/spec/src/main/java/tech/pegasys/teku/spec/config/builder/AltairBuilder.java b/ethereum/spec/src/main/java/tech/pegasys/teku/spec/config/builder/AltairBuilder.java index bd30f3552b9..feccb2e8d0b 100644 --- a/ethereum/spec/src/main/java/tech/pegasys/teku/spec/config/builder/AltairBuilder.java +++ b/ethereum/spec/src/main/java/tech/pegasys/teku/spec/config/builder/AltairBuilder.java @@ -24,6 +24,7 @@ import tech.pegasys.teku.spec.config.SpecConfig; import tech.pegasys.teku.spec.config.SpecConfigAltair; import tech.pegasys.teku.spec.config.SpecConfigAltairImpl; +import tech.pegasys.teku.spec.config.SpecConfigAndParent; public class AltairBuilder implements ForkConfigBuilder { @@ -57,22 +58,25 @@ public class AltairBuilder implements ForkConfigBuilder build( + final SpecConfigAndParent specConfigAndParent) { + return SpecConfigAndParent.of( + new SpecConfigAltairImpl( + specConfigAndParent.specConfig(), + inactivityPenaltyQuotientAltair, + minSlashingPenaltyQuotientAltair, + proportionalSlashingMultiplierAltair, + syncCommitteeSize, + inactivityScoreBias, + inactivityScoreRecoveryRate, + epochsPerSyncCommitteePeriod, + altairForkVersion, + altairForkEpoch, + minSyncCommitteeParticipants, + updateTimeout, + syncCommitteeBranchLength, + finalityBranchLength), + specConfigAndParent); } @Override diff --git a/ethereum/spec/src/main/java/tech/pegasys/teku/spec/config/builder/BellatrixBuilder.java b/ethereum/spec/src/main/java/tech/pegasys/teku/spec/config/builder/BellatrixBuilder.java index e6d6bc53c07..621ad059c0a 100644 --- a/ethereum/spec/src/main/java/tech/pegasys/teku/spec/config/builder/BellatrixBuilder.java +++ b/ethereum/spec/src/main/java/tech/pegasys/teku/spec/config/builder/BellatrixBuilder.java @@ -27,6 +27,7 @@ import tech.pegasys.teku.infrastructure.unsigned.UInt64; import tech.pegasys.teku.spec.config.SpecConfig; import tech.pegasys.teku.spec.config.SpecConfigAltair; +import tech.pegasys.teku.spec.config.SpecConfigAndParent; import tech.pegasys.teku.spec.config.SpecConfigBellatrix; import tech.pegasys.teku.spec.config.SpecConfigBellatrixImpl; @@ -54,22 +55,25 @@ public class BellatrixBuilder implements ForkConfigBuilder build( + final SpecConfigAndParent specConfigAndParent) { + return SpecConfigAndParent.of( + new SpecConfigBellatrixImpl( + specConfigAndParent.specConfig(), + bellatrixForkVersion, + bellatrixForkEpoch, + inactivityPenaltyQuotientBellatrix, + minSlashingPenaltyQuotientBellatrix, + proportionalSlashingMultiplierBellatrix, + maxBytesPerTransaction, + maxTransactionsPerPayload, + bytesPerLogsBloom, + maxExtraDataBytes, + terminalTotalDifficulty, + terminalBlockHash, + terminalBlockHashActivationEpoch, + safeSlotsToImportOptimistically), + specConfigAndParent); } @Override diff --git a/ethereum/spec/src/main/java/tech/pegasys/teku/spec/config/builder/BuilderChain.java b/ethereum/spec/src/main/java/tech/pegasys/teku/spec/config/builder/BuilderChain.java index 7e2d99a6817..2398c168b7d 100644 --- a/ethereum/spec/src/main/java/tech/pegasys/teku/spec/config/builder/BuilderChain.java +++ b/ethereum/spec/src/main/java/tech/pegasys/teku/spec/config/builder/BuilderChain.java @@ -17,6 +17,7 @@ import java.util.function.BiConsumer; import java.util.function.Consumer; import tech.pegasys.teku.spec.config.SpecConfig; +import tech.pegasys.teku.spec.config.SpecConfigAndParent; /** * Hides some serious abuse of Java's type system so that from the outside we have a type safe chain @@ -76,9 +77,9 @@ public void addOverridableItemsToRawConfig(final BiConsumer rawC @Override @SuppressWarnings("unchecked") - public Out build(final In specConfig) { - final SpecConfig config = builderToApply.build(specConfig); - return (Out) tail.build(config); + public SpecConfigAndParent build(final SpecConfigAndParent specConfig) { + SpecConfigAndParent config = builderToApply.build(specConfig); + return tail.build(config); } @Override @@ -95,7 +96,7 @@ public Map getValidationMap() { private static class NoOpForkBuilder implements ForkConfigBuilder { @Override - public T build(final T specConfig) { + public SpecConfigAndParent build(final SpecConfigAndParent specConfig) { return specConfig; } diff --git a/ethereum/spec/src/main/java/tech/pegasys/teku/spec/config/builder/CapellaBuilder.java b/ethereum/spec/src/main/java/tech/pegasys/teku/spec/config/builder/CapellaBuilder.java index 5d8736dd9f2..42d77643db3 100644 --- a/ethereum/spec/src/main/java/tech/pegasys/teku/spec/config/builder/CapellaBuilder.java +++ b/ethereum/spec/src/main/java/tech/pegasys/teku/spec/config/builder/CapellaBuilder.java @@ -22,6 +22,7 @@ import tech.pegasys.teku.infrastructure.bytes.Bytes4; import tech.pegasys.teku.infrastructure.unsigned.UInt64; import tech.pegasys.teku.spec.config.SpecConfig; +import tech.pegasys.teku.spec.config.SpecConfigAndParent; import tech.pegasys.teku.spec.config.SpecConfigBellatrix; import tech.pegasys.teku.spec.config.SpecConfigCapella; import tech.pegasys.teku.spec.config.SpecConfigCapellaImpl; @@ -38,14 +39,17 @@ public class CapellaBuilder implements ForkConfigBuilder build( + final SpecConfigAndParent specConfig) { + return SpecConfigAndParent.of( + new SpecConfigCapellaImpl( + specConfig.specConfig(), + capellaForkVersion, + capellaForkEpoch, + maxBlsToExecutionChanges, + maxWithdrawalsPerPayload, + maxValidatorsPerWithdrawalSweep), + specConfig); } public CapellaBuilder capellaForkEpoch(final UInt64 capellaForkEpoch) { diff --git a/ethereum/spec/src/main/java/tech/pegasys/teku/spec/config/builder/DenebBuilder.java b/ethereum/spec/src/main/java/tech/pegasys/teku/spec/config/builder/DenebBuilder.java index 2ddd5990e00..b352c3e60e8 100644 --- a/ethereum/spec/src/main/java/tech/pegasys/teku/spec/config/builder/DenebBuilder.java +++ b/ethereum/spec/src/main/java/tech/pegasys/teku/spec/config/builder/DenebBuilder.java @@ -23,6 +23,7 @@ import tech.pegasys.teku.infrastructure.bytes.Bytes4; import tech.pegasys.teku.infrastructure.unsigned.UInt64; import tech.pegasys.teku.spec.config.SpecConfig; +import tech.pegasys.teku.spec.config.SpecConfigAndParent; import tech.pegasys.teku.spec.config.SpecConfigCapella; import tech.pegasys.teku.spec.config.SpecConfigDeneb; import tech.pegasys.teku.spec.config.SpecConfigDenebImpl; @@ -46,21 +47,24 @@ public class DenebBuilder implements ForkConfigBuilder build( + final SpecConfigAndParent specConfigAndParent) { + return SpecConfigAndParent.of( + new SpecConfigDenebImpl( + specConfigAndParent.specConfig(), + denebForkVersion, + denebForkEpoch, + maxPerEpochActivationChurnLimit, + fieldElementsPerBlob, + maxBlobCommitmentsPerBlock, + maxBlobsPerBlock, + kzgCommitmentInclusionProofDepth, + maxRequestBlocksDeneb, + maxRequestBlobSidecars, + minEpochsForBlobSidecarsRequests, + blobSidecarSubnetCount, + epochsStoreBlobs), + specConfigAndParent); } public DenebBuilder denebForkEpoch(final UInt64 denebForkEpoch) { diff --git a/ethereum/spec/src/main/java/tech/pegasys/teku/spec/config/builder/ElectraBuilder.java b/ethereum/spec/src/main/java/tech/pegasys/teku/spec/config/builder/ElectraBuilder.java index baafd2a7691..962bd8315f3 100644 --- a/ethereum/spec/src/main/java/tech/pegasys/teku/spec/config/builder/ElectraBuilder.java +++ b/ethereum/spec/src/main/java/tech/pegasys/teku/spec/config/builder/ElectraBuilder.java @@ -22,6 +22,7 @@ import tech.pegasys.teku.infrastructure.bytes.Bytes4; import tech.pegasys.teku.infrastructure.unsigned.UInt64; import tech.pegasys.teku.spec.config.SpecConfig; +import tech.pegasys.teku.spec.config.SpecConfigAndParent; import tech.pegasys.teku.spec.config.SpecConfigDeneb; import tech.pegasys.teku.spec.config.SpecConfigElectra; import tech.pegasys.teku.spec.config.SpecConfigElectraImpl; @@ -55,30 +56,33 @@ public class ElectraBuilder implements ForkConfigBuilder build( + final SpecConfigAndParent specConfigAndParent) { + return SpecConfigAndParent.of( + new SpecConfigElectraImpl( + specConfigAndParent.specConfig(), + electraForkVersion, + electraForkEpoch, + minPerEpochChurnLimitElectra, + minActivationBalance, + maxEffectiveBalanceElectra, + minSlashingPenaltyQuotientElectra, + whistleblowerRewardQuotientElectra, + pendingDepositsLimit, + pendingPartialWithdrawalsLimit, + pendingConsolidationsLimit, + maxAttesterSlashingsElectra, + maxAttestationsElectra, + maxDepositRequestsPerPayload, + maxWithdrawalRequestsPerPayload, + maxConsolidationRequestsPerPayload, + maxPendingPartialsPerWithdrawalsSweep, + maxPendingDepositsPerEpoch, + maxBlobsPerBlockElectra, + targetBlobsPerBlockElectra, + maxRequestBlobSidecarsElectra, + blobSidecarSubnetCountElectra), + specConfigAndParent); } public ElectraBuilder electraForkVersion(final Bytes4 electraForkVersion) { diff --git a/ethereum/spec/src/main/java/tech/pegasys/teku/spec/config/builder/ForkConfigBuilder.java b/ethereum/spec/src/main/java/tech/pegasys/teku/spec/config/builder/ForkConfigBuilder.java index d811492d378..52e8bfe5be2 100644 --- a/ethereum/spec/src/main/java/tech/pegasys/teku/spec/config/builder/ForkConfigBuilder.java +++ b/ethereum/spec/src/main/java/tech/pegasys/teku/spec/config/builder/ForkConfigBuilder.java @@ -19,10 +19,11 @@ import java.util.Optional; import java.util.function.BiConsumer; import tech.pegasys.teku.spec.config.SpecConfig; +import tech.pegasys.teku.spec.config.SpecConfigAndParent; interface ForkConfigBuilder { - ForkType build(ParentType specConfig); + SpecConfigAndParent build(SpecConfigAndParent specConfigAndParent); void validate(); diff --git a/ethereum/spec/src/main/java/tech/pegasys/teku/spec/config/builder/SpecConfigBuilder.java b/ethereum/spec/src/main/java/tech/pegasys/teku/spec/config/builder/SpecConfigBuilder.java index d79d7723be4..5e48e29614c 100644 --- a/ethereum/spec/src/main/java/tech/pegasys/teku/spec/config/builder/SpecConfigBuilder.java +++ b/ethereum/spec/src/main/java/tech/pegasys/teku/spec/config/builder/SpecConfigBuilder.java @@ -28,6 +28,7 @@ import tech.pegasys.teku.infrastructure.bytes.Bytes4; import tech.pegasys.teku.infrastructure.unsigned.UInt64; import tech.pegasys.teku.spec.config.SpecConfig; +import tech.pegasys.teku.spec.config.SpecConfigAndParent; import tech.pegasys.teku.spec.config.SpecConfigElectra; import tech.pegasys.teku.spec.config.SpecConfigPhase0; @@ -138,7 +139,7 @@ public class SpecConfigBuilder { .appendBuilder(new DenebBuilder()) .appendBuilder(new ElectraBuilder()); - public SpecConfig build() { + public SpecConfigAndParent build() { builderChain.addOverridableItemsToRawConfig( (key, value) -> { if (value != null) { @@ -146,77 +147,78 @@ public SpecConfig build() { } }); validate(); - final SpecConfig config = - new SpecConfigPhase0( - rawConfig, - eth1FollowDistance, - maxCommitteesPerSlot, - targetCommitteeSize, - maxValidatorsPerCommittee, - minPerEpochChurnLimit, - churnLimitQuotient, - shuffleRoundCount, - minGenesisActiveValidatorCount, - minGenesisTime, - hysteresisQuotient, - hysteresisDownwardMultiplier, - hysteresisUpwardMultiplier, - proportionalSlashingMultiplier, - minDepositAmount, - maxEffectiveBalance, - ejectionBalance, - effectiveBalanceIncrement, - genesisForkVersion, - genesisDelay, - secondsPerSlot, - minAttestationInclusionDelay, - slotsPerEpoch, - minSeedLookahead, - maxSeedLookahead, - minEpochsToInactivityPenalty, - epochsPerEth1VotingPeriod, - slotsPerHistoricalRoot, - minValidatorWithdrawabilityDelay, - shardCommitteePeriod, - epochsPerHistoricalVector, - epochsPerSlashingsVector, - historicalRootsLimit, - validatorRegistryLimit, - baseRewardFactor, - whistleblowerRewardQuotient, - proposerRewardQuotient, - inactivityPenaltyQuotient, - minSlashingPenaltyQuotient, - maxProposerSlashings, - maxAttesterSlashings, - maxAttestations, - maxDeposits, - maxVoluntaryExits, - secondsPerEth1Block, - safeSlotsToUpdateJustified, - proposerScoreBoost, - depositChainId, - depositNetworkId, - depositContractAddress, - gossipMaxSize, - maxChunkSize, - maxRequestBlocks, - epochsPerSubnetSubscription, - minEpochsForBlockRequests, - ttfbTimeout, - respTimeout, - attestationPropagationSlotRange, - maximumGossipClockDisparity, - messageDomainInvalidSnappy, - messageDomainValidSnappy, - subnetsPerNode, - attestationSubnetCount, - attestationSubnetExtraBits, - attestationSubnetPrefixBits, - reorgMaxEpochsSinceFinalization, - reorgHeadWeightThreshold, - reorgParentWeightThreshold, - maxPerEpochActivationExitChurnLimit); + final SpecConfigAndParent config = + SpecConfigAndParent.of( + new SpecConfigPhase0( + rawConfig, + eth1FollowDistance, + maxCommitteesPerSlot, + targetCommitteeSize, + maxValidatorsPerCommittee, + minPerEpochChurnLimit, + churnLimitQuotient, + shuffleRoundCount, + minGenesisActiveValidatorCount, + minGenesisTime, + hysteresisQuotient, + hysteresisDownwardMultiplier, + hysteresisUpwardMultiplier, + proportionalSlashingMultiplier, + minDepositAmount, + maxEffectiveBalance, + ejectionBalance, + effectiveBalanceIncrement, + genesisForkVersion, + genesisDelay, + secondsPerSlot, + minAttestationInclusionDelay, + slotsPerEpoch, + minSeedLookahead, + maxSeedLookahead, + minEpochsToInactivityPenalty, + epochsPerEth1VotingPeriod, + slotsPerHistoricalRoot, + minValidatorWithdrawabilityDelay, + shardCommitteePeriod, + epochsPerHistoricalVector, + epochsPerSlashingsVector, + historicalRootsLimit, + validatorRegistryLimit, + baseRewardFactor, + whistleblowerRewardQuotient, + proposerRewardQuotient, + inactivityPenaltyQuotient, + minSlashingPenaltyQuotient, + maxProposerSlashings, + maxAttesterSlashings, + maxAttestations, + maxDeposits, + maxVoluntaryExits, + secondsPerEth1Block, + safeSlotsToUpdateJustified, + proposerScoreBoost, + depositChainId, + depositNetworkId, + depositContractAddress, + gossipMaxSize, + maxChunkSize, + maxRequestBlocks, + epochsPerSubnetSubscription, + minEpochsForBlockRequests, + ttfbTimeout, + respTimeout, + attestationPropagationSlotRange, + maximumGossipClockDisparity, + messageDomainInvalidSnappy, + messageDomainValidSnappy, + subnetsPerNode, + attestationSubnetCount, + attestationSubnetExtraBits, + attestationSubnetPrefixBits, + reorgMaxEpochsSinceFinalization, + reorgHeadWeightThreshold, + reorgParentWeightThreshold, + maxPerEpochActivationExitChurnLimit)); return builderChain.build(config); } diff --git a/ethereum/spec/src/main/java/tech/pegasys/teku/spec/schemas/SchemaDefinitionCache.java b/ethereum/spec/src/main/java/tech/pegasys/teku/spec/schemas/SchemaDefinitionCache.java index faff07cddf0..fa9b3050559 100644 --- a/ethereum/spec/src/main/java/tech/pegasys/teku/spec/schemas/SchemaDefinitionCache.java +++ b/ethereum/spec/src/main/java/tech/pegasys/teku/spec/schemas/SchemaDefinitionCache.java @@ -48,7 +48,9 @@ private SchemaDefinitions createSchemaDefinition(final SpecMilestone milestone) return specVersion.getSchemaDefinitions(); } return SpecVersion.create( - milestone, spec.getGenesisSpecConfig(), SchemaRegistryBuilder.create()) + milestone, + spec.getSpecConfigAndParent().forMilestone(milestone), + SchemaRegistryBuilder.create()) .orElseThrow( () -> new IllegalArgumentException( diff --git a/ethereum/spec/src/test/java/tech/pegasys/teku/spec/ForkScheduleTest.java b/ethereum/spec/src/test/java/tech/pegasys/teku/spec/ForkScheduleTest.java index ea4b0e548fc..235f4c29c09 100644 --- a/ethereum/spec/src/test/java/tech/pegasys/teku/spec/ForkScheduleTest.java +++ b/ethereum/spec/src/test/java/tech/pegasys/teku/spec/ForkScheduleTest.java @@ -29,7 +29,7 @@ public class ForkScheduleTest { private static final SpecConfig MINIMAL_CONFIG = - SpecConfigLoader.loadConfig(Eth2Network.MINIMAL.configName()); + SpecConfigLoader.loadConfig(Eth2Network.MINIMAL.configName()).specConfig(); // Set up config for a post-genesis altair transition private static final UInt64 FORK_EPOCH_ALTAIR = UInt64.valueOf(10); @@ -38,19 +38,21 @@ public class ForkScheduleTest { private static final SpecConfigAltair TRANSITION_CONFIG = SpecConfigAltair.required( SpecConfigLoader.loadConfig( - Eth2Network.MINIMAL.configName(), - c -> c.altairBuilder(a -> a.altairForkEpoch(FORK_EPOCH_ALTAIR)))); + Eth2Network.MINIMAL.configName(), + c -> c.altairBuilder(a -> a.altairForkEpoch(FORK_EPOCH_ALTAIR))) + .specConfig()); // Set config starting altair at genesis private static final SpecConfigAltair ALTAIR_CONFIG = SpecConfigAltair.required( SpecConfigLoader.loadConfig( - Eth2Network.MINIMAL.configName(), - c -> c.altairBuilder(a -> a.altairForkEpoch(UInt64.ZERO)))); + Eth2Network.MINIMAL.configName(), + c -> c.altairBuilder(a -> a.altairForkEpoch(UInt64.ZERO))) + .specConfig()); // Set up default config private static final SpecConfig PHASE0_CONFIG = - SpecConfigLoader.loadConfig(Eth2Network.MINIMAL.configName()); + SpecConfigLoader.loadConfig(Eth2Network.MINIMAL.configName()).specConfig(); // Fork versions static final Bytes4 PHASE_0_FORK_VERSION = TRANSITION_CONFIG.getGenesisForkVersion(); diff --git a/ethereum/spec/src/test/java/tech/pegasys/teku/spec/SpecMilestoneTest.java b/ethereum/spec/src/test/java/tech/pegasys/teku/spec/SpecMilestoneTest.java index 0fb4a59ea80..327795ae97d 100644 --- a/ethereum/spec/src/test/java/tech/pegasys/teku/spec/SpecMilestoneTest.java +++ b/ethereum/spec/src/test/java/tech/pegasys/teku/spec/SpecMilestoneTest.java @@ -21,6 +21,7 @@ import tech.pegasys.teku.infrastructure.unsigned.UInt64; import tech.pegasys.teku.spec.config.SpecConfig; import tech.pegasys.teku.spec.config.SpecConfigAltair; +import tech.pegasys.teku.spec.config.SpecConfigAndParent; import tech.pegasys.teku.spec.config.SpecConfigBellatrix; import tech.pegasys.teku.spec.config.SpecConfigCapella; import tech.pegasys.teku.spec.config.SpecConfigDeneb; @@ -30,17 +31,27 @@ public class SpecMilestoneTest { private final SpecConfigElectra electraSpecConfig = - SpecConfigElectra.required(SpecConfigLoader.loadConfig(Eth2Network.MINIMAL.configName())); + SpecConfigAndParent.requireElectra( + SpecConfigLoader.loadConfig(Eth2Network.MINIMAL.configName())) + .specConfig(); private final SpecConfigDeneb denebSpecConfig = - SpecConfigDeneb.required(SpecConfigLoader.loadConfig(Eth2Network.MINIMAL.configName())); + SpecConfigAndParent.requireDeneb( + SpecConfigLoader.loadConfig(Eth2Network.MINIMAL.configName())) + .specConfig(); private final SpecConfigCapella capellaSpecConfig = - SpecConfigCapella.required(SpecConfigLoader.loadConfig(Eth2Network.MINIMAL.configName())); + SpecConfigAndParent.requireCapella( + SpecConfigLoader.loadConfig(Eth2Network.MINIMAL.configName())) + .specConfig(); private final SpecConfigBellatrix bellatrixSpecConfig = - SpecConfigBellatrix.required(SpecConfigLoader.loadConfig(Eth2Network.MINIMAL.configName())); + SpecConfigAndParent.requireBellatrix( + SpecConfigLoader.loadConfig(Eth2Network.MINIMAL.configName())) + .specConfig(); private final SpecConfigAltair altairSpecConfig = - SpecConfigAltair.required(SpecConfigLoader.loadConfig(Eth2Network.MINIMAL.configName())); + SpecConfigAndParent.requireAltair( + SpecConfigLoader.loadConfig(Eth2Network.MINIMAL.configName())) + .specConfig(); private final SpecConfig phase0SpecConfig = - SpecConfigLoader.loadConfig(Eth2Network.MINIMAL.configName()); + SpecConfigLoader.loadConfig(Eth2Network.MINIMAL.configName()).specConfig(); @Test public void isGreaterThanOrEqualTo() { diff --git a/ethereum/spec/src/test/java/tech/pegasys/teku/spec/SpecVersionTest.java b/ethereum/spec/src/test/java/tech/pegasys/teku/spec/SpecVersionTest.java index d622f58989e..9d2e00b6b43 100644 --- a/ethereum/spec/src/test/java/tech/pegasys/teku/spec/SpecVersionTest.java +++ b/ethereum/spec/src/test/java/tech/pegasys/teku/spec/SpecVersionTest.java @@ -30,7 +30,7 @@ class SpecVersionTest { private final SpecConfig minimalConfig = - SpecConfigLoader.loadConfig(Eth2Network.MINIMAL.configName()); + SpecConfigLoader.loadConfig(Eth2Network.MINIMAL.configName()).specConfig(); @ParameterizedTest @EnumSource(SpecMilestone.class) diff --git a/ethereum/spec/src/test/java/tech/pegasys/teku/spec/config/SpecConfigAltairTest.java b/ethereum/spec/src/test/java/tech/pegasys/teku/spec/config/SpecConfigAltairTest.java index 1908784ba61..60b79debefa 100644 --- a/ethereum/spec/src/test/java/tech/pegasys/teku/spec/config/SpecConfigAltairTest.java +++ b/ethereum/spec/src/test/java/tech/pegasys/teku/spec/config/SpecConfigAltairTest.java @@ -26,9 +26,9 @@ public class SpecConfigAltairTest { @Test public void equals_mainnet() { SpecConfigAltair configA = - SpecConfigLoader.loadConfig("mainnet").toVersionAltair().orElseThrow(); + SpecConfigLoader.loadConfig("mainnet").specConfig().toVersionAltair().orElseThrow(); SpecConfigAltair configB = - SpecConfigLoader.loadConfig("mainnet").toVersionAltair().orElseThrow(); + SpecConfigLoader.loadConfig("mainnet").specConfig().toVersionAltair().orElseThrow(); assertThat(configA).isEqualTo(configB); assertThat(configA.hashCode()).isEqualTo(configB.hashCode()); @@ -36,7 +36,7 @@ public void equals_mainnet() { @Test public void equals_sameRandomValues() { - SpecConfig phase0 = SpecConfigLoader.loadConfig("mainnet"); + SpecConfig phase0 = SpecConfigLoader.loadConfig("mainnet").specConfig(); SpecConfigAltair configA = createRandomAltairConfig(phase0, 1); SpecConfigAltair configB = createRandomAltairConfig(phase0, 1); @@ -46,7 +46,7 @@ public void equals_sameRandomValues() { @Test public void equals_differentRandomValues() { - SpecConfig phase0 = SpecConfigLoader.loadConfig("mainnet"); + SpecConfig phase0 = SpecConfigLoader.loadConfig("mainnet").specConfig(); SpecConfigAltair configA = createRandomAltairConfig(phase0, 1); SpecConfigAltair configB = createRandomAltairConfig(phase0, 2); @@ -56,8 +56,9 @@ public void equals_differentRandomValues() { @Test public void equals_phase0ConfigDiffer() { - SpecConfig phase0A = SpecConfigLoader.loadConfig("swift", b -> {}); - SpecConfig phase0B = SpecConfigLoader.loadConfig("swift", b -> b.maxValidatorsPerCommittee(1)); + SpecConfig phase0A = SpecConfigLoader.loadConfig("swift", b -> {}).specConfig(); + SpecConfig phase0B = + SpecConfigLoader.loadConfig("swift", b -> b.maxValidatorsPerCommittee(1)).specConfig(); SpecConfigAltair configA = createRandomAltairConfig(phase0A, 1); SpecConfigAltair configB = createRandomAltairConfig(phase0B, 1); diff --git a/ethereum/spec/src/test/java/tech/pegasys/teku/spec/config/SpecConfigBellatrixTest.java b/ethereum/spec/src/test/java/tech/pegasys/teku/spec/config/SpecConfigBellatrixTest.java index 60136cc8731..ffaea8940b4 100644 --- a/ethereum/spec/src/test/java/tech/pegasys/teku/spec/config/SpecConfigBellatrixTest.java +++ b/ethereum/spec/src/test/java/tech/pegasys/teku/spec/config/SpecConfigBellatrixTest.java @@ -26,9 +26,9 @@ public class SpecConfigBellatrixTest { @Test public void equals_mainnet() { SpecConfigBellatrix configA = - SpecConfigLoader.loadConfig("mainnet").toVersionBellatrix().orElseThrow(); + SpecConfigLoader.loadConfig("mainnet").specConfig().toVersionBellatrix().orElseThrow(); SpecConfigBellatrix configB = - SpecConfigLoader.loadConfig("mainnet").toVersionBellatrix().orElseThrow(); + SpecConfigLoader.loadConfig("mainnet").specConfig().toVersionBellatrix().orElseThrow(); assertThat(configA).isEqualTo(configB); assertThat(configA.hashCode()).isEqualTo(configB.hashCode()); @@ -37,7 +37,7 @@ public void equals_mainnet() { @Test public void equals_sameRandomValues() { SpecConfigAltair altair = - SpecConfigLoader.loadConfig("mainnet").toVersionAltair().orElseThrow(); + SpecConfigLoader.loadConfig("mainnet").specConfig().toVersionAltair().orElseThrow(); SpecConfigBellatrix configA = createRandomBellatrixConfig(altair, 1); SpecConfigBellatrix configB = createRandomBellatrixConfig(altair, 1); @@ -48,7 +48,7 @@ public void equals_sameRandomValues() { @Test public void equals_differentRandomValues() { SpecConfigAltair altair = - SpecConfigLoader.loadConfig("mainnet").toVersionAltair().orElseThrow(); + SpecConfigLoader.loadConfig("mainnet").specConfig().toVersionAltair().orElseThrow(); SpecConfigBellatrix configA = createRandomBellatrixConfig(altair, 1); SpecConfigBellatrix configB = createRandomBellatrixConfig(altair, 2); @@ -59,12 +59,16 @@ public void equals_differentRandomValues() { @Test public void equals_altairConfigDiffer() { SpecConfigAltair altairA = - SpecConfigLoader.loadConfig("mainnet", b -> {}).toVersionAltair().orElseThrow(); + SpecConfigLoader.loadConfig("mainnet", b -> {}) + .specConfig() + .toVersionAltair() + .orElseThrow(); SpecConfigAltair altairB = SpecConfigLoader.loadConfig( "mainnet", b -> b.altairBuilder(ab -> ab.syncCommitteeSize(altairA.getSyncCommitteeSize() + 4))) + .specConfig() .toVersionAltair() .orElseThrow(); diff --git a/ethereum/spec/src/test/java/tech/pegasys/teku/spec/config/SpecConfigBuilderTest.java b/ethereum/spec/src/test/java/tech/pegasys/teku/spec/config/SpecConfigBuilderTest.java index 85e7800a290..45942b2a8e0 100644 --- a/ethereum/spec/src/test/java/tech/pegasys/teku/spec/config/SpecConfigBuilderTest.java +++ b/ethereum/spec/src/test/java/tech/pegasys/teku/spec/config/SpecConfigBuilderTest.java @@ -169,7 +169,8 @@ public void shouldLoadTerminalBlockHashActivationEpoch() { } private Spec getSpec(final Consumer consumer) { - final SpecConfig config = SpecConfigLoader.loadConfig("mainnet", consumer); + final SpecConfigAndParent config = + SpecConfigLoader.loadConfig("mainnet", consumer); return SpecFactory.create(config); } } diff --git a/ethereum/spec/src/test/java/tech/pegasys/teku/spec/config/SpecConfigCapellaTest.java b/ethereum/spec/src/test/java/tech/pegasys/teku/spec/config/SpecConfigCapellaTest.java index a95edb57a89..a996f5d4695 100644 --- a/ethereum/spec/src/test/java/tech/pegasys/teku/spec/config/SpecConfigCapellaTest.java +++ b/ethereum/spec/src/test/java/tech/pegasys/teku/spec/config/SpecConfigCapellaTest.java @@ -26,9 +26,9 @@ public class SpecConfigCapellaTest { @Test public void equals_mainnet() { SpecConfigCapella configA = - SpecConfigLoader.loadConfig("mainnet").toVersionCapella().orElseThrow(); + SpecConfigLoader.loadConfig("mainnet").specConfig().toVersionCapella().orElseThrow(); SpecConfigCapella configB = - SpecConfigLoader.loadConfig("mainnet").toVersionCapella().orElseThrow(); + SpecConfigLoader.loadConfig("mainnet").specConfig().toVersionCapella().orElseThrow(); assertThat(configA).isEqualTo(configB); assertThat(configA.hashCode()).isEqualTo(configB.hashCode()); @@ -37,7 +37,7 @@ public void equals_mainnet() { @Test public void equals_sameRandomValues() { SpecConfigBellatrix specConfigBellatrix = - SpecConfigLoader.loadConfig("mainnet").toVersionBellatrix().orElseThrow(); + SpecConfigLoader.loadConfig("mainnet").specConfig().toVersionBellatrix().orElseThrow(); ; SpecConfigBellatrix configA = createRandomCapellaConfig(specConfigBellatrix, 1); SpecConfigBellatrix configB = createRandomCapellaConfig(specConfigBellatrix, 1); @@ -49,7 +49,7 @@ public void equals_sameRandomValues() { @Test public void equals_differentRandomValues() { SpecConfigBellatrix specConfigBellatrix = - SpecConfigLoader.loadConfig("mainnet").toVersionBellatrix().orElseThrow(); + SpecConfigLoader.loadConfig("mainnet").specConfig().toVersionBellatrix().orElseThrow(); ; SpecConfigBellatrix configA = createRandomCapellaConfig(specConfigBellatrix, 1); SpecConfigBellatrix configB = createRandomCapellaConfig(specConfigBellatrix, 2); @@ -61,7 +61,7 @@ public void equals_differentRandomValues() { @Test public void equals_bellatrixConfigDiffer() { SpecConfigBellatrix bellatrixA = - SpecConfigLoader.loadConfig("mainnet").toVersionBellatrix().orElseThrow(); + SpecConfigLoader.loadConfig("mainnet").specConfig().toVersionBellatrix().orElseThrow(); SpecConfigBellatrix bellatrixB = SpecConfigLoader.loadConfig( "mainnet", @@ -69,6 +69,7 @@ public void equals_bellatrixConfigDiffer() { b.bellatrixBuilder( ab -> ab.maxBytesPerTransaction(bellatrixA.getMaxBytesPerTransaction() + 4))) + .specConfig() .toVersionBellatrix() .orElseThrow(); diff --git a/ethereum/spec/src/test/java/tech/pegasys/teku/spec/config/SpecConfigDenebTest.java b/ethereum/spec/src/test/java/tech/pegasys/teku/spec/config/SpecConfigDenebTest.java index 6e73567060c..481545ab9d8 100644 --- a/ethereum/spec/src/test/java/tech/pegasys/teku/spec/config/SpecConfigDenebTest.java +++ b/ethereum/spec/src/test/java/tech/pegasys/teku/spec/config/SpecConfigDenebTest.java @@ -26,8 +26,10 @@ public class SpecConfigDenebTest { @Test public void equals_mainnet() { - SpecConfigDeneb configA = SpecConfigLoader.loadConfig("mainnet").toVersionDeneb().orElseThrow(); - SpecConfigDeneb configB = SpecConfigLoader.loadConfig("mainnet").toVersionDeneb().orElseThrow(); + SpecConfigDeneb configA = + SpecConfigLoader.loadConfig("mainnet").specConfig().toVersionDeneb().orElseThrow(); + SpecConfigDeneb configB = + SpecConfigLoader.loadConfig("mainnet").specConfig().toVersionDeneb().orElseThrow(); assertThat(configA).isEqualTo(configB); assertThat(configA.hashCode()).isEqualTo(configB.hashCode()); @@ -36,7 +38,7 @@ public void equals_mainnet() { @Test public void equals_sameRandomValues() { SpecConfigCapella specConfigCapella = - SpecConfigLoader.loadConfig("mainnet").toVersionCapella().orElseThrow(); + SpecConfigLoader.loadConfig("mainnet").specConfig().toVersionCapella().orElseThrow(); SpecConfigDeneb configA = createRandomDenebConfig(specConfigCapella, 1); SpecConfigDeneb configB = createRandomDenebConfig(specConfigCapella, 1); @@ -47,7 +49,7 @@ public void equals_sameRandomValues() { @Test public void equals_differentRandomValues() { SpecConfigCapella specConfigCapella = - SpecConfigLoader.loadConfig("mainnet").toVersionCapella().orElseThrow(); + SpecConfigLoader.loadConfig("mainnet").specConfig().toVersionCapella().orElseThrow(); SpecConfigDeneb configA = createRandomDenebConfig(specConfigCapella, 1); SpecConfigDeneb configB = createRandomDenebConfig(specConfigCapella, 2); @@ -58,7 +60,7 @@ public void equals_differentRandomValues() { @Test public void equals_capellaConfigDiffer() { SpecConfigCapella capellaA = - SpecConfigLoader.loadConfig("mainnet").toVersionCapella().orElseThrow(); + SpecConfigLoader.loadConfig("mainnet").specConfig().toVersionCapella().orElseThrow(); SpecConfigCapella capellaB = SpecConfigLoader.loadConfig( "mainnet", @@ -67,6 +69,7 @@ public void equals_capellaConfigDiffer() { cb -> cb.maxWithdrawalsPerPayload( capellaA.getMaxWithdrawalsPerPayload() + 4))) + .specConfig() .toVersionCapella() .orElseThrow(); diff --git a/ethereum/spec/src/test/java/tech/pegasys/teku/spec/config/SpecConfigElectraTest.java b/ethereum/spec/src/test/java/tech/pegasys/teku/spec/config/SpecConfigElectraTest.java index 0691cc70fb9..42c14686a12 100644 --- a/ethereum/spec/src/test/java/tech/pegasys/teku/spec/config/SpecConfigElectraTest.java +++ b/ethereum/spec/src/test/java/tech/pegasys/teku/spec/config/SpecConfigElectraTest.java @@ -26,9 +26,9 @@ public class SpecConfigElectraTest { @Test public void equals_mainnet() { final SpecConfigElectra configA = - SpecConfigLoader.loadConfig("mainnet").toVersionElectra().orElseThrow(); + SpecConfigLoader.loadConfig("mainnet").specConfig().toVersionElectra().orElseThrow(); final SpecConfigElectra configB = - SpecConfigLoader.loadConfig("mainnet").toVersionElectra().orElseThrow(); + SpecConfigLoader.loadConfig("mainnet").specConfig().toVersionElectra().orElseThrow(); assertThat(configA).isEqualTo(configB); assertThat(configA.hashCode()).isEqualTo(configB.hashCode()); @@ -37,7 +37,7 @@ public void equals_mainnet() { @Test public void equals_sameRandomValues() { final SpecConfigDeneb specConfigDeneb = - SpecConfigLoader.loadConfig("mainnet").toVersionDeneb().orElseThrow(); + SpecConfigLoader.loadConfig("mainnet").specConfig().toVersionDeneb().orElseThrow(); final SpecConfigElectra configA = createRandomElectraConfig(specConfigDeneb, 1); final SpecConfigElectra configB = createRandomElectraConfig(specConfigDeneb, 1); @@ -48,7 +48,7 @@ public void equals_sameRandomValues() { @Test public void equals_differentRandomValues() { final SpecConfigDeneb specConfigDeneb = - SpecConfigLoader.loadConfig("mainnet").toVersionDeneb().orElseThrow(); + SpecConfigLoader.loadConfig("mainnet").specConfig().toVersionDeneb().orElseThrow(); final SpecConfigElectra configA = createRandomElectraConfig(specConfigDeneb, 1); final SpecConfigElectra configB = createRandomElectraConfig(specConfigDeneb, 2); @@ -59,11 +59,12 @@ public void equals_differentRandomValues() { @Test public void equals_denebConfigDiffer() { final SpecConfigDeneb denebA = - SpecConfigLoader.loadConfig("mainnet").toVersionDeneb().orElseThrow(); + SpecConfigLoader.loadConfig("mainnet").specConfig().toVersionDeneb().orElseThrow(); final SpecConfigDeneb denebB = SpecConfigLoader.loadConfig( "mainnet", b -> b.denebBuilder(db -> db.maxBlobsPerBlock(denebA.getMaxBlobsPerBlock() + 4))) + .specConfig() .toVersionDeneb() .orElseThrow(); diff --git a/ethereum/spec/src/test/java/tech/pegasys/teku/spec/config/SpecConfigLoaderTest.java b/ethereum/spec/src/test/java/tech/pegasys/teku/spec/config/SpecConfigLoaderTest.java index 6b5280a9e12..d790ef2ecf9 100644 --- a/ethereum/spec/src/test/java/tech/pegasys/teku/spec/config/SpecConfigLoaderTest.java +++ b/ethereum/spec/src/test/java/tech/pegasys/teku/spec/config/SpecConfigLoaderTest.java @@ -41,7 +41,7 @@ public class SpecConfigLoaderTest { @ParameterizedTest(name = "{0}") @EnumSource(Eth2Network.class) public void shouldLoadAllKnownNetworks(final Eth2Network network) throws Exception { - final SpecConfig config = SpecConfigLoader.loadConfigStrict(network.configName()); + final SpecConfig config = SpecConfigLoader.loadConfigStrict(network.configName()).specConfig(); // testing latest SpecConfig ensures all fields will be asserted on assertAllFieldsSet(config, SpecConfigElectra.class); } @@ -57,20 +57,20 @@ public void shouldLoadAllKnownNetworks(final Eth2Network network) throws Excepti @ParameterizedTest(name = "{0}") @ValueSource(strings = {"holesky", "mainnet"}) public void shouldMaintainConfigNameBackwardsCompatibility(final String name) { - final SpecConfig config = SpecConfigLoader.loadConfig(name); + final SpecConfig config = SpecConfigLoader.loadConfig(name).specConfig(); assertThat(config.getRawConfig().get("CONFIG_NAME")).isEqualTo(name); } @Test public void shouldLoadMainnet() throws Exception { - final SpecConfig config = SpecConfigLoader.loadConfig("mainnet"); + final SpecConfig config = SpecConfigLoader.loadConfig("mainnet").specConfig(); assertAllBellatrixFieldsSet(config); } @Test public void shouldLoadMainnetFromFileUrl() throws Exception { final URL url = getMainnetConfigResourceAsUrl(); - final SpecConfig config = SpecConfigLoader.loadConfig(url.toString()); + final SpecConfig config = SpecConfigLoader.loadConfig(url.toString()).specConfig(); assertAllBellatrixFieldsSet(config); } @@ -79,7 +79,8 @@ public void shouldLoadMainnetFromFile(@TempDir final Path tempDir) throws Except try (final InputStream inputStream = getMainnetConfigAsStream()) { final Path file = tempDir.resolve("mainnet.yml"); writeStreamToFile(inputStream, file); - final SpecConfig config = SpecConfigLoader.loadConfig(file.toAbsolutePath().toString()); + final SpecConfig config = + SpecConfigLoader.loadConfig(file.toAbsolutePath().toString()).specConfig(); assertAllBellatrixFieldsSet(config); } } @@ -90,7 +91,7 @@ void shouldLoadMainnetPreservingBackwardsCompatibilityWithRestApi(final String s throws Exception { try (final InputStream in = Resources.getResource(SpecConfigLoaderTest.class, specFilename).openStream()) { - final SpecConfig config = SpecConfigLoader.loadRemoteConfig(readJsonConfig(in)); + final SpecConfig config = SpecConfigLoader.loadRemoteConfig(readJsonConfig(in)).specConfig(); assertAllAltairFieldsSet(config); } } @@ -135,7 +136,8 @@ public void shouldHandleInvalidPresetValue_unknownPreset(@TempDir final Path tem @Test public void shouldBeAbleToOverridePresetValues() { final URL configUrl = SpecConfigLoaderTest.class.getResource("standard/with-overrides.yaml"); - final SpecConfig config = SpecConfigLoader.loadConfig(configUrl.toString(), false, __ -> {}); + final SpecConfig config = + SpecConfigLoader.loadConfig(configUrl.toString(), false, __ -> {}).specConfig(); assertThat(config).isNotNull(); assertThat(config.getMaxCommitteesPerSlot()).isEqualTo(12); // Mainnet preset is 64. } diff --git a/ethereum/spec/src/test/java/tech/pegasys/teku/spec/config/SpecConfigReaderTest.java b/ethereum/spec/src/test/java/tech/pegasys/teku/spec/config/SpecConfigReaderTest.java index aae9dfadf36..592102ab47c 100644 --- a/ethereum/spec/src/test/java/tech/pegasys/teku/spec/config/SpecConfigReaderTest.java +++ b/ethereum/spec/src/test/java/tech/pegasys/teku/spec/config/SpecConfigReaderTest.java @@ -68,7 +68,7 @@ void read_ignoringUnknownConstant() { processFileAsInputStream( getInvalidConfigPath("unknownField"), source -> reader.readAndApply(source, true)); - assertAllAltairFieldsSet(reader.build()); + assertAllAltairFieldsSet(reader.build().specConfig()); }) .doesNotThrowAnyException(); } diff --git a/ethereum/spec/src/test/java/tech/pegasys/teku/spec/datastructures/state/beaconstate/common/AbstractBeaconStateSchemaTest.java b/ethereum/spec/src/test/java/tech/pegasys/teku/spec/datastructures/state/beaconstate/common/AbstractBeaconStateSchemaTest.java index f83b19ee38c..015ac23ba02 100644 --- a/ethereum/spec/src/test/java/tech/pegasys/teku/spec/datastructures/state/beaconstate/common/AbstractBeaconStateSchemaTest.java +++ b/ethereum/spec/src/test/java/tech/pegasys/teku/spec/datastructures/state/beaconstate/common/AbstractBeaconStateSchemaTest.java @@ -70,18 +70,19 @@ void vectorLengthsTest() { @Test public void changeSpecConfigTest() { - final Spec standardSpec = TestSpecFactory.createMinimalPhase0(); + final Spec standardSpec = TestSpecFactory.createMinimal(genesisConfig.getMilestone()); final SpecConfig modifiedConfig = SpecConfigLoader.loadConfig( - "minimal", - b -> - b.slotsPerHistoricalRoot(123) - .historicalRootsLimit(123) - .epochsPerEth1VotingPeriod(123) - .validatorRegistryLimit(123L) - .epochsPerHistoricalVector(123) - .epochsPerSlashingsVector(123) - .maxAttestations(123)); + "minimal", + b -> + b.slotsPerHistoricalRoot(123) + .historicalRootsLimit(123) + .epochsPerEth1VotingPeriod(123) + .validatorRegistryLimit(123L) + .epochsPerHistoricalVector(123) + .epochsPerSlashingsVector(123) + .maxAttestations(123)) + .specConfig(); BeaconState s1 = getSchema(modifiedConfig).createEmpty(); BeaconState s2 = getSchema(standardSpec.getGenesisSpecConfig()).createEmpty(); @@ -109,9 +110,11 @@ void roundTripViaSsz() { @Test public void create_compareDifferentSpecs() { final BeaconStateSchema minimalState = - getSchema(TestSpecFactory.createMinimalPhase0().getGenesisSpecConfig()); + getSchema( + TestSpecFactory.createMinimal(genesisConfig.getMilestone()).getGenesisSpecConfig()); final BeaconStateSchema mainnetState = - getSchema(TestSpecFactory.createMainnetPhase0().getGenesisSpecConfig()); + getSchema( + TestSpecFactory.createMainnet(genesisConfig.getMilestone()).getGenesisSpecConfig()); assertThat(minimalState).isNotEqualTo(mainnetState); } diff --git a/ethereum/spec/src/test/java/tech/pegasys/teku/spec/datastructures/state/beaconstate/versions/altair/BeaconStateSchemaAltairTest.java b/ethereum/spec/src/test/java/tech/pegasys/teku/spec/datastructures/state/beaconstate/versions/altair/BeaconStateSchemaAltairTest.java index 1ed45ba5087..edfa58c135d 100644 --- a/ethereum/spec/src/test/java/tech/pegasys/teku/spec/datastructures/state/beaconstate/versions/altair/BeaconStateSchemaAltairTest.java +++ b/ethereum/spec/src/test/java/tech/pegasys/teku/spec/datastructures/state/beaconstate/versions/altair/BeaconStateSchemaAltairTest.java @@ -60,9 +60,9 @@ protected BeaconStateAltair randomState() { @Test public void changeSpecConfigTest_checkAltairFields() { - final Spec standardSpec = TestSpecFactory.createMinimalPhase0(); + final Spec standardSpec = TestSpecFactory.createMinimalAltair(); final SpecConfig modifiedConstants = - SpecConfigLoader.loadConfig("minimal", b -> b.validatorRegistryLimit(123L)); + SpecConfigLoader.loadConfig("minimal", b -> b.validatorRegistryLimit(123L)).specConfig(); BeaconStateAltair s1 = getSchema(modifiedConstants).createEmpty(); BeaconStateAltair s2 = getSchema(standardSpec.getGenesisSpecConfig()).createEmpty(); diff --git a/ethereum/spec/src/test/java/tech/pegasys/teku/spec/datastructures/state/beaconstate/versions/phase0/BeaconStateSchemaPhase0Test.java b/ethereum/spec/src/test/java/tech/pegasys/teku/spec/datastructures/state/beaconstate/versions/phase0/BeaconStateSchemaPhase0Test.java index 3c8834462a0..9d0897377c9 100644 --- a/ethereum/spec/src/test/java/tech/pegasys/teku/spec/datastructures/state/beaconstate/versions/phase0/BeaconStateSchemaPhase0Test.java +++ b/ethereum/spec/src/test/java/tech/pegasys/teku/spec/datastructures/state/beaconstate/versions/phase0/BeaconStateSchemaPhase0Test.java @@ -46,7 +46,7 @@ protected BeaconStatePhase0 randomState() { public void changeSpecConfigTest_checkPhase0Fields() { final Spec standardSpec = TestSpecFactory.createMinimalPhase0(); final SpecConfig modifiedConfig = - SpecConfigLoader.loadConfig("minimal", b -> b.maxAttestations(123)); + SpecConfigLoader.loadConfig("minimal", b -> b.maxAttestations(123)).specConfig(); BeaconStatePhase0 s1 = getSchema(modifiedConfig).createEmpty(); BeaconStatePhase0 s2 = getSchema(standardSpec.getGenesisSpecConfig()).createEmpty(); diff --git a/ethereum/spec/src/test/java/tech/pegasys/teku/spec/logic/common/util/ForkChoiceUtilTest.java b/ethereum/spec/src/test/java/tech/pegasys/teku/spec/logic/common/util/ForkChoiceUtilTest.java index f8da1efc1fd..ead209e70d0 100644 --- a/ethereum/spec/src/test/java/tech/pegasys/teku/spec/logic/common/util/ForkChoiceUtilTest.java +++ b/ethereum/spec/src/test/java/tech/pegasys/teku/spec/logic/common/util/ForkChoiceUtilTest.java @@ -35,6 +35,7 @@ import org.junit.jupiter.params.provider.MethodSource; 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.datastructures.blocks.BlockCheckpoints; import tech.pegasys.teku.spec.datastructures.blocks.SignedBeaconBlock; @@ -53,7 +54,7 @@ class ForkChoiceUtilTest { private static final UInt64 GENESIS_TIME = UInt64.valueOf("1591924193"); private static final UInt64 GENESIS_TIME_MILLIS = GENESIS_TIME.times(1000L); - private final Spec spec = TestSpecFactory.createMinimalPhase0(); + private final Spec spec = TestSpecFactory.createMinimalBellatrix(); private final DataStructureUtil dataStructureUtil = new DataStructureUtil(spec); private final RandomChainBuilder chainBuilder = new RandomChainBuilder(dataStructureUtil); private final RandomChainBuilderForkChoiceStrategy forkChoiceStrategy = @@ -396,7 +397,8 @@ private ReadOnlyStore mockStore( } private int getSafeSyncDistance() { - return spec.getGenesisSpecConfig() + return spec.forMilestone(SpecMilestone.BELLATRIX) + .getConfig() .toVersionBellatrix() .orElseThrow() .getSafeSlotsToImportOptimistically(); diff --git a/ethereum/spec/src/test/java/tech/pegasys/teku/spec/schemas/SchemaDefinitionCacheTest.java b/ethereum/spec/src/test/java/tech/pegasys/teku/spec/schemas/SchemaDefinitionCacheTest.java index 2eb238995fd..adf512454e3 100644 --- a/ethereum/spec/src/test/java/tech/pegasys/teku/spec/schemas/SchemaDefinitionCacheTest.java +++ b/ethereum/spec/src/test/java/tech/pegasys/teku/spec/schemas/SchemaDefinitionCacheTest.java @@ -40,6 +40,7 @@ import tech.pegasys.teku.spec.SpecMilestone; import tech.pegasys.teku.spec.TestSpecFactory; import tech.pegasys.teku.spec.config.SpecConfig; +import tech.pegasys.teku.spec.config.SpecConfigAndParent; import tech.pegasys.teku.spec.config.SpecConfigLoader; import tech.pegasys.teku.spec.networks.Eth2Network; import tech.pegasys.teku.spec.schemas.SchemaDefinitions.NonSchema; @@ -51,7 +52,8 @@ public class SchemaDefinitionCacheTest { @MethodSource("allNetworksWithAllMilestones") void shouldGetSchemasForAllMilestonesOnAllNetworks( final Eth2Network network, final SpecMilestone specMilestone) { - final SpecConfig specConfig = SpecConfigLoader.loadConfigStrict(network.configName()); + final SpecConfigAndParent specConfig = + SpecConfigLoader.loadConfigStrict(network.configName()); final Spec spec = SpecFactory.create(specConfig); final SchemaDefinitionCache cache = new SchemaDefinitionCache(spec); assertThat(cache.getSchemaDefinition(specMilestone)).isNotNull(); diff --git a/ethereum/spec/src/testFixtures/java/tech/pegasys/teku/spec/TestSpecFactory.java b/ethereum/spec/src/testFixtures/java/tech/pegasys/teku/spec/TestSpecFactory.java index fe146369334..c23068f50d4 100644 --- a/ethereum/spec/src/testFixtures/java/tech/pegasys/teku/spec/TestSpecFactory.java +++ b/ethereum/spec/src/testFixtures/java/tech/pegasys/teku/spec/TestSpecFactory.java @@ -18,6 +18,7 @@ import tech.pegasys.teku.infrastructure.unsigned.UInt64; import tech.pegasys.teku.spec.config.SpecConfig; import tech.pegasys.teku.spec.config.SpecConfigAltair; +import tech.pegasys.teku.spec.config.SpecConfigAndParent; import tech.pegasys.teku.spec.config.SpecConfigBellatrix; import tech.pegasys.teku.spec.config.SpecConfigCapella; import tech.pegasys.teku.spec.config.SpecConfigDeneb; @@ -33,7 +34,7 @@ public static Spec createDefault() { } public static Spec createDefault(final Consumer modifier) { - final SpecConfig config = + final SpecConfigAndParent config = SpecConfigLoader.loadConfig(Eth2Network.MINIMAL.configName(), modifier); return create(config, SpecMilestone.PHASE0); } @@ -67,49 +68,55 @@ public static Spec createMinimalWithAltairAndBellatrixForkEpoch( String.format( "Altair epoch %s must be less than bellatrix epoch %s", altairEpoch, bellatrixForkEpoch)); - final SpecConfigBellatrix config = + final SpecConfigAndParent specConfig = getBellatrixSpecConfig(Eth2Network.MINIMAL, altairEpoch, bellatrixForkEpoch); - return create(config, SpecMilestone.BELLATRIX); + return create(specConfig, SpecMilestone.BELLATRIX); } public static Spec createMinimalBellatrix() { - final SpecConfigBellatrix specConfig = getBellatrixSpecConfig(Eth2Network.MINIMAL); + final SpecConfigAndParent specConfig = + getBellatrixSpecConfig(Eth2Network.MINIMAL); return create(specConfig, SpecMilestone.BELLATRIX); } public static Spec createMinimalBellatrix(final Consumer configAdapter) { - final SpecConfigBellatrix specConfig = + final SpecConfigAndParent specConfig = getBellatrixSpecConfig(Eth2Network.MINIMAL, configAdapter); return create(specConfig, SpecMilestone.BELLATRIX); } public static Spec createMinimalAltair() { - final SpecConfigAltair specConfig = getAltairSpecConfig(Eth2Network.MINIMAL); + final SpecConfigAndParent specConfig = + getAltairSpecConfig(Eth2Network.MINIMAL); return create(specConfig, SpecMilestone.ALTAIR); } public static Spec createMinimalCapella() { - final SpecConfigCapella specConfig = getCapellaSpecConfig(Eth2Network.MINIMAL); + final SpecConfigAndParent specConfig = + getCapellaSpecConfig(Eth2Network.MINIMAL); return create(specConfig, SpecMilestone.CAPELLA); } public static Spec createMinimalDeneb() { - final SpecConfigDeneb specConfig = getDenebSpecConfig(Eth2Network.MINIMAL); + final SpecConfigAndParent specConfig = getDenebSpecConfig(Eth2Network.MINIMAL); return create(specConfig, SpecMilestone.DENEB); } public static Spec createMinimalDeneb(final Consumer configAdapter) { - final SpecConfigDeneb specConfig = getDenebSpecConfig(Eth2Network.MINIMAL, configAdapter); + final SpecConfigAndParent specConfig = + getDenebSpecConfig(Eth2Network.MINIMAL, configAdapter); return create(specConfig, SpecMilestone.DENEB); } public static Spec createMinimalElectra() { - final SpecConfigElectra specConfig = getElectraSpecConfig(Eth2Network.MINIMAL); + final SpecConfigAndParent specConfig = + getElectraSpecConfig(Eth2Network.MINIMAL); return create(specConfig, SpecMilestone.ELECTRA); } public static Spec createMinimalElectra(final Consumer configAdapter) { - final SpecConfigElectra specConfig = getElectraSpecConfig(Eth2Network.MINIMAL, configAdapter); + final SpecConfigAndParent specConfig = + getElectraSpecConfig(Eth2Network.MINIMAL, configAdapter); return create(specConfig, SpecMilestone.ELECTRA); } @@ -120,7 +127,8 @@ public static Spec createMinimalElectra(final Consumer config * @return A spec with phase0 and altair enabled, forking to altair at the given epoch */ public static Spec createMinimalWithAltairForkEpoch(final UInt64 altairForkEpoch) { - final SpecConfigAltair config = getAltairSpecConfig(Eth2Network.MINIMAL, altairForkEpoch); + final SpecConfigAndParent config = + getAltairSpecConfig(Eth2Network.MINIMAL, altairForkEpoch); return create(config, SpecMilestone.ALTAIR); } @@ -131,7 +139,7 @@ public static Spec createMinimalWithAltairForkEpoch(final UInt64 altairForkEpoch * @return A spec with altair and bellatrix enabled, forking to bellatrix at the given epoch */ public static Spec createMinimalWithBellatrixForkEpoch(final UInt64 bellatrixForkEpoch) { - final SpecConfigBellatrix config = + final SpecConfigAndParent config = getBellatrixSpecConfig(Eth2Network.MINIMAL, UInt64.ZERO, bellatrixForkEpoch); return create(config, SpecMilestone.BELLATRIX); } @@ -144,7 +152,8 @@ public static Spec createMinimalWithBellatrixForkEpoch(final UInt64 bellatrixFor * epoch */ public static Spec createMinimalWithCapellaForkEpoch(final UInt64 capellaForkEpoch) { - final SpecConfigCapella config = getCapellaSpecConfig(Eth2Network.MINIMAL, capellaForkEpoch); + final SpecConfigAndParent config = + getCapellaSpecConfig(Eth2Network.MINIMAL, capellaForkEpoch); return create(config, SpecMilestone.CAPELLA); } @@ -155,7 +164,7 @@ public static Spec createMinimalWithCapellaForkEpoch(final UInt64 capellaForkEpo * @return A spec with Deneb enabled, forking to Deneb at the given epoch */ public static Spec createMinimalWithDenebForkEpoch(final UInt64 denebForkEpoch) { - final SpecConfigDeneb config = + final SpecConfigAndParent config = getDenebSpecConfig(Eth2Network.MINIMAL, UInt64.ZERO, denebForkEpoch); return create(config, SpecMilestone.DENEB); } @@ -167,55 +176,61 @@ public static Spec createMinimalWithDenebForkEpoch(final UInt64 denebForkEpoch) * @return A spec with Electra enabled, forking to Electra at the given epoch */ public static Spec createMinimalWithElectraForkEpoch(final UInt64 electraForkEpoch) { - final SpecConfigElectra config = + final SpecConfigAndParent config = getElectraSpecConfig(Eth2Network.MINIMAL, UInt64.ZERO, UInt64.ZERO, electraForkEpoch); return create(config, SpecMilestone.ELECTRA); } public static Spec createMinimalPhase0() { - final SpecConfig specConfig = SpecConfigLoader.loadConfig(Eth2Network.MINIMAL.configName()); - return create(specConfig, SpecMilestone.PHASE0); + final SpecConfigAndParent configAndParent = + SpecConfigLoader.loadConfig(Eth2Network.MINIMAL.configName()); + return create(configAndParent, SpecMilestone.PHASE0); } public static Spec createMainnetPhase0() { - final SpecConfig specConfig = SpecConfigLoader.loadConfig(Eth2Network.MAINNET.configName()); - return create(specConfig, SpecMilestone.PHASE0); + final SpecConfigAndParent configAndParent = + SpecConfigLoader.loadConfig(Eth2Network.MAINNET.configName()); + return create(configAndParent, SpecMilestone.PHASE0); } public static Spec createMainnetBellatrix() { - final SpecConfigBellatrix specConfig = getBellatrixSpecConfig(Eth2Network.MAINNET); - return create(specConfig, SpecMilestone.BELLATRIX); + final SpecConfigAndParent configAndParent = + getBellatrixSpecConfig(Eth2Network.MAINNET); + return create(configAndParent, SpecMilestone.BELLATRIX); } public static Spec createMainnetAltair() { - final SpecConfigAltair specConfig = getAltairSpecConfig(Eth2Network.MAINNET); + final SpecConfigAndParent specConfig = + getAltairSpecConfig(Eth2Network.MAINNET); return create(specConfig, SpecMilestone.ALTAIR); } public static Spec createMainnetCapella() { - final SpecConfigCapella specConfig = getCapellaSpecConfig(Eth2Network.MAINNET); + final SpecConfigAndParent specConfig = + getCapellaSpecConfig(Eth2Network.MAINNET); return create(specConfig, SpecMilestone.CAPELLA); } public static Spec createMainnetDeneb() { - final SpecConfigDeneb specConfig = getDenebSpecConfig(Eth2Network.MAINNET); + final SpecConfigAndParent specConfig = getDenebSpecConfig(Eth2Network.MAINNET); return create(specConfig, SpecMilestone.DENEB); } public static Spec createMainnetElectra() { - final SpecConfigElectra specConfig = getElectraSpecConfig(Eth2Network.MAINNET); + final SpecConfigAndParent specConfig = + getElectraSpecConfig(Eth2Network.MAINNET); return create(specConfig, SpecMilestone.ELECTRA); } - public static Spec createPhase0(final SpecConfig config) { + public static Spec createPhase0(final SpecConfigAndParent config) { return create(config, SpecMilestone.PHASE0); } - public static Spec createAltair(final SpecConfig config) { + public static Spec createAltair(final SpecConfigAndParent config) { return create(config, SpecMilestone.ALTAIR); } - public static Spec createBellatrix(final SpecConfig config) { + public static Spec createBellatrix(final SpecConfigAndParent config) { return create(config, SpecMilestone.BELLATRIX); } @@ -264,27 +279,30 @@ public static Spec create( } public static Spec create( - final SpecConfig config, final SpecMilestone highestSupportedMilestone) { + final SpecConfigAndParent config, + final SpecMilestone highestSupportedMilestone) { return Spec.create(config, highestSupportedMilestone); } - private static SpecConfigAltair getAltairSpecConfig(final Eth2Network network) { + private static SpecConfigAndParent getAltairSpecConfig( + final Eth2Network network) { return getAltairSpecConfig(network, UInt64.ZERO); } - private static SpecConfigAltair getAltairSpecConfig( + private static SpecConfigAndParent getAltairSpecConfig( final Eth2Network network, final UInt64 altairForkEpoch) { - return SpecConfigAltair.required( + return SpecConfigAndParent.requireAltair( SpecConfigLoader.loadConfig( network.configName(), builder -> builder.altairBuilder(a -> a.altairForkEpoch(altairForkEpoch)))); } - private static SpecConfigBellatrix getBellatrixSpecConfig(final Eth2Network network) { + private static SpecConfigAndParent getBellatrixSpecConfig( + final Eth2Network network) { return getBellatrixSpecConfig(network, UInt64.ZERO, UInt64.ZERO); } - private static SpecConfigBellatrix getBellatrixSpecConfig( + private static SpecConfigAndParent getBellatrixSpecConfig( final Eth2Network network, final UInt64 altairForkEpoch, final UInt64 bellatrixForkEpoch) { return getBellatrixSpecConfig( network, @@ -294,9 +312,9 @@ private static SpecConfigBellatrix getBellatrixSpecConfig( .bellatrixBuilder(b -> b.bellatrixForkEpoch(bellatrixForkEpoch))); } - private static SpecConfigBellatrix getBellatrixSpecConfig( + private static SpecConfigAndParent getBellatrixSpecConfig( final Eth2Network network, final Consumer configAdapter) { - return SpecConfigBellatrix.required( + return SpecConfigAndParent.requireBellatrix( SpecConfigLoader.loadConfig( network.configName(), builder -> { @@ -307,11 +325,12 @@ private static SpecConfigBellatrix getBellatrixSpecConfig( })); } - private static SpecConfigCapella getCapellaSpecConfig(final Eth2Network network) { + private static SpecConfigAndParent getCapellaSpecConfig( + final Eth2Network network) { return getCapellaSpecConfig(network, UInt64.ZERO); } - private static SpecConfigCapella getCapellaSpecConfig( + private static SpecConfigAndParent getCapellaSpecConfig( final Eth2Network network, final UInt64 capellaForkEpoch) { return getCapellaSpecConfig( network, @@ -322,9 +341,9 @@ private static SpecConfigCapella getCapellaSpecConfig( .capellaBuilder(c -> c.capellaForkEpoch(capellaForkEpoch))); } - private static SpecConfigCapella getCapellaSpecConfig( + private static SpecConfigAndParent getCapellaSpecConfig( final Eth2Network network, final Consumer configAdapter) { - return SpecConfigCapella.required( + return SpecConfigAndParent.requireCapella( SpecConfigLoader.loadConfig( network.configName(), builder -> { @@ -336,11 +355,12 @@ private static SpecConfigCapella getCapellaSpecConfig( })); } - private static SpecConfigDeneb getDenebSpecConfig(final Eth2Network network) { + private static SpecConfigAndParent getDenebSpecConfig( + final Eth2Network network) { return getDenebSpecConfig(network, UInt64.ZERO, UInt64.ZERO); } - private static SpecConfigDeneb getDenebSpecConfig( + private static SpecConfigAndParent getDenebSpecConfig( final Eth2Network network, final UInt64 capellaForkEpoch, final UInt64 denebForkEpoch) { return getDenebSpecConfig( network, @@ -352,9 +372,9 @@ private static SpecConfigDeneb getDenebSpecConfig( .denebBuilder(d -> d.denebForkEpoch(denebForkEpoch))); } - private static SpecConfigDeneb getDenebSpecConfig( + private static SpecConfigAndParent getDenebSpecConfig( final Eth2Network network, final Consumer configAdapter) { - return SpecConfigDeneb.required( + return SpecConfigAndParent.requireDeneb( SpecConfigLoader.loadConfig( network.configName(), builder -> { @@ -367,11 +387,12 @@ private static SpecConfigDeneb getDenebSpecConfig( })); } - private static SpecConfigElectra getElectraSpecConfig(final Eth2Network network) { + private static SpecConfigAndParent getElectraSpecConfig( + final Eth2Network network) { return getElectraSpecConfig(network, UInt64.ZERO, UInt64.ZERO, UInt64.ZERO); } - private static SpecConfigElectra getElectraSpecConfig( + private static SpecConfigAndParent getElectraSpecConfig( final Eth2Network network, final UInt64 capellaForkEpoch, final UInt64 denebForkEpoch, @@ -387,9 +408,9 @@ private static SpecConfigElectra getElectraSpecConfig( .electraBuilder(e -> e.electraForkEpoch(electraForkEpoch))); } - private static SpecConfigElectra getElectraSpecConfig( + private static SpecConfigAndParent getElectraSpecConfig( final Eth2Network network, final Consumer configAdapter) { - return SpecConfigElectra.required( + return SpecConfigAndParent.requireElectra( SpecConfigLoader.loadConfig( network.configName(), builder -> { @@ -405,7 +426,7 @@ private static SpecConfigElectra getElectraSpecConfig( public static Spec createMinimalWithCapellaDenebAndElectraForkEpoch( final UInt64 capellaForkEpoch, final UInt64 denebForkEpoch, final UInt64 electraForkEpoch) { - final SpecConfigBellatrix config = + final SpecConfigAndParent config = getElectraSpecConfig( Eth2Network.MINIMAL, capellaForkEpoch, denebForkEpoch, electraForkEpoch); return create(config, SpecMilestone.ELECTRA); diff --git a/ethereum/statetransition/src/test/java/tech/pegasys/teku/statetransition/genesis/GenesisHandlerTest.java b/ethereum/statetransition/src/test/java/tech/pegasys/teku/statetransition/genesis/GenesisHandlerTest.java index c00bfe8dc17..78512bb67c4 100644 --- a/ethereum/statetransition/src/test/java/tech/pegasys/teku/statetransition/genesis/GenesisHandlerTest.java +++ b/ethereum/statetransition/src/test/java/tech/pegasys/teku/statetransition/genesis/GenesisHandlerTest.java @@ -32,6 +32,7 @@ import tech.pegasys.teku.spec.Spec; import tech.pegasys.teku.spec.TestSpecFactory; import tech.pegasys.teku.spec.config.SpecConfig; +import tech.pegasys.teku.spec.config.SpecConfigAndParent; import tech.pegasys.teku.spec.config.SpecConfigLoader; import tech.pegasys.teku.spec.datastructures.interop.MockStartDepositGenerator; import tech.pegasys.teku.spec.datastructures.operations.DepositData; @@ -42,7 +43,7 @@ public class GenesisHandlerTest { private static final List VALIDATOR_KEYS = BLSKeyGenerator.generateKeyPairs(3); - private final SpecConfig specConfig = + private final SpecConfigAndParent specConfig = SpecConfigLoader.loadConfig( "minimal", b -> b.minGenesisActiveValidatorCount(VALIDATOR_KEYS.size())); private final Spec spec = TestSpecFactory.createPhase0(specConfig); @@ -78,7 +79,7 @@ public void setup() { @Test public void onDepositsFromBlock_shouldInitializeGenesis() { - final UInt64 genesisTime = specConfig.getMinGenesisTime(); + final UInt64 genesisTime = specConfig.specConfig().getMinGenesisTime(); final int batchSize = initialDepositData.size() / 2; final DepositsFromBlockEvent event1 = diff --git a/ethereum/statetransition/src/test/java/tech/pegasys/teku/statetransition/synccommittee/SyncCommitteeContributionPoolTest.java b/ethereum/statetransition/src/test/java/tech/pegasys/teku/statetransition/synccommittee/SyncCommitteeContributionPoolTest.java index 331f1717a0f..63f05d2c2bf 100644 --- a/ethereum/statetransition/src/test/java/tech/pegasys/teku/statetransition/synccommittee/SyncCommitteeContributionPoolTest.java +++ b/ethereum/statetransition/src/test/java/tech/pegasys/teku/statetransition/synccommittee/SyncCommitteeContributionPoolTest.java @@ -32,6 +32,7 @@ import tech.pegasys.teku.infrastructure.async.SafeFuture; 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.config.SpecConfigAltair; import tech.pegasys.teku.spec.datastructures.blocks.blockbody.versions.altair.SyncAggregate; @@ -47,7 +48,8 @@ class SyncCommitteeContributionPoolTest { private final Spec spec = TestSpecFactory.createMinimalWithAltairForkEpoch(forkEpoch); private final UInt64 forkSlot = spec.computeStartSlotAtEpoch(forkEpoch); private final UInt64 altairSlot = forkSlot.plus(2); - private final SpecConfigAltair config = SpecConfigAltair.required(spec.getGenesisSpecConfig()); + private final SpecConfigAltair config = + SpecConfigAltair.required(spec.forMilestone(SpecMilestone.ALTAIR).getConfig()); private final DataStructureUtil dataStructureUtil = new DataStructureUtil(spec); @SuppressWarnings("unchecked") diff --git a/teku/src/main/java/tech/pegasys/teku/cli/subcommand/debug/PrettyPrintCommand.java b/teku/src/main/java/tech/pegasys/teku/cli/subcommand/debug/PrettyPrintCommand.java index 5e0d2467fd3..46de01d5577 100644 --- a/teku/src/main/java/tech/pegasys/teku/cli/subcommand/debug/PrettyPrintCommand.java +++ b/teku/src/main/java/tech/pegasys/teku/cli/subcommand/debug/PrettyPrintCommand.java @@ -97,7 +97,9 @@ public class PrettyPrintCommand implements Callable { public Integer call() throws IOException { final SpecVersion spec = SpecVersion.create( - milestone, SpecConfigLoader.loadConfig(network), SchemaRegistryBuilder.create()) + milestone, + SpecConfigLoader.loadConfig(network).specConfig(), + SchemaRegistryBuilder.create()) .orElseThrow(); final Bytes inputData; try (final InputStream in = openStream()) { diff --git a/teku/src/test/java/tech/pegasys/teku/cli/options/Eth2NetworkOptionsTest.java b/teku/src/test/java/tech/pegasys/teku/cli/options/Eth2NetworkOptionsTest.java index b90a05b603c..d90f2eb03e0 100644 --- a/teku/src/test/java/tech/pegasys/teku/cli/options/Eth2NetworkOptionsTest.java +++ b/teku/src/test/java/tech/pegasys/teku/cli/options/Eth2NetworkOptionsTest.java @@ -93,7 +93,8 @@ void shouldUseCustomSafeSlotsToImportOptimistically() { "256"); final Spec spec = config.eth2NetworkConfiguration().getSpec(); assertThat( - spec.getGenesisSpecConfig() + spec.forMilestone(SpecMilestone.BELLATRIX) + .getConfig() .toVersionBellatrix() .orElseThrow() .getSafeSlotsToImportOptimistically()) diff --git a/teku/src/test/java/tech/pegasys/teku/cli/subcommand/RemoteSpecLoaderTest.java b/teku/src/test/java/tech/pegasys/teku/cli/subcommand/RemoteSpecLoaderTest.java index c5a78b04542..a6818600c2c 100644 --- a/teku/src/test/java/tech/pegasys/teku/cli/subcommand/RemoteSpecLoaderTest.java +++ b/teku/src/test/java/tech/pegasys/teku/cli/subcommand/RemoteSpecLoaderTest.java @@ -70,7 +70,7 @@ void shouldDefaultNetworkConfigThatMovedFromConstants() throws IOException { final ObjectMapper objectMapper = new ObjectMapper(); TypeReference> typeReference = new TypeReference<>() {}; Map data = objectMapper.readValue(jsonConfig, typeReference); - final SpecConfig specConfig = SpecConfigLoader.loadRemoteConfig(data); + final SpecConfig specConfig = SpecConfigLoader.loadRemoteConfig(data).specConfig(); // Check values not assigned, using default values assertThat(specConfig.getGossipMaxSize()).isEqualTo(10485760); diff --git a/teku/src/test/java/tech/pegasys/teku/cli/subcommand/internal/validator/options/DepositOptionsTest.java b/teku/src/test/java/tech/pegasys/teku/cli/subcommand/internal/validator/options/DepositOptionsTest.java index 88626559ee6..adb7de8a4ad 100644 --- a/teku/src/test/java/tech/pegasys/teku/cli/subcommand/internal/validator/options/DepositOptionsTest.java +++ b/teku/src/test/java/tech/pegasys/teku/cli/subcommand/internal/validator/options/DepositOptionsTest.java @@ -158,8 +158,9 @@ public void shouldUseMaxEffectiveBalanceAsDefaultAmount() { final SpecConfig config = SpecConfigLoader.loadConfig( - Eth2Network.MAINNET.configName(), - builder -> builder.maxEffectiveBalance(expectedAmount)); + Eth2Network.MAINNET.configName(), + builder -> builder.maxEffectiveBalance(expectedAmount)) + .specConfig(); assertThat(depositOptions.getAmount(config)).isEqualTo(expectedAmount); } } diff --git a/validator/client/src/test/java/tech/pegasys/teku/validator/client/duties/synccommittee/SyncCommitteeAggregationDutyTest.java b/validator/client/src/test/java/tech/pegasys/teku/validator/client/duties/synccommittee/SyncCommitteeAggregationDutyTest.java index 45cca3f8b14..d580fc66506 100644 --- a/validator/client/src/test/java/tech/pegasys/teku/validator/client/duties/synccommittee/SyncCommitteeAggregationDutyTest.java +++ b/validator/client/src/test/java/tech/pegasys/teku/validator/client/duties/synccommittee/SyncCommitteeAggregationDutyTest.java @@ -42,7 +42,8 @@ import tech.pegasys.teku.infrastructure.unsigned.UInt64; import tech.pegasys.teku.spec.Spec; import tech.pegasys.teku.spec.TestSpecFactory; -import tech.pegasys.teku.spec.config.SpecConfig; +import tech.pegasys.teku.spec.config.SpecConfigAltair; +import tech.pegasys.teku.spec.config.SpecConfigAndParent; import tech.pegasys.teku.spec.config.SpecConfigLoader; import tech.pegasys.teku.spec.datastructures.operations.versions.altair.ContributionAndProof; import tech.pegasys.teku.spec.datastructures.operations.versions.altair.SignedContributionAndProof; @@ -104,15 +105,14 @@ void setUp() { assertThat(syncCommitteeUtil.isSyncCommitteeAggregator(aggregatorSignature)).isTrue(); } - private static SpecConfig createSpecConfig() { - return SpecConfigLoader.loadConfig( + private static SpecConfigAndParent createSpecConfig() { + return SpecConfigAndParent.requireAltair( + SpecConfigLoader.loadConfig( "minimal", modifier -> modifier.altairBuilder( altairModifier -> - altairModifier.altairForkEpoch(UInt64.ZERO).syncCommitteeSize(512))) - .toVersionAltair() - .orElseThrow(); + altairModifier.altairForkEpoch(UInt64.ZERO).syncCommitteeSize(512)))); } @Test