Skip to content

Commit

Permalink
Magneto hard fork (hyperledger#2315)
Browse files Browse the repository at this point in the history
* Magneto hard fork

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

* address code review

Signed-off-by: Antoine Toulme <antoine@lunar-ocean.com>
  • Loading branch information
atoulme authored May 23, 2021
1 parent 844ea35 commit 61bf0d9
Show file tree
Hide file tree
Showing 13 changed files with 102 additions and 20 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
15 changes: 9 additions & 6 deletions besu/src/test/java/org/hyperledger/besu/ForkIdsTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -113,17 +113,19 @@ public static Collection<Object[]> parameters() {
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,
List.of(
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,
Expand All @@ -139,8 +141,9 @@ public static Collection<Object[]> parameters() {
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))
});
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -191,6 +191,15 @@ default Optional<Long> getGenesisBaseFeePerGas() {
*/
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.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -317,6 +317,11 @@ public OptionalLong getThanosBlockNumber() {
return getOptionalLong("thanosblock");
}

@Override
public OptionalLong getMagnetoBlockNumber() {
return getOptionalLong("magnetoblock");
}

@Override
public OptionalLong getEcip1049BlockNumber() {
return getOptionalLong("ecip1049block");
Expand Down Expand Up @@ -405,6 +410,7 @@ public Map<String, Object> asMap() {
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));
Expand Down Expand Up @@ -503,6 +509,7 @@ public List<Long> getForks() {
getAghartaBlockNumber(),
getPhoenixBlockNumber(),
getThanosBlockNumber(),
getMagnetoBlockNumber(),
getEcip1049BlockNumber());
// when adding forks add an entry to ${REPO_ROOT}/config/src/test/resources/all_forks.json

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down Expand Up @@ -231,6 +232,11 @@ public OptionalLong getThanosBlockNumber() {
return thanosBlockNumber;
}

@Override
public OptionalLong getMagnetoBlockNumber() {
return magnetoBlockNumber;
}

@Override
public OptionalLong getEcip1049BlockNumber() {
return ecip1049BlockNumber;
Expand Down Expand Up @@ -292,6 +298,7 @@ public Map<String, Object> asMap() {
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));
Expand Down Expand Up @@ -446,6 +453,11 @@ public StubGenesisConfigOptions thanos(final long blockNumber) {
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;
Expand Down
1 change: 1 addition & 0 deletions config/src/main/resources/classic.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
"aghartaBlock": 9573000,
"phoenixBlock": 10500839,
"thanosBlock": 11700000,
"magnetoBlock": 13189133,
"ethash": {

}
Expand Down
1 change: 1 addition & 0 deletions config/src/main/resources/kotti.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
"atlantisBlock": 716617,
"aghartaBlock": 1705549,
"phoenixBlock": 2200013,
"magnetoBlock": 4368634,
"clique":{
"blockperiodseconds":15,
"epochlength":30000
Expand Down
1 change: 1 addition & 0 deletions config/src/main/resources/mordor.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
"phoenixBlock": 999983,
"ecip1017EraRounds": 2000000,
"thanosBlock": 2520000,
"magnetoBlock": 3985893,
"ethash": {}
},
"nonce": "0x0000000000000000",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -369,7 +369,8 @@ public void returnsClassicForkBlocks() {
.agharta(7)
.phoenix(8)
.thanos(9)
.ecip1049(10);
.magneto(10)
.ecip1049(11);

final AdminNodeInfo methodClassic =
new AdminNodeInfo(
Expand All @@ -383,17 +384,19 @@ public void returnsClassicForkBlocks() {
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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
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);
Expand Down Expand Up @@ -285,4 +286,34 @@ public static ProtocolSpecBuilder ecip1049Definition(
.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");
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -183,6 +183,16 @@ public ProtocolSpecBuilder thanosDefinition() {
quorumCompatibilityMode);
}

public ProtocolSpecBuilder magnetoDefinition() {
return ClassicProtocolSpecs.magnetoDefinition(
chainId,
contractSizeLimit,
evmStackSize,
isRevertReasonEnabled,
ecip1017EraRounds,
quorumCompatibilityMode);
}

public ProtocolSpecBuilder ecip1049Definition() {
return ClassicProtocolSpecs.ecip1049Definition(
chainId,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -616,7 +616,7 @@ private static TransactionReceipt byzantiumTransactionReceiptFactoryWithReasonEn
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,
Expand All @@ -629,7 +629,7 @@ private static TransactionReceipt berlinTransactionReceiptFactory(
Optional.empty());
}

private static TransactionReceipt berlinTransactionReceiptFactoryWithReasonEnabled(
static TransactionReceipt berlinTransactionReceiptFactoryWithReasonEnabled(
final TransactionType transactionType,
final TransactionProcessingResult transactionProcessingResult,
final WorldState worldState,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -234,6 +234,7 @@ private TreeMap<Long, BuilderMapEntry> buildMilestoneMap(
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)
Expand Down Expand Up @@ -327,6 +328,7 @@ private void validateClassicForkOrdering() {
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);
}
}

0 comments on commit 61bf0d9

Please sign in to comment.