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

Fix/6790 return accepted for rejected tx added to broadcast #6889

Merged
Show file tree
Hide file tree
Changes from 6 commits
Commits
Show all changes
22 commits
Select commit Hold shift + click to select a range
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
26 changes: 15 additions & 11 deletions src/Nethermind/Nethermind.TxPool/TxBroadcaster.cs
Original file line number Diff line number Diff line change
Expand Up @@ -97,31 +97,35 @@ public TxBroadcaster(IComparer<Transaction> comparer,
// only for testing reasons
internal Transaction[] GetSnapshot() => _persistentTxs.GetSnapshot();

public void Broadcast(Transaction tx, bool isPersistent)
public bool Broadcast(Transaction tx, bool isPersistent)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Minor cosmetic: would be good to rename method, right now we are not calling it if we want to broadcast (void), but when we want to try to broadcast (bool return depending on success). So I recommend renaming it to TryBroadcast and TryStartBroadcast

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Worth to consider before merging

{
if (isPersistent)
{
StartBroadcast(tx);
}
else
{
BroadcastOnce(tx);
return StartBroadcast(tx);
}

BroadcastOnce(tx);

return true;
}

private void StartBroadcast(Transaction tx)
private bool StartBroadcast(Transaction tx)
{
if (tx is null) return false;

bool txInserted = _persistentTxs.TryInsert(tx.Hash, tx.SupportsBlobs ? new LightTransaction(tx) : tx);

if (!txInserted) return false;

// 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 || tx.IsFree())
{
NotifyPeersAboutLocalTx(tx);
return true;
}

if (tx.Hash is not null)
{
_persistentTxs.TryInsert(tx.Hash, tx.SupportsBlobs ? new LightTransaction(tx) : tx);
}
return false;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

After this change, we will return false if tx was inserted, but is not close to base fee. It will be possible, that we return false, but tx will be included in the block in the future. We should decide on one of two options:

  1. just return txInserted at the end of the method. Even if tx is not good enough to send to peers right now, but if we add it to persistent collection, we need to return true
  2. move attempt to insert tx inside if statement checking price, so just return _persistentTxs.TryInsert(tx.Hash, tx.SupportsBlobs ? new LightTransaction(tx) : tx); inside if and return false at the end

It depends if we want to add local tx with fee lower than 70% of baseFee or reject it. I don't have a strong preference here, you can decide. If I would need to make this decision, I will probably go with option 1

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ah sorry I reviewed on wrong commit

}

private void BroadcastOnce(Transaction tx)
Expand Down
9 changes: 5 additions & 4 deletions src/Nethermind/Nethermind.TxPool/TxPool.cs
Original file line number Diff line number Diff line change
Expand Up @@ -450,14 +450,15 @@ private AcceptTxResult AddCore(Transaction tx, TxFilteringState state, bool isPe
if (tx.Hash == removed?.Hash)
{
// it means it was added and immediately evicted - pool was full of better txs
if (isPersistentBroadcast)
if (!isPersistentBroadcast || tx.SupportsBlobs || !_broadcaster.Broadcast(tx, true))
{
// we are adding only to persistent broadcast - not good enough for standard pool,
// but can be good enough for TxBroadcaster pool - for local txs only
_broadcaster.Broadcast(tx, isPersistentBroadcast);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

what happened to _broadcaster.Broadcast call?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since the if branch now has the opposite condition, if the tx is persistent (and not a blob tx), it would run to the end of the function (line 462~483).

_broadcaster.Broadcast will be run at line 477.

Copy link
Member

@LukaszRozmej LukaszRozmej Apr 2, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not sure if running through all the normal flow here is best choice as this is a special case, when something we are not adding to main pool will have broadcasting, will wait for @marcindsobczak opinion.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not a good option, we definitely don't want to run through all the normal flow here

Metrics.PendingTransactionsPassedFiltersButCannotCompeteOnFees++;
return AcceptTxResult.FeeTooLowToCompete;
} else {
return AcceptTxResult.Accepted;
}
Metrics.PendingTransactionsPassedFiltersButCannotCompeteOnFees++;
return AcceptTxResult.FeeTooLowToCompete;
}

relevantPool.UpdateGroup(tx.SenderAddress!, state.SenderAccount, UpdateBucketWithAddedTransaction);
Expand Down
Loading