diff --git a/src/Nethermind/Nethermind.Network/P2P/ProtocolHandlers/SyncPeerProtocolHandlerBase.cs b/src/Nethermind/Nethermind.Network/P2P/ProtocolHandlers/SyncPeerProtocolHandlerBase.cs index e9b1276baea..5d8ccbf054d 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); } @@ -190,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 }); } @@ -205,7 +207,7 @@ private IEnumerable TxsToSendAndMarkAsNotified(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.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) { diff --git a/src/Nethermind/Nethermind.TxPool/TransactionExtensions.cs b/src/Nethermind/Nethermind.TxPool/TransactionExtensions.cs index 004b3ae65ac..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) @@ -20,7 +21,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) { 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) {