Skip to content

Commit

Permalink
Add CONFIG_NAME back into specs returned from REST API (Consensys#4054)
Browse files Browse the repository at this point in the history
  • Loading branch information
ajsutton committed Jun 3, 2021
1 parent 3918c3d commit c01044c
Show file tree
Hide file tree
Showing 6 changed files with 37 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -45,9 +45,11 @@
public class SpecConfigReader {
private static final Logger LOG = LogManager.getLogger();
private static final String PRESET_KEY = "PRESET_BASE";
private static final String CONFIG_NAME_KEY = "CONFIG_NAME";
private static final ImmutableSet<String> KEYS_TO_IGNORE =
ImmutableSet.of(
PRESET_KEY,
CONFIG_NAME_KEY,
// Unsupported, upcoming fork-related keys
"MERGE_FORK_VERSION",
"MERGE_FORK_EPOCH",
Expand Down Expand Up @@ -125,11 +127,18 @@ private String castPresetValue(final Object preset) {
public void loadFromMap(final Map<String, ?> rawValues) {
processSeenValues(rawValues);
final Map<String, Object> unprocessedConfig = new HashMap<>(rawValues);
final Map<String, Object> apiSpecConfig = new HashMap<>(rawValues);
// Remove any keys that we're ignoring
KEYS_TO_IGNORE.forEach(unprocessedConfig::remove);
KEYS_TO_IGNORE.forEach(
key -> {
unprocessedConfig.remove(key);
if (!key.equals(PRESET_KEY) && !key.equals(CONFIG_NAME_KEY)) {
apiSpecConfig.remove(key);
}
});

// Process phase0 config
configBuilder.rawConfig(unprocessedConfig);
configBuilder.rawConfig(apiSpecConfig);
streamConfigSetters(configBuilder.getClass())
.forEach(
setter -> {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
import org.junit.jupiter.params.ParameterizedTest;
import org.junit.jupiter.params.provider.Arguments;
import org.junit.jupiter.params.provider.MethodSource;
import org.junit.jupiter.params.provider.ValueSource;
import tech.pegasys.teku.spec.networks.Eth2Network;
import tech.pegasys.teku.util.config.Constants;

Expand All @@ -45,6 +46,21 @@ public void shouldLoadAllKnownNetworks(final String name, final Class<?> configT
assertAllFieldsSet(config, configType);
}

/**
* For the three networks supported by Infura, go the extra mile and ensure the CONFIG_NAME key is
* still included in the raw config which is exposed by the config/spec REST API.
*
* <p>Prior to Altair, Lighthouse required this field to be a known testnet name, mainnet or
* minimal. Post-Altair we will be able to remove this as the new PRESET_BASE key will be
* sufficient.
*/
@ParameterizedTest(name = "{0}")
@ValueSource(strings = {"prater", "pyrmont", "mainnet"})
public void shouldMaintainConfigNameBackwardsCompatibility(final String name) {
final SpecConfig config = SpecConfigLoader.loadConfig(name);
assertThat(config.getRawConfig().get("CONFIG_NAME")).isEqualTo(name);
}

@Test
public void shouldLoadMainnet() throws Exception {
final SpecConfig config = SpecConfigLoader.loadConfig("mainnet");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ class ConstantsReader {
private static final ImmutableList<String> FIELDS_TO_IGNORE =
ImmutableList.of(
PRESET_FIELD,
"CONFIG_NAME", // Legacy field
// Altair fields
"ALTAIR_FORK_VERSION",
"ALTAIR_FORK_EPOCH",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,9 @@
# Extends the mainnet preset
PRESET_BASE: 'mainnet'

# For backwards compatibility in the config/spec API
CONFIG_NAME: "mainnet"

# Genesis
# ---------------------------------------------------------------
# `2**14` (= 16,384)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
# Prater preset

# For backwards compatibility in the config/spec API
CONFIG_NAME: "prater"

# Misc
# ---------------------------------------------------------------
# 2**6 (= 64)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
# Pyrmont preset

# For backwards compatibility in the config/spec API
CONFIG_NAME: "pyrmont"

# Misc
# ---------------------------------------------------------------
# 2**6 (= 64)
Expand Down

0 comments on commit c01044c

Please sign in to comment.