Skip to content

Commit

Permalink
Disable txpool if SequencerUrl is set
Browse files Browse the repository at this point in the history
  • Loading branch information
benaadams committed Sep 29, 2024
1 parent f773a71 commit 7bbfc99
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
2 changes: 2 additions & 0 deletions src/Nethermind/Nethermind.TxPool/ITxPool.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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<TxEventArgs> NewDiscovered;
event EventHandler<TxEventArgs> NewPending;
event EventHandler<TxEventArgs> RemovedPending;
Expand Down
1 change: 1 addition & 0 deletions src/Nethermind/Nethermind.TxPool/NullTxPool.cs
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,7 @@ public bool TryGetBlobAndProof(byte[] blobVersionedHash,

public UInt256 GetLatestPendingNonce(Address address) => 0;

public void Disable() { }

public event EventHandler<TxEventArgs> NewDiscovered
{
Expand Down
26 changes: 19 additions & 7 deletions src/Nethermind/Nethermind.TxPool/TxPool.cs
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ public class TxPool : ITxPool, IDisposable
/// </summary>
private ulong _txIndex;

private readonly ITimer? _timer;
private ITimer? _timer;
private Transaction[]? _transactionSnapshot;
private Transaction[]? _blobTransactionSnapshot;
private long _lastBlockNumber = -1;
Expand Down Expand Up @@ -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}");

Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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;
}

/// <summary>
Expand Down

0 comments on commit 7bbfc99

Please sign in to comment.