Skip to content

Commit

Permalink
Correct usage of chain ID and network ID (#4850)
Browse files Browse the repository at this point in the history
* Add engine_getPayloadV2

* Format whitespaces

* Refactor and remove redundant "V1"

* started adding Enginge V2 tests - V2_processing_block_should_serialize_valid_responses

* formatting

* formatting

* Implement withdrawal root validation

* working on tests and fixes

* fix block for processing

* BlockValidator WithdrawalRoot

* Fix withdrawal trie proof validation

* add WithdrawalApplier

* Remove redundant withdrawals hash check

* Remove withdrawal check for null

* Add withdrawals test chain spec

* Reformat whitespaces

* add withdrawalApplier to blockchainProcessor

* add withdrawals to ExecutionPayload

* test fixes

* fix EVM.test

* fix EthereumTests

* fix Benchmarks.sln

* Revise withdrawals representation according to the spec and refactor

* Rename `IWithdrawalApplier` to `IWithdrawalProcessor`

* Add tests for withdrawal encoding/decoding

* Rename `Recipient` to `Address`

* Reformat whitespaces

* Revise withdrawals length calculation in block encoding

* HasBody?

* Remove redundant withdrawals hash check

* fix withdrawals_test chainspec && added IReleaseSpec.WithdrawalsEnabled

* Fixes

* fix GenesisLoader

* fix extra-data

* Refactor withdrawal validation by implementing `IWithdrawalValidator`

* Fix failing tests

* Reformat whitespaces

* fix withdrawalsTimestamp

* temporary change validation

* null handling?

* Applying Marek's suggestion. Not sure about this one

* Fix Ethereum tests

* Fix test cases

* Fix benchmark build

* Fix payload attributes validation

* Remove "V1" from `IForkchoiceUpdatedHandler` name

* Update tests

* hack AuRa tests for now

* fix more tests

* fix more tests

* fix build

* + fix one more tests

* fix Synchronization tests

* Update tests to 0aa59689101f64cab8fa1526d9cf6e647ddba946

* fixed withdrawal chainspec

* withdrawals block validator tests

* Implement Engine API tests

* Reformat code

* fix chainspec?

* Fix withdrawals decoding

* fix chainspec timestamp

* Add and fix Engine API tests

* Revise block decoder tests

* Revise file headers

* Revise file headers

* Add missing file headers

* fix AuRa test

* adjusting comments

* load genesis tests

* Lukasz suggestions

* formating

* Fix build

* withdrawals_hivetests.json + cosmetic

* Add more unit tests

* spacing

* Try on fixing timestamp activation with same value as genesis timestamp

* Fix gnosis and chiado ForkId Calculations

* fix tests

* Cleanup and more tests

* Janky but working solution to very rare edge case?

* Fix flakiness of caused by Parallelizable

* Correct usage of chain ID and network ID

* adding engine tests

* working on more tests

* add loop in test

* Can_apply_withdrawals_correctly test

* more test cases

* Update withdrawals hive tests configuration

* Refactor and fix some null reference warnings

* Expose withdrawals to JSON-RPC modules

* Fix broken tests

* Revise `ForkchoiceUpdatedHandler` string output

* fix Can_apply_withdrawals_correctly

* fix whitespaces

* fix whitespaces

* more whitespaces fixes

* add more tests

* Fix chainId loading from spec

* Rename for clarity

* work on Withdrawals_transition test cases

* adjust CustomSpecProvider

* Introduce IEip1995Spec

* Make test NetworkId vs ChainId different

Changing ChainId to another number breaks a lot of test, that are based to hashes and RLP. Let at least test if the values differ

* small changes in tests

* Fix license

* add comments

* Apply Marek Suggestion

* Adjust Lic to Rubo

* Marek Suggestions

* Fix

* fix withdrawals in ChainLevelHelper

* Fix chainid for account abstraction; add and improve tests; fix a tutorial link

* Fix naming in other projects, whitespaces

* Fix more renaming

* fix hive sync tests

* fix?

* Revise withdrawals root hash encoding/decoding and its tests

* fix PayloadAttributes ToString

* add more temp logs to investigate hive tests

* more logs

* revert not needed logs

* fix test

* ignore incorrect tests

* Fix tests broken by withdrawals decoding revision

* Revise file headers

* Final appraoch, removed GetSpec complexity

* Forgotten changes

* SecondsPerSlot to BlocksConfig

* Minor + config changes

* Typo fix

* remove empty line

* Move BlocksConfig to Nethermind.Config project

* Benchmark build fix

* Rename `ExecutionPayloadV1` to `ExecutionPayloadV2`

* Revise withdrawals check

* Refactor tests

* Optimize withdrawals root hash decoding in block header

* Implements ForkId tests that are ub EIP-6122

* Spacing

* Fix build

* Fix ForkId Test case

* Removing 3675 and using MergeForkId Transition

* Final test fix

* Fix tests

* Rename `ExecutionPayloadV2` to `ExecutionPayload`

* add one more line in Nlog (temp)

* Revert NLog for jsonRpc

* fix missing body?

* adjust TxPool logs

* Add more test cases for `BlockBodiesMessageSerializer`

* Add tests for `BlockHeader.HasBody`

* Revise `null` handling for `BlockHeader.HasBody`

* fix BlockBody empty

* cosmetic

* fix CI

* Revise tests

* Update null checks with pattern matching

* Refactor block body initialization and add tests

* Revise whitespaces

* cosmetic

* ForkId calculation polish (#5068)

* Refactor - mainly ChainSpecBasedSpecProvider

* fixes

* Better warning message

* Simplify sanity check

* one more simplification

* Revise Clique block production according to withdrawals rules

* Add withdrawals to `eth_getBlockByNumber` tests

* SecondsPerSlot move to BlocksConfig (#4944)

Co-authored-by: MarekM25 <marekm2504@gmail.com>
Co-authored-by: lukasz.rozmej <lukasz.rozmej@gmail.com>
Resolves #4871

* fix build

* removed duplicated NSubstitute

* Fix network id in node info

* Rollback spec change

* Rename NetworkId class to BlockchainIds; more renaming and usage of TestBlockChainIds

* Improve a test

* Fix chainid/networkid usage

* Refactors

* Improve CustomSpecProvider ctor

* Use test provider

* ethstats fix

* whitespace

* Fix

Co-authored-by: Ruben Buniatyan <rubo@users.noreply.github.com>
Co-authored-by: MarekM25 <marekm2504@gmail.com>
Co-authored-by: smartprogrammer <smartprogrammer@windowslive.com>
Co-authored-by: Lukasz Rozmej <lukasz.rozmej@gmail.com>
Co-authored-by: Ahmad Bitar <33181301+smartprogrammer93@users.noreply.github.com>
  • Loading branch information
6 people committed Jan 20, 2023
1 parent e9c1a85 commit fd34651
Show file tree
Hide file tree
Showing 126 changed files with 493 additions and 326 deletions.
2 changes: 1 addition & 1 deletion src/Nethermind/Ethereum.Basic.Test/TransactionTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ public static IEnumerable<TransactionTest> LoadTests()
[TestCaseSource(nameof(LoadTests))]
public void Test(TransactionTest test)
{
EthereumEcdsa ethereumEcdsa = new EthereumEcdsa(ChainId.Olympic, LimboLogs.Instance);
EthereumEcdsa ethereumEcdsa = new EthereumEcdsa(TestBlockchainIds.ChainId, LimboLogs.Instance);
Transaction decodedUnsigned = Rlp.Decode<Transaction>(test.Unsigned);
Assert.AreEqual(test.Value, decodedUnsigned.Value, "value");
Assert.AreEqual(test.GasPrice, decodedUnsigned.GasPrice, "gasPrice");
Expand Down
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.Specs;
using Nethermind.Specs.Forks;
using NUnit.Framework;
Expand All @@ -19,7 +20,7 @@ public static IEnumerable<DifficultyTests> LoadFrontierTests()
[TestCaseSource(nameof(LoadFrontierTests))]
public void Test(DifficultyTests test)
{
RunTest(test, new SingleReleaseSpecProvider(Homestead.Instance, 1));
RunTest(test, new TestSingleReleaseSpecProvider(Homestead.Instance));
}
}
}
2 changes: 1 addition & 1 deletion src/Nethermind/Ethereum.KeyAddress.Test/KeyAddressTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ public class KeyAddressTests
public void SetUp()
{
Directory.SetCurrentDirectory(AppDomain.CurrentDomain.BaseDirectory);
_ecdsa = new EthereumEcdsa(ChainId.Olympic, LimboLogs.Instance);
_ecdsa = new EthereumEcdsa(TestBlockchainIds.ChainId, LimboLogs.Instance);
}

private static IEnumerable<KeyAddressTest> LoadTests()
Expand Down
6 changes: 3 additions & 3 deletions src/Nethermind/Ethereum.Test.Base/BlockchainTestBase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -87,14 +87,14 @@ protected async Task<EthereumTestResult> RunTest(BlockchainTest test, Stopwatch?
ISpecProvider specProvider;
if (test.NetworkAfterTransition != null)
{
specProvider = new CustomSpecProvider(1,
specProvider = new CustomSpecProvider(
((ForkActivation)0, Frontier.Instance),
((ForkActivation)1, test.Network),
((ForkActivation)test.TransitionBlockNumber, test.NetworkAfterTransition));
}
else
{
specProvider = new CustomSpecProvider(1,
specProvider = new CustomSpecProvider(
((ForkActivation)0, Frontier.Instance), // TODO: this thing took a lot of time to find after it was removed!, genesis block is always initialized with Frontier
((ForkActivation)1, test.Network));
}
Expand Down Expand Up @@ -123,7 +123,7 @@ protected async Task<EthereumTestResult> RunTest(BlockchainTest test, Stopwatch?

IReceiptStorage receiptStorage = NullReceiptStorage.Instance;
IBlockhashProvider blockhashProvider = new BlockhashProvider(blockTree, _logManager);
ITxValidator txValidator = new TxValidator(ChainId.Mainnet);
ITxValidator txValidator = new TxValidator(TestBlockchainIds.ChainId);
IHeaderValidator headerValidator = new HeaderValidator(blockTree, Sealer, specProvider, _logManager);
IUnclesValidator unclesValidator = new UnclesValidator(blockTree, headerValidator, _logManager);
IBlockValidator blockValidator = new BlockValidator(txValidator, headerValidator, unclesValidator, specProvider, _logManager);
Expand Down
2 changes: 1 addition & 1 deletion src/Nethermind/Ethereum.Test.Base/GeneralTestBase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ protected EthereumTestResult RunTest(GeneralStateTest test, ITxTracer txTracer)
IDb stateDb = new MemDb();
IDb codeDb = new MemDb();

ISpecProvider specProvider = new CustomSpecProvider(1,
ISpecProvider specProvider = new CustomSpecProvider(
((ForkActivation)0, Frontier.Instance), // TODO: this thing took a lot of time to find after it was removed!, genesis block is always initialized with Frontier
((ForkActivation)1, test.Fork));

Expand Down
4 changes: 2 additions & 2 deletions src/Nethermind/Ethereum.Transaction.Test/TransactionTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -174,7 +174,7 @@ private void RunTest(TransactionTest test, IReleaseSpec spec)

bool useChainId = transaction.Signature.V > 28UL;

TxValidator validator = new(useChainId ? ChainId.Mainnet : 0UL);
TxValidator validator = new(useChainId ? BlockchainIds.Mainnet : 0UL);

if (validTest != null)
{
Expand All @@ -189,7 +189,7 @@ private void RunTest(TransactionTest test, IReleaseSpec spec)
Signature expectedSignature = new(validTest.R, validTest.S, validTest.V);
Assert.AreEqual(expectedSignature, transaction.Signature, "signature");

IEthereumEcdsa ecdsa = new EthereumEcdsa(useChainId ? ChainId.Mainnet : 0UL, LimboLogs.Instance);
IEthereumEcdsa ecdsa = new EthereumEcdsa(useChainId ? BlockchainIds.Mainnet : 0UL, LimboLogs.Instance);
bool verified = ecdsa.Verify(
validTest.Sender,
transaction);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,7 @@ private UserOperationPool GenerateUserOperationPool(Address entryPoint, int capa
_simulator,
userOperationSortedPool,
userOperationBroadcaster,
1);
TestBlockchainIds.ChainId);
}

}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@
using Nethermind.Core;
using Nethermind.Core.Crypto;
using Nethermind.Core.Specs;
using Nethermind.Core.Test;
using Nethermind.Core.Test.Blockchain;
using Nethermind.Core.Test.Builders;
using Nethermind.Evm.Tracing;
Expand All @@ -34,8 +33,6 @@
using Nethermind.JsonRpc.Test.Modules;
using Nethermind.Logging;
using Nethermind.Merge.Plugin.BlockProduction;
using Nethermind.Merge.Plugin.Data;
using Nethermind.Merge.Plugin.Handlers;
using Nethermind.Specs;
using Nethermind.Specs.Forks;
using Nethermind.State;
Expand All @@ -53,7 +50,6 @@ public partial class AccountAbstractionRpcModuleTests
TestSpecProvider testSpecProvider = releaseSpec is not null
? new TestSpecProvider(releaseSpec)
: new TestSpecProvider(London.Instance);
testSpecProvider.ChainId = 1;
return TestRpcBlockchain.ForTest(testMevRpcBlockchain).Build(testSpecProvider);
}

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
// SPDX-FileCopyrightText: 2022 Demerzel Solutions Limited
// SPDX-License-Identifier: LGPL-3.0-only

using Nethermind.Api;
using Nethermind.JsonRpc;
using NSubstitute;
using NUnit.Framework;

namespace Nethermind.AccountAbstraction.Test
{
[TestFixture]
internal class InitializationTests
{
private INethermindApi? _api;
private AccountAbstractionPlugin? _accountAbstractionPlugin;

[SetUp]
public void Setup()
{
_api = Substitute.For<INethermindApi>();
IAccountAbstractionConfig accountAbstractionConfig = Substitute.For<IAccountAbstractionConfig>();
accountAbstractionConfig.Enabled.Returns(true);
accountAbstractionConfig.EntryPointContractAddresses.Returns("0x0101010101010101010101010101010101010101");
_api.Config<IAccountAbstractionConfig>().Returns(accountAbstractionConfig);
_api.Config<IJsonRpcConfig>().Returns(Substitute.For<IJsonRpcConfig>());
_api.ForRpc.Returns((Substitute.For<IApiWithNetwork>(), Substitute.For<INethermindApi>()));
_api.ForProducer.Returns((Substitute.For<IApiWithBlockchain>(), Substitute.For<IApiWithBlockchain>()));

_accountAbstractionPlugin = new();
_accountAbstractionPlugin.Init(_api);
_accountAbstractionPlugin.InitNetworkProtocol();
}

[Test]
public void ChainId_is_used_for_UserOperationPool()
{
_ = _api!.SpecProvider!.Received().ChainId;
_ = _api.SpecProvider!.DidNotReceive().NetworkId;
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -428,7 +428,7 @@ private UserOperationPool GenerateUserOperationPool(int capacity = 10, int perSe
_simulator,
userOperationSortedPool,
userOperationBroadcaster,
1);
TestBlockchainIds.ChainId);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -189,7 +189,7 @@ public void NewPendingUserOperationsSubscription_creating_result_with_wrong_entr
public void NewPendingUserOperationsSubscription_on_NewPending_event()
{
UserOperation userOperation = Build.A.UserOperation.TestObject;
userOperation.CalculateRequestId(_entryPointAddress, 1);
userOperation.CalculateRequestId(_entryPointAddress, TestBlockchainIds.ChainId);
UserOperationEventArgs userOperationEventArgs = new(userOperation, _entryPointAddress);

JsonRpcResult jsonRpcResult = GetNewPendingUserOpsResult(userOperationEventArgs, out var subscriptionId, true);
Expand All @@ -204,7 +204,7 @@ public void NewPendingUserOperationsSubscription_on_NewPending_event()
public void NewPendingUserOperationsSubscription_on_NewPending_event_without_full_user_operations()
{
UserOperation userOperation = Build.A.UserOperation.TestObject;
userOperation.CalculateRequestId(_entryPointAddress, 1);
userOperation.CalculateRequestId(_entryPointAddress, TestBlockchainIds.ChainId);
UserOperationEventArgs userOperationEventArgs = new(userOperation, _entryPointAddress);

JsonRpcResult jsonRpcResult = GetNewPendingUserOpsResult(userOperationEventArgs, out string subscriptionId, false);
Expand Down Expand Up @@ -250,7 +250,7 @@ public void NewReceivedUserOperationsSubscription_creating_result_with_wrong_ent
public void NewReceivedUserOperationsSubscription_on_NewPending_event()
{
UserOperation userOperation = Build.A.UserOperation.TestObject;
userOperation.CalculateRequestId(_entryPointAddress, 1);
userOperation.CalculateRequestId(_entryPointAddress, TestBlockchainIds.ChainId);
UserOperationEventArgs userOperationEventArgs = new(userOperation, _entryPointAddress);

JsonRpcResult jsonRpcResult = GetNewReceivedUserOpsResult(userOperationEventArgs, out var subscriptionId, true);
Expand All @@ -265,7 +265,7 @@ public void NewReceivedUserOperationsSubscription_on_NewPending_event()
public void NewReceivedUserOperationsSubscription_on_NewPending_event_without_full_user_operations()
{
UserOperation userOperation = Build.A.UserOperation.TestObject;
userOperation.CalculateRequestId(_entryPointAddress, 1);
userOperation.CalculateRequestId(_entryPointAddress, TestBlockchainIds.ChainId);
UserOperationEventArgs userOperationEventArgs = new(userOperation, _entryPointAddress);

JsonRpcResult jsonRpcResult = GetNewReceivedUserOpsResult(userOperationEventArgs, out var subscriptionId, false);
Expand Down
4 changes: 2 additions & 2 deletions src/Nethermind/Nethermind.AuRa.Test/AuRaSealerTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ public void Setup()
_auRaStepCalculator = Substitute.For<IAuRaStepCalculator>();
_validatorStore = Substitute.For<IValidatorStore>();
_validSealerStrategy = Substitute.For<IValidSealerStrategy>();
Signer signer = new(ChainId.Mainnet, Build.A.PrivateKey.TestObject, LimboLogs.Instance);
Signer signer = new(TestBlockchainIds.ChainId, Build.A.PrivateKey.TestObject, LimboLogs.Instance);
_address = signer.Address;

_auRaSealer = new AuRaSealer(
Expand Down Expand Up @@ -78,7 +78,7 @@ public async Task seal_can_recover_address()

block = await _auRaSealer.SealBlock(block, CancellationToken.None);

EthereumEcdsa ecdsa = new(ChainId.Morden, LimboLogs.Instance);
EthereumEcdsa ecdsa = new(BlockchainIds.Morden, LimboLogs.Instance);
Signature signature = new(block.Header.AuRaSignature);
signature.V += Signature.VOffset;
Address? recoveredAddress = ecdsa.RecoverAddress(signature, block.Header.CalculateHash(RlpBehaviors.ForSealing));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
using NSubstitute;
using NUnit.Framework;
using BlockTree = Nethermind.Blockchain.BlockTree;
using Nethermind.Core.Specs;

namespace Nethermind.AuRa.Test.Validators
{
Expand Down Expand Up @@ -551,8 +552,8 @@ IEnumerable<Block> GetAllBlocks(BlockTree bt)

Address validators = TestItem.Addresses[initialValidatorsIndex * 10];
InMemoryReceiptStorage inMemoryReceiptStorage = new();
BlockTreeBuilder blockTreeBuilder = Build.A.BlockTree().WithTransactions(inMemoryReceiptStorage,
RopstenSpecProvider.Instance, delegate (Block block, Transaction transaction)
BlockTreeBuilder blockTreeBuilder = Build.A.BlockTree(RopstenSpecProvider.Instance)
.WithTransactions(inMemoryReceiptStorage, delegate (Block block, Transaction transaction)
{
byte i = 0;
return new[]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@ public async Task Tree_tracker_insert_leaves([ValueSource(nameof(InsertLeavesTes

private async Task<(TestRpcBlockchain TestRpc, BaselineModule BaselineModule)> InitializeTestRpc(Address address)
{
SingleReleaseSpecProvider spec = new(ConstantinopleFix.Instance, 1);
SingleReleaseSpecProvider spec = new(ConstantinopleFix.Instance, TestBlockchainIds.NetworkId, TestBlockchainIds.ChainId);
BlockBuilder blockBuilder = Build.A.Block.Genesis.WithGasLimit(10000000000);
TestRpcBlockchain testRpc = await TestRpcBlockchain.ForTest<BaseLineTreeReorgTestBlockChain>(SealEngineType.NethDev)
.WithGenesisBlockBuilder(blockBuilder)
Expand Down
Loading

0 comments on commit fd34651

Please sign in to comment.