Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/master' into discv5-v4-same-port
Browse files Browse the repository at this point in the history
  • Loading branch information
alexb5dh committed Aug 12, 2024
2 parents 5de9c47 + 984b602 commit 9c971c1
Show file tree
Hide file tree
Showing 73 changed files with 116 additions and 124 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 @@ -39,7 +39,7 @@ public static IEnumerable<TransactionTest> LoadTests()
[TestCaseSource(nameof(LoadTests))]
public void Test(TransactionTest test)
{
EthereumEcdsa ethereumEcdsa = new EthereumEcdsa(TestBlockchainIds.ChainId, LimboLogs.Instance);
EthereumEcdsa ethereumEcdsa = new EthereumEcdsa(TestBlockchainIds.ChainId);
Transaction decodedUnsigned = Rlp.Decode<Transaction>(test.Unsigned);
Assert.That(decodedUnsigned.Value, Is.EqualTo(test.Value), "value");
Assert.That(decodedUnsigned.GasPrice, Is.EqualTo(test.GasPrice), "gasPrice");
Expand Down
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 @@ -26,7 +26,7 @@ public class KeyAddressTests
public void SetUp()
{
Directory.SetCurrentDirectory(AppDomain.CurrentDomain.BaseDirectory);
_ecdsa = new EthereumEcdsa(TestBlockchainIds.ChainId, LimboLogs.Instance);
_ecdsa = new EthereumEcdsa(TestBlockchainIds.ChainId);
}

private static IEnumerable<KeyAddressTest> LoadTests()
Expand Down
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 @@ -131,7 +131,7 @@ protected async Task<EthereumTestResult> RunTest(BlockchainTest test, Stopwatch?
specProvider.UpdateMergeTransitionInfo(0, 0);
}

IEthereumEcdsa ecdsa = new EthereumEcdsa(specProvider.ChainId, _logManager);
IEthereumEcdsa ecdsa = new EthereumEcdsa(specProvider.ChainId);

TrieStore trieStore = new(stateDb, _logManager);
IWorldState stateProvider = new WorldState(trieStore, codeDb, _logManager);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -190,7 +190,7 @@ private void RunTest(TransactionTest test, IReleaseSpec spec)
Signature expectedSignature = new(validTest.R, validTest.S, validTest.V);
Assert.That(transaction.Signature, Is.EqualTo(expectedSignature), "signature");

IEthereumEcdsa ecdsa = new EthereumEcdsa(useChainId ? BlockchainIds.Mainnet : 0UL, LimboLogs.Instance);
IEthereumEcdsa ecdsa = new EthereumEcdsa(useChainId ? BlockchainIds.Mainnet : 0UL);
bool verified = ecdsa.Verify(
validTest.Sender,
transaction);
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 @@ -73,7 +73,7 @@ public async Task seal_can_recover_address()

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

EthereumEcdsa ecdsa = new(BlockchainIds.Morden, LimboLogs.Instance);
EthereumEcdsa ecdsa = new(BlockchainIds.Morden);
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 @@ -296,7 +296,7 @@ public class TxPermissionContractBlockchainWithBlocks : TxPermissionContractBloc
{
protected override async Task AddBlocksOnStart()
{
EthereumEcdsa ecdsa = new(ChainSpec.ChainId, LimboLogs.Instance);
EthereumEcdsa ecdsa = new(ChainSpec.ChainId);

await AddBlock(
SignTransactions(ecdsa, TestItem.PrivateKeyA, 0,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ public RlpDecodeBlockBenchmark()
var transactions = new Transaction[100];
for (int i = 0; i < 100; i++)
{
transactions[i] = Build.A.Transaction.WithData(new byte[] { (byte)i }).WithNonce((UInt256)i).WithValue((UInt256)i).Signed(new EthereumEcdsa(TestBlockchainIds.ChainId, LimboLogs.Instance), TestItem.PrivateKeyA).TestObject;
transactions[i] = Build.A.Transaction.WithData(new byte[] { (byte)i }).WithNonce((UInt256)i).WithValue((UInt256)i).Signed(new EthereumEcdsa(TestBlockchainIds.ChainId), TestItem.PrivateKeyA).TestObject;
}

_scenarios = new[]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ public RlpEncodeBlockBenchmark()
var transactions = new Transaction[100];
for (int i = 0; i < 100; i++)
{
transactions[i] = Build.A.Transaction.WithData(new byte[] { (byte)i }).WithNonce((UInt256)i).WithValue((UInt256)i).Signed(new EthereumEcdsa(TestBlockchainIds.ChainId, LimboLogs.Instance), TestItem.PrivateKeyA).TestObject;
transactions[i] = Build.A.Transaction.WithData(new byte[] { (byte)i }).WithNonce((UInt256)i).WithValue((UInt256)i).Signed(new EthereumEcdsa(TestBlockchainIds.ChainId), TestItem.PrivateKeyA).TestObject;
}

_scenarios = new[]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ public RlpEncodeHeaderBenchmark()
var transactions = new Transaction[100];
for (int i = 0; i < 100; i++)
{
transactions[i] = Build.A.Transaction.WithData(new byte[] { (byte)i }).WithNonce((UInt256)i).WithValue((UInt256)i).Signed(new EthereumEcdsa(TestBlockchainIds.ChainId, LimboLogs.Instance), TestItem.PrivateKeyA).TestObject;
transactions[i] = Build.A.Transaction.WithData(new byte[] { (byte)i }).WithNonce((UInt256)i).WithValue((UInt256)i).Signed(new EthereumEcdsa(TestBlockchainIds.ChainId), TestItem.PrivateKeyA).TestObject;
}

_scenarios = new[]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ public PersistentReceiptStorageTests(bool useCompactReceipts)
public void SetUp()
{
MainnetSpecProvider specProvider = MainnetSpecProvider.Instance;
EthereumEcdsa ethereumEcdsa = new(specProvider.ChainId, LimboLogs.Instance);
EthereumEcdsa ethereumEcdsa = new(specProvider.ChainId);
_receiptConfig = new ReceiptConfig();
_receiptsRecovery = new(ethereumEcdsa, specProvider);
_receiptsDb = new TestMemColumnsDb<ReceiptsColumns>();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ private ReceiptsIterator CreateIterator(TxReceipt[] receipts, Block block)
Span<byte> span = stream.AsSpan();
TestMemDb blockDb = new TestMemDb();
ReceiptsRecovery recovery = new ReceiptsRecovery(
new EthereumEcdsa(MainnetSpecProvider.Instance.ChainId, LimboLogs.Instance),
new EthereumEcdsa(MainnetSpecProvider.Instance.ChainId),
MainnetSpecProvider.Instance,
false
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ public class ReceiptsRecoveryTests
public void Setup()
{
MainnetSpecProvider specProvider = MainnetSpecProvider.Instance;
EthereumEcdsa ethereumEcdsa = new(specProvider.ChainId, LimboLogs.Instance);
EthereumEcdsa ethereumEcdsa = new(specProvider.ChainId);

_receiptsRecovery = new ReceiptsRecovery(ethereumEcdsa, specProvider);
}
Expand Down
2 changes: 1 addition & 1 deletion src/Nethermind/Nethermind.Blockchain.Test/ReorgTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ public void Setup()
WorldState stateProvider = new(trieStore, memDbProvider.CodeDb, LimboLogs.Instance);
StateReader stateReader = new(trieStore, memDbProvider.CodeDb, LimboLogs.Instance);
ISpecProvider specProvider = MainnetSpecProvider.Instance;
EthereumEcdsa ecdsa = new(1, LimboLogs.Instance);
EthereumEcdsa ecdsa = new(1);
ITransactionComparerProvider transactionComparerProvider =
new TransactionComparerProvider(specProvider, _blockTree);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ private class On
private readonly ILogger _logger;
private static readonly ITimestamper _timestamper = Timestamper.Default;
private readonly CliqueConfig _cliqueConfig;
private readonly EthereumEcdsa _ethereumEcdsa = new(BlockchainIds.Goerli, LimboLogs.Instance);
private readonly EthereumEcdsa _ethereumEcdsa = new(BlockchainIds.Goerli);
private readonly Dictionary<PrivateKey, ILogManager> _logManagers = new();
private readonly Dictionary<PrivateKey, ISnapshotManager> _snapshotManager = new();
private readonly Dictionary<PrivateKey, BlockTree> _blockTrees = new();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ public void Setup_chain()

private CliqueSealer BuildSealer(int currentBlock, IDb db)
{
IEthereumEcdsa ecdsa = new EthereumEcdsa(BlockchainIds.Goerli, LimboLogs.Instance);
IEthereumEcdsa ecdsa = new EthereumEcdsa(BlockchainIds.Goerli);
CliqueConfig config = new();
int currentSignerIndex = (currentBlock % _signers.Count);
_currentSigner = _signers[currentSignerIndex];
Expand Down
2 changes: 1 addition & 1 deletion src/Nethermind/Nethermind.Clique.Test/CliqueTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ public void Setup_chain()
MemDb db = new();
CliqueConfig config = new();

_ecdsa = new EthereumEcdsa(BlockchainIds.Goerli, LimboLogs.Instance);
_ecdsa = new EthereumEcdsa(BlockchainIds.Goerli);
_snapshotManager = new SnapshotManager(config, db, _blockTree, _ecdsa, LimboLogs.Instance);
_clique = new CliqueSealer(new Signer(BlockchainIds.Goerli, key, LimboLogs.Instance), config, _snapshotManager, LimboLogs.Instance);
_sealValidator = new CliqueSealValidator(config, _snapshotManager, LimboLogs.Instance);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ public void Recognises_signer_turn()
Block genesis = CliqueTests.GetGenesis();
Snapshot snapshot = snapshotManager.GetOrCreateSnapshot(0, genesis.Hash);
// Here we use a random chain id, should be test independent.
SnapshotManager manager = new(CliqueConfig.Default, _snapshotDb, _blockTree, new EthereumEcdsa(BlockchainIds.GenericNonRealNetwork, LimboLogs.Instance), LimboLogs.Instance);
SnapshotManager manager = new(CliqueConfig.Default, _snapshotDb, _blockTree, new EthereumEcdsa(BlockchainIds.GenericNonRealNetwork), LimboLogs.Instance);
// Block 1
Assert.IsTrue(manager.IsInTurn(snapshot, 1, _signer1));
Assert.IsFalse(manager.IsInTurn(snapshot, 1, _signer2));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,7 @@ private AddingTxEventArgs CheckTxPosdaoRules(AddingTxEventArgs args)
if (tx.Signature is not null)
{
IReleaseSpec spec = _specProvider.GetSpec(args.Block.Header);
EthereumEcdsa ecdsa = new(_specProvider.ChainId, LimboLogs.Instance);
EthereumEcdsa ecdsa = new(_specProvider.ChainId);
Address txSenderAddress = ecdsa.RecoverAddress(tx, !spec.ValidateChainId);
if (tx.SenderAddress != txSenderAddress)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@ protected virtual async Task<TestBlockchain> Build(ISpecProvider? specProvider =
Timestamper = new ManualTimestamper(new DateTime(2020, 2, 15, 12, 50, 30, DateTimeKind.Utc));
JsonSerializer = new EthereumJsonSerializer();
SpecProvider = CreateSpecProvider(specProvider ?? MainnetSpecProvider.Instance);
EthereumEcdsa = new EthereumEcdsa(SpecProvider.ChainId, LogManager);
EthereumEcdsa = new EthereumEcdsa(SpecProvider.ChainId);
DbProvider = await CreateDbProvider();
TrieStore = new TrieStore(StateDb, LogManager);
State = new WorldState(TrieStore, DbProvider.CodeDb, LogManager, new PreBlockCaches());
Expand Down Expand Up @@ -206,7 +206,7 @@ protected virtual async Task<TestBlockchain> Build(ISpecProvider? specProvider =
SealEngine = new SealEngine(sealer, Always.Valid);

BloomStorage bloomStorage = new(new BloomConfig(), new MemDb(), new InMemoryDictionaryFileStoreFactory());
ReceiptsRecovery receiptsRecovery = new(new EthereumEcdsa(SpecProvider.ChainId, LimboLogs.Instance), SpecProvider);
ReceiptsRecovery receiptsRecovery = new(new EthereumEcdsa(SpecProvider.ChainId), SpecProvider);
LogFinder = new LogFinder(BlockTree, ReceiptStorage, ReceiptStorage, bloomStorage, LimboLogs.Instance, receiptsRecovery);
BeaconBlockRootHandler = new BeaconBlockRootHandler();
BlockProcessor = CreateBlockProcessor();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -383,7 +383,7 @@ public static void ExtendTree(IBlockTree blockTree, long newChainLength)

public BlockTreeBuilder WithTransactions(IReceiptStorage receiptStorage, Func<Block, Transaction, IEnumerable<LogEntry>>? logsForBlockBuilder = null)
{
_ecdsa = new EthereumEcdsa(BlockTree.ChainId, LimboLogs.Instance);
_ecdsa = new EthereumEcdsa(BlockTree.ChainId);
_receiptStorage = receiptStorage;
_logCreationFunction = logsForBlockBuilder;
return this;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -239,7 +239,7 @@ public TransactionBuilder<T> Signed(IEthereumEcdsa ecdsa, PrivateKey privateKey,
public TransactionBuilder<T> Signed(PrivateKey? privateKey = null)
{
privateKey ??= TestItem.IgnoredPrivateKey;
EthereumEcdsa ecdsa = new(TestObjectInternal.ChainId ?? TestBlockchainIds.ChainId, LimboLogs.Instance);
EthereumEcdsa ecdsa = new(TestObjectInternal.ChainId ?? TestBlockchainIds.ChainId);

return Signed(ecdsa, privateKey, isEip155Enabled: true);
}
Expand All @@ -256,7 +256,7 @@ public TransactionBuilder<T> SignedAndResolved(IEthereumEcdsa ecdsa, PrivateKey
public TransactionBuilder<T> SignedAndResolved(PrivateKey? privateKey = null)
{
privateKey ??= TestItem.IgnoredPrivateKey;
EthereumEcdsa ecdsa = new(TestObjectInternal.ChainId ?? TestBlockchainIds.ChainId, LimboLogs.Instance);
EthereumEcdsa ecdsa = new(TestObjectInternal.ChainId ?? TestBlockchainIds.ChainId);
ecdsa.Sign(privateKey, TestObjectInternal, true);
TestObjectInternal.SenderAddress = privateKey.Address;
return this;
Expand Down
10 changes: 5 additions & 5 deletions src/Nethermind/Nethermind.Core.Test/Crypto/EthereumEcdsaTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ public class EthereumEcdsaTests
[TestCaseSource(nameof(TestCaseSources))]
public void Signature_verify_test((string Name, Transaction Tx) testCase)
{
EthereumEcdsa ecdsa = new(BlockchainIds.Sepolia, LimboLogs.Instance);
EthereumEcdsa ecdsa = new(BlockchainIds.Sepolia);
ecdsa.Verify(testCase.Tx.SenderAddress!, testCase.Tx);
}

Expand All @@ -30,7 +30,7 @@ public void Signature_verify_test((string Name, Transaction Tx) testCase)
[TestCase(false)]
public void Signature_test_sepolia(bool eip155)
{
EthereumEcdsa ecdsa = new(BlockchainIds.Sepolia, LimboLogs.Instance);
EthereumEcdsa ecdsa = new(BlockchainIds.Sepolia);
PrivateKey key = Build.A.PrivateKey.TestObject;
Transaction tx = Build.A.Transaction.TestObject;
ecdsa.Sign(key, tx, eip155);
Expand All @@ -42,7 +42,7 @@ public void Signature_test_sepolia(bool eip155)
[TestCase(false)]
public void Signature_test_sepolia_1559(bool eip155)
{
EthereumEcdsa ecdsa = new(BlockchainIds.Sepolia, LimboLogs.Instance);
EthereumEcdsa ecdsa = new(BlockchainIds.Sepolia);
PrivateKey key = Build.A.PrivateKey.TestObject;
Transaction tx = Build.A.Transaction.WithType(TxType.EIP1559).TestObject;
ecdsa.Sign(key, tx, eip155);
Expand All @@ -54,7 +54,7 @@ public void Signature_test_sepolia_1559(bool eip155)
[TestCase(false)]
public void Signature_test_olympic(bool isEip155Enabled)
{
EthereumEcdsa ecdsa = new(BlockchainIds.Mainnet, LimboLogs.Instance);
EthereumEcdsa ecdsa = new(BlockchainIds.Mainnet);
PrivateKey key = Build.A.PrivateKey.TestObject;
Transaction tx = Build.A.Transaction.TestObject;
ecdsa.Sign(key, tx, isEip155Enabled);
Expand All @@ -66,7 +66,7 @@ public void Signature_test_olympic(bool isEip155Enabled)
public void Sign_generic_network()
{
// maybe make random id so it captures the idea that signature should work irrespective of chain
EthereumEcdsa ecdsa = new(BlockchainIds.GenericNonRealNetwork, LimboLogs.Instance);
EthereumEcdsa ecdsa = new(BlockchainIds.GenericNonRealNetwork);
PrivateKey key = Build.A.PrivateKey.TestObject;
Transaction tx = Build.A.Transaction.TestObject;
ecdsa.Sign(key, tx, true);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ public BlockDecoderTests()
.WithData(new byte[] { (byte)i })
.WithNonce((UInt256)i)
.WithValue((UInt256)i)
.Signed(new EthereumEcdsa(TestBlockchainIds.ChainId, LimboLogs.Instance), TestItem.PrivateKeyA, true)
.Signed(new EthereumEcdsa(TestBlockchainIds.ChainId), TestItem.PrivateKeyA, true)
.TestObject;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ public void Roundtrip_ExecutionPayloadForm_for_shard_blobs((Transaction Tx, stri
rlpStream.Position = 0;
Transaction? decoded = _txDecoder.Decode(rlpStream);
decoded!.SenderAddress =
new EthereumEcdsa(TestBlockchainIds.ChainId, LimboLogs.Instance).RecoverAddress(decoded);
new EthereumEcdsa(TestBlockchainIds.ChainId).RecoverAddress(decoded);
decoded.Hash = decoded.CalculateHash();
decoded.Should().BeEquivalentTo(testCase.Tx, testCase.Description);
}
Expand All @@ -54,7 +54,7 @@ public void Roundtrip_ValueDecoderContext_ExecutionPayloadForm_for_shard_blobs((
rlpStream.Position = 0;
Transaction? decoded = _txDecoder.Decode(ref decoderContext);
decoded!.SenderAddress =
new EthereumEcdsa(TestBlockchainIds.ChainId, LimboLogs.Instance).RecoverAddress(decoded);
new EthereumEcdsa(TestBlockchainIds.ChainId).RecoverAddress(decoded);
decoded.Hash = decoded.CalculateHash();
decoded.Should().BeEquivalentTo(testCase.Tx, testCase.Description);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ public void Roundtrip((Transaction Tx, string Description) testCase)
rlpStream.Position = 0;
Transaction? decoded = _txDecoder.Decode(rlpStream);
decoded!.SenderAddress =
new EthereumEcdsa(TestBlockchainIds.ChainId, LimboLogs.Instance).RecoverAddress(decoded);
new EthereumEcdsa(TestBlockchainIds.ChainId).RecoverAddress(decoded);
decoded.Hash = decoded.CalculateHash();
decoded.EqualToTransaction(testCase.Tx);
}
Expand All @@ -115,7 +115,7 @@ public void Roundtrip_ValueDecoderContext((Transaction Tx, string Description) t
rlpStream.Position = 0;
Transaction? decoded = _txDecoder.Decode(ref decoderContext);
decoded!.SenderAddress =
new EthereumEcdsa(TestBlockchainIds.ChainId, LimboLogs.Instance).RecoverAddress(decoded);
new EthereumEcdsa(TestBlockchainIds.ChainId).RecoverAddress(decoded);
decoded.Hash = decoded.CalculateHash();
decoded.EqualToTransaction(testCase.Tx);
}
Expand All @@ -130,7 +130,7 @@ public void Roundtrip_ValueDecoderContext_WithMemorySlice((Transaction Tx, strin
rlpStream.Position = 0;
Transaction? decoded = _txDecoder.Decode(ref decoderContext);
decoded!.SenderAddress =
new EthereumEcdsa(TestBlockchainIds.ChainId, LimboLogs.Instance).RecoverAddress(decoded);
new EthereumEcdsa(TestBlockchainIds.ChainId).RecoverAddress(decoded);
decoded.Hash = decoded.CalculateHash();
decoded.EqualToTransaction(testCase.Tx);
}
Expand Down
4 changes: 2 additions & 2 deletions src/Nethermind/Nethermind.Core.Test/SignerTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ public void Hex_and_back_again(string hexSignature)
[Test]
public void Sign_and_recover()
{
EthereumEcdsa ethereumEcdsa = new(BlockchainIds.Olympic, LimboLogs.Instance);
EthereumEcdsa ethereumEcdsa = new(BlockchainIds.Olympic);

Hash256 message = Keccak.Compute("Test message");
PrivateKey privateKey = Build.A.PrivateKey.TestObject;
Expand All @@ -43,7 +43,7 @@ public void Sign_and_recover()
[Test]
public void Decompress()
{
EthereumEcdsa ethereumEcdsa = new(BlockchainIds.Olympic, LimboLogs.Instance);
EthereumEcdsa ethereumEcdsa = new(BlockchainIds.Olympic);
PrivateKey privateKey = Build.A.PrivateKey.TestObject;
CompressedPublicKey compressedPublicKey = privateKey.CompressedPublicKey;
PublicKey expected = privateKey.PublicKey;
Expand Down
Loading

0 comments on commit 9c971c1

Please sign in to comment.