added genesis config option ecip1017EraRounds for Ethereum Classic chains (#1329)

* addded genesis config option getEcip1017EraRounds

to define the number of Rounds in an Era for Ethereum Classic Emission
Schedule.

Signed-off-by: Edward Mack <ed@edwardmack.com>

* add entry to CHANGLOG.mg

Signed-off-by: Edward Mack <ed@edwardmack.com>

* some doc changes and implemented style suggestions

Signed-off-by: Edward Mack <ed@edwardmack.com>
pull/1341/head
Edward Mack 4 years ago committed by GitHub
parent 210c85c82e
commit 6684a5b843
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 1
      CHANGELOG.md
  2. 12
      config/src/main/java/org/hyperledger/besu/config/GenesisConfigOptions.java
  3. 7
      config/src/main/java/org/hyperledger/besu/config/JsonGenesisConfigOptions.java
  4. 6
      config/src/main/java/org/hyperledger/besu/config/StubGenesisConfigOptions.java
  5. 1
      config/src/main/resources/mordor.json
  6. 1
      config/src/test/java/org/hyperledger/besu/config/GenesisConfigFileTest.java
  7. 6
      ethereum/api/src/test/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/results/tracing/flat/RewardTraceGeneratorTest.java
  8. 13
      ethereum/core/src/main/java/org/hyperledger/besu/ethereum/mainnet/ClassicBlockProcessor.java
  9. 36
      ethereum/core/src/main/java/org/hyperledger/besu/ethereum/mainnet/ClassicProtocolSpecs.java
  10. 19
      ethereum/core/src/main/java/org/hyperledger/besu/ethereum/mainnet/ProtocolScheduleBuilder.java

@ -6,6 +6,7 @@
* The EvmTool now processes State Tests from the Ethereum Reference Tests. [\#1311](https://github.com/hyperledger/besu/pull/1311)
* Experimental dns support added via the `Xdns-enabled` and `Xdns-update-enabled` CLI commands. [\#1247](https://github.com/hyperledger/besu/pull/1247)
* Add genesis config option `ecip1017EraRounds` for Ethereum Classic chanis. [\#1329](https://github.com/hyperledger/besu/pull/1329)
### Bug Fixes

@ -160,6 +160,18 @@ public interface GenesisConfigOptions {
OptionalInt getEvmStackSize();
/**
* Number of rounds contained within an Era for calculating Ethereum Classic Emission Schedule,
* ECIP defines this as 5,000,000 however this config option allows for adjusting (for using with
* other networks, for example Mordor testnet uses 2,000,000). The values defaults to 5,000,000 if
* not set.
*
* @see <a
* href="https://ecips.ethereumclassic.org/ECIPs/ecip-1017">https://ecips.ethereumclassic.org/ECIPs/ecip-1017</a>
* @return number of rounds pre Era
*/
OptionalLong getEcip1017EraRounds();
Map<String, Object> asMap();
TransitionsConfigOptions getTransitions();

@ -289,6 +289,11 @@ public class JsonGenesisConfigOptions implements GenesisConfigOptions {
return getOptionalInt("evmstacksize");
}
@Override
public OptionalLong getEcip1017EraRounds() {
return getOptionalLong("ecip1017erarounds");
}
@Override
public Map<String, Object> asMap() {
final ImmutableMap.Builder<String, Object> builder = ImmutableMap.builder();
@ -322,6 +327,8 @@ public class JsonGenesisConfigOptions implements GenesisConfigOptions {
getEIP1559BlockNumber().ifPresent(l -> builder.put("eip1559Block", l));
getContractSizeLimit().ifPresent(l -> builder.put("contractSizeLimit", l));
getEvmStackSize().ifPresent(l -> builder.put("evmstacksize", l));
getEcip1017EraRounds().ifPresent(l -> builder.put("ecip1017EraRounds", l));
if (isClique()) {
builder.put("clique", getCliqueConfigOptions().asMap());
}

@ -49,6 +49,7 @@ public class StubGenesisConfigOptions implements GenesisConfigOptions {
private Optional<BigInteger> chainId = Optional.empty();
private OptionalInt contractSizeLimit = OptionalInt.empty();
private OptionalInt stackSizeLimit = OptionalInt.empty();
private final OptionalLong ecip1017EraRounds = OptionalLong.empty();
@Override
public String getConsensusEngine() {
@ -201,6 +202,11 @@ public class StubGenesisConfigOptions implements GenesisConfigOptions {
return stackSizeLimit;
}
@Override
public OptionalLong getEcip1017EraRounds() {
return ecip1017EraRounds;
}
@Override
public Optional<BigInteger> getChainId() {
return chainId;

@ -4,6 +4,7 @@
"atlantisBlock": 0,
"aghartaBlock": 301243,
"phoenixBlock": 999983,
"ecip1017EraRounds": 2000000,
"ethash": {}
},
"nonce": "0x0000000000000000",

@ -297,6 +297,7 @@ public class GenesisConfigFileTest {
assertThat(config.getConfigOptions().getChainId()).hasValue(BigInteger.valueOf(2018));
assertThat(config.getConfigOptions().getContractSizeLimit()).hasValue(2147483647);
assertThat(config.getConfigOptions().getEvmStackSize()).isNotPresent();
assertThat(config.getConfigOptions().getEcip1017EraRounds()).isNotPresent();
}
@Test

@ -36,6 +36,7 @@ import org.hyperledger.besu.ethereum.mainnet.TransactionProcessor;
import java.util.Collections;
import java.util.List;
import java.util.OptionalLong;
import java.util.stream.Collectors;
import java.util.stream.Stream;
@ -62,7 +63,7 @@ public class RewardTraceGeneratorTest {
Address.wrap(Bytes.fromHexString("0x095e7baea6a6c7c4c2dfeb977efac326af552d88"));
private final Wei blockReward = Wei.of(10000);
private final BlockHeader ommerHeader = gen.header(0x09);
private final OptionalLong eraRounds = OptionalLong.of(5000000);
private Block block;
@Before
@ -149,7 +150,8 @@ public class RewardTraceGeneratorTest {
transactionReceiptFactory,
blockReward,
BlockHeader::getCoinbase,
true);
true,
eraRounds);
when(protocolSpec.getBlockProcessor()).thenReturn(blockProcessor);
final Stream<Trace> traceStream =

@ -23,6 +23,7 @@ import org.hyperledger.besu.ethereum.core.fees.TransactionGasBudgetCalculator;
import java.math.BigInteger;
import java.util.List;
import java.util.OptionalLong;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
@ -31,14 +32,17 @@ public class ClassicBlockProcessor extends AbstractBlockProcessor {
private static final Logger LOG = LogManager.getLogger();
private static final long ERA_LENGTH = 5_000_000L;
private static final long DEFALUT_ERA_LENGTH = 5_000_000L;
private final long eraLength;
public ClassicBlockProcessor(
final TransactionProcessor transactionProcessor,
final TransactionReceiptFactory transactionReceiptFactory,
final Wei blockReward,
final MiningBeneficiaryCalculator miningBeneficiaryCalculator,
final boolean skipZeroBlockRewards) {
final boolean skipZeroBlockRewards,
final OptionalLong eraLen) {
super(
transactionProcessor,
transactionReceiptFactory,
@ -46,6 +50,7 @@ public class ClassicBlockProcessor extends AbstractBlockProcessor {
miningBeneficiaryCalculator,
skipZeroBlockRewards,
TransactionGasBudgetCalculator.frontier());
eraLength = eraLen.orElse(DEFALUT_ERA_LENGTH);
}
@Override
@ -135,7 +140,7 @@ public class ClassicBlockProcessor extends AbstractBlockProcessor {
@Override
public Wei getOmmerReward(
final Wei blockReward, final long blockNumber, final long ommerBlockNumber) {
final int blockEra = getBlockEra(blockNumber, ERA_LENGTH);
final int blockEra = getBlockEra(blockNumber, eraLength);
final long distance = blockNumber - ommerBlockNumber;
return calculateOmmerReward(blockEra, distance);
}
@ -143,7 +148,7 @@ public class ClassicBlockProcessor extends AbstractBlockProcessor {
@Override
public Wei getCoinbaseReward(
final Wei blockReward, final long blockNumber, final int ommersSize) {
final int blockEra = getBlockEra(blockNumber, ERA_LENGTH);
final int blockEra = getBlockEra(blockNumber, eraLength);
final Wei winnerReward = getBlockWinnerRewardByEra(blockEra);
return winnerReward.plus(winnerReward.multiply(ommersSize).divide(32));
}

@ -27,6 +27,7 @@ import java.math.BigInteger;
import java.util.Collections;
import java.util.Optional;
import java.util.OptionalInt;
import java.util.OptionalLong;
public class ClassicProtocolSpecs {
private static final Wei MAX_BLOCK_REWARD = Wei.fromEth(5);
@ -62,7 +63,8 @@ public class ClassicProtocolSpecs {
public static ProtocolSpecBuilder gothamDefinition(
final Optional<BigInteger> chainId,
final OptionalInt contractSizeLimit,
final OptionalInt configStackSizeLimit) {
final OptionalInt configStackSizeLimit,
final OptionalLong ecip1017EraRounds) {
return dieHardDefinition(chainId, contractSizeLimit, configStackSizeLimit)
.blockReward(MAX_BLOCK_REWARD)
.difficultyCalculator(ClassicDifficultyCalculators.DIFFICULTY_BOMB_DELAYED)
@ -78,15 +80,17 @@ public class ClassicProtocolSpecs {
transactionReceiptFactory,
blockReward,
miningBeneficiaryCalculator,
skipZeroBlockRewards))
skipZeroBlockRewards,
ecip1017EraRounds))
.name("Gotham");
}
public static ProtocolSpecBuilder defuseDifficultyBombDefinition(
final Optional<BigInteger> chainId,
final OptionalInt contractSizeLimit,
final OptionalInt configStackSizeLimit) {
return gothamDefinition(chainId, contractSizeLimit, configStackSizeLimit)
final OptionalInt configStackSizeLimit,
final OptionalLong ecip1017EraRounds) {
return gothamDefinition(chainId, contractSizeLimit, configStackSizeLimit, ecip1017EraRounds)
.difficultyCalculator(ClassicDifficultyCalculators.DIFFICULTY_BOMB_REMOVED)
.transactionValidatorBuilder(
gasCalculator -> new MainnetTransactionValidator(gasCalculator, true, chainId))
@ -97,11 +101,13 @@ public class ClassicProtocolSpecs {
final Optional<BigInteger> chainId,
final OptionalInt configContractSizeLimit,
final OptionalInt configStackSizeLimit,
final boolean enableRevertReason) {
final boolean enableRevertReason,
final OptionalLong ecip1017EraRounds) {
final int contractSizeLimit =
configContractSizeLimit.orElse(MainnetProtocolSpecs.SPURIOUS_DRAGON_CONTRACT_SIZE_LIMIT);
final int stackSizeLimit = configStackSizeLimit.orElse(MessageFrame.DEFAULT_MAX_STACK_SIZE);
return gothamDefinition(chainId, configContractSizeLimit, configStackSizeLimit)
return gothamDefinition(
chainId, configContractSizeLimit, configStackSizeLimit, ecip1017EraRounds)
.evmBuilder(MainnetEvmRegistries::byzantium)
.gasCalculator(SpuriousDragonGasCalculator::new)
.skipZeroBlockRewards(true)
@ -144,9 +150,14 @@ public class ClassicProtocolSpecs {
final Optional<BigInteger> chainId,
final OptionalInt configContractSizeLimit,
final OptionalInt configStackSizeLimit,
final boolean enableRevertReason) {
final boolean enableRevertReason,
final OptionalLong ecip1017EraRounds) {
return atlantisDefinition(
chainId, configContractSizeLimit, configStackSizeLimit, enableRevertReason)
chainId,
configContractSizeLimit,
configStackSizeLimit,
enableRevertReason,
ecip1017EraRounds)
.evmBuilder(MainnetEvmRegistries::constantinople)
.gasCalculator(ConstantinopleFixGasCalculator::new)
.evmBuilder(gasCalculator -> MainnetEvmRegistries.constantinople(gasCalculator))
@ -158,9 +169,14 @@ public class ClassicProtocolSpecs {
final Optional<BigInteger> chainId,
final OptionalInt configContractSizeLimit,
final OptionalInt configStackSizeLimit,
final boolean enableRevertReason) {
final boolean enableRevertReason,
final OptionalLong ecip1017EraRounds) {
return aghartaDefinition(
chainId, configContractSizeLimit, configStackSizeLimit, enableRevertReason)
chainId,
configContractSizeLimit,
configStackSizeLimit,
enableRevertReason,
ecip1017EraRounds)
.gasCalculator(IstanbulGasCalculator::new)
.evmBuilder(
gasCalculator ->

@ -234,12 +234,18 @@ public class ProtocolScheduleBuilder {
protocolSchedule,
config.getGothamBlockNumber(),
ClassicProtocolSpecs.gothamDefinition(
chainId, config.getContractSizeLimit(), config.getEvmStackSize()));
chainId,
config.getContractSizeLimit(),
config.getEvmStackSize(),
config.getEcip1017EraRounds()));
addProtocolSpec(
protocolSchedule,
config.getDefuseDifficultyBombBlockNumber(),
ClassicProtocolSpecs.defuseDifficultyBombDefinition(
chainId, config.getContractSizeLimit(), config.getEvmStackSize()));
chainId,
config.getContractSizeLimit(),
config.getEvmStackSize(),
config.getEcip1017EraRounds()));
addProtocolSpec(
protocolSchedule,
config.getAtlantisBlockNumber(),
@ -247,7 +253,8 @@ public class ProtocolScheduleBuilder {
chainId,
config.getContractSizeLimit(),
config.getEvmStackSize(),
isRevertReasonEnabled));
isRevertReasonEnabled,
config.getEcip1017EraRounds()));
addProtocolSpec(
protocolSchedule,
config.getAghartaBlockNumber(),
@ -255,7 +262,8 @@ public class ProtocolScheduleBuilder {
chainId,
config.getContractSizeLimit(),
config.getEvmStackSize(),
isRevertReasonEnabled));
isRevertReasonEnabled,
config.getEcip1017EraRounds()));
addProtocolSpec(
protocolSchedule,
config.getPhoenixBlockNumber(),
@ -263,7 +271,8 @@ public class ProtocolScheduleBuilder {
chainId,
config.getContractSizeLimit(),
config.getEvmStackSize(),
isRevertReasonEnabled));
isRevertReasonEnabled,
config.getEcip1017EraRounds()));
LOG.info("Protocol schedule created with milestones: {}", protocolSchedule.listMilestones());
return protocolSchedule;

Loading…
Cancel
Save