Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Disable txpool if SequencerUrl is set #7513

Merged
merged 5 commits into from
Oct 11, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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();
}

LukaszRozmej marked this conversation as resolved.
Show resolved Hide resolved
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