add support for 1559 in retesteth besu command (#2181)

Signed-off-by: garyschulte <garyschulte@gmail.com>
pull/2143/head
garyschulte 4 years ago committed by GitHub
parent d7edb37c39
commit 089bfabd9c
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 10
      config/src/main/java/org/hyperledger/besu/config/GenesisConfigOptions.java
  2. 3
      config/src/main/java/org/hyperledger/besu/config/experimental/ExperimentalEIPs.java
  3. 15
      config/src/test/java/org/hyperledger/besu/config/GenesisConfigOptionsTest.java
  4. 1
      ethereum/core/src/main/java/org/hyperledger/besu/ethereum/chain/GenesisState.java
  5. 15
      ethereum/retesteth/src/main/java/org/hyperledger/besu/ethereum/retesteth/methods/TestSetChainParams.java
  6. 28
      ethereum/retesteth/src/test/java/org/hyperledger/besu/ethereum/retesteth/methods/TestSetChainParamsTest.java
  7. 21
      ethereum/retesteth/src/test/resources/org/hyperledger/besu/ethereum/retesteth/methods/1559ChainParams.json

@ -14,6 +14,8 @@
*/
package org.hyperledger.besu.config;
import org.hyperledger.besu.config.experimental.ExperimentalEIPs;
import java.math.BigInteger;
import java.util.List;
import java.util.Map;
@ -70,6 +72,14 @@ public interface GenesisConfigOptions {
// TODO EIP-1559 change for the actual fork name when known
OptionalLong getEIP1559BlockNumber();
default Optional<Long> getGenesisBaseFee() {
return getEIP1559BlockNumber().stream()
.boxed()
.filter(g -> g.equals(0L))
.map(g -> ExperimentalEIPs.initialBasefee)
.findAny();
}
List<Long> getForks();
/**

@ -23,6 +23,7 @@ import picocli.CommandLine.Option;
public class ExperimentalEIPs {
// To make it easier for tests to reset the value to default
public static final boolean EIP1559_ENABLED_DEFAULT_VALUE = false;
public static final long EIP1559_BASEFEE_DEFAULT_VALUE = 1000000000L;
@Option(
hidden = true,
@ -47,7 +48,7 @@ public class ExperimentalEIPs {
hidden = true,
names = {"--Xeip1559-initial-base-fee"},
arity = "1")
public static Long initialBasefee = 1000000000L;
public static Long initialBasefee = EIP1559_BASEFEE_DEFAULT_VALUE;
@Option(
hidden = true,

@ -193,6 +193,21 @@ public class GenesisConfigOptionsTest {
ExperimentalEIPs.eip1559Enabled = true;
final GenesisConfigOptions config = fromConfigOptions(singletonMap("aleutblock", 1000));
assertThat(config.getEIP1559BlockNumber()).hasValue(1000);
assertThat(config.getGenesisBaseFee()).isEmpty();
} finally {
ExperimentalEIPs.eip1559Enabled = ExperimentalEIPs.EIP1559_ENABLED_DEFAULT_VALUE;
}
}
@Test
// TODO EIP-1559 change for the actual fork name when known
public void shouldGetEIP1559BaseFeeAtGenesis() {
try {
ExperimentalEIPs.eip1559Enabled = true;
final GenesisConfigOptions config = fromConfigOptions(singletonMap("aleutblock", 0));
assertThat(config.getEIP1559BlockNumber()).hasValue(0);
assertThat(config.getGenesisBaseFee())
.hasValue(ExperimentalEIPs.EIP1559_BASEFEE_DEFAULT_VALUE);
} finally {
ExperimentalEIPs.eip1559Enabled = ExperimentalEIPs.EIP1559_ENABLED_DEFAULT_VALUE;
}

@ -156,6 +156,7 @@ public final class GenesisState {
.mixHash(parseMixHash(genesis))
.nonce(parseNonce(genesis))
.blockHeaderFunctions(ScheduleBasedBlockHeaderFunctions.create(protocolSchedule))
.baseFee(genesis.getConfigOptions().getGenesisBaseFee().orElse(null))
.buildBlockHeader();
}

@ -14,6 +14,7 @@
*/
package org.hyperledger.besu.ethereum.retesteth.methods;
import org.hyperledger.besu.config.experimental.ExperimentalEIPs;
import org.hyperledger.besu.ethereum.api.jsonrpc.internal.JsonRpcRequestContext;
import org.hyperledger.besu.ethereum.api.jsonrpc.internal.methods.JsonRpcMethod;
import org.hyperledger.besu.ethereum.api.jsonrpc.internal.response.JsonRpcError;
@ -123,6 +124,7 @@ public class TestSetChainParams implements JsonRpcMethod {
maybeMoveToNumber(params, "muirGlacierForkBlock", config, "muirGlacierBlock");
maybeMoveToNumber(params, "berlinForkBlock", config, "berlinBlock");
maybeMoveToNumber(params, "chainID", config, "chainId", 1);
maybeMove(genesis, "author", chainParamsJson, "coinbase");
maybeMove(genesis, "difficulty", chainParamsJson, "difficulty");
maybeMove(genesis, "extraData", chainParamsJson, "extraData");
@ -132,6 +134,19 @@ public class TestSetChainParams implements JsonRpcMethod {
maybeMove(genesis, "timestamp", chainParamsJson, "timestamp");
maybeMove(chainParamsJson, "accounts", chainParamsJson, "alloc");
if (ExperimentalEIPs.eip1559Enabled) {
// TODO EIP-1559 change for the actual fork name when known
maybeMoveToNumber(params, "londonForkBlock", config, "aleutBlock");
ExperimentalEIPs.initialBasefee =
Optional.ofNullable(
chainParamsJson
.getJsonObject("genesis", new JsonObject())
.getString("baseFeePerGas"))
.map(Long::decode)
.orElse(ExperimentalEIPs.EIP1559_BASEFEE_DEFAULT_VALUE);
maybeMove(genesis, "gasTarget", chainParamsJson, "gasLimit");
}
// strip out precompiles with zero balance
final JsonObject alloc = chainParamsJson.getJsonObject("alloc");
final Iterator<String> fieldNamesIter = alloc.fieldNames().iterator();

@ -16,6 +16,7 @@ package org.hyperledger.besu.ethereum.retesteth.methods;
import static org.assertj.core.api.Assertions.assertThat;
import org.hyperledger.besu.config.experimental.ExperimentalEIPs;
import org.hyperledger.besu.ethereum.api.jsonrpc.internal.JsonRpcRequest;
import org.hyperledger.besu.ethereum.api.jsonrpc.internal.JsonRpcRequestContext;
import org.hyperledger.besu.ethereum.api.jsonrpc.internal.response.JsonRpcSuccessResponse;
@ -85,4 +86,31 @@ public class TestSetChainParamsTest {
assertThat(blockHeader.getOmmersHash().toString())
.isEqualTo("0x1dcc4de8dec75d7aab85b567b6ccd41ad312451b948a7413f0a142fd40d49347");
}
@Test
public void testValidate1559GenesisImport() throws IOException {
ExperimentalEIPs.eip1559Enabled = true;
final String chainParamsJsonString =
Resources.toString(
TestSetChainParamsTest.class.getResource("1559ChainParams.json"), Charsets.UTF_8);
final JsonObject chainParamsJson = new JsonObject(chainParamsJsonString);
final JsonRpcRequestContext request =
new JsonRpcRequestContext(
new JsonRpcRequest(
"2.0", TestSetChainParams.METHOD_NAME, new Object[] {chainParamsJson.getMap()}));
assertThat(test_setChainParams.response(request))
.isEqualTo(new JsonRpcSuccessResponse(null, true));
final BlockHeader blockHeader = context.getBlockHeader(0);
assertThat(blockHeader.getDifficulty()).isEqualTo(UInt256.fromHexString("0x20000"));
assertThat(blockHeader.getGasLimit()).isEqualTo(1234L);
assertThat(blockHeader.getBaseFee()).hasValue(12345L);
assertThat(blockHeader.getExtraData().toHexString()).isEqualTo("0x00");
assertThat(blockHeader.getTimestamp()).isEqualTo(0l);
assertThat(blockHeader.getNonce()).isEqualTo(0L);
assertThat(blockHeader.getMixHash().toHexString())
.isEqualTo("0x0000000000000000000000000000000000000000000000000000000000000000");
}
}

@ -0,0 +1,21 @@
{
"genesis" : {
"author" : "0x2adc25665018aa1fe0e6bc666dac8fc2697ff9ba",
"difficulty" : "0x020000",
"gasTarget" : "0x04d2",
"baseFeePerGas" : "0x3039",
"extraData" : "0x00",
"timestamp" : "0x00",
"nonce" : "0x0000000000000000",
"mixHash" : "0x0000000000000000000000000000000000000000000000000000000000000000"
},
"params": {
"EIP150ForkBlock": "0x00",
"EIP158ForkBlock": "0x00",
"byzantiumForkBlock": "0x00",
"homesteadForkBlock": "0x00",
"londonForkBlock": "0x00"
},
"sealEngine": "NoProof",
"accounts": {}
}
Loading…
Cancel
Save