From 7c329bde266ee8e88dcbe93a9b2dce3212363a09 Mon Sep 17 00:00:00 2001 From: Marcin Sobczak Date: Mon, 11 Dec 2023 13:37:56 +0100 Subject: [PATCH 01/11] limit initial broadcast --- src/Nethermind/Nethermind.TxPool/TxBroadcaster.cs | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/src/Nethermind/Nethermind.TxPool/TxBroadcaster.cs b/src/Nethermind/Nethermind.TxPool/TxBroadcaster.cs index ef53ab53208..afaf69f5ff5 100644 --- a/src/Nethermind/Nethermind.TxPool/TxBroadcaster.cs +++ b/src/Nethermind/Nethermind.TxPool/TxBroadcaster.cs @@ -99,7 +99,12 @@ public void Broadcast(Transaction tx, bool isPersistent) private void StartBroadcast(Transaction tx) { - NotifyPeersAboutLocalTx(tx); + // broadcast tx only if MaxFeePerGas is equal at least 70% of current base fee + // otherwise only add to persistent collection and broadcast when tx will be ready for inclusion + if (tx.MaxFeePerGas >= _headInfo.CurrentBaseFee / 10 * 7) + { + NotifyPeersAboutLocalTx(tx); + } if (tx.Hash is not null) { _persistentTxs.TryInsert(tx.Hash, tx.SupportsBlobs ? new LightTransaction(tx) : tx); @@ -274,7 +279,6 @@ private void Notify(ITxPoolPeer peer, IEnumerable txs, bool sendFul { try { - peer.SendNewTransactions(txs.Where(t => _txGossipPolicy.ShouldGossipTransaction(t)), sendFullTx); if (_logger.IsTrace) _logger.Trace($"Notified {peer} about transactions."); } From e87d5515744408556964819803e19270855d6337 Mon Sep 17 00:00:00 2001 From: Marcin Sobczak Date: Mon, 11 Dec 2023 14:35:48 +0100 Subject: [PATCH 02/11] add BaseFeeThreshold to ChainHeadInfoProvider --- .../Nethermind.Blockchain/ChainHeadInfoProvider.cs | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/src/Nethermind/Nethermind.Blockchain/ChainHeadInfoProvider.cs b/src/Nethermind/Nethermind.Blockchain/ChainHeadInfoProvider.cs index 8a0b721db9f..ddbcb14fcfb 100644 --- a/src/Nethermind/Nethermind.Blockchain/ChainHeadInfoProvider.cs +++ b/src/Nethermind/Nethermind.Blockchain/ChainHeadInfoProvider.cs @@ -46,6 +46,8 @@ public ChainHeadInfoProvider(IChainHeadSpecProvider specProvider, IBlockTree blo public UInt256 CurrentBaseFee { get; private set; } + public UInt256 BaseFeeThreshold { get; private set; } + public UInt256 CurrentPricePerBlobGas { get; internal set; } public event EventHandler? HeadChanged; @@ -55,6 +57,9 @@ private void OnHeadChanged(object? sender, BlockReplacementEventArgs e) HeadNumber = e.Block.Number; BlockGasLimit = e.Block!.GasLimit; CurrentBaseFee = e.Block.Header.BaseFeePerGas; + BaseFeeThreshold = UInt256.MultiplyOverflow(CurrentBaseFee, 7, out UInt256 baseFeeThreshold) + ? CurrentBaseFee + : baseFeeThreshold; CurrentPricePerBlobGas = BlobGasCalculator.TryCalculateBlobGasPricePerUnit(e.Block.Header, out UInt256 currentPricePerBlobGas) ? currentPricePerBlobGas From d9c31de8d922ef50ad8c5401fea92b5deeb1887f Mon Sep 17 00:00:00 2001 From: Marcin Sobczak Date: Mon, 11 Dec 2023 14:37:57 +0100 Subject: [PATCH 03/11] simplify broadcaster --- src/Nethermind/Nethermind.TxPool/IChainHeadInfoProvider.cs | 2 ++ src/Nethermind/Nethermind.TxPool/TxBroadcaster.cs | 2 +- 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/src/Nethermind/Nethermind.TxPool/IChainHeadInfoProvider.cs b/src/Nethermind/Nethermind.TxPool/IChainHeadInfoProvider.cs index 457322785a4..a13ec1c0107 100644 --- a/src/Nethermind/Nethermind.TxPool/IChainHeadInfoProvider.cs +++ b/src/Nethermind/Nethermind.TxPool/IChainHeadInfoProvider.cs @@ -20,6 +20,8 @@ public interface IChainHeadInfoProvider public UInt256 CurrentBaseFee { get; } + UInt256 BaseFeeThreshold { get; } + public UInt256 CurrentPricePerBlobGas { get; } event EventHandler HeadChanged; diff --git a/src/Nethermind/Nethermind.TxPool/TxBroadcaster.cs b/src/Nethermind/Nethermind.TxPool/TxBroadcaster.cs index afaf69f5ff5..4718870aa1d 100644 --- a/src/Nethermind/Nethermind.TxPool/TxBroadcaster.cs +++ b/src/Nethermind/Nethermind.TxPool/TxBroadcaster.cs @@ -101,7 +101,7 @@ private void StartBroadcast(Transaction tx) { // broadcast tx only if MaxFeePerGas is equal at least 70% of current base fee // otherwise only add to persistent collection and broadcast when tx will be ready for inclusion - if (tx.MaxFeePerGas >= _headInfo.CurrentBaseFee / 10 * 7) + if (tx.MaxFeePerGas >= _headInfo.BaseFeeThreshold) { NotifyPeersAboutLocalTx(tx); } From a9db3c0f3a2187ae39de45131d69054836da7089 Mon Sep 17 00:00:00 2001 From: Marcin Sobczak Date: Mon, 11 Dec 2023 14:53:36 +0100 Subject: [PATCH 04/11] add simple test --- .../TxBroadcasterTests.cs | 30 +++++++++++++++++++ 1 file changed, 30 insertions(+) diff --git a/src/Nethermind/Nethermind.TxPool.Test/TxBroadcasterTests.cs b/src/Nethermind/Nethermind.TxPool.Test/TxBroadcasterTests.cs index 3a1448b7951..6bf3bda795b 100644 --- a/src/Nethermind/Nethermind.TxPool.Test/TxBroadcasterTests.cs +++ b/src/Nethermind/Nethermind.TxPool.Test/TxBroadcasterTests.cs @@ -334,6 +334,36 @@ public void should_not_pick_txs_with_GasPrice_lower_than_CurrentBaseFee([Values( expectedTxs.Should().BeEquivalentTo(pickedTxs); } + [TestCase(0, false)] + [TestCase(69, false)] + [TestCase(70, true)] + [TestCase(100, true)] + [TestCase(150, true)] + public void should_not_broadcast_tx_with_MaxFeePerGas_lower_than_70_percent_of_CurrentBaseFee(int maxFeePerGas, bool shouldBroadcast) + { + _headInfo.BaseFeeThreshold.Returns((UInt256)70); + + _broadcaster = new TxBroadcaster(_comparer, TimerFactory.Default, _txPoolConfig, _headInfo, _logManager); + + ITxPoolPeer peer = Substitute.For(); + peer.Id.Returns(TestItem.PublicKeyA); + _broadcaster.AddPeer(peer); + + Transaction transaction = Build.A.Transaction + .WithType(TxType.EIP1559) + .WithMaxFeePerGas((UInt256)maxFeePerGas) + .SignedAndResolved(_ethereumEcdsa, TestItem.PrivateKeyA) + .TestObject; + + _broadcaster.Broadcast(transaction, true); + + // tx should be immediately broadcasted only if MaxFeePerGas is equal at least 70% of current base fee + peer.Received(shouldBroadcast ? 1 : 0).SendNewTransaction(Arg.Any()); + + // tx should always be added to persistent collection, without any fee restrictions + _broadcaster.GetSnapshot().Length.Should().Be(1); + } + [Test] public void should_not_pick_1559_txs_with_MaxFeePerGas_lower_than_CurrentBaseFee([Values(1, 2, 99, 100, 101, 1000)] int threshold) { From d5ec8528280a64ec9623e0fd53d7e2347d29f555 Mon Sep 17 00:00:00 2001 From: Marcin Sobczak Date: Mon, 11 Dec 2023 15:39:02 +0100 Subject: [PATCH 05/11] make BaseFeeThreshold configurable in TxPoolConfig --- .../Nethermind.TxPool/ITxPoolConfig.cs | 3 ++ .../Nethermind.TxPool/TxBroadcaster.cs | 28 +++++++++++++++++-- src/Nethermind/Nethermind.TxPool/TxPool.cs | 2 +- .../Nethermind.TxPool/TxPoolConfig.cs | 1 + 4 files changed, 30 insertions(+), 4 deletions(-) diff --git a/src/Nethermind/Nethermind.TxPool/ITxPoolConfig.cs b/src/Nethermind/Nethermind.TxPool/ITxPoolConfig.cs index 95ba7cd7ca7..84d61cdbe22 100644 --- a/src/Nethermind/Nethermind.TxPool/ITxPoolConfig.cs +++ b/src/Nethermind/Nethermind.TxPool/ITxPoolConfig.cs @@ -10,6 +10,9 @@ public interface ITxPoolConfig : IConfig [ConfigItem(DefaultValue = "5", Description = "The average percentage of transaction hashes from persistent broadcast sent to a peer together with hashes of the last added transactions.")] int PeerNotificationThreshold { get; set; } + [ConfigItem(DefaultValue = "70", Description = "Minimal percentage of the current base fee which must be surpassed by MaxFeePerGas for the transaction to be broadcasted.")] + int MinBaseFeeThreshold { get; set; } + [ConfigItem(DefaultValue = "2048", Description = "The max number of transactions held in the mempool (the more transactions in the mempool, the more memory used).")] int Size { get; set; } diff --git a/src/Nethermind/Nethermind.TxPool/TxBroadcaster.cs b/src/Nethermind/Nethermind.TxPool/TxBroadcaster.cs index 4718870aa1d..fefcfc08544 100644 --- a/src/Nethermind/Nethermind.TxPool/TxBroadcaster.cs +++ b/src/Nethermind/Nethermind.TxPool/TxBroadcaster.cs @@ -52,11 +52,18 @@ internal class TxBroadcaster : IDisposable /// private ResettableList _txsToSend; + + /// + /// Minimal value of MaxFeePreGas of local tx to be broadcasted immediately after receiving it + /// + private UInt256 _baseFeeThreshold; + /// /// Used to throttle tx broadcast. Particularly during forward sync where the head changes a lot which triggers /// a lot of broadcast. There are no transaction in pool but its quite spammy on the log. /// private DateTimeOffset _lastPersistedTxBroadcast = DateTimeOffset.UnixEpoch; + private readonly TimeSpan _minTimeBetweenPersistedTxBroadcast = TimeSpan.FromSeconds(1); private readonly ILogger _logger; @@ -99,12 +106,13 @@ public void Broadcast(Transaction tx, bool isPersistent) private void StartBroadcast(Transaction tx) { - // broadcast tx only if MaxFeePerGas is equal at least 70% of current base fee + // broadcast local tx only if MaxFeePerGas is equal at least 70% of current base fee // otherwise only add to persistent collection and broadcast when tx will be ready for inclusion - if (tx.MaxFeePerGas >= _headInfo.BaseFeeThreshold) + if (tx.MaxFeePerGas >= _baseFeeThreshold) { NotifyPeersAboutLocalTx(tx); } + if (tx.Hash is not null) { _persistentTxs.TryInsert(tx.Hash, tx.SupportsBlobs ? new LightTransaction(tx) : tx); @@ -127,7 +135,21 @@ public void AnnounceOnce(ITxPoolPeer peer, Transaction[] txs) } } - public void BroadcastPersistentTxs() + public void OnNewHead() + { + SetBaseFeeThreshold(); + BroadcastPersistentTxs(); + } + + private void SetBaseFeeThreshold() + { + bool overflow = UInt256.MultiplyOverflow(_headInfo.CurrentBaseFee, (UInt256)_txPoolConfig.MinBaseFeeThreshold, out UInt256 baseFeeThreshold); + UInt256.Divide(baseFeeThreshold, 100, out baseFeeThreshold); + + _baseFeeThreshold = overflow ? _headInfo.CurrentBaseFee : baseFeeThreshold; + } + + internal void BroadcastPersistentTxs() { if (_persistentTxs.Count == 0) { diff --git a/src/Nethermind/Nethermind.TxPool/TxPool.cs b/src/Nethermind/Nethermind.TxPool/TxPool.cs index f28b42d9ec0..701c2bf9eea 100644 --- a/src/Nethermind/Nethermind.TxPool/TxPool.cs +++ b/src/Nethermind/Nethermind.TxPool/TxPool.cs @@ -201,7 +201,7 @@ private void ProcessNewHeads() ReAddReorganisedTransactions(args.PreviousBlock); RemoveProcessedTransactions(args.Block.Transactions); UpdateBuckets(); - _broadcaster.BroadcastPersistentTxs(); + _broadcaster.OnNewHead(); Metrics.TransactionCount = _transactions.Count; Metrics.BlobTransactionCount = _blobTransactions.Count; } diff --git a/src/Nethermind/Nethermind.TxPool/TxPoolConfig.cs b/src/Nethermind/Nethermind.TxPool/TxPoolConfig.cs index 071ed94dd04..7ae41d8bebb 100644 --- a/src/Nethermind/Nethermind.TxPool/TxPoolConfig.cs +++ b/src/Nethermind/Nethermind.TxPool/TxPoolConfig.cs @@ -6,6 +6,7 @@ namespace Nethermind.TxPool public class TxPoolConfig : ITxPoolConfig { public int PeerNotificationThreshold { get; set; } = 5; + public int MinBaseFeeThreshold { get; set; } = 70; public int Size { get; set; } = 2048; public bool BlobSupportEnabled { get; set; } = false; public bool PersistentBlobStorageEnabled { get; set; } = false; From af1b1879f34b62af59612dc6dc7f76319ea56830 Mon Sep 17 00:00:00 2001 From: Marcin Sobczak Date: Mon, 11 Dec 2023 15:48:50 +0100 Subject: [PATCH 06/11] remove from ChainHeadInfoProvider --- .../Nethermind.Blockchain/ChainHeadInfoProvider.cs | 5 ----- src/Nethermind/Nethermind.TxPool.Test/TxBroadcasterTests.cs | 2 +- src/Nethermind/Nethermind.TxPool/IChainHeadInfoProvider.cs | 2 -- src/Nethermind/Nethermind.TxPool/TxBroadcaster.cs | 2 ++ 4 files changed, 3 insertions(+), 8 deletions(-) diff --git a/src/Nethermind/Nethermind.Blockchain/ChainHeadInfoProvider.cs b/src/Nethermind/Nethermind.Blockchain/ChainHeadInfoProvider.cs index ddbcb14fcfb..8a0b721db9f 100644 --- a/src/Nethermind/Nethermind.Blockchain/ChainHeadInfoProvider.cs +++ b/src/Nethermind/Nethermind.Blockchain/ChainHeadInfoProvider.cs @@ -46,8 +46,6 @@ public ChainHeadInfoProvider(IChainHeadSpecProvider specProvider, IBlockTree blo public UInt256 CurrentBaseFee { get; private set; } - public UInt256 BaseFeeThreshold { get; private set; } - public UInt256 CurrentPricePerBlobGas { get; internal set; } public event EventHandler? HeadChanged; @@ -57,9 +55,6 @@ private void OnHeadChanged(object? sender, BlockReplacementEventArgs e) HeadNumber = e.Block.Number; BlockGasLimit = e.Block!.GasLimit; CurrentBaseFee = e.Block.Header.BaseFeePerGas; - BaseFeeThreshold = UInt256.MultiplyOverflow(CurrentBaseFee, 7, out UInt256 baseFeeThreshold) - ? CurrentBaseFee - : baseFeeThreshold; CurrentPricePerBlobGas = BlobGasCalculator.TryCalculateBlobGasPricePerUnit(e.Block.Header, out UInt256 currentPricePerBlobGas) ? currentPricePerBlobGas diff --git a/src/Nethermind/Nethermind.TxPool.Test/TxBroadcasterTests.cs b/src/Nethermind/Nethermind.TxPool.Test/TxBroadcasterTests.cs index 6bf3bda795b..393d13ae9b7 100644 --- a/src/Nethermind/Nethermind.TxPool.Test/TxBroadcasterTests.cs +++ b/src/Nethermind/Nethermind.TxPool.Test/TxBroadcasterTests.cs @@ -341,7 +341,7 @@ public void should_not_pick_txs_with_GasPrice_lower_than_CurrentBaseFee([Values( [TestCase(150, true)] public void should_not_broadcast_tx_with_MaxFeePerGas_lower_than_70_percent_of_CurrentBaseFee(int maxFeePerGas, bool shouldBroadcast) { - _headInfo.BaseFeeThreshold.Returns((UInt256)70); + _headInfo.CurrentBaseFee.Returns((UInt256)100); _broadcaster = new TxBroadcaster(_comparer, TimerFactory.Default, _txPoolConfig, _headInfo, _logManager); diff --git a/src/Nethermind/Nethermind.TxPool/IChainHeadInfoProvider.cs b/src/Nethermind/Nethermind.TxPool/IChainHeadInfoProvider.cs index a13ec1c0107..457322785a4 100644 --- a/src/Nethermind/Nethermind.TxPool/IChainHeadInfoProvider.cs +++ b/src/Nethermind/Nethermind.TxPool/IChainHeadInfoProvider.cs @@ -20,8 +20,6 @@ public interface IChainHeadInfoProvider public UInt256 CurrentBaseFee { get; } - UInt256 BaseFeeThreshold { get; } - public UInt256 CurrentPricePerBlobGas { get; } event EventHandler HeadChanged; diff --git a/src/Nethermind/Nethermind.TxPool/TxBroadcaster.cs b/src/Nethermind/Nethermind.TxPool/TxBroadcaster.cs index fefcfc08544..fdba51878fb 100644 --- a/src/Nethermind/Nethermind.TxPool/TxBroadcaster.cs +++ b/src/Nethermind/Nethermind.TxPool/TxBroadcaster.cs @@ -87,6 +87,8 @@ public TxBroadcaster(IComparer comparer, _timer.Elapsed += TimerOnElapsed; _timer.AutoReset = false; _timer.Start(); + + SetBaseFeeThreshold(); } // only for testing reasons From 746917f72fdc4ac467ac868f1edae8093a611be8 Mon Sep 17 00:00:00 2001 From: Marcin Sobczak Date: Mon, 11 Dec 2023 18:13:07 +0100 Subject: [PATCH 07/11] more tests --- .../TxBroadcasterTests.cs | 33 +++++++++++++++++++ .../Nethermind.TxPool/TxBroadcaster.cs | 18 +++++++--- 2 files changed, 46 insertions(+), 5 deletions(-) diff --git a/src/Nethermind/Nethermind.TxPool.Test/TxBroadcasterTests.cs b/src/Nethermind/Nethermind.TxPool.Test/TxBroadcasterTests.cs index 393d13ae9b7..4591721c912 100644 --- a/src/Nethermind/Nethermind.TxPool.Test/TxBroadcasterTests.cs +++ b/src/Nethermind/Nethermind.TxPool.Test/TxBroadcasterTests.cs @@ -687,6 +687,39 @@ public void should_rebroadcast_all_persistent_transactions_if_PeerNotificationTh } } + [TestCase(0, 0)] + [TestCase(2, 1)] + [TestCase(3, 2)] + [TestCase(7, 4)] + [TestCase(8, 5)] + [TestCase(100, 70)] + [TestCase(9999, 6999)] + [TestCase(10000, 7000)] + public void should_calculate_baseFeeThreshold_correctly(int baseFee, int expectedThreshold) + { + _headInfo.CurrentBaseFee.Returns((UInt256)baseFee); + _broadcaster = new TxBroadcaster(_comparer, TimerFactory.Default, _txPoolConfig, _headInfo, _logManager); + _broadcaster.CalculateBaseFeeThreshold().Should().Be((UInt256)expectedThreshold); + } + + [Test] + public void calculation_of_baseFeeThreshold_should_handle_overflow_correctly([Values(0, 70, 100, 101, 500)] int threshold, [Values(2, 3, 4, 5, 6, 7, 8, 9, 10, 11)] int divisor) + { + UInt256.Divide(UInt256.MaxValue, (UInt256)divisor, out UInt256 baseFee); + _headInfo.CurrentBaseFee.Returns(baseFee); + + _txPoolConfig = new TxPoolConfig() { MinBaseFeeThreshold = threshold }; + _broadcaster = new TxBroadcaster(_comparer, TimerFactory.Default, _txPoolConfig, _headInfo, _logManager); + + UInt256.Divide(baseFee, 100, out UInt256 result); + bool overflow = UInt256.MultiplyOverflow(result, (UInt256)threshold, out result); + + _broadcaster.CalculateBaseFeeThreshold().Should().Be( + UInt256.MultiplyOverflow(baseFee, (UInt256)threshold, out UInt256 baseFeeThreshold) + ? overflow ? UInt256.MaxValue : result + : baseFeeThreshold); + } + private (IList expectedTxs, IList expectedHashes) GetTxsAndHashesExpectedToBroadcast(Transaction[] transactions, int expectedCountTotal) { List expectedTxs = new(); diff --git a/src/Nethermind/Nethermind.TxPool/TxBroadcaster.cs b/src/Nethermind/Nethermind.TxPool/TxBroadcaster.cs index fdba51878fb..ce69f3b767a 100644 --- a/src/Nethermind/Nethermind.TxPool/TxBroadcaster.cs +++ b/src/Nethermind/Nethermind.TxPool/TxBroadcaster.cs @@ -54,7 +54,7 @@ internal class TxBroadcaster : IDisposable /// - /// Minimal value of MaxFeePreGas of local tx to be broadcasted immediately after receiving it + /// Minimal value of MaxFeePerGas of local tx to be broadcasted immediately after receiving it /// private UInt256 _baseFeeThreshold; @@ -88,7 +88,7 @@ public TxBroadcaster(IComparer comparer, _timer.AutoReset = false; _timer.Start(); - SetBaseFeeThreshold(); + _baseFeeThreshold = CalculateBaseFeeThreshold(); } // only for testing reasons @@ -139,16 +139,24 @@ public void AnnounceOnce(ITxPoolPeer peer, Transaction[] txs) public void OnNewHead() { - SetBaseFeeThreshold(); + _baseFeeThreshold = CalculateBaseFeeThreshold(); BroadcastPersistentTxs(); } - private void SetBaseFeeThreshold() + internal UInt256 CalculateBaseFeeThreshold() { bool overflow = UInt256.MultiplyOverflow(_headInfo.CurrentBaseFee, (UInt256)_txPoolConfig.MinBaseFeeThreshold, out UInt256 baseFeeThreshold); UInt256.Divide(baseFeeThreshold, 100, out baseFeeThreshold); - _baseFeeThreshold = overflow ? _headInfo.CurrentBaseFee : baseFeeThreshold; + if (overflow) + { + UInt256.Divide(_headInfo.CurrentBaseFee, 100, out baseFeeThreshold); + overflow = UInt256.MultiplyOverflow(baseFeeThreshold, (UInt256)_txPoolConfig.MinBaseFeeThreshold, out baseFeeThreshold); + } + + // if there is still an overflow, it means that MinBaseFeeThreshold > 100 + // we are returning max possible value of UInt256.MaxValue + return overflow ? UInt256.MaxValue : baseFeeThreshold; } internal void BroadcastPersistentTxs() From e5bee47f5ae94206b970070aa56dc307759130cd Mon Sep 17 00:00:00 2001 From: Marcin Sobczak Date: Mon, 11 Dec 2023 20:05:30 +0100 Subject: [PATCH 08/11] cosmetic --- src/Nethermind/Nethermind.TxPool.Test/TxBroadcasterTests.cs | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/Nethermind/Nethermind.TxPool.Test/TxBroadcasterTests.cs b/src/Nethermind/Nethermind.TxPool.Test/TxBroadcasterTests.cs index 4591721c912..4a1f694bca3 100644 --- a/src/Nethermind/Nethermind.TxPool.Test/TxBroadcasterTests.cs +++ b/src/Nethermind/Nethermind.TxPool.Test/TxBroadcasterTests.cs @@ -711,12 +711,12 @@ public void calculation_of_baseFeeThreshold_should_handle_overflow_correctly([Va _txPoolConfig = new TxPoolConfig() { MinBaseFeeThreshold = threshold }; _broadcaster = new TxBroadcaster(_comparer, TimerFactory.Default, _txPoolConfig, _headInfo, _logManager); - UInt256.Divide(baseFee, 100, out UInt256 result); - bool overflow = UInt256.MultiplyOverflow(result, (UInt256)threshold, out result); + UInt256.Divide(baseFee, 100, out UInt256 onePercentOfBaseFee); + bool overflow = UInt256.MultiplyOverflow(onePercentOfBaseFee, (UInt256)threshold, out UInt256 lessAccurateBaseFeeThreshold); _broadcaster.CalculateBaseFeeThreshold().Should().Be( UInt256.MultiplyOverflow(baseFee, (UInt256)threshold, out UInt256 baseFeeThreshold) - ? overflow ? UInt256.MaxValue : result + ? overflow ? UInt256.MaxValue : lessAccurateBaseFeeThreshold : baseFeeThreshold); } From 493e92a1a7ba7c2ec833de91f32b46b13843a8c7 Mon Sep 17 00:00:00 2001 From: Marcin Sobczak Date: Mon, 11 Dec 2023 20:12:14 +0100 Subject: [PATCH 09/11] cosmetic --- src/Nethermind/Nethermind.TxPool/TxBroadcaster.cs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/Nethermind/Nethermind.TxPool/TxBroadcaster.cs b/src/Nethermind/Nethermind.TxPool/TxBroadcaster.cs index ce69f3b767a..84a230ca01a 100644 --- a/src/Nethermind/Nethermind.TxPool/TxBroadcaster.cs +++ b/src/Nethermind/Nethermind.TxPool/TxBroadcaster.cs @@ -108,8 +108,8 @@ public void Broadcast(Transaction tx, bool isPersistent) private void StartBroadcast(Transaction tx) { - // broadcast local tx only if MaxFeePerGas is equal at least 70% of current base fee - // otherwise only add to persistent collection and broadcast when tx will be ready for inclusion + // broadcast local tx only if MaxFeePerGas is not lower than configurable percent of current base fee + // (70% by default). Otherwise only add to persistent txs and broadcast when tx will be ready for inclusion if (tx.MaxFeePerGas >= _baseFeeThreshold) { NotifyPeersAboutLocalTx(tx); From 777ae37b92e82aa685f43b93177d0535871044b6 Mon Sep 17 00:00:00 2001 From: Marcin Sobczak Date: Tue, 12 Dec 2023 15:06:13 +0100 Subject: [PATCH 10/11] fix posdao tests --- src/Nethermind/Nethermind.TxPool/TxBroadcaster.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Nethermind/Nethermind.TxPool/TxBroadcaster.cs b/src/Nethermind/Nethermind.TxPool/TxBroadcaster.cs index 84a230ca01a..be55ae965ff 100644 --- a/src/Nethermind/Nethermind.TxPool/TxBroadcaster.cs +++ b/src/Nethermind/Nethermind.TxPool/TxBroadcaster.cs @@ -110,7 +110,7 @@ private void StartBroadcast(Transaction tx) { // broadcast local tx only if MaxFeePerGas is not lower than configurable percent of current base fee // (70% by default). Otherwise only add to persistent txs and broadcast when tx will be ready for inclusion - if (tx.MaxFeePerGas >= _baseFeeThreshold) + if (tx.MaxFeePerGas >= _baseFeeThreshold || tx.IsFree()) { NotifyPeersAboutLocalTx(tx); } From 605916c1bbd705c1269805d0af431ee4cbba21e9 Mon Sep 17 00:00:00 2001 From: Marcin Sobczak <77129288+marcindsobczak@users.noreply.github.com> Date: Wed, 13 Dec 2023 10:19:17 +0100 Subject: [PATCH 11/11] Update src/Nethermind/Nethermind.TxPool/ITxPoolConfig.cs Co-authored-by: Ruben Buniatyan --- src/Nethermind/Nethermind.TxPool/ITxPoolConfig.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Nethermind/Nethermind.TxPool/ITxPoolConfig.cs b/src/Nethermind/Nethermind.TxPool/ITxPoolConfig.cs index 84d61cdbe22..02420aca0b0 100644 --- a/src/Nethermind/Nethermind.TxPool/ITxPoolConfig.cs +++ b/src/Nethermind/Nethermind.TxPool/ITxPoolConfig.cs @@ -10,7 +10,7 @@ public interface ITxPoolConfig : IConfig [ConfigItem(DefaultValue = "5", Description = "The average percentage of transaction hashes from persistent broadcast sent to a peer together with hashes of the last added transactions.")] int PeerNotificationThreshold { get; set; } - [ConfigItem(DefaultValue = "70", Description = "Minimal percentage of the current base fee which must be surpassed by MaxFeePerGas for the transaction to be broadcasted.")] + [ConfigItem(DefaultValue = "70", Description = "The minimal percentage of the current base fee that must be surpassed by the max fee (`max_fee_per_gas`) for the transaction to be broadcasted.")] int MinBaseFeeThreshold { get; set; } [ConfigItem(DefaultValue = "2048", Description = "The max number of transactions held in the mempool (the more transactions in the mempool, the more memory used).")]