Fork sync targets are handled inefficiently #525
Labels
I9-optimisation
An enhancement to provide better overall performance in terms of time-to-completion for a task.
T10-tests
This PR/Issue is related to tests.
Is there an existing issue?
Experiencing problems? Have you tried our Stack Exchange first?
Description of bug
While refactoring the syncing code, I looked into
sync_to_tip_when_we_sync_with_multiple_peers
and while the test itself is dubious (more on that below), it also showed that fork sync targets are stored and handled inefficiently. The test takes over a minute because it spends most of the time looping over fork sync targets and checking if they can be removed or downloaded. Blocks of the same fork are not associated in the fork sync targets queue so if block A is too far in the future, all of its descendants are too so there is no reason to check them separately. The code should be improved to store the targets differently so that we don't have to check every block of the fork in order to determine whether to download it or not.I'm also not entirely sure if the test is testing what is supposed to. It adds 10000 and 5000 blocks for two different peers and buffers the block announcements so after the blocks have been imported and the network is polled for the first time, the network is flooded with thousands of block announcements. Because peers are idling when the announcements are received, they treat them as fork sync targets and third peer has something like 4000+ fork sync targets even though there are only two forks. And because the fork sync targets are handled inefficiently, the peers spend lots of time going over the list of targets and checking which can be removed and which can be downloaded.
The test probably should be rewritten to not spam the block announcements and instead download the 2 forks gracefully and without unnecessarily checking the same things over and over again.
Steps to reproduce
No response
The text was updated successfully, but these errors were encountered: