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

Don't resend tx hashes that were sent to us #5449

Merged
merged 7 commits into from
Mar 21, 2023
Merged

Conversation

LukaszRozmej
Copy link
Member

Changes

  • Move TxPoolPeer into base peer functionality
  • When we get sent transaction or hash don't re-send it to the peer that send it in the first place
  • don't allocate unnecessary arrays on block & receipts sync

Types of changes

What types of changes does your code introduce?

  • Bugfix (a non-breaking change that fixes an issue)
  • New feature (a non-breaking change that adds functionality)
  • Breaking change (a change that causes existing functionality not to work as expected)
  • Optimization
  • Refactoring
  • Documentation update
  • Build-related changes
  • Other: Description

Testing

Requires testing

  • Yes
  • No

If yes, did you write tests?

  • Yes
  • No

@LukaszRozmej
Copy link
Member Author

Managed to get Sent hashes down fro average 104k->62k.
image

Post-sync darkpool looks fine:
image

@LukaszRozmej LukaszRozmej marked this pull request as ready for review March 18, 2023 09:43
Copy link
Contributor

@marcindsobczak marcindsobczak left a comment

Choose a reason for hiding this comment

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

In PR description:

When we get sent transaction or hash don't re-send it to the peer that send it in the first place

  1. full transactions are sent anyway: https://github.com/NethermindEth/nethermind/blob/perf/tx-pool-peer/src/Nethermind/Nethermind.Network/P2P/ProtocolHandlers/SyncPeerProtocolHandlerBase.cs#L198
    and it is fine - we want to broadcast local txs as fast and as wide as possible
  2. PR name Don't resend tx hashes that were sent to us - we already have protection from sending hashes to the peer which sent this tx to us:
    https://github.com/NethermindEth/nethermind/blob/master/src/Nethermind/Nethermind.TxPool/TxBroadcaster.cs#L224
    https://github.com/NethermindEth/nethermind/blob/master/src/Nethermind/Nethermind.TxPool/TxBroadcaster.cs#L239-L242

I'm not sure why you achieved such reduction in number of hashes sent, for me it looks like we are doing the same as before, just adding to the cache tx hashes which will not be sent anyway - we have logic in TxBroadcaster which is preparing messages exclusively for every peer to protect from sending back hash to the original sender of tx.

@LukaszRozmej
Copy link
Member Author

LukaszRozmej commented Mar 20, 2023

Good question about DeliveredBy, still I think this abstraction in Nethermind.TxPool/PeerInfo.cs was not useful and this is better.

Copy link
Contributor

@marcindsobczak marcindsobczak left a comment

Choose a reason for hiding this comment

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

Ah I got it, we were not sending back hashes of txs added to the pool, now we are not sending back hashes received and not pooled too. At this point I think we can consider simplifying TxBroadcaster - remove logic of skipping tx by sender and prepare only one HashesMessage for all peers, and then not-resending will be handled by peer cache

@marcindsobczak
Copy link
Contributor

I mean we can drop this https://github.com/NethermindEth/nethermind/blob/master/src/Nethermind/Nethermind.TxPool/TxBroadcaster.cs#L234-L244
and just pass all _txsToSend to all peers instead of iterating it for every peer
https://github.com/NethermindEth/nethermind/blob/master/src/Nethermind/Nethermind.TxPool/TxBroadcaster.cs#L224
Notify(peer, _txsToSend, false);

Also I think we should add

foreach (Keccak hash in msg.Hashes)
{
    NotifiedTransactions.Set(hash);
}

to Eth68ProtocolHandler as well, same as to Eth65ProtocolHandler
https://github.com/NethermindEth/nethermind/blob/master/src/Nethermind/Nethermind.Network/P2P/Subprotocols/Eth/V68/Eth68ProtocolHandler.cs#L67-L93

@marcindsobczak
Copy link
Contributor

Ah I got it, we were not sending back hashes of txs added to the pool, now we are not sending back hashes received and not pooled too

Actually it is wrong, we were not sending not pooled hashes anyway, hashes are added to broadcaster only after adding txs to the pool. But we could received tx hash from many peers and full tx from only one. Before we were announcing that hash to every peer except of one, now we are announcing only to the ones which didn't sent that hash to us. It explains why number of sent hashes dropped.

Refactoring TxBroadcaster to not iterate _txsToSend 100x every second and caching hashes just after receiving them seems good. We can only consider increasing cache - it is only 2048 and one single NewPooledTransactionsHashes message might be bigger. But it will increase memory usage significantly, as we have dedicated cache per every peer

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants