From 80ab783828ef8f6601b072167760dfc4e3ed30f0 Mon Sep 17 00:00:00 2001 From: MarekM25 Date: Mon, 5 Jun 2023 13:53:52 +0200 Subject: [PATCH 1/3] Working on GnosisSpecProvider --- .../ChainSpecBasedSpecProviderTests.cs | 29 ++++++++++++ .../Nethermind.Specs/GnosisSpecProvider.cs | 45 +++++++++++++++++++ 2 files changed, 74 insertions(+) create mode 100644 src/Nethermind/Nethermind.Specs/GnosisSpecProvider.cs diff --git a/src/Nethermind/Nethermind.Specs.Test/ChainSpecStyle/ChainSpecBasedSpecProviderTests.cs b/src/Nethermind/Nethermind.Specs.Test/ChainSpecStyle/ChainSpecBasedSpecProviderTests.cs index 80194534802..9c57ea32a00 100644 --- a/src/Nethermind/Nethermind.Specs.Test/ChainSpecStyle/ChainSpecBasedSpecProviderTests.cs +++ b/src/Nethermind/Nethermind.Specs.Test/ChainSpecStyle/ChainSpecBasedSpecProviderTests.cs @@ -232,6 +232,35 @@ public void Chiado_loads_properly() provider.GetSpec((1, ChiadoSpecProvider.ShanghaiTimestamp)).MaxInitCodeSize.Should().Be(2 * 24576L); } + [Test] + public void Gnosis_loads_properly() + { + ChainSpecLoader loader = new(new EthereumJsonSerializer()); + string path = Path.Combine(TestContext.CurrentContext.WorkDirectory, "../../../../Chains/gnosis.json"); + ChainSpec chainSpec = loader.Load(File.ReadAllText(path)); + + ChainSpecBasedSpecProvider provider = new(chainSpec); + GnosisSpecProvider gnosisSpecProvider = GnosisSpecProvider.Instance; + + List forkActivationsToTest = new() + { + (ForkActivation)0, + //(ForkActivation)1, + (1, ChiadoSpecProvider.ShanghaiTimestamp - 1), + (1, ChiadoSpecProvider.ShanghaiTimestamp), + (999_999_999, 999_999_999) // far in the future + }; + + CompareSpecProviders(gnosisSpecProvider, provider, forkActivationsToTest, CompareSpecsOptions.IsGnosis); + Assert.That(provider.TerminalTotalDifficulty, Is.EqualTo(ChiadoSpecProvider.Instance.TerminalTotalDifficulty)); + Assert.That(provider.ChainId, Is.EqualTo(BlockchainIds.Gnosis)); + Assert.That(provider.NetworkId, Is.EqualTo(BlockchainIds.Gnosis)); + + provider.GetSpec((1, ChiadoSpecProvider.ShanghaiTimestamp - 1)).MaxCodeSize.Should().Be(long.MaxValue); + provider.GetSpec((1, ChiadoSpecProvider.ShanghaiTimestamp)).MaxCodeSize.Should().Be(24576L); + provider.GetSpec((1, ChiadoSpecProvider.ShanghaiTimestamp)).MaxInitCodeSize.Should().Be(2 * 24576L); + } + [Test] public void Mainnet_loads_properly() diff --git a/src/Nethermind/Nethermind.Specs/GnosisSpecProvider.cs b/src/Nethermind/Nethermind.Specs/GnosisSpecProvider.cs new file mode 100644 index 00000000000..216ac975c0b --- /dev/null +++ b/src/Nethermind/Nethermind.Specs/GnosisSpecProvider.cs @@ -0,0 +1,45 @@ +// SPDX-FileCopyrightText: 2023 Demerzel Solutions Limited +// SPDX-License-Identifier: LGPL-3.0-only + +using Nethermind.Core; +using Nethermind.Core.Specs; +using Nethermind.Int256; +using Nethermind.Specs.Forks; + +namespace Nethermind.Specs; + +public class GnosisSpecProvider : ISpecProvider +{ + public const ulong ShanghaiTimestamp = 0x646e0e4cUL; + + private GnosisSpecProvider() { } + + public IReleaseSpec GetSpec(ForkActivation forkActivation) => forkActivation.BlockNumber switch + { + _ => forkActivation.Timestamp switch + { + null or < ShanghaiTimestamp => GenesisSpec, + _ => Shanghai.Instance + } + }; + + public void UpdateMergeTransitionInfo(long? blockNumber, UInt256? terminalTotalDifficulty = null) + { + if (blockNumber is not null) + MergeBlockNumber = (ForkActivation)blockNumber; + + if (terminalTotalDifficulty is not null) + TerminalTotalDifficulty = terminalTotalDifficulty; + } + + public ForkActivation? MergeBlockNumber { get; private set; } + public ulong TimestampFork => ShanghaiTimestamp; + public UInt256? TerminalTotalDifficulty { get; private set; } = UInt256.Parse("231707791542740786049188744689299064356246512"); + public IReleaseSpec GenesisSpec => London.Instance; + public long? DaoBlockNumber => null; + public ulong NetworkId => BlockchainIds.Gnosis; + public ulong ChainId => BlockchainIds.Gnosis; + public ForkActivation[] TransitionActivations { get; } + + public static GnosisSpecProvider Instance { get; } = new(); +} From 652d09c75244e3313a06b77d545880c33967d42d Mon Sep 17 00:00:00 2001 From: MarekM25 Date: Mon, 5 Jun 2023 14:08:01 +0200 Subject: [PATCH 2/3] Passed test --- .../ChainSpecBasedSpecProviderTests.cs | 14 ++++---- .../Nethermind.Specs/GnosisSpecProvider.cs | 33 +++++++++++++------ 2 files changed, 31 insertions(+), 16 deletions(-) diff --git a/src/Nethermind/Nethermind.Specs.Test/ChainSpecStyle/ChainSpecBasedSpecProviderTests.cs b/src/Nethermind/Nethermind.Specs.Test/ChainSpecStyle/ChainSpecBasedSpecProviderTests.cs index 9c57ea32a00..cd853b77253 100644 --- a/src/Nethermind/Nethermind.Specs.Test/ChainSpecStyle/ChainSpecBasedSpecProviderTests.cs +++ b/src/Nethermind/Nethermind.Specs.Test/ChainSpecStyle/ChainSpecBasedSpecProviderTests.cs @@ -246,19 +246,21 @@ public void Gnosis_loads_properly() { (ForkActivation)0, //(ForkActivation)1, - (1, ChiadoSpecProvider.ShanghaiTimestamp - 1), - (1, ChiadoSpecProvider.ShanghaiTimestamp), + (1, GnosisSpecProvider.ShanghaiTimestamp - 1), + (1, GnosisSpecProvider.ShanghaiTimestamp), (999_999_999, 999_999_999) // far in the future }; CompareSpecProviders(gnosisSpecProvider, provider, forkActivationsToTest, CompareSpecsOptions.IsGnosis); - Assert.That(provider.TerminalTotalDifficulty, Is.EqualTo(ChiadoSpecProvider.Instance.TerminalTotalDifficulty)); + Assert.That(provider.TerminalTotalDifficulty, Is.EqualTo(GnosisSpecProvider.Instance.TerminalTotalDifficulty)); Assert.That(provider.ChainId, Is.EqualTo(BlockchainIds.Gnosis)); Assert.That(provider.NetworkId, Is.EqualTo(BlockchainIds.Gnosis)); - provider.GetSpec((1, ChiadoSpecProvider.ShanghaiTimestamp - 1)).MaxCodeSize.Should().Be(long.MaxValue); - provider.GetSpec((1, ChiadoSpecProvider.ShanghaiTimestamp)).MaxCodeSize.Should().Be(24576L); - provider.GetSpec((1, ChiadoSpecProvider.ShanghaiTimestamp)).MaxInitCodeSize.Should().Be(2 * 24576L); + provider.GetSpec((1, GnosisSpecProvider.ShanghaiTimestamp - 1)).MaxCodeSize.Should().Be(long.MaxValue); + + /* ToDo uncomment when we have gnosis shapella timestamp + provider.GetSpec((1, GnosisSpecProvider.ShanghaiTimestamp)).MaxCodeSize.Should().Be(24576L); + provider.GetSpec((1, GnosisSpecProvider.ShanghaiTimestamp)).MaxInitCodeSize.Should().Be(2 * 24576L);*/ } diff --git a/src/Nethermind/Nethermind.Specs/GnosisSpecProvider.cs b/src/Nethermind/Nethermind.Specs/GnosisSpecProvider.cs index 216ac975c0b..935f8c77d28 100644 --- a/src/Nethermind/Nethermind.Specs/GnosisSpecProvider.cs +++ b/src/Nethermind/Nethermind.Specs/GnosisSpecProvider.cs @@ -10,18 +10,24 @@ namespace Nethermind.Specs; public class GnosisSpecProvider : ISpecProvider { - public const ulong ShanghaiTimestamp = 0x646e0e4cUL; - private GnosisSpecProvider() { } - public IReleaseSpec GetSpec(ForkActivation forkActivation) => forkActivation.BlockNumber switch + public IReleaseSpec GetSpec(ForkActivation forkActivation) { - _ => forkActivation.Timestamp switch + return forkActivation.BlockNumber switch { - null or < ShanghaiTimestamp => GenesisSpec, - _ => Shanghai.Instance - } - }; + < ConstantinopoleBlockNumber => GenesisSpec, + < ConstantinopoleFixBlockNumber => Constantinople.Instance, + < IstanbulBlockNumber => ConstantinopleFix.Instance, + < BerlinBlockNumber => Istanbul.Instance, + < LondonBlockNumber => Berlin.Instance, + _ => forkActivation.Timestamp switch + { + null or < ShanghaiTimestamp => London.Instance, + _ => Shanghai.Instance + } + }; + } public void UpdateMergeTransitionInfo(long? blockNumber, UInt256? terminalTotalDifficulty = null) { @@ -34,12 +40,19 @@ public void UpdateMergeTransitionInfo(long? blockNumber, UInt256? terminalTotalD public ForkActivation? MergeBlockNumber { get; private set; } public ulong TimestampFork => ShanghaiTimestamp; - public UInt256? TerminalTotalDifficulty { get; private set; } = UInt256.Parse("231707791542740786049188744689299064356246512"); - public IReleaseSpec GenesisSpec => London.Instance; + public UInt256? TerminalTotalDifficulty { get; private set; } = UInt256.Parse("8626000000000000000000058750000000000000000000"); + public IReleaseSpec GenesisSpec => Byzantium.Instance; public long? DaoBlockNumber => null; public ulong NetworkId => BlockchainIds.Gnosis; public ulong ChainId => BlockchainIds.Gnosis; public ForkActivation[] TransitionActivations { get; } + public const long ConstantinopoleBlockNumber = 1_604_400; + public const long ConstantinopoleFixBlockNumber = 2_508_800; + public const long IstanbulBlockNumber = 7_298_030; + public const long BerlinBlockNumber = 16_101_500; + public const long LondonBlockNumber = 19_040_000; + public const ulong ShanghaiTimestamp = long.MaxValue; + public static GnosisSpecProvider Instance { get; } = new(); } From e331b140915f0ca72b32501d32e6c1a7b1d4075c Mon Sep 17 00:00:00 2001 From: MarekM25 Date: Mon, 5 Jun 2023 14:14:07 +0200 Subject: [PATCH 3/3] More GetSpec checks --- .../ChainSpecBasedSpecProviderTests.cs | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/src/Nethermind/Nethermind.Specs.Test/ChainSpecStyle/ChainSpecBasedSpecProviderTests.cs b/src/Nethermind/Nethermind.Specs.Test/ChainSpecStyle/ChainSpecBasedSpecProviderTests.cs index cd853b77253..84b64b91bae 100644 --- a/src/Nethermind/Nethermind.Specs.Test/ChainSpecStyle/ChainSpecBasedSpecProviderTests.cs +++ b/src/Nethermind/Nethermind.Specs.Test/ChainSpecStyle/ChainSpecBasedSpecProviderTests.cs @@ -245,7 +245,17 @@ public void Gnosis_loads_properly() List forkActivationsToTest = new() { (ForkActivation)0, - //(ForkActivation)1, + (ForkActivation)1, + (ForkActivation)(GnosisSpecProvider.ConstantinopoleBlockNumber -1), + (ForkActivation)(GnosisSpecProvider.ConstantinopoleBlockNumber), + (ForkActivation)(GnosisSpecProvider.ConstantinopoleFixBlockNumber -1), + (ForkActivation)(GnosisSpecProvider.ConstantinopoleFixBlockNumber), + (ForkActivation)(GnosisSpecProvider.IstanbulBlockNumber -1), + (ForkActivation)(GnosisSpecProvider.IstanbulBlockNumber), + (ForkActivation)(GnosisSpecProvider.BerlinBlockNumber -1), + (ForkActivation)(GnosisSpecProvider.BerlinBlockNumber), + (ForkActivation)(GnosisSpecProvider.LondonBlockNumber -1), + (ForkActivation)(GnosisSpecProvider.LondonBlockNumber), (1, GnosisSpecProvider.ShanghaiTimestamp - 1), (1, GnosisSpecProvider.ShanghaiTimestamp), (999_999_999, 999_999_999) // far in the future