Improve Relay after Persisting blocks (relay last 2 instead of first 1) #458
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Had a discussion with @vncoelho about the code that happens on
OnNewBlock
and during the discussion I noticed something that looked sub-optimal related to how the code determines which blocks to relay upon persist.The code was only relaying the first block persisted in the case that there are multiple blocks also being persisted from the block cache. Since the idea is to keep nodes on the chain aware of the the most recent blocks, it should be relaying the last block rather than the first one. The code change I've made here will relay the last 2 blocks when multiple were persisted at once by taking some from the block cache.
@vncoelho indicated he would be able to do some testing with this, and I'll give it some testing also and update notes here after.
I believe this change will help nodes to obtain the latest blocks more quickly.