Skip to content

Commit 6ed5360

Browse files
committed
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.
1 parent 9f36e59 commit 6ed5360

File tree

1 file changed

+7
-2
lines changed

1 file changed

+7
-2
lines changed

src/net_processing.cpp

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -133,6 +133,8 @@ static const unsigned int MAX_BLOCKS_TO_ANNOUNCE = 8;
133133
static const int MAX_NUM_UNCONNECTING_HEADERS_MSGS = 10;
134134
/** Minimum blocks required to signal NODE_NETWORK_LIMITED */
135135
static const unsigned int NODE_NETWORK_LIMITED_MIN_BLOCKS = 288;
136+
/** Window, in blocks, for connecting to NODE_NETWORK_LIMITED peers */
137+
static const unsigned int NODE_NETWORK_LIMITED_ALLOW_CONN_BLOCKS = 144;
136138
/** Average delay between local address broadcasts */
137139
static constexpr auto AVG_LOCAL_ADDRESS_BROADCAST_INTERVAL{24h};
138140
/** Average delay between peer address broadcasts */
@@ -1678,8 +1680,11 @@ bool PeerManagerImpl::HasAllDesirableServiceFlags(ServiceFlags services) const
16781680

16791681
ServiceFlags PeerManagerImpl::GetDesirableServiceFlags(ServiceFlags services) const
16801682
{
1681-
if (services & NODE_NETWORK_LIMITED && GetServicesFlagsIBDCache()) {
1682-
return ServiceFlags(NODE_NETWORK_LIMITED | NODE_WITNESS);
1683+
if (services & NODE_NETWORK_LIMITED) {
1684+
// Limited peers are desirable when we are close to the tip.
1685+
if (ApproximateBestBlockDepth() < NODE_NETWORK_LIMITED_ALLOW_CONN_BLOCKS) {
1686+
return ServiceFlags(NODE_NETWORK_LIMITED | NODE_WITNESS);
1687+
}
16831688
}
16841689
return ServiceFlags(NODE_NETWORK | NODE_WITNESS);
16851690
}

0 commit comments

Comments
 (0)