-
Notifications
You must be signed in to change notification settings - Fork 417
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* eth68 implementation * test * refactor serializer * change typesSize back * Tests and enable capability * serializer tests * Fix whitespaces * fix whitespaces * Refactor * Fix serialization & peer drop * RequestTransactions68 * Metrics & logs * Reduce paket max size * Calculate length properly * fix tests & length * huge transaction test * fix spaces * Make size calculated once per transaction * Refactor & optimizations * Fix hive tests * Copyright fix * ubuntu 20.04 workflow * Revert "ubuntu 20.04 workflow" This reverts commit 77701f6. * Revert "Revert "ubuntu 20.04 workflow"" This reverts commit 648e156. * Remove metrics & for loop * Remove test & RequestTransactionsEth68 * EncodeList implementation * Fix test * Revert renaming * Rename write * Remove Request68 * Fix run-nethermind-tests.yml * Fix run-nethermind-tests.yml Co-authored-by: Marcin Sobczak <marcindsobczak@gmail.com>
- Loading branch information
1 parent
9ff2de2
commit 120c623
Showing
23 changed files
with
629 additions
and
21 deletions.
There are no files selected for viewing
2 changes: 1 addition & 1 deletion
2
src/Nethermind/Nethermind.AccountAbstraction/Data/UserOperationDecoder.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
189 changes: 189 additions & 0 deletions
189
src/Nethermind/Nethermind.Network.Test/P2P/Subprotocols/Eth/V68/Eth68ProtocolHandlerTests.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,189 @@ | ||
// SPDX-FileCopyrightText: 2022 Demerzel Solutions Limited | ||
// SPDX-License-Identifier: LGPL-3.0-only | ||
|
||
using System; | ||
using System.Collections.Generic; | ||
using System.Net; | ||
using DotNetty.Buffers; | ||
using FluentAssertions; | ||
using Nethermind.Consensus; | ||
using Nethermind.Core; | ||
using Nethermind.Core.Crypto; | ||
using Nethermind.Core.Specs; | ||
using Nethermind.Core.Test.Builders; | ||
using Nethermind.Core.Timers; | ||
using Nethermind.Logging; | ||
using Nethermind.Network.P2P; | ||
using Nethermind.Network.P2P.Subprotocols; | ||
using Nethermind.Network.P2P.Subprotocols.Eth.V62.Messages; | ||
using Nethermind.Network.P2P.Subprotocols.Eth.V65; | ||
using Nethermind.Network.P2P.Subprotocols.Eth.V66.Messages; | ||
using Nethermind.Network.P2P.Subprotocols.Eth.V68; | ||
using Nethermind.Network.P2P.Subprotocols.Eth.V68.Messages; | ||
using Nethermind.Network.Rlpx; | ||
using Nethermind.Network.Test.Builders; | ||
using Nethermind.Serialization.Rlp; | ||
using Nethermind.Stats; | ||
using Nethermind.Stats.Model; | ||
using Nethermind.Synchronization; | ||
using Nethermind.TxPool; | ||
using NSubstitute; | ||
using NUnit.Framework; | ||
|
||
namespace Nethermind.Network.Test.P2P.Subprotocols.Eth.V68; | ||
|
||
public class Eth68ProtocolHandlerTests | ||
{ | ||
private ISession _session; | ||
private IMessageSerializationService _svc; | ||
private ISyncServer _syncManager; | ||
private ITxPool _transactionPool; | ||
private IPooledTxsRequestor _pooledTxsRequestor; | ||
private IGossipPolicy _gossipPolicy; | ||
private ISpecProvider _specProvider; | ||
private Block _genesisBlock; | ||
private Eth68ProtocolHandler _handler; | ||
|
||
[SetUp] | ||
public void Setup() | ||
{ | ||
_svc = Build.A.SerializationService().WithEth68().TestObject; | ||
|
||
NetworkDiagTracer.IsEnabled = true; | ||
|
||
_session = Substitute.For<ISession>(); | ||
Node node = new(TestItem.PublicKeyA, new IPEndPoint(IPAddress.Broadcast, 30303)); | ||
_session.Node.Returns(node); | ||
_syncManager = Substitute.For<ISyncServer>(); | ||
_transactionPool = Substitute.For<ITxPool>(); | ||
_pooledTxsRequestor = Substitute.For<IPooledTxsRequestor>(); | ||
_specProvider = Substitute.For<ISpecProvider>(); | ||
_gossipPolicy = Substitute.For<IGossipPolicy>(); | ||
_genesisBlock = Build.A.Block.Genesis.TestObject; | ||
_syncManager.Head.Returns(_genesisBlock.Header); | ||
_syncManager.Genesis.Returns(_genesisBlock.Header); | ||
ITimerFactory timerFactory = Substitute.For<ITimerFactory>(); | ||
_handler = new Eth68ProtocolHandler( | ||
_session, | ||
_svc, | ||
new NodeStatsManager(timerFactory, LimboLogs.Instance), | ||
_syncManager, | ||
_transactionPool, | ||
_pooledTxsRequestor, | ||
_gossipPolicy, | ||
_specProvider, | ||
LimboLogs.Instance); | ||
_handler.Init(); | ||
} | ||
|
||
[TearDown] | ||
public void TearDown() | ||
{ | ||
_handler.Dispose(); | ||
} | ||
|
||
[Test] | ||
public void Metadata_correct() | ||
{ | ||
_handler.ProtocolCode.Should().Be("eth"); | ||
_handler.Name.Should().Be("eth68"); | ||
_handler.ProtocolVersion.Should().Be(68); | ||
_handler.MessageIdSpaceSize.Should().Be(17); | ||
_handler.IncludeInTxPool.Should().BeTrue(); | ||
_handler.ClientId.Should().Be(_session.Node?.ClientId); | ||
_handler.HeadHash.Should().BeNull(); | ||
_handler.HeadNumber.Should().Be(0); | ||
} | ||
|
||
[TestCase(0)] | ||
[TestCase(1)] | ||
[TestCase(2)] | ||
[TestCase(100)] | ||
public void Can_handle_NewPooledTransactions_message(int txCount) | ||
{ | ||
GenerateLists(txCount, out List<byte> types, out List<int> sizes, out List<Keccak> hashes); | ||
|
||
var msg = new NewPooledTransactionHashesMessage68(types, sizes, hashes); | ||
|
||
HandleIncomingStatusMessage(); | ||
HandleZeroMessage(msg, Eth68MessageCode.NewPooledTransactionHashes); | ||
_pooledTxsRequestor.Received().RequestTransactionsEth66(Arg.Any<Action<GetPooledTransactionsMessage>>(), | ||
Arg.Any<IReadOnlyList<Keccak>>()); | ||
} | ||
|
||
[TestCase(true)] | ||
[TestCase(false)] | ||
public void Should_throw_when_sizes_doesnt_match(bool removeSize) | ||
{ | ||
GenerateLists(4, out List<byte> types, out List<int> sizes, out List<Keccak> hashes); | ||
|
||
if (removeSize) | ||
{ | ||
sizes.RemoveAt(sizes.Count - 1); | ||
} | ||
else | ||
{ | ||
types.RemoveAt(sizes.Count - 1); | ||
} | ||
|
||
var msg = new NewPooledTransactionHashesMessage68(types, sizes, hashes); | ||
|
||
HandleIncomingStatusMessage(); | ||
Action action = () => HandleZeroMessage(msg, Eth68MessageCode.NewPooledTransactionHashes); | ||
action.Should().Throw<SubprotocolException>(); | ||
} | ||
|
||
[Test] | ||
public void Should_process_huge_transaction() | ||
{ | ||
Transaction tx = Build.A.Transaction.WithType(TxType.EIP1559).WithData(new byte[2 * 1024 * 1024]) | ||
.WithHash(TestItem.KeccakA).TestObject; | ||
|
||
TxDecoder txDecoder = new(); | ||
|
||
var msg = new NewPooledTransactionHashesMessage68(new[] { (byte)tx.Type }, | ||
new[] { txDecoder.GetLength(tx, RlpBehaviors.None) }, new[] { tx.Hash }); | ||
|
||
HandleIncomingStatusMessage(); | ||
|
||
HandleZeroMessage(msg, Eth68MessageCode.NewPooledTransactionHashes); | ||
_pooledTxsRequestor.Received().RequestTransactionsEth66(Arg.Any<Action<GetPooledTransactionsMessage>>(), | ||
Arg.Any<IReadOnlyList<Keccak>>()); | ||
} | ||
|
||
private void HandleIncomingStatusMessage() | ||
{ | ||
var statusMsg = new StatusMessage(); | ||
statusMsg.GenesisHash = _genesisBlock.Hash; | ||
statusMsg.BestHash = _genesisBlock.Hash; | ||
|
||
IByteBuffer statusPacket = _svc.ZeroSerialize(statusMsg); | ||
statusPacket.ReadByte(); | ||
_handler.HandleMessage(new ZeroPacket(statusPacket) { PacketType = 0 }); | ||
} | ||
|
||
private void HandleZeroMessage<T>(T msg, byte messageCode) where T : MessageBase | ||
{ | ||
IByteBuffer getBlockHeadersPacket = _svc.ZeroSerialize(msg); | ||
getBlockHeadersPacket.ReadByte(); | ||
_handler.HandleMessage(new ZeroPacket(getBlockHeadersPacket) { PacketType = messageCode }); | ||
} | ||
|
||
private void GenerateLists(int txCount, out List<byte> types, out List<int> sizes, out List<Keccak> hashes) | ||
{ | ||
TxDecoder txDecoder = new(); | ||
types = new(); | ||
sizes = new(); | ||
hashes = new(); | ||
|
||
for (int i = 0; i < txCount; ++i) | ||
{ | ||
Transaction tx = Build.A.Transaction.WithType((TxType)(i % 3)).WithData(new byte[i]) | ||
.WithHash(i % 2 == 0 ? TestItem.KeccakA : TestItem.KeccakB).TestObject; | ||
|
||
types.Add((byte)tx.Type); | ||
sizes.Add(txDecoder.GetLength(tx, RlpBehaviors.None)); | ||
hashes.Add(tx.Hash); | ||
} | ||
} | ||
} |
61 changes: 61 additions & 0 deletions
61
...Network.Test/P2P/Subprotocols/Eth/V68/NewPooledTransactionHashesMessageSerializerTests.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
// SPDX-FileCopyrightText: 2022 Demerzel Solutions Limited | ||
// SPDX-License-Identifier: LGPL-3.0-only | ||
|
||
using System.Linq; | ||
using Nethermind.Core; | ||
using Nethermind.Core.Crypto; | ||
using Nethermind.Core.Test.Builders; | ||
using Nethermind.Network.P2P.Subprotocols.Eth.V68.Messages; | ||
using NUnit.Framework; | ||
|
||
namespace Nethermind.Network.Test.P2P.Subprotocols.Eth.V68; | ||
|
||
[TestFixture, Parallelizable(ParallelScope.All)] | ||
public class NewPooledTransactionHashesMessageSerializerTests | ||
{ | ||
private static void Test(TxType[] types, int[] sizes, Keccak[] hashes, string expected = null) | ||
{ | ||
NewPooledTransactionHashesMessage68 message = new(types.Select(t => (byte)t).ToList(), sizes, hashes); | ||
NewPooledTransactionHashesMessageSerializer serializer = new(); | ||
|
||
SerializerTester.TestZero(serializer, message, expected); | ||
} | ||
|
||
[Test] | ||
public void Roundtrip() | ||
{ | ||
TxType[] types = { TxType.Legacy, TxType.AccessList, TxType.EIP1559 }; | ||
int[] sizes = { 5, 10, 1500 }; | ||
Keccak[] hashes = { TestItem.KeccakA, TestItem.KeccakB, TestItem.KeccakC }; | ||
Test(types, sizes, hashes); | ||
} | ||
|
||
[Test] | ||
public void Empty_serialization() | ||
{ | ||
TxType[] types = { }; | ||
int[] sizes = { }; | ||
Keccak[] hashes = { }; | ||
Test(types, sizes, hashes, "c380c0c0"); | ||
} | ||
|
||
[Test] | ||
public void Empty_hashes_serialization() | ||
{ | ||
TxType[] types = { TxType.EIP1559 }; | ||
int[] sizes = { 10 }; | ||
Keccak[] hashes = { }; | ||
Test(types, sizes, hashes, "c402c10ac0"); | ||
} | ||
|
||
[Test] | ||
public void Non_empty_serialization() | ||
{ | ||
TxType[] types = { TxType.AccessList }; | ||
int[] sizes = { 2 }; | ||
Keccak[] hashes = { TestItem.KeccakA }; | ||
Test(types, sizes, hashes, | ||
"e5" + "01" + "c102" + "e1a0" + TestItem.KeccakA.ToString(false)); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
src/Nethermind/Nethermind.Network/P2P/Subprotocols/Eth/V65/IPooledTxsRequestor.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.