Skip to content

Commit

Permalink
Correct usage of chain ID and network ID
Browse files Browse the repository at this point in the history
  • Loading branch information
flcl42 committed Nov 24, 2022
1 parent e76a320 commit c8c6868
Show file tree
Hide file tree
Showing 99 changed files with 274 additions and 220 deletions.
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 SingleReleaseSpecProvider(Homestead.Instance, TestChainIds.NetworkId, TestChainIds.ChainId));
}
}
}
2 changes: 1 addition & 1 deletion src/Nethermind/Ethereum.Test.Base/BlockchainTestBase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,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(TestChainIds.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
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,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 @@ -33,8 +32,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 @@ -51,7 +48,6 @@ public static Task<TestAccountAbstractionRpcBlockchain> CreateChain(IReleaseSpec
TestSpecProvider testSpecProvider = releaseSpec is not null
? new TestSpecProvider(releaseSpec)
: new TestSpecProvider(London.Instance);
testSpecProvider.ChainId = 1;
return TestRpcBlockchain.ForTest(testMevRpcBlockchain).Build(testSpecProvider);
}

Expand Down Expand Up @@ -247,7 +243,7 @@ protected override BlockProcessor CreateBlockProcessor()
LogManager,
_accountAbstractionConfig.MaximumUserOperationPerSender),
broadcaster,
SpecProvider.ChainId);
SpecProvider.NetworkId);
}

return blockProcessor;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ private IUserOperationPool UserOperationPool(Address entryPoint)
UserOperationSimulator(entryPoint),
userOperationSortedPool,
UserOperationBroadcaster,
_nethermindApi.SpecProvider!.ChainId);
_nethermindApi.SpecProvider!.NetworkId);

return _userOperationPools[entryPoint];
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,9 +40,9 @@ private Keccak CalculateHash()

private readonly AbiSignature _idSignature = new AbiSignature("RequestId", AbiType.Bytes32, AbiAddress.Instance, AbiType.UInt256);

public void CalculateRequestId(Address entryPointAddress, ulong chainId)
public void CalculateRequestId(Address entryPointAddress, ulong networkId)
{
RequestId = Keccak.Compute(_abiEncoder.Encode(AbiEncodingStyle.None, _idSignature, CalculateHash(), entryPointAddress, chainId));
RequestId = Keccak.Compute(_abiEncoder.Encode(AbiEncodingStyle.None, _idSignature, CalculateHash(), entryPointAddress, networkId));
}

public UserOperationAbi Abi => new()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ public class UserOperationPool : IUserOperationPool, IDisposable
private readonly Channel<BlockReplacementEventArgs> _headBlocksReplacementChannel = Channel.CreateUnbounded<BlockReplacementEventArgs>(new UnboundedChannelOptions() { SingleReader = true, SingleWriter = true });
private readonly Channel<BlockEventArgs> _headBlockChannel = Channel.CreateUnbounded<BlockEventArgs>(new UnboundedChannelOptions() { SingleReader = true, SingleWriter = true });

private readonly ulong _chainId;
private readonly ulong _networkId;

private UInt256 _currentBaseFee;

Expand All @@ -70,7 +70,7 @@ public UserOperationPool(
IUserOperationSimulator userOperationSimulator,
UserOperationSortedPool userOperationSortedPool,
IUserOperationBroadcaster userOperationBroadcaster,
ulong chainId
ulong networkId
)
{
_blockTree = blockTree;
Expand All @@ -86,7 +86,7 @@ ulong chainId
_userOperationSortedPool = userOperationSortedPool;
_userOperationBroadcaster = userOperationBroadcaster;
_userOperationSimulator = userOperationSimulator;
_chainId = chainId;
_networkId = networkId;

// topic hash emitted by a successful user operation
_userOperationEventTopic = new Keccak("0x33fd4d1f25a5461bea901784a6571de6debc16cd0831932c22c6969cd73ba994");
Expand Down Expand Up @@ -260,7 +260,7 @@ private void UpdateCurrentBaseFee()

public ResultWrapper<Keccak> AddUserOperation(UserOperation userOperation)
{
userOperation.CalculateRequestId(_entryPointAddress, _chainId);
userOperation.CalculateRequestId(_entryPointAddress, _networkId);
Metrics.UserOperationsReceived++;
if (_logger.IsDebug) _logger.Debug($"UserOperation {userOperation.RequestId!} received");

Expand Down
2 changes: 1 addition & 1 deletion 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(TestChainIds.ChainId, Build.A.PrivateKey.TestObject, LimboLogs.Instance);
_address = signer.Address;

_auRaSealer = new AuRaSealer(
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 @@ -535,8 +536,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, TestChainIds.NetworkId, TestChainIds.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 c8c6868

Please sign in to comment.