Skip to content

Commit

Permalink
Mainnet london (#3202)
Browse files Browse the repository at this point in the history
* update mainnet block

* one more test

* Difficulty bomb check

* fix bad opcodes test
  • Loading branch information
MarekM25 authored Jul 8, 2021
1 parent d94c28d commit 3100374
Show file tree
Hide file tree
Showing 7 changed files with 62 additions and 11 deletions.
9 changes: 7 additions & 2 deletions src/Nethermind/Chains/foundation.json
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,8 @@
"difficultyBombDelays": {
"0x42ae50": "0x2dc6c0",
"0x6f1580": "0x1e8480",
"0x8C6180": "0x3D0900"
"0x8C6180": "0x3D0900",
"0xC5D488": "0xAAE60"
}
}
}
Expand Down Expand Up @@ -173,7 +174,11 @@
"eip2200Transition": "0x8a61c8",
"eip2565Transition": "0xBAD420",
"eip2929Transition": "0xBAD420",
"eip2930Transition": "0xBAD420"
"eip2930Transition": "0xBAD420",
"eip1559Transition": "0xC5D488",
"eip3198Transition": "0xC5D488",
"eip3529Transition": "0xC5D488",
"eip3541Transition": "0xC5D488"
},
"genesis": {
"seal": {
Expand Down
18 changes: 17 additions & 1 deletion src/Nethermind/Nethermind.Evm.Test/InvalidOpcodeTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,20 @@ public class InvalidOpcodeTests : VirtualMachineTestsBase
// }
new Instruction[] { }
))))).ToArray();

private static readonly Instruction[] LondonInstructions =
FrontierInstructions.Union(
HomesteadInstructions.Union(
ByzantiumInstructions.Union(
ConstantinopleFixInstructions.Union(
IstanbulInstructions.Union(
BerlinInstructions.Union(
new Instruction[]
{
Instruction.BASEFEE
}
)
))))).ToArray();

private Dictionary<long, Instruction[]> _validOpcodes
= new()
Expand All @@ -118,7 +132,8 @@ private Dictionary<long, Instruction[]> _validOpcodes
{MainnetSpecProvider.IstanbulBlockNumber, IstanbulInstructions},
{MainnetSpecProvider.MuirGlacierBlockNumber, IstanbulInstructions},
{MainnetSpecProvider.BerlinBlockNumber, BerlinInstructions},
{long.MaxValue, BerlinInstructions}
{MainnetSpecProvider.LondonBlockNumber, LondonInstructions},
{long.MaxValue, LondonInstructions}
};

private const string InvalidOpCodeErrorMessage = "BadInstruction";
Expand All @@ -141,6 +156,7 @@ protected override ILogManager GetLogManager()
[TestCase(MainnetSpecProvider.MuirGlacierBlockNumber)]
[TestCase(MainnetSpecProvider.BerlinBlockNumber)]
[TestCase(MainnetSpecProvider.BerlinBlockNumber)]
[TestCase(MainnetSpecProvider.LondonBlockNumber)]
[TestCase(long.MaxValue)]
public void Test(long blockNumber)
{
Expand Down
5 changes: 4 additions & 1 deletion src/Nethermind/Nethermind.Network.Test/ForkInfoTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,10 @@ public class ForkInfoTests
[TestCase(9_069_000, "0x879d6e30", 9_200_000, "First Istanbul block")]
[TestCase(9_199_999, "0x879d6e30", 9_200_000, "Last Istanbul block")]
[TestCase(9_200_000, "0xe029e991", 12_244_000, "Last Muir Glacier")]
[TestCase(12_244_000, "0x0eb440f6", 0, "First Berlin")]
[TestCase(12_244_000, "0x0eb440f6", 12_965_000, "First Berlin")]
[TestCase(12_964_999, "0x0eb440f6", 12_965_000, "Last Berlin")]
[TestCase(12_965_000, "0xb715077d", 0L, "First London")]
[TestCase(12_985_100, "0xb715077d", 0L, "Future London")]
public void Fork_id_and_hash_as_expected(long head, string forkHashHex, long next, string description)
{
Test(head, KnownHashes.MainnetGenesis, forkHashHex, next, description, MainnetSpecProvider.Instance, "foundation.json");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -118,13 +118,16 @@ public void Mainnet_loads_properly()
MainnetSpecProvider.IstanbulBlockNumber,
MainnetSpecProvider.MuirGlacierBlockNumber - 1,
MainnetSpecProvider.MuirGlacierBlockNumber,
MainnetSpecProvider.BerlinBlockNumber - 1,
MainnetSpecProvider.BerlinBlockNumber,
MainnetSpecProvider.BerlinBlockNumber,
MainnetSpecProvider.LondonBlockNumber - 1,
MainnetSpecProvider.LondonBlockNumber,
99000000, // far in the future
};

CompareSpecProviders(mainnet, provider, blockNumbersToTest);

Assert.AreEqual(MainnetSpecProvider.LondonBlockNumber, provider.GenesisSpec.Eip1559TransitionBlock);
Assert.AreEqual(0_000_000, provider.GetSpec(4_369_999).DifficultyBombDelay);
Assert.AreEqual(3_000_000, provider.GetSpec(4_370_000).DifficultyBombDelay);
Assert.AreEqual(3_000_000, provider.GetSpec(7_279_999).DifficultyBombDelay);
Expand All @@ -133,7 +136,9 @@ public void Mainnet_loads_properly()
Assert.AreEqual(5_000_000, provider.GetSpec(9_199_999).DifficultyBombDelay);
Assert.AreEqual(9_000_000, provider.GetSpec(9_200_000).DifficultyBombDelay);
Assert.AreEqual(9_000_000, provider.GetSpec(12_000_000).DifficultyBombDelay);
Assert.AreEqual(9_000_000, provider.GetSpec(15_000_000).DifficultyBombDelay);
Assert.AreEqual(9_000_000, provider.GetSpec(12_964_999).DifficultyBombDelay);
Assert.AreEqual(9_700_000, provider.GetSpec(12_965_000).DifficultyBombDelay);
Assert.AreEqual(9_700_000, provider.GetSpec(15_000_000).DifficultyBombDelay);
}

private static void CompareSpecProviders(
Expand Down Expand Up @@ -164,7 +169,7 @@ private static void CompareSpecs(IReleaseSpec oldSpec, IReleaseSpec newSpec, lon
.Where(p => isMainnet || p.Name != nameof(IReleaseSpec.BlockReward))
.Where(p => isMainnet || checkDifficultyBomb || p.Name != nameof(IReleaseSpec.DifficultyBombDelay))
.Where(p => isMainnet || checkDifficultyBomb || p.Name != nameof(IReleaseSpec.DifficultyBoundDivisor))
.Where(p => isMainnet || p.Name != nameof(IReleaseSpec.Eip1559TransitionBlock)))
.Where(p => p.Name != nameof(IReleaseSpec.Eip1559TransitionBlock)))
{
Assert.AreEqual(propertyInfo.GetValue(oldSpec), propertyInfo.GetValue(newSpec),
blockNumber + "." + propertyInfo.Name);
Expand Down
16 changes: 16 additions & 0 deletions src/Nethermind/Nethermind.Specs.Test/MainnetSpecProviderTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@

using FluentAssertions;
using Nethermind.Core.Specs;
using Nethermind.Specs.Forks;
using NUnit.Framework;

namespace Nethermind.Specs.Test
Expand All @@ -37,6 +38,21 @@ public void Berlin_eips(long blockNumber, bool isEnabled)
_specProvider.GetSpec(blockNumber).IsEip2930Enabled.Should().Be(isEnabled);
}

[TestCase(12_964_999, false)]
[TestCase(12_965_000, true)]
public void London_eips(long blockNumber, bool isEnabled)
{
if (isEnabled)
_specProvider.GetSpec(blockNumber).DifficultyBombDelay.Should().Be(London.Instance.DifficultyBombDelay);
else
_specProvider.GetSpec(blockNumber).DifficultyBombDelay.Should().Be(Berlin.Instance.DifficultyBombDelay);

_specProvider.GetSpec(blockNumber).IsEip1559Enabled.Should().Be(isEnabled);
_specProvider.GetSpec(blockNumber).IsEip3198Enabled.Should().Be(isEnabled);
_specProvider.GetSpec(blockNumber).IsEip3529Enabled.Should().Be(isEnabled);
_specProvider.GetSpec(blockNumber).IsEip3541Enabled.Should().Be(isEnabled);
}

[Test]
public void Dao_block_number_is_correct()
{
Expand Down
2 changes: 1 addition & 1 deletion src/Nethermind/Nethermind.Specs/Forks/12_London.cs
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,6 @@ private London()
public bool IsEip3198Enabled => true;
public bool IsEip3529Enabled => true;
public bool IsEip3541Enabled => true;
public long Eip1559TransitionBlock => long.MaxValue;
public long Eip1559TransitionBlock => 12965000;
}
}
12 changes: 9 additions & 3 deletions src/Nethermind/Nethermind.Specs/MainNetSpecProvider.cs
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,12 @@ public IReleaseSpec GetSpec(long blockNumber)
return MuirGlacier.Instance;
}

return Berlin.Instance;
if (blockNumber < LondonBlockNumber)
{
return Berlin.Instance;
}

return London.Instance;
}

public const long HomesteadBlockNumber = 1_150_000;
Expand All @@ -83,7 +88,7 @@ public IReleaseSpec GetSpec(long blockNumber)
public const long IstanbulBlockNumber = 9_069_000;
public const long MuirGlacierBlockNumber = 9_200_000;
public const long BerlinBlockNumber = 12_244_000;
public const long LondonBlockNumber = long.MaxValue -5;
public const long LondonBlockNumber = 12_965_000;
public const long ShanghaiBlockNumber = long.MaxValue -4;
public const long CancunBlockNumber = long.MaxValue -3;
public const long PragueBlockNumber = long.MaxValue -2;
Expand All @@ -101,7 +106,8 @@ public IReleaseSpec GetSpec(long blockNumber)
ConstantinopleFixBlockNumber,
IstanbulBlockNumber,
MuirGlacierBlockNumber,
BerlinBlockNumber
BerlinBlockNumber,
LondonBlockNumber
};

private MainnetSpecProvider() { }
Expand Down

0 comments on commit 3100374

Please sign in to comment.