Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added GnosisSpecProvider and gnosis_loads_properly test #5775

Merged
merged 3 commits into from
Jun 5, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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));
Comment on lines +238 to +240
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is used all over those test would be good to make it a method.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

agreed, will do in next PR


ChainSpecBasedSpecProvider provider = new(chainSpec);
GnosisSpecProvider gnosisSpecProvider = GnosisSpecProvider.Instance;

List<ForkActivation> 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
};
Comment on lines +245 to +262
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

similarly to some extent

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yeah, it might be a bit harder though. Of course, doable ;)


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()
Expand Down
58 changes: 58 additions & 0 deletions src/Nethermind/Nethermind.Specs/GnosisSpecProvider.cs
Original file line number Diff line number Diff line change
@@ -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();
}