Magneto hard fork (#2315)

* Magneto hard fork

Signed-off-by: Antoine Toulme <antoine@lunar-ocean.com>

* address code review

Signed-off-by: Antoine Toulme <antoine@lunar-ocean.com>
pull/2318/head
Antoine Toulme 4 years ago committed by GitHub
parent 844ea35670
commit 61bf0d9cad
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 2
      CHANGELOG.md
  2. 15
      besu/src/test/java/org/hyperledger/besu/ForkIdsTest.java
  3. 9
      config/src/main/java/org/hyperledger/besu/config/GenesisConfigOptions.java
  4. 7
      config/src/main/java/org/hyperledger/besu/config/JsonGenesisConfigOptions.java
  5. 12
      config/src/main/java/org/hyperledger/besu/config/StubGenesisConfigOptions.java
  6. 1
      config/src/main/resources/classic.json
  7. 1
      config/src/main/resources/kotti.json
  8. 1
      config/src/main/resources/mordor.json
  9. 27
      ethereum/api/src/test/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/AdminNodeInfoTest.java
  10. 31
      ethereum/core/src/main/java/org/hyperledger/besu/ethereum/mainnet/ClassicProtocolSpecs.java
  11. 10
      ethereum/core/src/main/java/org/hyperledger/besu/ethereum/mainnet/MainnetProtocolSpecFactory.java
  12. 4
      ethereum/core/src/main/java/org/hyperledger/besu/ethereum/mainnet/MainnetProtocolSpecs.java
  13. 2
      ethereum/core/src/main/java/org/hyperledger/besu/ethereum/mainnet/ProtocolScheduleBuilder.java

@ -4,6 +4,8 @@
### Additions and Improvements
* Ethereum Classic Magneto Hard Fork [\#2315](https://github.com/hyperledger/besu/pull/2315)
### Bug Fixes
### Early Access Features

@ -113,8 +113,9 @@ public class ForkIdsTest {
new ForkId(Bytes.ofUnsignedInt(0x175782aaL), 301243L),
new ForkId(Bytes.ofUnsignedInt(0x604f6ee1L), 999983L),
new ForkId(Bytes.ofUnsignedInt(0xf42f5539L), 2520000L),
new ForkId(Bytes.ofUnsignedInt(0x66b5c286L), 0L),
new ForkId(Bytes.ofUnsignedInt(0x66b5c286L), 0L))
new ForkId(Bytes.ofUnsignedInt(0x66b5c286L), 3985893),
new ForkId(Bytes.ofUnsignedInt(0x92b323e0L), 0),
new ForkId(Bytes.ofUnsignedInt(0x92b323e0L), 0))
},
new Object[] {
NetworkName.KOTTI,
@ -122,8 +123,9 @@ public class ForkIdsTest {
new ForkId(Bytes.ofUnsignedInt(0x550152eL), 716617L),
new ForkId(Bytes.ofUnsignedInt(0xa3270822L), 1705549L),
new ForkId(Bytes.ofUnsignedInt(0x8f3698e0L), 2200013L),
new ForkId(Bytes.ofUnsignedInt(0x6f402821L), 0L),
new ForkId(Bytes.ofUnsignedInt(0x6f402821L), 0L))
new ForkId(Bytes.ofUnsignedInt(0x6f402821L), 4368634),
new ForkId(Bytes.ofUnsignedInt(0xf03e54e7L), 0),
new ForkId(Bytes.ofUnsignedInt(0xf03e54e7L), 0))
},
new Object[] {
NetworkName.CLASSIC,
@ -139,8 +141,9 @@ public class ForkIdsTest {
new ForkId(Bytes.ofUnsignedInt(0x518b59c6L), 9573000L),
new ForkId(Bytes.ofUnsignedInt(0x7ba22882L), 10500839L),
new ForkId(Bytes.ofUnsignedInt(0x9007bfccL), 11700000L),
new ForkId(Bytes.ofUnsignedInt(0xdb63a1caL), 0L),
new ForkId(Bytes.ofUnsignedInt(0xdb63a1caL), 0L))
new ForkId(Bytes.ofUnsignedInt(0xdb63a1caL), 13189133),
new ForkId(Bytes.ofUnsignedInt(0x0f6bf187L), 0),
new ForkId(Bytes.ofUnsignedInt(0x0f6bf187L), 0))
});
}

@ -191,6 +191,15 @@ public interface GenesisConfigOptions {
*/
OptionalLong getThanosBlockNumber();
/**
* Block number to activate Magneto on Classic networks.
*
* @return block number of Magneto fork on Classic networks
* @see <a
* href="https://github.com/ethereumclassic/ECIPs/issues/424">https://github.com/ethereumclassic/ECIPs/issues/424</a>
*/
OptionalLong getMagnetoBlockNumber();
/**
* Block number to activate ECIP-1049 on Classic networks. Changes the hashing algorithm to
* keccak-256.

@ -317,6 +317,11 @@ public class JsonGenesisConfigOptions implements GenesisConfigOptions {
return getOptionalLong("thanosblock");
}
@Override
public OptionalLong getMagnetoBlockNumber() {
return getOptionalLong("magnetoblock");
}
@Override
public OptionalLong getEcip1049BlockNumber() {
return getOptionalLong("ecip1049block");
@ -405,6 +410,7 @@ public class JsonGenesisConfigOptions implements GenesisConfigOptions {
getAghartaBlockNumber().ifPresent(l -> builder.put("aghartaBlock", l));
getPhoenixBlockNumber().ifPresent(l -> builder.put("phoenixBlock", l));
getThanosBlockNumber().ifPresent(l -> builder.put("thanosBlock", l));
getMagnetoBlockNumber().ifPresent(l -> builder.put("magnetoBlock", l));
getEcip1049BlockNumber().ifPresent(l -> builder.put("ecip1049Block", l));
getContractSizeLimit().ifPresent(l -> builder.put("contractSizeLimit", l));
@ -503,6 +509,7 @@ public class JsonGenesisConfigOptions implements GenesisConfigOptions {
getAghartaBlockNumber(),
getPhoenixBlockNumber(),
getThanosBlockNumber(),
getMagnetoBlockNumber(),
getEcip1049BlockNumber());
// when adding forks add an entry to ${REPO_ROOT}/config/src/test/resources/all_forks.json

@ -49,6 +49,7 @@ public class StubGenesisConfigOptions implements GenesisConfigOptions {
private OptionalLong aghartaBlockNumber = OptionalLong.empty();
private OptionalLong phoenixBlockNumber = OptionalLong.empty();
private OptionalLong thanosBlockNumber = OptionalLong.empty();
private OptionalLong magnetoBlockNumber = OptionalLong.empty();
private OptionalLong ecip1049BlockNumber = OptionalLong.empty();
private Optional<BigInteger> chainId = Optional.empty();
private OptionalInt contractSizeLimit = OptionalInt.empty();
@ -231,6 +232,11 @@ public class StubGenesisConfigOptions implements GenesisConfigOptions {
return thanosBlockNumber;
}
@Override
public OptionalLong getMagnetoBlockNumber() {
return magnetoBlockNumber;
}
@Override
public OptionalLong getEcip1049BlockNumber() {
return ecip1049BlockNumber;
@ -292,6 +298,7 @@ public class StubGenesisConfigOptions implements GenesisConfigOptions {
getAghartaBlockNumber().ifPresent(l -> builder.put("aghartaBlock", l));
getPhoenixBlockNumber().ifPresent(l -> builder.put("phoenixBlock", l));
getThanosBlockNumber().ifPresent(l -> builder.put("thanosBlock", l));
getMagnetoBlockNumber().ifPresent(l -> builder.put("magnetoBlock", l));
getEcip1049BlockNumber().ifPresent(l -> builder.put("ecip1049Block", l));
getContractSizeLimit().ifPresent(l -> builder.put("contractSizeLimit", l));
@ -446,6 +453,11 @@ public class StubGenesisConfigOptions implements GenesisConfigOptions {
return this;
}
public StubGenesisConfigOptions magneto(final long blockNumber) {
magnetoBlockNumber = OptionalLong.of(blockNumber);
return this;
}
public StubGenesisConfigOptions ecip1049(final long blockNumber) {
ecip1049BlockNumber = OptionalLong.of(blockNumber);
return this;

@ -11,6 +11,7 @@
"aghartaBlock": 9573000,
"phoenixBlock": 10500839,
"thanosBlock": 11700000,
"magnetoBlock": 13189133,
"ethash": {
}

@ -5,6 +5,7 @@
"atlantisBlock": 716617,
"aghartaBlock": 1705549,
"phoenixBlock": 2200013,
"magnetoBlock": 4368634,
"clique":{
"blockperiodseconds":15,
"epochlength":30000

@ -6,6 +6,7 @@
"phoenixBlock": 999983,
"ecip1017EraRounds": 2000000,
"thanosBlock": 2520000,
"magnetoBlock": 3985893,
"ethash": {}
},
"nonce": "0x0000000000000000",

@ -369,7 +369,8 @@ public class AdminNodeInfoTest {
.agharta(7)
.phoenix(8)
.thanos(9)
.ecip1049(10);
.magneto(10)
.ecip1049(11);
final AdminNodeInfo methodClassic =
new AdminNodeInfo(
@ -383,17 +384,19 @@ public class AdminNodeInfoTest {
final JsonRpcRequestContext request = adminNodeInfo();
final Map<String, Long> expectedConfig =
Map.of(
"classicForkBlock", 1L,
"ecip1015Block", 2L,
"dieHardBlock", 3L,
"gothamBlock", 4L,
"ecip1041Block", 5L,
"atlantisBlock", 6L,
"aghartaBlock", 7L,
"phoenixBlock", 8L,
"thanosBlock", 9L,
"ecip1049Block", 10L);
new HashMap<>(
Map.of(
"classicForkBlock", 1L,
"ecip1015Block", 2L,
"dieHardBlock", 3L,
"gothamBlock", 4L,
"ecip1041Block", 5L,
"atlantisBlock", 6L,
"aghartaBlock", 7L,
"phoenixBlock", 8L,
"thanosBlock", 9L,
"magnetoBlock", 10L));
expectedConfig.put("ecip1049Block", 11L);
final JsonRpcResponse response = methodClassic.response(request);
assertThat(response).isInstanceOf(JsonRpcSuccessResponse.class);

@ -33,6 +33,7 @@ import java.util.Collections;
import java.util.Optional;
import java.util.OptionalInt;
import java.util.OptionalLong;
import java.util.Set;
public class ClassicProtocolSpecs {
private static final Wei MAX_BLOCK_REWARD = Wei.fromEth(5);
@ -285,4 +286,34 @@ public class ClassicProtocolSpecs {
.powHasher(powHasher(PowAlgorithm.KECCAK256))
.name("ecip1049");
}
public static ProtocolSpecBuilder magnetoDefinition(
final Optional<BigInteger> chainId,
final OptionalInt configContractSizeLimit,
final OptionalInt configStackSizeLimit,
final boolean enableRevertReason,
final OptionalLong ecip1017EraRounds,
final boolean quorumCompatibilityMode) {
return thanosDefinition(
chainId,
configContractSizeLimit,
configStackSizeLimit,
enableRevertReason,
ecip1017EraRounds,
quorumCompatibilityMode)
.gasCalculator(BerlinGasCalculator::new)
.transactionValidatorBuilder(
gasCalculator ->
new MainnetTransactionValidator(
gasCalculator,
true,
chainId,
Set.of(TransactionType.FRONTIER, TransactionType.ACCESS_LIST),
quorumCompatibilityMode))
.transactionReceiptFactory(
enableRevertReason
? MainnetProtocolSpecs::berlinTransactionReceiptFactoryWithReasonEnabled
: MainnetProtocolSpecs::berlinTransactionReceiptFactory)
.name("Magneto");
}
}

@ -183,6 +183,16 @@ public class MainnetProtocolSpecFactory {
quorumCompatibilityMode);
}
public ProtocolSpecBuilder magnetoDefinition() {
return ClassicProtocolSpecs.magnetoDefinition(
chainId,
contractSizeLimit,
evmStackSize,
isRevertReasonEnabled,
ecip1017EraRounds,
quorumCompatibilityMode);
}
public ProtocolSpecBuilder ecip1049Definition() {
return ClassicProtocolSpecs.ecip1049Definition(
chainId,

@ -616,7 +616,7 @@ public abstract class MainnetProtocolSpecs {
result.isSuccessful() ? 1 : 0, gasUsed, result.getLogs(), result.getRevertReason());
}
private static TransactionReceipt berlinTransactionReceiptFactory(
static TransactionReceipt berlinTransactionReceiptFactory(
final TransactionType transactionType,
final TransactionProcessingResult transactionProcessingResult,
final WorldState worldState,
@ -629,7 +629,7 @@ public abstract class MainnetProtocolSpecs {
Optional.empty());
}
private static TransactionReceipt berlinTransactionReceiptFactoryWithReasonEnabled(
static TransactionReceipt berlinTransactionReceiptFactoryWithReasonEnabled(
final TransactionType transactionType,
final TransactionProcessingResult transactionProcessingResult,
final WorldState worldState,

@ -234,6 +234,7 @@ public class ProtocolScheduleBuilder {
create(config.getAghartaBlockNumber(), specFactory.aghartaDefinition()),
create(config.getPhoenixBlockNumber(), specFactory.phoenixDefinition()),
create(config.getThanosBlockNumber(), specFactory.thanosDefinition()),
create(config.getMagnetoBlockNumber(), specFactory.magnetoDefinition()),
create(config.getEcip1049BlockNumber(), specFactory.ecip1049Definition()))
.stream()
.filter(Optional::isPresent)
@ -327,6 +328,7 @@ public class ProtocolScheduleBuilder {
lastForkBlock = validateForkOrder("Agharta", config.getAghartaBlockNumber(), lastForkBlock);
lastForkBlock = validateForkOrder("Phoenix", config.getPhoenixBlockNumber(), lastForkBlock);
lastForkBlock = validateForkOrder("Thanos", config.getThanosBlockNumber(), lastForkBlock);
lastForkBlock = validateForkOrder("Magneto", config.getMagnetoBlockNumber(), lastForkBlock);
assert (lastForkBlock >= 0);
}
}

Loading…
Cancel
Save