From 3f7b55274c3f827d9b13e0dcc2ef29e774daa237 Mon Sep 17 00:00:00 2001 From: Alexey Date: Wed, 3 Apr 2024 09:41:49 +0000 Subject: [PATCH] Fix sending new single tx p2p update (#6895) --- .../Eth/V68/Eth68ProtocolHandlerTests.cs | 20 ++++++++++++++++++- .../SyncPeerProtocolHandlerBase.cs | 1 - .../Eth/V68/Eth68ProtocolHandler.cs | 4 ++-- .../Collections/BlobTxDistinctSortedPool.cs | 12 ++--------- .../Collections/TxDistinctSortedPool.cs | 7 +++---- 5 files changed, 26 insertions(+), 18 deletions(-) diff --git a/src/Nethermind/Nethermind.Network.Test/P2P/Subprotocols/Eth/V68/Eth68ProtocolHandlerTests.cs b/src/Nethermind/Nethermind.Network.Test/P2P/Subprotocols/Eth/V68/Eth68ProtocolHandlerTests.cs index dbcd5b777f2..4994ba3b840 100644 --- a/src/Nethermind/Nethermind.Network.Test/P2P/Subprotocols/Eth/V68/Eth68ProtocolHandlerTests.cs +++ b/src/Nethermind/Nethermind.Network.Test/P2P/Subprotocols/Eth/V68/Eth68ProtocolHandlerTests.cs @@ -175,7 +175,25 @@ public void should_send_up_to_MaxCount_hashes_in_one_NewPooledTransactionHashesM _handler.SendNewTransactions(txs, false); - _session.Received(1).DeliverMessage(Arg.Is(m => m.Hashes.Count == txCount)); + _session.Received(1).DeliverMessage(Arg.Is(m => + m.Hashes.Count == txCount && + m.Sizes.Count == txCount && + m.Types.Count == txCount)); + } + + [Test] + public void should_send_blob_tx_announcement_in_NewPooledTransactionHashesMessage68() + { + Transaction tx = Build.A.Transaction.WithNonce((UInt256)0).WithShardBlobTxTypeAndFields().SignedAndResolved().TestObject; + + _handler.SendNewTransaction(tx); + + _session.Received(1).DeliverMessage(Arg.Is(m => + m.Hashes.Count == 1 && + m.Sizes.Count == 1 && + m.Types.Count == 1 && + m.Hashes[0] == tx.Hash && + (TxType)m.Types[0] == tx.Type)); } [TestCase(NewPooledTransactionHashesMessage68.MaxCount - 1)] diff --git a/src/Nethermind/Nethermind.Network/P2P/ProtocolHandlers/SyncPeerProtocolHandlerBase.cs b/src/Nethermind/Nethermind.Network/P2P/ProtocolHandlers/SyncPeerProtocolHandlerBase.cs index 56c784b6fb9..d2aa29eb951 100644 --- a/src/Nethermind/Nethermind.Network/P2P/ProtocolHandlers/SyncPeerProtocolHandlerBase.cs +++ b/src/Nethermind/Nethermind.Network/P2P/ProtocolHandlers/SyncPeerProtocolHandlerBase.cs @@ -17,7 +17,6 @@ using Nethermind.Core.Extensions; using Nethermind.Int256; using Nethermind.Logging; -using Nethermind.Network.P2P.Messages; using Nethermind.Network.P2P.Subprotocols.Eth.V62; using Nethermind.Network.P2P.Subprotocols.Eth.V62.Messages; using Nethermind.Network.P2P.Subprotocols.Eth.V63.Messages; diff --git a/src/Nethermind/Nethermind.Network/P2P/Subprotocols/Eth/V68/Eth68ProtocolHandler.cs b/src/Nethermind/Nethermind.Network/P2P/Subprotocols/Eth/V68/Eth68ProtocolHandler.cs index 575417bb54c..0bd40e6fe08 100644 --- a/src/Nethermind/Nethermind.Network/P2P/Subprotocols/Eth/V68/Eth68ProtocolHandler.cs +++ b/src/Nethermind/Nethermind.Network/P2P/Subprotocols/Eth/V68/Eth68ProtocolHandler.cs @@ -113,8 +113,8 @@ protected override void SendNewTransactionCore(Transaction tx) else { SendMessage( - new ArrayPoolList((byte)tx.Type), - new ArrayPoolList(tx.GetLength()), + new ArrayPoolList(1) { (byte)tx.Type }, + new ArrayPoolList(1) { tx.GetLength() }, new ArrayPoolList(1) { tx.Hash } ); } diff --git a/src/Nethermind/Nethermind.TxPool/Collections/BlobTxDistinctSortedPool.cs b/src/Nethermind/Nethermind.TxPool/Collections/BlobTxDistinctSortedPool.cs index 196b0b1262c..807a03fe519 100644 --- a/src/Nethermind/Nethermind.TxPool/Collections/BlobTxDistinctSortedPool.cs +++ b/src/Nethermind/Nethermind.TxPool/Collections/BlobTxDistinctSortedPool.cs @@ -1,7 +1,6 @@ // SPDX-FileCopyrightText: 2023 Demerzel Solutions Limited // SPDX-License-Identifier: LGPL-3.0-only -using System; using System.Collections.Generic; using Nethermind.Core; using Nethermind.Core.Crypto; @@ -9,16 +8,9 @@ namespace Nethermind.TxPool.Collections; -public class BlobTxDistinctSortedPool : TxDistinctSortedPool +public class BlobTxDistinctSortedPool(int capacity, IComparer comparer, ILogManager logManager) + : TxDistinctSortedPool(capacity, comparer, logManager) { - private readonly ILogger _logger; - - public BlobTxDistinctSortedPool(int capacity, IComparer comparer, ILogManager logManager) - : base(capacity, comparer, logManager) - { - _logger = logManager?.GetClassLogger() ?? throw new ArgumentNullException(nameof(logManager)); - } - protected override IComparer GetReplacementComparer(IComparer comparer) => comparer.GetBlobReplacementComparer(); diff --git a/src/Nethermind/Nethermind.TxPool/Collections/TxDistinctSortedPool.cs b/src/Nethermind/Nethermind.TxPool/Collections/TxDistinctSortedPool.cs index 07223685f5b..e4ba610644a 100644 --- a/src/Nethermind/Nethermind.TxPool/Collections/TxDistinctSortedPool.cs +++ b/src/Nethermind/Nethermind.TxPool/Collections/TxDistinctSortedPool.cs @@ -4,12 +4,11 @@ using System; using System.Collections.Generic; using System.Diagnostics; -using System.Runtime.CompilerServices; using System.Runtime.InteropServices; - using Nethermind.Core; using Nethermind.Core.Collections; using Nethermind.Core.Crypto; +using Nethermind.Core.Threading; using Nethermind.Int256; using Nethermind.Logging; using Nethermind.TxPool.Comparison; @@ -73,7 +72,7 @@ protected override void UpdateGroup(AddressAsKey groupKey, EnhancedSortedSet, IEnumerable<(Transaction Tx, UInt256? changedGasBottleneck)>> changingElements) { - using var lockRelease = Lock.Acquire(); + using McsLock.Disposable lockRelease = Lock.Acquire(); EnsureCapacity(); foreach ((AddressAsKey address, EnhancedSortedSet bucket) in _buckets) @@ -122,7 +121,7 @@ private void UpdateGroupNonLocked(Address groupKey, AccountStruct groupValue, En public void UpdateGroup(Address groupKey, AccountStruct groupValue, Func, IEnumerable<(Transaction Tx, UInt256? changedGasBottleneck)>> changingElements) { - using var lockRelease = Lock.Acquire(); + using McsLock.Disposable lockRelease = Lock.Acquire(); ArgumentNullException.ThrowIfNull(groupKey); if (_buckets.TryGetValue(groupKey, out EnhancedSortedSet? bucket))