From d5116ee82bace074db20120f2d1efd810e1ca192 Mon Sep 17 00:00:00 2001 From: Marcin Sobczak Date: Wed, 26 Apr 2023 12:11:50 +0200 Subject: [PATCH 1/5] move duplicated logic to ShouldNotifyTransaction --- .../P2P/ProtocolHandlers/SyncPeerProtocolHandlerBase.cs | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/Nethermind/Nethermind.Network/P2P/ProtocolHandlers/SyncPeerProtocolHandlerBase.cs b/src/Nethermind/Nethermind.Network/P2P/ProtocolHandlers/SyncPeerProtocolHandlerBase.cs index e9b1276baea..2f6d0d79126 100644 --- a/src/Nethermind/Nethermind.Network/P2P/ProtocolHandlers/SyncPeerProtocolHandlerBase.cs +++ b/src/Nethermind/Nethermind.Network/P2P/ProtocolHandlers/SyncPeerProtocolHandlerBase.cs @@ -180,9 +180,11 @@ public virtual Task GetNodeData(IReadOnlyList hashes, Cancella public abstract void NotifyOfNewBlock(Block block, SendBlockMode mode); + private bool ShouldNotifyTransaction(Keccak? hash) => hash is not null && NotifiedTransactions.Set(hash); + public void SendNewTransaction(Transaction tx) { - if (tx.Hash != null && NotifiedTransactions.Set(tx.Hash)) + if (ShouldNotifyTransaction(tx.Hash)) { SendNewTransactionCore(tx); } @@ -205,7 +207,7 @@ private IEnumerable TxsToSendAndMarkAsNotified(IEnumerable Date: Wed, 26 Apr 2023 12:16:37 +0200 Subject: [PATCH 2/5] use SupportsBlobs abstraction instead of checking type --- .../P2P/ProtocolHandlers/SyncPeerProtocolHandlerBase.cs | 4 ++-- src/Nethermind/Nethermind.TxPool/TransactionExtensions.cs | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/src/Nethermind/Nethermind.Network/P2P/ProtocolHandlers/SyncPeerProtocolHandlerBase.cs b/src/Nethermind/Nethermind.Network/P2P/ProtocolHandlers/SyncPeerProtocolHandlerBase.cs index 2f6d0d79126..5d8ccbf054d 100644 --- a/src/Nethermind/Nethermind.Network/P2P/ProtocolHandlers/SyncPeerProtocolHandlerBase.cs +++ b/src/Nethermind/Nethermind.Network/P2P/ProtocolHandlers/SyncPeerProtocolHandlerBase.cs @@ -192,7 +192,7 @@ public void SendNewTransaction(Transaction tx) protected virtual void SendNewTransactionCore(Transaction tx) { - if (tx.Type != TxType.Blob) //additional protection from sending full blob-type txs + if (!tx.SupportsBlobs) //additional protection from sending full tx with blob { SendMessage(new[] { tx }); } @@ -230,7 +230,7 @@ protected virtual void SendNewTransactionsCore(IEnumerable txs, boo packetSizeLeft = TransactionsMessage.MaxPacketSize; } - if (tx.Hash is not null && tx.Type != TxType.Blob) //additional protection from sending full blob-type txs + if (tx.Hash is not null && !tx.SupportsBlobs) //additional protection from sending full tx with blob { txsToSend.Add(tx); packetSizeLeft -= txSize; diff --git a/src/Nethermind/Nethermind.TxPool/TransactionExtensions.cs b/src/Nethermind/Nethermind.TxPool/TransactionExtensions.cs index 004b3ae65ac..a6ca4cb5c22 100644 --- a/src/Nethermind/Nethermind.TxPool/TransactionExtensions.cs +++ b/src/Nethermind/Nethermind.TxPool/TransactionExtensions.cs @@ -20,7 +20,7 @@ public static int GetLength(this Transaction tx) return tx.GetLength(_transactionSizeCalculator); } - public static bool CanBeBroadcast(this Transaction tx) => tx.Type != TxType.Blob && tx.GetLength() <= MaxSizeOfTxForBroadcast; + public static bool CanBeBroadcast(this Transaction tx) => !tx.SupportsBlobs && tx.GetLength() <= MaxSizeOfTxForBroadcast; internal static UInt256 CalculateGasPrice(this Transaction tx, bool eip1559Enabled, in UInt256 baseFee) { From 07b72ea77efc182218d6037c6cbde435f7a21c0a Mon Sep 17 00:00:00 2001 From: Marcin Sobczak Date: Wed, 26 Apr 2023 13:10:05 +0200 Subject: [PATCH 3/5] add quick return in BroadcastPersistentTxs if collection of persistent txs is empty --- src/Nethermind/Nethermind.TxPool/TxBroadcaster.cs | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/src/Nethermind/Nethermind.TxPool/TxBroadcaster.cs b/src/Nethermind/Nethermind.TxPool/TxBroadcaster.cs index 165d374d237..469fa15170a 100644 --- a/src/Nethermind/Nethermind.TxPool/TxBroadcaster.cs +++ b/src/Nethermind/Nethermind.TxPool/TxBroadcaster.cs @@ -124,6 +124,12 @@ public void BroadcastOnce(ITxPoolPeer peer, Transaction[] txs) public void BroadcastPersistentTxs() { + if (_persistentTxs.Count == 0) + { + if (_logger.IsTrace) _logger.Trace($"There is nothing to broadcast - collection of persistent txs is empty"); + return; + } + DateTimeOffset now = DateTimeOffset.Now; if (_lastPersistedTxBroadcast + _minTimeBetweenPersistedTxBroadcast > now) { From d6910fb1e83b4678900ad3d6a9b1766e6dd5e5cc Mon Sep 17 00:00:00 2001 From: Marcin Sobczak Date: Wed, 26 Apr 2023 13:16:17 +0200 Subject: [PATCH 4/5] fix MaxSizeOfTxForBroadcast to be 128KB instead of 128kB --- src/Nethermind/Nethermind.TxPool/TransactionExtensions.cs | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/Nethermind/Nethermind.TxPool/TransactionExtensions.cs b/src/Nethermind/Nethermind.TxPool/TransactionExtensions.cs index a6ca4cb5c22..2c1ee5cfbcf 100644 --- a/src/Nethermind/Nethermind.TxPool/TransactionExtensions.cs +++ b/src/Nethermind/Nethermind.TxPool/TransactionExtensions.cs @@ -3,6 +3,7 @@ using System.Runtime.CompilerServices; using Nethermind.Core; +using Nethermind.Core.Extensions; using Nethermind.Int256; using Nethermind.Serialization.Rlp; @@ -12,7 +13,7 @@ namespace Nethermind.TxPool { public static class TransactionExtensions { - private static readonly int MaxSizeOfTxForBroadcast = 128_000; //128KB, as proposed in https://eips.ethereum.org/EIPS/eip-5793 + private static readonly long MaxSizeOfTxForBroadcast = 128.KiB(); //128KB, as proposed in https://eips.ethereum.org/EIPS/eip-5793 private static readonly ITransactionSizeCalculator _transactionSizeCalculator = new TxDecoder(); public static int GetLength(this Transaction tx) From c39797bfa0efa7a97d22035f733d128b7d3d3a85 Mon Sep 17 00:00:00 2001 From: Marcin Sobczak Date: Wed, 26 Apr 2023 13:42:57 +0200 Subject: [PATCH 5/5] adjust tests --- src/Nethermind/Nethermind.TxPool.Test/TxBroadcasterTests.cs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/Nethermind/Nethermind.TxPool.Test/TxBroadcasterTests.cs b/src/Nethermind/Nethermind.TxPool.Test/TxBroadcasterTests.cs index 9268883ef4b..f068e011786 100644 --- a/src/Nethermind/Nethermind.TxPool.Test/TxBroadcasterTests.cs +++ b/src/Nethermind/Nethermind.TxPool.Test/TxBroadcasterTests.cs @@ -449,8 +449,8 @@ public void should_broadcast_hash_of_blob_local_tx_to_eth68_peers_immediately_af } [TestCase(1_000, true)] - [TestCase(128_000, true)] - [TestCase(128_001, false)] + [TestCase(128 * 1024, true)] + [TestCase(128 * 1024 + 1, false)] [TestCase(1_000_000, false)] public void should_broadcast_full_local_tx_up_to_max_size_and_only_announce_if_larger(int txSize, bool shouldBroadcastFullTx) {