mirror of
https://github.com/bitcoin/bitcoin.git
synced 2025-11-11 14:38:29 +01:00
Replace relevant services logic with a function suite.
Adds HasAllRelevantServices and GetRelevantServices, which check for NETWORK|WITNESS. This changes the following: * Removes nRelevantServices from CConnman, disconnecting it a bit more from protocol-level logic. * Replaces our sometimes-connect-to-!WITNESS-nodes logic with simply always requiring WITNESS|NETWORK for outbound non-feeler connections (feelers still only require NETWORK). * This has the added benefit of removing nServicesExpected from CNode - instead letting net_processing's VERSION message handling simply check HasAllRelevantServices. * This implies we believe WITNESS nodes to continue to be a significant majority of nodes on the network, but also because we cannot sync properly from !WITNESS nodes, it is strange to continue using our valuable outbound slots on them. * In order to prevent this change from preventing connection to -connect= nodes which have !WITNESS, -connect nodes are now given the "addnode" flag. This also allows outbound connections to !NODE_NETWORK nodes for -connect nodes (which was already true of addnodes). * Has the (somewhat unintended) consequence of changing one of the eviction metrics from the same sometimes-connect-to-!WITNESS-nodes metric to requiring HasRelevantServices. This should make NODE_NETWORK_LIMITED much simpler to implement.
This commit is contained in:
@@ -277,6 +277,43 @@ enum ServiceFlags : uint64_t {
|
||||
// BIP process.
|
||||
};
|
||||
|
||||
/**
|
||||
* Gets the set of service flags which are "desirable" for a given peer.
|
||||
*
|
||||
* These are the flags which are required for a peer to support for them
|
||||
* to be "interesting" to us, ie for us to wish to use one of our few
|
||||
* outbound connection slots for or for us to wish to prioritize keeping
|
||||
* their connection around.
|
||||
*
|
||||
* Relevant service flags may be peer- and state-specific in that the
|
||||
* version of the peer may determine which flags are required (eg in the
|
||||
* case of NODE_NETWORK_LIMITED where we seek out NODE_NETWORK peers
|
||||
* unless they set NODE_NETWORK_LIMITED and we are out of IBD, in which
|
||||
* case NODE_NETWORK_LIMITED suffices).
|
||||
*
|
||||
* Thus, generally, avoid calling with peerServices == NODE_NONE.
|
||||
*/
|
||||
static ServiceFlags GetDesirableServiceFlags(ServiceFlags services) {
|
||||
return ServiceFlags(NODE_NETWORK | NODE_WITNESS);
|
||||
}
|
||||
|
||||
/**
|
||||
* A shortcut for (services & GetDesirableServiceFlags(services))
|
||||
* == GetDesirableServiceFlags(services), ie determines whether the given
|
||||
* set of service flags are sufficient for a peer to be "relevant".
|
||||
*/
|
||||
static inline bool HasAllDesirableServiceFlags(ServiceFlags services) {
|
||||
return !(GetDesirableServiceFlags(services) & (~services));
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks if a peer with the given service flags may be capable of having a
|
||||
* robust address-storage DB. Currently an alias for checking NODE_NETWORK.
|
||||
*/
|
||||
static inline bool MayHaveUsefulAddressDB(ServiceFlags services) {
|
||||
return services & NODE_NETWORK;
|
||||
}
|
||||
|
||||
/** A CService with information about it as peer */
|
||||
class CAddress : public CService
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user