fix(network): only send responded updates on handshake/ping/pong #3463
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.
Motivation
During the initial sync, Zebra sends a peer timestamp update to the address book for every inbound message.
This uses approximately:
When I sync testnet from a few nodes on my local network, it takes about an hour to get to the tip.
Solution
I changed Zebra to send a peer timestamp update to the address book after the handshake, and for every inbound Ping or Pong message. This uses approximately 1 thousand address book update channel messages, time system calls, and address book mutex locks, a 2000x decrease.
After this change, when I sync testnet from a few nodes on my local network, it takes about 30-45 minutes to get to the tip.
This change is correct because:
MIN_PEER_RECONNECTION_DELAY
interval. (Typically, there should be 1-3 per interval.)The impact of this change is that peer timestamps update every 1-2 minutes, rather than potentially hundreds of times per second. This might change Zebra's internal reconnection order slightly for some peers.
But Zebra already truncates peer timestamps to the nearest 30 seconds before sending them externally. So this change won't have much impact on the times that we send to other peers.
Mainnet sync time doesn't change on my machine. So it probably depends on network latency, block size, or verification CPU time.
Review
@jvff can review this PR.
Reviewer Checklist