diff --git a/src/Nethermind/Nethermind.Optimism/Rpc/RegisterOptimismRpcModules.cs b/src/Nethermind/Nethermind.Optimism/Rpc/RegisterOptimismRpcModules.cs index 04da5fca22e..25a5b4dd119 100644 --- a/src/Nethermind/Nethermind.Optimism/Rpc/RegisterOptimismRpcModules.cs +++ b/src/Nethermind/Nethermind.Optimism/Rpc/RegisterOptimismRpcModules.cs @@ -54,6 +54,11 @@ protected override void RegisterEthRpcModule(IRpcModuleProvider rpcModuleProvide _logger.Warn($"SequencerUrl is not set. Nethermind will behave as a Sequencer"); } + if (_config.SequencerUrl is not null) + { + _api.TxPool.Disable(); + } + BasicJsonRpcClient? sequencerJsonRpcClient = _config.SequencerUrl is null ? null : new(new Uri(_config.SequencerUrl), _api.EthereumJsonSerializer, _api.LogManager); diff --git a/src/Nethermind/Nethermind.TxPool/ITxPool.cs b/src/Nethermind/Nethermind.TxPool/ITxPool.cs index ff418e574cd..f209f27492a 100644 --- a/src/Nethermind/Nethermind.TxPool/ITxPool.cs +++ b/src/Nethermind/Nethermind.TxPool/ITxPool.cs @@ -49,6 +49,8 @@ bool TryGetBlobAndProof(byte[] blobVersionedHash, [NotNullWhen(true)] out byte[]? blob, [NotNullWhen(true)] out byte[]? proof); UInt256 GetLatestPendingNonce(Address address); + void Disable(); + event EventHandler NewDiscovered; event EventHandler NewPending; event EventHandler RemovedPending; diff --git a/src/Nethermind/Nethermind.TxPool/NullTxPool.cs b/src/Nethermind/Nethermind.TxPool/NullTxPool.cs index bcc1b237745..fb75f2365ed 100644 --- a/src/Nethermind/Nethermind.TxPool/NullTxPool.cs +++ b/src/Nethermind/Nethermind.TxPool/NullTxPool.cs @@ -73,6 +73,7 @@ public bool TryGetBlobAndProof(byte[] blobVersionedHash, public UInt256 GetLatestPendingNonce(Address address) => 0; + public void Disable() { } public event EventHandler NewDiscovered { diff --git a/src/Nethermind/Nethermind.TxPool/TxPool.cs b/src/Nethermind/Nethermind.TxPool/TxPool.cs index b79fce3ce91..596458ad4a3 100644 --- a/src/Nethermind/Nethermind.TxPool/TxPool.cs +++ b/src/Nethermind/Nethermind.TxPool/TxPool.cs @@ -66,7 +66,7 @@ public class TxPool : ITxPool, IDisposable /// private ulong _txIndex; - private readonly ITimer? _timer; + private ITimer? _timer; private Transaction[]? _transactionSnapshot; private Transaction[]? _blobTransactionSnapshot; private long _lastBlockNumber = -1; @@ -369,7 +369,7 @@ private bool RemoveIncludedTransaction(Transaction tx) public void AddPeer(ITxPoolPeer peer) { - if (_broadcaster.AddPeer(peer)) + if (!_disabled && _broadcaster.AddPeer(peer)) { if (_logger.IsTrace) _logger.Trace($"Added a peer to TX pool: {peer}"); @@ -399,6 +399,8 @@ public void RemovePeer(PublicKey nodeId) public AcceptTxResult SubmitTx(Transaction tx, TxHandlingOptions handlingOptions) { + if (_disabled) return AcceptTxResult.AlreadyKnown; + Metrics.PendingTransactionsReceived++; // assign a sequence number to transaction so we can order them by arrival times when @@ -752,11 +754,21 @@ public UInt256 GetLatestPendingNonce(Address address) public void Dispose() { - _timer?.Dispose(); - TxPoolHeadChanged -= _broadcaster.OnNewHead; - _broadcaster.Dispose(); - _headInfo.HeadChanged -= OnHeadChange; - _headBlocksChannel.Writer.Complete(); + if (!_disabled) + { + _timer?.Dispose(); + TxPoolHeadChanged -= _broadcaster.OnNewHead; + _broadcaster.Dispose(); + _headInfo.HeadChanged -= OnHeadChange; + _headBlocksChannel.Writer.Complete(); + } + } + + private bool _disabled = false; + void ITxPool.Disable() + { + Dispose(); + _disabled = true; } ///