Page MenuHomePhabricator

Reduce bandwidth during initial headers sync when a block is found
ClosedPublic

Authored by PiRK on Dec 5 2023, 15:16.

Details

Summary

If our headers chain is behind on startup, then if a block is found we'll try
to catch up from all peers announcing the block, in addition to our initial
headers-sync peer. This commit changes behavior so that in this situation,
we'll choose at most one peer announcing a block to additionally sync headers
from.

This is a backport of core#25720

Depends on D14913

Test Plan

ninja all check-all

I also successfully ran the new functional test 50 times to reduce the risks of introducing a flaky test.

Event Timeline

src/net_processing.cpp
4510

Note that currently m_chainman.GetMutex() and cs_main are the same lock. In the future this could change if the chainstate manager gets its own lock. Here we need the lock for both m_chainman.ActiveChain() and for State(pfrom.GetId()), so use cs_main to be sure we won't loose the lock for State in the future. If the lock for ActiveChain() changes we will need to correct it in many places anyway, so we are unlikely to miss this one.

fix comment layout and use BlockHash

PiRK published this revision for review.Dec 5 2023, 15:32
This revision is now accepted and ready to land.Dec 6 2023, 08:47