aboutsummaryrefslogtreecommitdiff
path: root/src/net_processing.cpp
diff options
context:
space:
mode:
authorfurszy <matiasfurszyfer@protonmail.com>2023-12-22 10:32:32 -0300
committerfurszy <matiasfurszyfer@protonmail.com>2024-01-23 10:25:05 -0300
commit6ed53602ac7c565273b5722de167cb2569a0e381 (patch)
tree1003316de6138ce4028f04bb860dafcc00b3452e /src/net_processing.cpp
parent9f36e591c551ec2e58a6496334541bfdae8fdfe5 (diff)
downloadbitcoin-6ed53602ac7c565273b5722de167cb2569a0e381.tar.xz
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.
Diffstat (limited to 'src/net_processing.cpp')
-rw-r--r--src/net_processing.cpp9
1 files changed, 7 insertions, 2 deletions
diff --git a/src/net_processing.cpp b/src/net_processing.cpp
index 3e09b54336..84a7f4c4d5 100644
--- a/src/net_processing.cpp
+++ b/src/net_processing.cpp
@@ -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);
}