Address 1559 config assumption (#2193)

* address assumption that if 1559 is enabled there is a london fork block config
fixes #2192

Signed-off-by: garyschulte <garyschulte@gmail.com>

* fix tests

Signed-off-by: garyschulte <garyschulte@gmail.com>

* spotless. bump

Signed-off-by: garyschulte <garyschulte@gmail.com>

Co-authored-by: Sally MacFarlane <sally.macfarlane@consensys.net>
pull/2224/head
garyschulte 4 years ago committed by GitHub
parent 0733a7d3bb
commit eaafaaaae8
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 23
      config/src/main/java/org/hyperledger/besu/config/GenesisConfigFile.java
  2. 5
      config/src/test/java/org/hyperledger/besu/config/GenesisConfigFileTest.java
  3. 3
      ethereum/core/src/main/java/org/hyperledger/besu/ethereum/mainnet/ProtocolScheduleBuilder.java

@ -18,6 +18,7 @@ import static java.nio.charset.StandardCharsets.UTF_8;
import static org.hyperledger.besu.config.JsonUtil.normalizeKeys;
import java.io.IOException;
import java.util.Arrays;
import java.util.Collections;
import java.util.List;
import java.util.Map;
@ -118,7 +119,7 @@ public class GenesisConfigFile {
}
public long getGasLimit() {
return parseLong("gasLimit", getRequiredString("gaslimit"));
return parseLong("gasLimit", getFirstRequiredString("gaslimit", "gastarget"));
}
public String getMixHash() {
@ -138,11 +139,21 @@ public class GenesisConfigFile {
}
private String getRequiredString(final String key) {
if (!configRoot.has(key)) {
throw new IllegalArgumentException(
String.format("Invalid genesis block configuration, missing value for '%s'", key));
}
return configRoot.get(key).asText();
return getFirstRequiredString(key);
}
private String getFirstRequiredString(final String... keys) {
List<String> keysList = Arrays.asList(keys);
return keysList.stream()
.filter(key -> configRoot.has(key))
.findFirst()
.map(key -> configRoot.get(key).asText())
.orElseThrow(
() ->
new IllegalArgumentException(
String.format(
"Invalid genesis block configuration, missing value for one of '%s'",
keysList)));
}
private long parseLong(final String name, final String value) {

@ -102,6 +102,11 @@ public class GenesisConfigFileTest {
assertThat(configWithProperty("gasLimit", "1000").getGasLimit()).isEqualTo(1000);
}
@Test
public void shouldGetGasTarget() {
assertThat(configWithProperty("gasTarget", "9999").getGasLimit()).isEqualTo(9999);
}
@Test
public void shouldRequireGasLimit() {
assertInvalidConfiguration(EMPTY_CONFIG::getGasLimit);

@ -248,7 +248,8 @@ public class ProtocolScheduleBuilder {
if (ExperimentalEIPs.eip1559Enabled) {
final Optional<TransactionPriceCalculator> transactionPriceCalculator =
Optional.of(TransactionPriceCalculator.eip1559());
final long eip1559Block = config.getEIP1559BlockNumber().getAsLong();
// if we do not have a 1559 block number, assume we are running pre-London config:
final long eip1559Block = config.getEIP1559BlockNumber().orElse(Long.MAX_VALUE);
builders.put(
eip1559Block,
new BuilderMapEntry(

Loading…
Cancel
Save