diff --git a/src/Nethermind/Nethermind.Specs.Test/ChainSpecStyle/ChainSpecBasedSpecProviderTests.cs b/src/Nethermind/Nethermind.Specs.Test/ChainSpecStyle/ChainSpecBasedSpecProviderTests.cs index 80194534802..84b64b91bae 100644 --- a/src/Nethermind/Nethermind.Specs.Test/ChainSpecStyle/ChainSpecBasedSpecProviderTests.cs +++ b/src/Nethermind/Nethermind.Specs.Test/ChainSpecStyle/ChainSpecBasedSpecProviderTests.cs @@ -232,6 +232,47 @@ 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, + (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 + }; + + CompareSpecProviders(gnosisSpecProvider, provider, forkActivationsToTest, CompareSpecsOptions.IsGnosis); + 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, 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);*/ + } + [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..935f8c77d28 --- /dev/null +++ b/src/Nethermind/Nethermind.Specs/GnosisSpecProvider.cs @@ -0,0 +1,58 @@ +// 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 +{ + private GnosisSpecProvider() { } + + public IReleaseSpec GetSpec(ForkActivation forkActivation) + { + return forkActivation.BlockNumber switch + { + < 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) + { + 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("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(); +}