mirror of
https://github.com/bitcoin/bitcoin.git
synced 2025-02-08 10:31:50 -05:00
net: peer manager, dynamically adjust desirable services flag
Introduces functionality to detect when limited peers connections are desirable or not. Ensuring that the new connections desirable services flags stay relevant throughout the software's lifecycle. (Unlike the previous approach, where once the validation IBD flag was set, the desirable services flags remained constant forever). This will let us recover from stalling scenarios where the node had successfully synced, but subsequently dropped connections and remained inactive for a duration longer than the limited peers threshold (the timeframe within which limited peers can provide blocks). Then, upon reconnection to the network, the node may end up only establishing connections with limited peers, leading to an inability to synchronize the chain. This also fixes a possible limited peers threshold violation during IBD, when the user configures `-maxtipage` further than the BIP159's limits. This rule violation could lead to sync delays and, in the worst-case scenario, trigger the same post-IBD stalling scenario (mentioned above) but during IBD.
This commit is contained in:
parent
9f36e591c5
commit
6ed53602ac
1 changed files with 7 additions and 2 deletions
|
@ -133,6 +133,8 @@ static const unsigned int MAX_BLOCKS_TO_ANNOUNCE = 8;
|
|||
static const int MAX_NUM_UNCONNECTING_HEADERS_MSGS = 10;
|
||||
/** Minimum blocks required to signal NODE_NETWORK_LIMITED */
|
||||
static const unsigned int NODE_NETWORK_LIMITED_MIN_BLOCKS = 288;
|
||||
/** Window, in blocks, for connecting to NODE_NETWORK_LIMITED peers */
|
||||
static const unsigned int NODE_NETWORK_LIMITED_ALLOW_CONN_BLOCKS = 144;
|
||||
/** Average delay between local address broadcasts */
|
||||
static constexpr auto AVG_LOCAL_ADDRESS_BROADCAST_INTERVAL{24h};
|
||||
/** Average delay between peer address broadcasts */
|
||||
|
@ -1678,8 +1680,11 @@ bool PeerManagerImpl::HasAllDesirableServiceFlags(ServiceFlags services) const
|
|||
|
||||
ServiceFlags PeerManagerImpl::GetDesirableServiceFlags(ServiceFlags services) const
|
||||
{
|
||||
if (services & NODE_NETWORK_LIMITED && GetServicesFlagsIBDCache()) {
|
||||
return ServiceFlags(NODE_NETWORK_LIMITED | NODE_WITNESS);
|
||||
if (services & NODE_NETWORK_LIMITED) {
|
||||
// Limited peers are desirable when we are close to the tip.
|
||||
if (ApproximateBestBlockDepth() < NODE_NETWORK_LIMITED_ALLOW_CONN_BLOCKS) {
|
||||
return ServiceFlags(NODE_NETWORK_LIMITED | NODE_WITNESS);
|
||||
}
|
||||
}
|
||||
return ServiceFlags(NODE_NETWORK | NODE_WITNESS);
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue