Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove ConstantsReader #4922

Merged
merged 2 commits into from
Feb 1, 2022
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -17,15 +17,12 @@
import static tech.pegasys.teku.infrastructure.unsigned.UInt64.ONE;
import static tech.pegasys.teku.infrastructure.unsigned.UInt64.ZERO;

import org.junit.jupiter.api.AfterAll;
import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.Test;
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.SpecConfigLoader;
import tech.pegasys.teku.util.config.Constants;

class Eth1VotingPeriodTest {

Expand Down Expand Up @@ -58,16 +55,6 @@ class Eth1VotingPeriodTest {
// Next Voting Period Start Time = 1408
// Next Voting Period Lower Bound = 1378

@BeforeAll
static void setConstants() {
Constants.SLOTS_PER_EPOCH = 6;
}

@AfterAll
static void restoreConstants() {
Constants.setConstants("minimal");
}

@Test
void checkTimeValues() {
assertThat(votingPeriod.getSpecRangeLowerBound(START_SLOT, GENESIS_TIME))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
import io.swagger.v3.oas.annotations.media.Schema;
import java.util.List;
import tech.pegasys.teku.infrastructure.unsigned.UInt64;
import tech.pegasys.teku.util.config.Constants;
import tech.pegasys.teku.spec.config.Constants;

public class ValidatorsRequest {
@Schema(type = "string", format = "uint64")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
import org.apache.tuweni.bytes.Bytes;
import tech.pegasys.teku.infrastructure.ssz.collections.SszBitlist;
import tech.pegasys.teku.infrastructure.ssz.schema.collections.SszBitlistSchema;
import tech.pegasys.teku.util.config.Constants;
import tech.pegasys.teku.spec.config.Constants;

public class SszBitlistDeserializer extends JsonDeserializer<SszBitlist> {
@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@
import tech.pegasys.teku.infrastructure.ssz.collections.SszMutableUInt64List;
import tech.pegasys.teku.spec.Spec;
import tech.pegasys.teku.spec.TestSpecFactory;
import tech.pegasys.teku.spec.config.Constants;
import tech.pegasys.teku.spec.datastructures.blocks.SignedBeaconBlock;
import tech.pegasys.teku.spec.datastructures.state.beaconstate.BeaconState;
import tech.pegasys.teku.spec.datastructures.state.beaconstate.MutableBeaconState;
Expand All @@ -55,7 +56,6 @@
import tech.pegasys.teku.statetransition.forkchoice.ForkChoiceNotifier;
import tech.pegasys.teku.storage.client.MemoryOnlyRecentChainData;
import tech.pegasys.teku.storage.client.RecentChainData;
import tech.pegasys.teku.util.config.Constants;
import tech.pegasys.teku.weaksubjectivity.WeakSubjectivityFactory;
import tech.pegasys.teku.weaksubjectivity.WeakSubjectivityValidator;

Expand Down Expand Up @@ -85,7 +85,7 @@ public class EpochTransitionBenchmark {

@Setup(Level.Trial)
public void init() throws Exception {
Constants.setConstants("mainnet");
Constants.setConstants(TestSpecFactory.createMainnetPhase0());
AbstractBlockProcessor.BLS_VERIFY_DEPOSIT = false;

String blocksFile =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
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.Constants;
import tech.pegasys.teku.spec.datastructures.blocks.SignedBeaconBlock;
import tech.pegasys.teku.spec.datastructures.interop.InteropStartupUtil;
import tech.pegasys.teku.spec.datastructures.state.Validator;
Expand All @@ -49,7 +50,6 @@
import tech.pegasys.teku.statetransition.forkchoice.ForkChoiceNotifier;
import tech.pegasys.teku.storage.client.MemoryOnlyRecentChainData;
import tech.pegasys.teku.storage.client.RecentChainData;
import tech.pegasys.teku.util.config.Constants;
import tech.pegasys.teku.weaksubjectivity.WeakSubjectivityFactory;
import tech.pegasys.teku.weaksubjectivity.WeakSubjectivityValidator;

Expand All @@ -62,7 +62,7 @@ public class ProfilingRun {
@Test
public void importBlocks() throws Exception {

Constants.setConstants("mainnet");
Constants.setConstants(TestSpecFactory.createMainnetPhase0());
AbstractBlockProcessor.BLS_VERIFY_DEPOSIT = false;

int validatorsCount = 32 * 1024;
Expand Down Expand Up @@ -143,7 +143,7 @@ public static void main(String[] args) throws Exception {
@Test
public void importBlocksMemProfiling() throws Exception {

Constants.setConstants("mainnet");
Constants.setConstants(TestSpecFactory.createMainnetPhase0());
AbstractBlockProcessor.BLS_VERIFY_DEPOSIT = false;

int validatorsCount = 32 * 1024;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,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.Constants;
import tech.pegasys.teku.spec.logic.common.helpers.MiscHelpers;
import tech.pegasys.teku.util.config.Constants;

@Fork(3)
@BenchmarkMode(Mode.SingleShotTime)
Expand All @@ -44,7 +44,7 @@ public class ShuffleBenchmark {
private final MiscHelpers miscHelpers = spec.atSlot(UInt64.ZERO).miscHelpers();

public ShuffleBenchmark() {
Constants.setConstants("mainnet");
Constants.setConstants(spec);
}

@Benchmark
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@
import tech.pegasys.teku.infrastructure.async.eventthread.InlineEventThread;
import tech.pegasys.teku.spec.Spec;
import tech.pegasys.teku.spec.TestSpecFactory;
import tech.pegasys.teku.spec.config.Constants;
import tech.pegasys.teku.spec.datastructures.blocks.SignedBeaconBlock;
import tech.pegasys.teku.spec.executionengine.ExecutionEngineChannel;
import tech.pegasys.teku.spec.logic.common.block.AbstractBlockProcessor;
Expand All @@ -46,7 +47,6 @@
import tech.pegasys.teku.statetransition.forkchoice.ForkChoiceNotifier;
import tech.pegasys.teku.storage.client.MemoryOnlyRecentChainData;
import tech.pegasys.teku.storage.client.RecentChainData;
import tech.pegasys.teku.util.config.Constants;
import tech.pegasys.teku.weaksubjectivity.WeakSubjectivityFactory;
import tech.pegasys.teku.weaksubjectivity.WeakSubjectivityValidator;

Expand All @@ -69,7 +69,7 @@ public abstract class TransitionBenchmark {

@Setup(Level.Trial)
public void init() throws Exception {
Constants.setConstants("mainnet");
Constants.setConstants(TestSpecFactory.createMainnetPhase0());
AbstractBlockProcessor.BLS_VERIFY_DEPOSIT = false;

String blocksFile =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
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.Constants;
import tech.pegasys.teku.spec.datastructures.blocks.SignedBeaconBlock;
import tech.pegasys.teku.spec.datastructures.blocks.StateAndBlockSummary;
import tech.pegasys.teku.spec.datastructures.operations.Attestation;
Expand All @@ -38,7 +39,6 @@
import tech.pegasys.teku.statetransition.BeaconChainUtil;
import tech.pegasys.teku.storage.client.MemoryOnlyRecentChainData;
import tech.pegasys.teku.storage.client.RecentChainData;
import tech.pegasys.teku.util.config.Constants;

/**
* Utility class for generating BLS keypairs and blocks files Test methods need to be run manually
Expand All @@ -49,7 +49,7 @@ public class Generator {
@Test
public void generateBlocks() throws Exception {
final Spec spec = TestSpecFactory.createMainnetAltair();
Constants.setConstants("mainnet");
Constants.setConstants(spec);

AbstractBlockProcessor.BLS_VERIFY_DEPOSIT = false;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,11 @@
import tech.pegasys.teku.bls.BLSPublicKey;
import tech.pegasys.teku.bls.BLSTestUtil;
import tech.pegasys.teku.infrastructure.unsigned.UInt64;
import tech.pegasys.teku.spec.TestSpecFactory;
import tech.pegasys.teku.spec.config.Constants;
import tech.pegasys.teku.spec.datastructures.state.Validator;
import tech.pegasys.teku.spec.datastructures.state.beaconstate.BeaconState;
import tech.pegasys.teku.spec.util.DataStructureUtil;
import tech.pegasys.teku.util.config.Constants;

@State(Scope.Thread)
public class BeaconStateBenchmark {
Expand All @@ -37,7 +38,7 @@ public class BeaconStateBenchmark {
private static final BeaconState beaconState = dataStructureUtil.randomBeaconState(32 * 1024);

public BeaconStateBenchmark() {
Constants.setConstants("mainnet");
Constants.setConstants(TestSpecFactory.createMainnetPhase0());
}

@Benchmark
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@
import tech.pegasys.teku.reference.phase0.ssz_generic.SszGenericTests;
import tech.pegasys.teku.reference.phase0.ssz_static.SszTestExecutor;
import tech.pegasys.teku.reference.phase0.ssz_static.SszTestExecutorDeprecated;
import tech.pegasys.teku.util.config.Constants;
import tech.pegasys.teku.spec.config.Constants;
import tech.pegasys.teku.util.config.SpecDependent;

public abstract class Eth2ReferenceTestCase {
Expand Down Expand Up @@ -72,17 +72,11 @@ public abstract class Eth2ReferenceTestCase {
.build();

protected void runReferenceTest(final TestDefinition testDefinition) throws Throwable {
setConstants(testDefinition.getConfigName());
Constants.setConstants(testDefinition.getSpec());
SpecDependent.resetAll();
getExecutorFor(testDefinition).runTest(testDefinition);
}

private void setConstants(final String spec) {
if (!spec.equals("general") && !spec.equals("bls")) {
Constants.setConstants(spec);
SpecDependent.resetAll();
}
}

private TestExecutor getExecutorFor(final TestDefinition testDefinition) {
TestExecutor testExecutor = null;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,18 +11,15 @@
* specific language governing permissions and limitations under the License.
*/

package tech.pegasys.teku.util.config;
package tech.pegasys.teku.spec.config;

import com.google.common.collect.ImmutableList;
import java.time.Duration;
import tech.pegasys.teku.infrastructure.unsigned.UInt64;
import tech.pegasys.teku.spec.Spec;
import tech.pegasys.teku.util.config.SpecDependent;

public class Constants {

public static final ImmutableList<String> NETWORK_DEFINITIONS =
ImmutableList.of(
"mainnet", "minimal", "swift", "pyrmont", "prater", "kintsugi", "less-swift");

@Deprecated public static int MAX_VALIDATORS_PER_COMMITTEE;

@Deprecated public static int SLOTS_PER_EPOCH;
Expand All @@ -46,7 +43,6 @@ public class Constants {
public static final int VALID_CONTRIBUTION_AND_PROOF_SET_SIZE = 10000;
public static final int VALID_SYNC_COMMITTEE_MESSAGE_SET_SIZE = 10000;

public static final double TIME_TICKER_REFRESH_RATE = 2; // per sec
public static final Duration ETH1_INDIVIDUAL_BLOCK_RETRY_TIMEOUT = Duration.ofMillis(500);
public static final Duration ETH1_DEPOSIT_REQUEST_RETRY_TIMEOUT = Duration.ofSeconds(2);
public static final Duration ETH1_ENDPOINT_MONITOR_SERVICE_POLL_INTERVAL = Duration.ofSeconds(10);
Expand All @@ -72,16 +68,27 @@ public class Constants {
public static final Duration GENESIS_DATA_RETRY_DELAY = Duration.ofSeconds(10);

static {
setConstants("minimal");
setConstants(SpecConfigLoader.loadConfig("minimal"));
}

/**
* @deprecated Use tech.pegasys.teku.spec.constants.SpecConfig
* @param spec The spec from which to load constants
*/
@Deprecated
public static void setConstants(final Spec spec) {
setConstants(spec.getGenesisSpecConfig());
}

/**
* @deprecated Use tech.pegasys.teku.spec.constants.SpecConfig
* @param source The source from which to load constants
* @param config The config from which to load constants
*/
@Deprecated
public static void setConstants(final String source) {
ConstantsReader.loadConstantsFrom(source);
public static void setConstants(final SpecConfig config) {
MAX_VALIDATORS_PER_COMMITTEE = config.getMaxValidatorsPerCommittee();
SLOTS_PER_EPOCH = config.getSlotsPerEpoch();
SLOTS_PER_HISTORICAL_ROOT = config.getSlotsPerHistoricalRoot();
SpecDependent.resetAll();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@
import tech.pegasys.teku.infrastructure.io.resource.ResourceLoader;
import tech.pegasys.teku.spec.networks.Eth2Network;
import tech.pegasys.teku.spec.networks.Eth2Presets;
import tech.pegasys.teku.util.config.Constants;

public class SpecConfigLoader {
private static final String CONFIG_PATH = "configs/";
Expand Down Expand Up @@ -122,17 +121,15 @@ private static Optional<InputStream> loadBellatrixPreset(final String preset) th
}

private static ResourceLoader getConfigLoader() {
// TODO(#3394) - move Constants resources from util to this module
return ResourceLoader.classpathUrlOrFile(
Constants.class,
SpecConfig.class,
enumerateAvailableConfigResources(),
s -> s.endsWith(".yaml") || s.endsWith(".yml"));
}

private static ResourceLoader getPresetLoader() {
// TODO(#3394) - move Constants resources from util to this module
return ResourceLoader.classpathUrlOrFile(
Constants.class,
SpecConfig.class,
enumerateAvailablePresetResources(),
s -> s.endsWith(".yaml") || s.endsWith(".yml"));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@

package tech.pegasys.teku.spec.datastructures.networking.libp2p.rpc;

import static tech.pegasys.teku.util.config.Constants.MAX_REQUEST_BLOCKS;
import static tech.pegasys.teku.spec.config.Constants.MAX_REQUEST_BLOCKS;

import java.util.List;
import java.util.stream.Collectors;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,9 @@
import tech.pegasys.teku.infrastructure.ssz.schema.collections.SszBitvectorSchema;
import tech.pegasys.teku.infrastructure.ssz.tree.TreeNode;
import tech.pegasys.teku.infrastructure.unsigned.UInt64;
import tech.pegasys.teku.spec.config.Constants;
import tech.pegasys.teku.spec.constants.NetworkConstants;
import tech.pegasys.teku.spec.datastructures.networking.libp2p.rpc.metadata.MetadataMessageSchema;
import tech.pegasys.teku.util.config.Constants;

public class MetadataMessageSchemaAltair
extends ContainerSchema3<MetadataMessageAltair, SszUInt64, SszBitvector, SszBitvector>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,8 @@
import tech.pegasys.teku.infrastructure.ssz.schema.collections.SszBitvectorSchema;
import tech.pegasys.teku.infrastructure.ssz.tree.TreeNode;
import tech.pegasys.teku.infrastructure.unsigned.UInt64;
import tech.pegasys.teku.spec.config.Constants;
import tech.pegasys.teku.spec.datastructures.networking.libp2p.rpc.metadata.MetadataMessageSchema;
import tech.pegasys.teku.util.config.Constants;

public class MetadataMessageSchemaPhase0
extends ContainerSchema2<MetadataMessagePhase0, SszUInt64, SszBitvector>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,9 @@
import tech.pegasys.teku.infrastructure.ssz.tree.TreeNode;
import tech.pegasys.teku.infrastructure.unsigned.UInt64;
import tech.pegasys.teku.spec.Spec;
import tech.pegasys.teku.spec.config.Constants;
import tech.pegasys.teku.spec.datastructures.type.SszSignature;
import tech.pegasys.teku.spec.datastructures.type.SszSignatureSchema;
import tech.pegasys.teku.util.config.Constants;

public class Attestation
extends Container3<Attestation, SszBitlist, AttestationData, SszSignature> {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,9 @@
import tech.pegasys.teku.infrastructure.ssz.containers.ContainerSchema3;
import tech.pegasys.teku.infrastructure.ssz.schema.collections.SszUInt64ListSchema;
import tech.pegasys.teku.infrastructure.ssz.tree.TreeNode;
import tech.pegasys.teku.spec.config.Constants;
import tech.pegasys.teku.spec.datastructures.type.SszSignature;
import tech.pegasys.teku.spec.datastructures.type.SszSignatureSchema;
import tech.pegasys.teku.util.config.Constants;

public class IndexedAttestation
extends Container3<IndexedAttestation, SszUInt64List, AttestationData, SszSignature> {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
import tech.pegasys.teku.infrastructure.ssz.containers.ContainerSchema2;
import tech.pegasys.teku.infrastructure.ssz.schema.collections.SszBytes32VectorSchema;
import tech.pegasys.teku.infrastructure.ssz.tree.TreeNode;
import tech.pegasys.teku.util.config.Constants;
import tech.pegasys.teku.spec.config.Constants;
import tech.pegasys.teku.util.config.SpecDependent;

public class HistoricalBatch
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,8 @@
import tech.pegasys.teku.infrastructure.ssz.schema.collections.SszBitlistSchema;
import tech.pegasys.teku.infrastructure.ssz.tree.TreeNode;
import tech.pegasys.teku.infrastructure.unsigned.UInt64;
import tech.pegasys.teku.spec.config.Constants;
import tech.pegasys.teku.spec.datastructures.operations.AttestationData;
import tech.pegasys.teku.util.config.Constants;

public class PendingAttestation
extends Container4<PendingAttestation, SszBitlist, AttestationData, SszUInt64, SszUInt64> {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
package tech.pegasys.teku.spec.logic.common.util;

import static java.util.stream.Collectors.toUnmodifiableList;
import static tech.pegasys.teku.util.config.Constants.ATTESTATION_SUBNET_COUNT;
import static tech.pegasys.teku.spec.config.Constants.ATTESTATION_SUBNET_COUNT;

import java.util.List;
import java.util.stream.Stream;
Expand Down
Loading