Skip to content

Commit

Permalink
merge master into ilevm branch
Browse files Browse the repository at this point in the history
  • Loading branch information
Demuirgos committed Oct 31, 2024
2 parents 69cc361 + efe8dba commit 6d2b76d
Show file tree
Hide file tree
Showing 151 changed files with 3,739 additions and 952 deletions.
13 changes: 13 additions & 0 deletions .github/workflows/sync-supported-chains.yml
Original file line number Diff line number Diff line change
Expand Up @@ -296,6 +296,19 @@ jobs:
config: ${{fromJson(needs.setup-matrix.outputs.matrix)}}
runs-on: ubuntu-latest
steps:
- name: Destroy VM (if initialization failed)
uses: kamilchodola/linode-github-runner/.github/actions/linode-machine-manager@main
if: ${{ failure() && needs.create_a_runner.result == 'failure' }}
with:
linode_token: ${{ secrets.LINODE_TOKEN }}
github_token: "${{ secrets.REPOSITORY_DISPATCH_TOKEN }}"
action: "destroy-machine"
runner_label: t-${{ github.run_id }}-${{ matrix.config.network }}
search_phrase: t-${{ github.run_id }}-${{ matrix.config.network }}
root_password: ${{ secrets.LINODE_ROOT_PASSWORD }}
organization: "NethermindEth"
repo_name: "nethermind"

- name: Destroy Runner
uses: kamilchodola/linode-github-runner/.github/actions/linode-machine-manager@main
with:
Expand Down
5 changes: 3 additions & 2 deletions src/Nethermind/Directory.Packages.props
Original file line number Diff line number Diff line change
Expand Up @@ -47,14 +47,15 @@
<PackageVersion Include="Microsoft.IO.RecyclableMemoryStream" Version="3.0.1" />
<PackageVersion Include="Microsoft.NET.Test.Sdk" Version="17.10.0" />
<PackageVersion Include="Microsoft.VisualStudio.Azure.Containers.Tools.Targets" Version="1.21.0" />
<PackageVersion Include="Nethermind.Crypto.Bls" Version="1.0.3" />
<PackageVersion Include="Nethermind.Crypto.Bls" Version="1.0.4" />
<PackageVersion Include="Nethermind.Crypto.Pairings" Version="1.1.1" />
<PackageVersion Include="Nethermind.Crypto.SecP256k1" Version="1.2.2" />
<PackageVersion Include="Nethermind.DotNetty.Buffers" Version="1.0.1" />
<PackageVersion Include="Nethermind.DotNetty.Handlers" Version="1.0.1" />
<PackageVersion Include="Nethermind.DotNetty.Transport" Version="1.0.1" />
<PackageVersion Include="Nethermind.Gmp" Version="1.0.1" />
<PackageVersion Include="Nethermind.Libp2p" Version="1.0.0-preview.33" />
<PackageVersion Include="Nethermind.Libp2p" Version="1.0.0-preview.34" />
<PackageVersion Include="Nethermind.Libp2p.Protocols.PubsubPeerDiscovery" Version="1.0.0-preview.34" />
<PackageVersion Include="Nethermind.Numerics.Int256" Version="1.2.0" />
<PackageVersion Include="Nito.Collections.Deque" Version="1.2.1" />
<PackageVersion Include="NLog" Version="5.3.2" />
Expand Down
4 changes: 2 additions & 2 deletions src/Nethermind/Ethereum.Test.Base/AccountState.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,9 @@ namespace Ethereum.Test.Base
{
public class AccountState
{
public byte[] Code { get; set; }
public byte[] Code { get; set; } = [];
public UInt256 Balance { get; set; }
public UInt256 Nonce { get; set; }
public Dictionary<UInt256, byte[]> Storage { get; set; }
public Dictionary<UInt256, byte[]> Storage { get; set; } = new();
}
}
15 changes: 0 additions & 15 deletions src/Nethermind/Ethereum.Test.Base/AccountStateJson.cs

This file was deleted.

9 changes: 5 additions & 4 deletions src/Nethermind/Ethereum.Test.Base/AuthorizationListJson.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,16 @@
// SPDX-License-Identifier: LGPL-3.0-only

using Nethermind.Core;
using Nethermind.Int256;

namespace Ethereum.Test.Base;
public class AuthorizationListJson
{
public ulong ChainId { get; set; }
public UInt256 ChainId { get; set; }
public Address Address { get; set; }
public ulong Nonce { get; set; }
public UInt256 Nonce { get; set; }
public ulong V { get; set; }
public byte[] R { get; set; }
public byte[] S { get; set; }
public string R { get; set; }
public string S { get; set; }
public Address Signer { get; set; }
}
5 changes: 3 additions & 2 deletions src/Nethermind/Ethereum.Test.Base/BlockchainTestJson.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
// SPDX-License-Identifier: LGPL-3.0-only

using System.Collections.Generic;
using Nethermind.Core;
using Nethermind.Core.Crypto;
using Nethermind.Core.Specs;

Expand All @@ -24,8 +25,8 @@ public class BlockchainTestJson
public TestBlockJson[]? Blocks { get; set; }
public TestBlockHeaderJson? GenesisBlockHeader { get; set; }

public Dictionary<string, AccountStateJson>? Pre { get; set; }
public Dictionary<string, AccountStateJson>? PostState { get; set; }
public Dictionary<Address, AccountState>? Pre { get; set; }
public Dictionary<Address, AccountState>? PostState { get; set; }

public Hash256? PostStateHash { get; set; }

Expand Down
3 changes: 2 additions & 1 deletion src/Nethermind/Ethereum.Test.Base/GeneralStateTestJson.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@

using System.Collections.Generic;
using System.Text.Json.Serialization;
using Nethermind.Core;

namespace Ethereum.Test.Base
{
Expand All @@ -12,7 +13,7 @@ public class GeneralStateTestJson
public GeneralStateTestInfoJson? Info { get; set; }
public GeneralStateTestEnvJson? Env { get; set; }
public Dictionary<string, PostStateJson[]>? Post { get; set; }
public Dictionary<string, AccountStateJson>? Pre { get; set; }
public Dictionary<Address, AccountState>? Pre { get; set; }
public string? SealEngine { get; set; }
public string? LoadFailure { get; set; }
public TransactionJson? Transaction { get; set; }
Expand Down
27 changes: 3 additions & 24 deletions src/Nethermind/Ethereum.Test.Base/GeneralTestBase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,11 @@
using System;
using System.Collections.Generic;
using System.Diagnostics;
using Nethermind.Blockchain;
using Nethermind.Consensus.Ethash;
using Nethermind.Consensus.Validators;
using Nethermind.Core;
using Nethermind.Core.Crypto;
using Nethermind.Core.Extensions;
using Nethermind.Core.Specs;
using Nethermind.Core.Test.Builders;
using Nethermind.Crypto;
using Nethermind.Db;
using Nethermind.Int256;
Expand Down Expand Up @@ -89,7 +86,7 @@ protected EthereumTestResult RunTest(GeneralStateTest test, ITxTracer txTracer)
codeInfoRepository,
_logManager);

InitializeTestState(test, stateProvider, specProvider);
InitializeTestState(test.Pre, stateProvider, specProvider);

BlockHeader header = new(
test.PreviousHash,
Expand Down Expand Up @@ -135,8 +132,6 @@ protected EthereumTestResult RunTest(GeneralStateTest test, ITxTracer txTracer)
header.ExcessBlobGas = BlobGasCalculator.CalculateExcessBlobGas(parent, spec);
}

Block block = Build.A.Block.WithTransactions(test.Transaction).WithHeader(header).TestObject;

ValidationResult txIsValid = _txValidator.IsWellFormed(test.Transaction, spec);

if (txIsValid)
Expand Down Expand Up @@ -172,9 +167,9 @@ protected EthereumTestResult RunTest(GeneralStateTest test, ITxTracer txTracer)
return testResult;
}

private static void InitializeTestState(GeneralStateTest test, WorldState stateProvider, ISpecProvider specProvider)
private static void InitializeTestState(Dictionary<Address, AccountState> preState, WorldState stateProvider, ISpecProvider specProvider)
{
foreach (KeyValuePair<Address, AccountState> accountState in test.Pre)
foreach (KeyValuePair<Address, AccountState> accountState in preState)
{
foreach (KeyValuePair<UInt256, byte[]> storageItem in accountState.Value.Storage)
{
Expand All @@ -192,22 +187,6 @@ private static void InitializeTestState(GeneralStateTest test, WorldState stateP
stateProvider.Reset();
}

private bool IsValidBlock(Block block, ISpecProvider specProvider)
{
IBlockTree blockTree = Build.A.BlockTree()
.WithSpecProvider(specProvider)
.WithoutSettingHead
.TestObject;

var difficultyCalculator = new EthashDifficultyCalculator(specProvider);
var sealer = new EthashSealValidator(_logManager, difficultyCalculator, new CryptoRandom(), new Ethash(_logManager), Timestamper.Default);
IHeaderValidator headerValidator = new HeaderValidator(blockTree, sealer, specProvider, _logManager);
IUnclesValidator unclesValidator = new UnclesValidator(blockTree, headerValidator, _logManager);
IBlockValidator blockValidator = new BlockValidator(_txValidator, headerValidator, unclesValidator, specProvider, _logManager);

return blockValidator.ValidateOrphanedBlock(block, out _);
}

private List<string> RunAssertions(GeneralStateTest test, IWorldState stateProvider)
{
List<string> differences = [];
Expand Down
92 changes: 53 additions & 39 deletions src/Nethermind/Ethereum.Test.Base/JsonToEthereumTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -21,13 +21,13 @@ namespace Ethereum.Test.Base
{
public static class JsonToEthereumTest
{
private static IReleaseSpec ParseSpec(string network)
public static IReleaseSpec ParseSpec(string network)
{
network = network.Replace("EIP150", "TangerineWhistle");
network = network.Replace("EIP158", "SpuriousDragon");
network = network.Replace("DAO", "Dao");
network = network.Replace("Merged", "GrayGlacier");
network = network.Replace("Merge", "GrayGlacier");
network = network.Replace("Merged", "Paris");
network = network.Replace("Merge", "Paris");
network = network.Replace("London+3540+3670", "Shanghai");
network = network.Replace("GrayGlacier+3540+3670", "Shanghai");
network = network.Replace("GrayGlacier+3860", "Shanghai");
Expand Down Expand Up @@ -55,6 +55,7 @@ private static IReleaseSpec ParseSpec(string network)
"Istanbul" => Istanbul.Instance,
"Berlin" => Berlin.Instance,
"London" => London.Instance,
"ArrowGlacier" => ArrowGlacier.Instance,
"GrayGlacier" => GrayGlacier.Instance,
"Shanghai" => Shanghai.Instance,
"Cancun" => Cancun.Instance,
Expand Down Expand Up @@ -112,17 +113,6 @@ public static BlockHeader Convert(TestBlockHeaderJson? headerJson)
return header;
}

public static Block Convert(PostStateJson postStateJson, TestBlockJson testBlockJson)
{
BlockHeader? header = Convert(testBlockJson.BlockHeader);
BlockHeader[] uncles = testBlockJson.UncleHeaders?.Select(Convert).ToArray()
?? Array.Empty<BlockHeader>();
Transaction[] transactions = testBlockJson.Transactions?.Select(Convert).ToArray()
?? Array.Empty<Transaction>();
Block block = new(header, transactions, uncles);
return block;
}

public static Transaction Convert(PostStateJson postStateJson, TransactionJson transactionJson)
{
Transaction transaction = new();
Expand Down Expand Up @@ -162,13 +152,51 @@ public static Transaction Convert(PostStateJson postStateJson, TransactionJson t
{
transaction.AuthorizationList =
transactionJson.AuthorizationList
.Select(i => new AuthorizationTuple(
i.ChainId,
i.Address,
i.Nonce,
i.V,
i.R,
i.S)).ToArray();
.Select(i =>
{
if (i.ChainId > ulong.MaxValue)
{
i.ChainId = 0;
transaction.SenderAddress = Address.Zero;
}
if (i.Nonce > ulong.MaxValue)
{
i.Nonce = 0;
transaction.SenderAddress = Address.Zero;
}
UInt256 s = UInt256.Zero;
if (i.S.Length > 66)
{
i.S = "0x0";
transaction.SenderAddress = Address.Zero;
}
else
{
s = UInt256.Parse(i.S);
}
UInt256 r = UInt256.Zero;
if (i.R.Length > 66)
{
i.R = "0x0";
transaction.SenderAddress = Address.Zero;
}
else
{
r = UInt256.Parse(i.R);
}
if (i.V > byte.MaxValue)
{
i.V = 0;
transaction.SenderAddress = Address.Zero;
}
return new AuthorizationTuple(
i.ChainId.u0,
i.Address,
i.Nonce.u0,
(byte)i.V,
r,
s);
}).ToArray();
if (transaction.AuthorizationList.Any())
{
transaction.Type = TxType.SetCode;
Expand All @@ -178,7 +206,7 @@ public static Transaction Convert(PostStateJson postStateJson, TransactionJson t
return transaction;
}

private static void ProcessAccessList(AccessListItemJson[]? accessList, AccessList.Builder builder)
public static void ProcessAccessList(AccessListItemJson[]? accessList, AccessList.Builder builder)
{
foreach (AccessListItemJson accessListItemJson in accessList ?? Array.Empty<AccessListItemJson>())
{
Expand All @@ -204,20 +232,6 @@ public static Transaction Convert(LegacyTransactionJson transactionJson)
return transaction;
}

private static AccountState Convert(AccountStateJson accountStateJson)
{
AccountState state = new();
state.Balance = accountStateJson.Balance is not null ? Bytes.FromHexString(accountStateJson.Balance).ToUInt256() : 0;
state.Code = accountStateJson.Code is not null ? Bytes.FromHexString(accountStateJson.Code) : Array.Empty<byte>();
state.Nonce = accountStateJson.Nonce is not null ? Bytes.FromHexString(accountStateJson.Nonce).ToUInt256() : 0;
state.Storage = accountStateJson.Storage is not null
? accountStateJson.Storage.ToDictionary(
p => Bytes.FromHexString(p.Key).ToUInt256(),
p => Bytes.FromHexString(p.Value))
: new();
return state;
}

public static IEnumerable<GeneralStateTest> Convert(string name, GeneralStateTestJson testJson)
{
if (testJson.LoadFailure is not null)
Expand Down Expand Up @@ -256,7 +270,7 @@ public static IEnumerable<GeneralStateTest> Convert(string name, GeneralStateTes
test.ParentExcessBlobGas = testJson.Env.ParentExcessBlobGas;
test.PostReceiptsRoot = stateJson.Logs;
test.PostHash = stateJson.Hash;
test.Pre = testJson.Pre.ToDictionary(p => new Address(p.Key), p => Convert(p.Value));
test.Pre = testJson.Pre.ToDictionary(p => p.Key, p => p.Value);
test.Transaction = Convert(stateJson, testJson.Transaction);

blockchainTests.Add(test);
Expand All @@ -283,7 +297,7 @@ public static BlockchainTest Convert(string name, BlockchainTestJson testJson)
test.GenesisRlp = testJson.GenesisRlp is null ? null : new Rlp(Bytes.FromHexString(testJson.GenesisRlp));
test.GenesisBlockHeader = testJson.GenesisBlockHeader;
test.Blocks = testJson.Blocks;
test.Pre = testJson.Pre.ToDictionary(p => new Address(p.Key), p => Convert(p.Value));
test.Pre = testJson.Pre.ToDictionary(p => p.Key, p => p.Value);

HalfBlockchainTestJson half = testJson as HalfBlockchainTestJson;
if (half is not null)
Expand All @@ -292,7 +306,7 @@ public static BlockchainTest Convert(string name, BlockchainTestJson testJson)
}
else
{
test.PostState = testJson.PostState?.ToDictionary(p => new Address(p.Key), p => Convert(p.Value));
test.PostState = testJson.PostState?.ToDictionary(p => p.Key, p => p.Value);
test.PostStateRoot = testJson.PostStateHash;
}

Expand Down
2 changes: 1 addition & 1 deletion src/Nethermind/Nethermind.Api/IApiWithStores.cs
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ public interface IApiWithStores : IBasicApi
IReceiptFinder? ReceiptFinder { get; set; }
IReceiptMonitor? ReceiptMonitor { get; set; }
IWallet? Wallet { get; set; }
IBlockStore? BadBlocksStore { get; set; }
IBadBlockStore? BadBlocksStore { get; set; }

public ContainerBuilder ConfigureContainerBuilderFromApiWithStores(ContainerBuilder builder)
{
Expand Down
2 changes: 1 addition & 1 deletion src/Nethermind/Nethermind.Api/NethermindApi.cs
Original file line number Diff line number Diff line change
Expand Up @@ -227,7 +227,7 @@ public ISealEngine SealEngine
public BackgroundTaskScheduler BackgroundTaskScheduler { get; set; } = null!;
public CensorshipDetector CensorshipDetector { get; set; } = null!;
public IWallet? Wallet { get; set; }
public IBlockStore? BadBlocksStore { get; set; }
public IBadBlockStore? BadBlocksStore { get; set; }
public ITransactionComparerProvider? TransactionComparerProvider { get; set; }
public IWebSocketsManager WebSocketsManager { get; set; } = new WebSocketsManager();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@ public void Test_StoreBeaconRoot_AccessListIsNull()
BlockHeader header = Build.A.BlockHeader.TestObject;
Block block = Build.A.Block.WithHeader(header).TestObject;

_beaconBlockRootHandler.StoreBeaconRoot(block, Cancun.Instance);
_beaconBlockRootHandler.StoreBeaconRoot(block, Cancun.Instance, NullTxTracer.Instance);

_transactionProcessor.DidNotReceive().Execute(Arg.Any<Transaction>(), Arg.Any<BlockExecutionContext>(), Arg.Any<ITxTracer>());
}
Expand All @@ -136,7 +136,7 @@ public void Test_StoreBeaconRoot_AccessListNotNull()
Block block = Build.A.Block.WithHeader(header).TestObject;
_worldState.AccountExists(Arg.Any<Address>()).Returns(true);

_beaconBlockRootHandler.StoreBeaconRoot(block, Cancun.Instance);
_beaconBlockRootHandler.StoreBeaconRoot(block, Cancun.Instance, NullTxTracer.Instance);

Transaction transaction = new()
{
Expand Down
Loading

0 comments on commit 6d2b76d

Please sign in to comment.