ETC - Cleanup (#201)

Cleans up issues relating to the Ethereum Classic configurations.

* Fixes Jira BESU-116
* Fixes ommer reward calculation
* Fixes Mordor config
* Fixes Kotti Sync issues

Signed-off-by: soc1c <soc1c@users.noreply.github.com>
Signed-off-by: edwardmack <ed@edwardmack.com>
pull/205/head
Gregory Markou 5 years ago committed by Danno Ferrin
parent bb0ba9b781
commit a449e81b2d
  1. 8
      besu/src/main/java/org/hyperledger/besu/cli/config/EthNetworkConfig.java
  2. 3
      besu/src/main/java/org/hyperledger/besu/cli/config/NetworkName.java
  3. 22
      besu/src/test/java/org/hyperledger/besu/cli/BesuCommandTest.java
  4. 2
      config/src/main/resources/classic.json
  5. 6
      config/src/main/resources/kotti.json
  6. 18
      config/src/main/resources/mordor.json
  7. 18
      ethereum/core/src/main/java/org/hyperledger/besu/ethereum/mainnet/ClassicBlockProcessor.java
  8. 2
      ethereum/core/src/main/java/org/hyperledger/besu/ethereum/mainnet/MainnetBlockHeaderValidator.java
  9. 2
      ethereum/core/src/main/java/org/hyperledger/besu/ethereum/mainnet/ProtocolScheduleBuilder.java
  10. 12
      ethereum/p2p/src/main/java/org/hyperledger/besu/ethereum/p2p/config/DiscoveryConfiguration.java

@ -19,6 +19,7 @@ import static org.hyperledger.besu.ethereum.p2p.config.DiscoveryConfiguration.CL
import static org.hyperledger.besu.ethereum.p2p.config.DiscoveryConfiguration.GOERLI_BOOTSTRAP_NODES;
import static org.hyperledger.besu.ethereum.p2p.config.DiscoveryConfiguration.KOTTI_BOOTSTRAP_NODES;
import static org.hyperledger.besu.ethereum.p2p.config.DiscoveryConfiguration.MAINNET_BOOTSTRAP_NODES;
import static org.hyperledger.besu.ethereum.p2p.config.DiscoveryConfiguration.MORDOR_BOOTSTRAP_NODES;
import static org.hyperledger.besu.ethereum.p2p.config.DiscoveryConfiguration.RINKEBY_BOOTSTRAP_NODES;
import static org.hyperledger.besu.ethereum.p2p.config.DiscoveryConfiguration.ROPSTEN_BOOTSTRAP_NODES;
@ -43,6 +44,7 @@ public class EthNetworkConfig {
public static final BigInteger DEV_NETWORK_ID = BigInteger.valueOf(2018);
public static final BigInteger CLASSIC_NETWORK_ID = BigInteger.valueOf(1);
public static final BigInteger KOTTI_NETWORK_ID = BigInteger.valueOf(6);
public static final BigInteger MORDOR_NETWORK_ID = BigInteger.valueOf(7);
private static final String MAINNET_GENESIS = "/mainnet.json";
private static final String ROPSTEN_GENESIS = "/ropsten.json";
private static final String RINKEBY_GENESIS = "/rinkeby.json";
@ -50,6 +52,7 @@ public class EthNetworkConfig {
private static final String DEV_GENESIS = "/dev.json";
private static final String CLASSIC_GENESIS = "/classic.json";
private static final String KOTTI_GENESIS = "/kotti.json";
private static final String MORDOR_GENESIS = "/mordor.json";
private final String genesisConfig;
private final BigInteger networkId;
private final List<EnodeURL> bootNodes;
@ -125,6 +128,9 @@ public class EthNetworkConfig {
case KOTTI:
return new EthNetworkConfig(
jsonConfig(KOTTI_GENESIS), KOTTI_NETWORK_ID, KOTTI_BOOTSTRAP_NODES);
case MORDOR:
return new EthNetworkConfig(
jsonConfig(MORDOR_GENESIS), MORDOR_NETWORK_ID, MORDOR_BOOTSTRAP_NODES);
case MAINNET:
default:
return new EthNetworkConfig(
@ -157,6 +163,8 @@ public class EthNetworkConfig {
return jsonConfig(CLASSIC_GENESIS);
case KOTTI:
return jsonConfig(KOTTI_GENESIS);
case MORDOR:
return jsonConfig(MORDOR_GENESIS);
default:
throw new IllegalArgumentException("Unknown network:" + network);
}

@ -21,5 +21,6 @@ public enum NetworkName {
GOERLI,
DEV,
CLASSIC,
KOTTI
KOTTI,
MORDOR
}

@ -22,6 +22,7 @@ import static org.hyperledger.besu.cli.config.NetworkName.DEV;
import static org.hyperledger.besu.cli.config.NetworkName.GOERLI;
import static org.hyperledger.besu.cli.config.NetworkName.KOTTI;
import static org.hyperledger.besu.cli.config.NetworkName.MAINNET;
import static org.hyperledger.besu.cli.config.NetworkName.MORDOR;
import static org.hyperledger.besu.cli.config.NetworkName.RINKEBY;
import static org.hyperledger.besu.cli.config.NetworkName.ROPSTEN;
import static org.hyperledger.besu.ethereum.api.jsonrpc.RpcApis.ETH;
@ -2512,6 +2513,22 @@ public class BesuCommandTest extends CommandTestAbstract {
assertThat(commandErrorOutput.toString()).isEmpty();
}
@Test
public void mordorValuesAreUsed() throws Exception {
parseCommand("--network", "mordor");
final ArgumentCaptor<EthNetworkConfig> networkArg =
ArgumentCaptor.forClass(EthNetworkConfig.class);
verify(mockControllerBuilderFactory).fromEthNetworkConfig(networkArg.capture(), any());
verify(mockControllerBuilder).build();
assertThat(networkArg.getValue()).isEqualTo(EthNetworkConfig.getNetworkConfig(MORDOR));
assertThat(commandOutput.toString()).isEmpty();
assertThat(commandErrorOutput.toString()).isEmpty();
}
@Test
public void rinkebyValuesCanBeOverridden() throws Exception {
networkValuesCanBeOverridden("rinkeby");
@ -2542,6 +2559,11 @@ public class BesuCommandTest extends CommandTestAbstract {
networkValuesCanBeOverridden("kotti");
}
@Test
public void mordorValuesCanBeOverridden() throws Exception {
networkValuesCanBeOverridden("mordor");
}
private void networkValuesCanBeOverridden(final String network) throws Exception {
parseCommand(
"--network",

@ -26703,4 +26703,4 @@
"number": "0x0",
"gasUsed": "0x0",
"parentHash": "0x0000000000000000000000000000000000000000000000000000000000000000"
}
}

@ -1,11 +1,7 @@
{
"config": {
"chainId": 6,
"homesteadBlock": 0,
"eip150Block": 0,
"eip150Hash": "0x14c2283285a88fe5fce9bf5c573ab03d6616695d717b12a127188bcacfc743c4",
"eip158Block": 0,
"eip160Block": 0,
"ecip1041Block": 0,
"atlantisBlock": 716617,
"clique":{
"blockperiodseconds":15,

@ -0,0 +1,18 @@
{
"config": {
"chainId": 63,
"atlantisBlock": 0,
"ethash": {}
},
"nonce": "0x0000000000000000",
"timestamp": "0x5d9676db",
"extraData": "0x70686f656e697820636869636b656e206162737572642062616e616e61",
"gasLimit": "0x2fefd8",
"difficulty": "0x20000",
"mixHash": "0x0000000000000000000000000000000000000000000000000000000000000000",
"coinbase": "0x0000000000000000000000000000000000000000",
"alloc": {},
"number": "0x0",
"gasUsed": "0x0",
"parentHash": "0x0000000000000000000000000000000000000000000000000000000000000000"
}

@ -20,7 +20,6 @@ import org.hyperledger.besu.ethereum.core.MutableWorldState;
import org.hyperledger.besu.ethereum.core.ProcessableBlockHeader;
import org.hyperledger.besu.ethereum.core.Wei;
import org.hyperledger.besu.ethereum.core.WorldUpdater;
import org.hyperledger.besu.ethereum.mainnet.AbstractBlockProcessor.TransactionReceiptFactory;
import java.math.BigInteger;
import java.util.List;
@ -59,8 +58,7 @@ public class ClassicBlockProcessor extends AbstractBlockProcessor {
}
final int blockEra = getBlockEra(header.getNumber(), ERA_LENGTH);
final Wei winnerReward = getBlockWinnerRewardByEra(blockEra);
final Wei uncleInclusionReward = winnerReward.dividedBy(32);
final Wei coinbaseReward = winnerReward.plus(uncleInclusionReward.times(ommers.size()));
final Wei coinbaseReward = winnerReward.plus(winnerReward.times(ommers.size()).dividedBy(32));
final WorldUpdater updater = worldState.updater();
final MutableAccount coinbase = updater.getOrCreate(header.getCoinbase()).getMutable();
@ -77,13 +75,25 @@ public class ClassicBlockProcessor extends AbstractBlockProcessor {
final MutableAccount ommerCoinbase =
updater.getOrCreate(ommerHeader.getCoinbase()).getMutable();
ommerCoinbase.incrementBalance(uncleInclusionReward);
final long distance = header.getNumber() - ommerHeader.getNumber();
final Wei ommerReward = calculateOmmerReward(blockEra, distance);
ommerCoinbase.incrementBalance(ommerReward);
}
updater.commit();
return true;
}
// getUncleInclusionReword return reward for including
// an uncle block
private Wei calculateOmmerReward(final int era, final long distance) {
Wei winnerReward = getBlockWinnerRewardByEra(era);
if (era < 1) {
return winnerReward.minus(winnerReward.times(distance).dividedBy(8));
}
return winnerReward.dividedBy(32);
}
// GetBlockEra gets which "Era" a given block is within, given an era length (ecip-1017 has
// era=5,000,000 blocks)
// Returns a zero-index era number, so "Era 1": 0, "Era 2": 1, "Era 3": 2 ...

@ -68,7 +68,7 @@ public final class MainnetBlockHeaderValidator {
}
public static boolean validateHeaderForClassicFork(final BlockHeader header) {
return header.getHash().equals(CLASSIC_FORK_BLOCK_HEADER);
return header.getNumber() != 1_920_000 || header.getHash().equals(CLASSIC_FORK_BLOCK_HEADER);
}
static BlockHeaderValidator<Void> createOmmerValidator(

@ -164,7 +164,7 @@ public class ProtocolScheduleBuilder<C> {
OptionalLong.of(classicBlockNumber),
ClassicProtocolSpecs.classicRecoveryInitDefinition(
config.getContractSizeLimit(), config.getEvmStackSize()));
protocolSchedule.putMilestone(classicBlockNumber + 10, originalProtocolSpce);
protocolSchedule.putMilestone(classicBlockNumber + 1, originalProtocolSpce);
});
addProtocolSpec(

@ -112,6 +112,18 @@ public class DiscoveryConfiguration {
.map(EnodeURL::fromString)
.collect(toList()));
public static List<EnodeURL> MORDOR_BOOTSTRAP_NODES =
Collections.unmodifiableList(
Stream.of(
"enode://03b133f731049e3f7be827339c3759be92778c05e54a1847d178c0fdb56fa168aa1e7e61fc77791a7afdd0328a00318f73c01212eb3f3bbe919f5ce8f5b4a314@192.227.105.4:32000",
"enode://06fdbeb591d26f53b2e7250025fe955ca013431ded930920cf1e3cd1f0c920e9a5e727949d209bc25a07288327b525279b11c5551315c50ff0db483e69fc159b@34.218.225.178:32000",
"enode://1813e90a0afdd7c1e4892c5376960e3577a9e6c5a4f86fa405a405c7421a4a1608248d77cc90333842f13d8954d82113dec480cfb76b4fef8cb475157cf4d5f2@10.28.224.3:30000",
"enode://2b69a3926f36a7748c9021c34050be5e0b64346225e477fe7377070f6289bd363b2be73a06010fd516e6ea3ee90778dd0399bc007bb1281923a79374f842675a@51.15.116.226:30303",
"enode://621e28e529146fd501709194885f50540c494f1a2985d1fb4ec8769226b5cb0b0d1a11545926077821474c2767cdd87888ead8a2509a2c9069dd5584e4b1c3b8@10.28.223.8:30000",
"enode://a59e33ccd2b3e52d578f1fbd70c6f9babda2650f0760d6ff3b37742fdcdfdb3defba5d56d315b40c46b70198c7621e63ffa3f987389c7118634b0fefbbdfa7fd@51.15.116.226:30303")
.map(EnodeURL::fromString)
.collect(toList()));
private boolean active = true;
private String bindHost = NetworkUtility.INADDR_ANY;
private int bindPort = 30303;

Loading…
Cancel
Save