LCOV - code coverage report
Current view: top level - src - protocol.h (source / functions) Hit Total Coverage
Test: total_coverage.info Lines: 55 55 100.0 %
Date: 2026-06-25 07:23:43 Functions: 81 85 95.3 %

          Line data    Source code
       1             : // Copyright (c) 2009-2010 Satoshi Nakamoto
       2             : // Copyright (c) 2009-2021 The Bitcoin Core developers
       3             : // Distributed under the MIT software license, see the accompanying
       4             : // file COPYING or http://www.opensource.org/licenses/mit-license.php.
       5             : 
       6             : #ifndef BITCOIN_PROTOCOL_H
       7             : #define BITCOIN_PROTOCOL_H
       8             : 
       9             : #include <netaddress.h>
      10             : #include <serialize.h>
      11             : #include <streams.h>
      12             : #include <uint256.h>
      13             : #include <util/time.h>
      14             : 
      15             : #include <cstdint>
      16             : #include <limits>
      17             : #include <string>
      18             : #include <variant>
      19             : 
      20             : /** Message header.
      21             :  * (4) message start.
      22             :  * (12) command.
      23             :  * (4) size.
      24             :  * (4) checksum.
      25             :  */
      26             : class CMessageHeader
      27             : {
      28             : public:
      29             :     static constexpr size_t MESSAGE_START_SIZE = 4;
      30             :     static constexpr size_t COMMAND_SIZE = 12;
      31             :     static constexpr size_t MESSAGE_SIZE_SIZE = 4;
      32             :     static constexpr size_t CHECKSUM_SIZE = 4;
      33             :     static constexpr size_t MESSAGE_SIZE_OFFSET = MESSAGE_START_SIZE + COMMAND_SIZE;
      34             :     static constexpr size_t CHECKSUM_OFFSET = MESSAGE_SIZE_OFFSET + MESSAGE_SIZE_SIZE;
      35             :     static constexpr size_t HEADER_SIZE = MESSAGE_START_SIZE + COMMAND_SIZE + MESSAGE_SIZE_SIZE + CHECKSUM_SIZE;
      36             :     typedef unsigned char MessageStartChars[MESSAGE_START_SIZE];
      37             : 
      38       30195 :     explicit CMessageHeader() = default;
      39             : 
      40             :     /** Construct a P2P message header from message-start characters, a command and the size of the message.
      41             :      * @note Passing in a `pszCommand` longer than COMMAND_SIZE will result in a run-time assertion error.
      42             :      */
      43             :     CMessageHeader(const MessageStartChars& pchMessageStartIn, const char* pszCommand, unsigned int nMessageSizeIn);
      44             : 
      45             :     std::string GetCommand() const;
      46             :     bool IsCommandValid() const;
      47             : 
      48     4795659 :     SERIALIZE_METHODS(CMessageHeader, obj) { READWRITE(obj.pchMessageStart, obj.pchCommand, obj.nMessageSize, obj.pchChecksum); }
      49             : 
      50       10065 :     char pchMessageStart[MESSAGE_START_SIZE]{};
      51       10065 :     char pchCommand[COMMAND_SIZE]{};
      52       10065 :     uint32_t nMessageSize{std::numeric_limits<uint32_t>::max()};
      53       10065 :     uint8_t pchChecksum[CHECKSUM_SIZE]{};
      54             : };
      55             : 
      56             : /**
      57             :  * Bitcoin protocol message types. When adding new message types, don't forget
      58             :  * to update allNetMessageTypes in protocol.cpp.
      59             :  */
      60             : namespace NetMsgType {
      61             : 
      62             : /**
      63             :  * The version message provides information about the transmitting node to the
      64             :  * receiving node at the beginning of a connection.
      65             :  */
      66             : extern const char* VERSION;
      67             : /**
      68             :  * The verack message acknowledges a previously-received version message,
      69             :  * informing the connecting node that it can begin to send other messages.
      70             :  */
      71             : extern const char* VERACK;
      72             : /**
      73             :  * The addr (IP address) message relays connection information for peers on the
      74             :  * network.
      75             :  */
      76             : extern const char* ADDR;
      77             : /**
      78             :  * The addrv2 message relays connection information for peers on the network just
      79             :  * like the addr message, but is extended to allow gossiping of longer node
      80             :  * addresses (see BIP155).
      81             :  */
      82             : extern const char *ADDRV2;
      83             : /**
      84             :  * The sendaddrv2 message signals support for receiving ADDRV2 messages (BIP155).
      85             :  * It also implies that its sender can encode as ADDRV2 and would send ADDRV2
      86             :  * instead of ADDR to a peer that has signaled ADDRV2 support by sending SENDADDRV2.
      87             :  */
      88             : extern const char *SENDADDRV2;
      89             : /**
      90             :  * The inv message (inventory message) transmits one or more inventories of
      91             :  * objects known to the transmitting peer.
      92             :  */
      93             : extern const char* INV;
      94             : /**
      95             :  * The getdata message requests one or more data objects from another node.
      96             :  */
      97             : extern const char* GETDATA;
      98             : /**
      99             :  * The merkleblock message is a reply to a getdata message which requested a
     100             :  * block using the inventory type MSG_MERKLEBLOCK.
     101             :  * @since protocol version 70001 as described by BIP37.
     102             :  */
     103             : extern const char* MERKLEBLOCK;
     104             : /**
     105             :  * The getblocks message requests an inv message that provides block header
     106             :  * hashes starting from a particular point in the block chain.
     107             :  */
     108             : extern const char* GETBLOCKS;
     109             : /**
     110             :  * The getheaders message requests a headers message that provides block
     111             :  * headers starting from a particular point in the block chain.
     112             :  * @since protocol version 31800.
     113             :  */
     114             : extern const char* GETHEADERS;
     115             : /**
     116             :  * The tx message transmits a single transaction.
     117             :  */
     118             : extern const char* TX;
     119             : /**
     120             :  * The headers message sends one or more block headers to a node which
     121             :  * previously requested certain headers with a getheaders message.
     122             :  * @since protocol version 31800.
     123             :  */
     124             : extern const char* HEADERS;
     125             : /**
     126             :  * The block message transmits a single serialized block.
     127             :  */
     128             : extern const char* BLOCK;
     129             : /**
     130             :  * The getaddr message requests an addr message from the receiving node,
     131             :  * preferably one with lots of IP addresses of other receiving nodes.
     132             :  */
     133             : extern const char* GETADDR;
     134             : /**
     135             :  * The mempool message requests the TXIDs of transactions that the receiving
     136             :  * node has verified as valid but which have not yet appeared in a block.
     137             :  * @since protocol version 60002 as described by BIP35.
     138             :  *   Only available with service bit NODE_BLOOM, see also BIP111.
     139             :  */
     140             : extern const char* MEMPOOL;
     141             : /**
     142             :  * The ping message is sent periodically to help confirm that the receiving
     143             :  * peer is still connected.
     144             :  */
     145             : extern const char* PING;
     146             : /**
     147             :  * The pong message replies to a ping message, proving to the pinging node that
     148             :  * the ponging node is still alive.
     149             :  * @since protocol version 60001 as described by BIP31.
     150             :  */
     151             : extern const char* PONG;
     152             : /**
     153             :  * The notfound message is a reply to a getdata message which requested an
     154             :  * object the receiving node does not have available for relay.
     155             :  * @since protocol version 70001.
     156             :  */
     157             : extern const char* NOTFOUND;
     158             : /**
     159             :  * The filterload message tells the receiving peer to filter all relayed
     160             :  * transactions and requested merkle blocks through the provided filter.
     161             :  * @since protocol version 70001 as described by BIP37.
     162             :  *   Only available with service bit NODE_BLOOM since protocol version
     163             :  *   70011 as described by BIP111.
     164             :  */
     165             : extern const char* FILTERLOAD;
     166             : /**
     167             :  * The filteradd message tells the receiving peer to add a single element to a
     168             :  * previously-set bloom filter, such as a new public key.
     169             :  * @since protocol version 70001 as described by BIP37.
     170             :  *   Only available with service bit NODE_BLOOM since protocol version
     171             :  *   70011 as described by BIP111.
     172             :  */
     173             : extern const char* FILTERADD;
     174             : /**
     175             :  * The filterclear message tells the receiving peer to remove a previously-set
     176             :  * bloom filter.
     177             :  * @since protocol version 70001 as described by BIP37.
     178             :  *   Only available with service bit NODE_BLOOM since protocol version
     179             :  *   70011 as described by BIP111.
     180             :  */
     181             : extern const char* FILTERCLEAR;
     182             : /**
     183             :  * Indicates that a node prefers to receive new block announcements via a
     184             :  * "headers" message rather than an "inv".
     185             :  * @since protocol version 70012 as described by BIP130.
     186             :  */
     187             : extern const char* SENDHEADERS;
     188             : 
     189             : /**
     190             :  * Contains a 1-byte bool and 8-byte LE version number.
     191             :  * Indicates that a node is willing to provide blocks via "cmpctblock" messages.
     192             :  * May indicate that a node prefers to receive new block announcements via a
     193             :  * "cmpctblock" message rather than an "inv", depending on message contents.
     194             :  * @since protocol version 70209 as described by BIP 152
     195             :  */
     196             : extern const char* SENDCMPCT;
     197             : /**
     198             :  * Contains a CBlockHeaderAndShortTxIDs object - providing a header and
     199             :  * list of "short txids".
     200             :  * @since protocol version 70209 as described by BIP 152
     201             :  */
     202             : extern const char* CMPCTBLOCK;
     203             : /**
     204             :  * Contains a BlockTransactionsRequest
     205             :  * Peer should respond with "blocktxn" message.
     206             :  * @since protocol version 70209 as described by BIP 152
     207             :  */
     208             : extern const char* GETBLOCKTXN;
     209             : /**
     210             :  * Contains a BlockTransactions.
     211             :  * Sent in response to a "getblocktxn" message.
     212             :  * @since protocol version 70209 as described by BIP 152
     213             :  */
     214             : extern const char* BLOCKTXN;
     215             : /**
     216             :  * getcfilters requests compact filters for a range of blocks.
     217             :  * Only available with service bit NODE_COMPACT_FILTERS as described by
     218             :  * BIP 157 & 158.
     219             :  */
     220             : extern const char* GETCFILTERS;
     221             : /**
     222             :  * cfilter is a response to a getcfilters request containing a single compact
     223             :  * filter.
     224             :  */
     225             : extern const char* CFILTER;
     226             : /**
     227             :  * getcfheaders requests a compact filter header and the filter hashes for a
     228             :  * range of blocks, which can then be used to reconstruct the filter headers
     229             :  * for those blocks.
     230             :  * Only available with service bit NODE_COMPACT_FILTERS as described by
     231             :  * BIP 157 & 158.
     232             :  */
     233             : extern const char* GETCFHEADERS;
     234             : /**
     235             :  * cfheaders is a response to a getcfheaders request containing a filter header
     236             :  * and a vector of filter hashes for each subsequent block in the requested range.
     237             :  */
     238             : extern const char* CFHEADERS;
     239             : /**
     240             :  * getcfcheckpt requests evenly spaced compact filter headers, enabling
     241             :  * parallelized download and validation of the headers between them.
     242             :  * Only available with service bit NODE_COMPACT_FILTERS as described by
     243             :  * BIP 157 & 158.
     244             :  */
     245             : extern const char* GETCFCHECKPT;
     246             : /**
     247             :  * cfcheckpt is a response to a getcfcheckpt request containing a vector of
     248             :  * evenly spaced filter headers for blocks on the requested chain.
     249             :  */
     250             : extern const char* CFCHECKPT;
     251             : /**
     252             :  * Contains a 4-byte version number and an 8-byte salt.
     253             :  * The salt is used to compute short txids needed for efficient
     254             :  * txreconciliation, as described by BIP 330.
     255             :  */
     256             : extern const char* SENDTXRCNCL;
     257             : 
     258             : // Dash message types
     259             : // NOTE: do NOT declare non-implmented here, we don't want them to be exposed to the outside
     260             : // TODO: add description
     261             : extern const char* SPORK;
     262             : extern const char* GETSPORKS;
     263             : extern const char* DSACCEPT;
     264             : extern const char* DSVIN;
     265             : extern const char* DSFINALTX;
     266             : extern const char* DSSIGNFINALTX;
     267             : extern const char* DSCOMPLETE;
     268             : extern const char* DSSTATUSUPDATE;
     269             : extern const char* DSTX;
     270             : extern const char* DSQUEUE;
     271             : extern const char* SENDDSQUEUE;
     272             : extern const char* SYNCSTATUSCOUNT;
     273             : extern const char* MNGOVERNANCESYNC;
     274             : extern const char* MNGOVERNANCEOBJECT;
     275             : extern const char* MNGOVERNANCEOBJECTVOTE;
     276             : extern const char* GETMNLISTDIFF;
     277             : extern const char* MNLISTDIFF;
     278             : extern const char* QSENDRECSIGS;
     279             : extern const char* QFCOMMITMENT;
     280             : extern const char* QCONTRIB;
     281             : extern const char* QCOMPLAINT;
     282             : extern const char* QJUSTIFICATION;
     283             : extern const char* QPCOMMITMENT;
     284             : extern const char* QWATCH;
     285             : extern const char* QSIGSESANN;
     286             : extern const char* QSIGSHARESINV;
     287             : extern const char* QGETSIGSHARES;
     288             : extern const char* QBSIGSHARES;
     289             : extern const char* QSIGREC;
     290             : extern const char* QSIGSHARE;
     291             : extern const char* QGETDATA;
     292             : extern const char* QDATA;
     293             : extern const char* CLSIG;
     294             : extern const char* ISDLOCK;
     295             : extern const char* MNAUTH;
     296             : extern const char* GETHEADERS2;
     297             : extern const char* SENDHEADERS2;
     298             : extern const char* HEADERS2;
     299             : extern const char* GETQUORUMROTATIONINFO;
     300             : extern const char* QUORUMROTATIONINFO;
     301             : extern const char* PLATFORMBAN;
     302             : };
     303             : 
     304             : /* Get a vector of all valid message types (see above) */
     305             : const std::vector<std::string>& getAllNetMessageTypes();
     306             : 
     307             : /* Whether the message type violates blocks-relay-only policy */
     308             : bool NetMessageViolatesBlocksOnly(const std::string& msg_type);
     309             : 
     310             : /** nServices flags */
     311             : enum ServiceFlags : uint64_t {
     312             :     // NOTE: When adding here, be sure to update serviceFlagToStr too
     313             :     // Nothing
     314             :     NODE_NONE = 0,
     315             :     // NODE_NETWORK means that the node is capable of serving the complete block chain. It is currently
     316             :     // set by all Dash Core non pruned nodes, and is unset by SPV clients or other light clients.
     317             :     NODE_NETWORK = (1 << 0),
     318             :     // NODE_BLOOM means the node is capable and willing to handle bloom-filtered connections.
     319             :     NODE_BLOOM = (1 << 2),
     320             :     // NODE_COMPACT_FILTERS means the node will service basic block filter requests.
     321             :     // See BIP157 and BIP158 for details on how this is implemented.
     322             :     NODE_COMPACT_FILTERS = (1 << 6),
     323             :     // NODE_NETWORK_LIMITED means the same as NODE_NETWORK with the limitation of only
     324             :     // serving the last 288 blocks
     325             :     // See BIP159 for details on how this is implemented.
     326             :     NODE_NETWORK_LIMITED = (1 << 10),
     327             :     // description will be provided
     328             :     NODE_HEADERS_COMPRESSED = (1 << 11),
     329             : 
     330             :     // NODE_P2P_V2 means the node supports BIP324 transport
     331             :     NODE_P2P_V2 = (1 << 12),
     332             : 
     333             :     // Bits 24-31 are reserved for temporary experiments. Just pick a bit that
     334             :     // isn't getting used, or one not being used much, and notify the
     335             :     // bitcoin-development mailing list. Remember that service bits are just
     336             :     // unauthenticated advertisements, so your code must be robust against
     337             :     // collisions and other cases where nodes may be advertising a service they
     338             :     // do not actually support. Other service bits should be allocated via the
     339             :     // BIP process.
     340             : };
     341             : 
     342             : /**
     343             :  * Convert service flags (a bitmask of NODE_*) to human readable strings.
     344             :  * It supports unknown service flags which will be returned as "UNKNOWN[...]".
     345             :  * @param[in] flags multiple NODE_* bitwise-OR-ed together
     346             :  */
     347             : std::vector<std::string> serviceFlagsToStr(uint64_t flags);
     348             : 
     349             : /**
     350             :  * Gets the set of service flags which are "desirable" for a given peer.
     351             :  *
     352             :  * These are the flags which are required for a peer to support for them
     353             :  * to be "interesting" to us, ie for us to wish to use one of our few
     354             :  * outbound connection slots for or for us to wish to prioritize keeping
     355             :  * their connection around.
     356             :  *
     357             :  * Relevant service flags may be peer- and state-specific in that the
     358             :  * version of the peer may determine which flags are required (eg in the
     359             :  * case of NODE_NETWORK_LIMITED where we seek out NODE_NETWORK peers
     360             :  * unless they set NODE_NETWORK_LIMITED and we are out of IBD, in which
     361             :  * case NODE_NETWORK_LIMITED suffices).
     362             :  *
     363             :  * Thus, generally, avoid calling with peerServices == NODE_NONE, unless
     364             :  * state-specific flags must absolutely be avoided. When called with
     365             :  * peerServices == NODE_NONE, the returned desirable service flags are
     366             :  * guaranteed to not change dependent on state - ie they are suitable for
     367             :  * use when describing peers which we know to be desirable, but for which
     368             :  * we do not have a confirmed set of service flags.
     369             :  *
     370             :  * If the NODE_NONE return value is changed, contrib/seeds/makeseeds.py
     371             :  * should be updated appropriately to filter for the same nodes.
     372             :  */
     373             : ServiceFlags GetDesirableServiceFlags(ServiceFlags services);
     374             : 
     375             : /** Set the current IBD status in order to figure out the desirable service flags */
     376             : void SetServiceFlagsIBDCache(bool status);
     377             : 
     378             : /**
     379             :  * A shortcut for (services & GetDesirableServiceFlags(services))
     380             :  * == GetDesirableServiceFlags(services), ie determines whether the given
     381             :  * set of service flags are sufficient for a peer to be "relevant".
     382             :  */
     383       12598 : static inline bool HasAllDesirableServiceFlags(ServiceFlags services)
     384             : {
     385       12598 :     return !(GetDesirableServiceFlags(services) & (~services));
     386             : }
     387             : 
     388             : /**
     389             :  * Checks if a peer with the given service flags may be capable of having a
     390             :  * robust address-storage DB.
     391             :  */
     392        2554 : static inline bool MayHaveUsefulAddressDB(ServiceFlags services)
     393             : {
     394        2554 :     return (services & NODE_NETWORK) || (services & NODE_NETWORK_LIMITED);
     395             : }
     396             : 
     397             : /** A CService with information about it as peer */
     398             : class CAddress : public CService
     399             : {
     400             :     static constexpr std::chrono::seconds TIME_INIT{100000000};
     401             : 
     402             :     /** Historically, CAddress disk serialization stored the CLIENT_VERSION, optionally OR'ed with
     403             :      *  the ADDRV2_FORMAT flag to indicate V2 serialization. The first field has since been
     404             :      *  disentangled from client versioning, and now instead:
     405             :      *  - The low bits (masked by DISK_VERSION_IGNORE_MASK) store the fixed value DISK_VERSION_INIT,
     406             :      *    (in case any code exists that treats it as a client version) but are ignored on
     407             :      *    deserialization.
     408             :      *  - The high bits (masked by ~DISK_VERSION_IGNORE_MASK) store actual serialization information.
     409             :      *    Only 0 or DISK_VERSION_ADDRV2 (equal to the historical ADDRV2_FORMAT) are valid now, and
     410             :      *    any other value triggers a deserialization failure. Other values can be added later if
     411             :      *    needed.
     412             :      *
     413             :      *  For disk deserialization, ADDRV2_FORMAT in the stream version signals that ADDRV2
     414             :      *  deserialization is permitted, but the actual format is determined by the high bits in the
     415             :      *  stored version field. For network serialization, the stream version having ADDRV2_FORMAT or
     416             :      *  not determines the actual format used (as it has no embedded version number).
     417             :      */
     418             :     static constexpr uint32_t DISK_VERSION_INIT{220000};
     419             :     static constexpr uint32_t DISK_VERSION_IGNORE_MASK{0b00000000'00000111'11111111'11111111};
     420             :     /** The version number written in disk serialized addresses to indicate V2 serializations.
     421             :      * It must be exactly 1<<29, as that is the value that historical versions used for this
     422             :      * (they used their internal ADDRV2_FORMAT flag here). */
     423             :     static constexpr uint32_t DISK_VERSION_ADDRV2{1 << 29};
     424             :     static_assert((DISK_VERSION_INIT & ~DISK_VERSION_IGNORE_MASK) == 0, "DISK_VERSION_INIT must be covered by DISK_VERSION_IGNORE_MASK");
     425             :     static_assert((DISK_VERSION_ADDRV2 & DISK_VERSION_IGNORE_MASK) == 0, "DISK_VERSION_ADDRV2 must not be covered by DISK_VERSION_IGNORE_MASK");
     426             : 
     427             : public:
     428      997286 :     CAddress() : CService{} {};
     429      179886 :     explicit CAddress(CService ipIn, ServiceFlags nServicesIn) : CService{ipIn}, nServices{nServicesIn} {};
     430         878 :     CAddress(CService ipIn, ServiceFlags nServicesIn, NodeSeconds time) : CService{ipIn}, nTime{time}, nServices{nServicesIn} {};
     431             : 
     432      611911 :     SERIALIZE_METHODS(CAddress, obj)
     433             :     {
     434             :         // CAddress has a distinct network serialization and a disk serialization, but it should never
     435             :         // be hashed (except through CHashWriter in addrdb.cpp, which sets SER_DISK), and it's
     436             :         // ambiguous what that would mean. Make sure no code relying on that is introduced:
     437      203969 :         assert(!(s.GetType() & SER_GETHASH));
     438             :         bool use_v2;
     439      203969 :         if (s.GetType() & SER_DISK) {
     440             :             // In the disk serialization format, the encoding (v1 or v2) is determined by a flag version
     441             :             // that's part of the serialization itself. ADDRV2_FORMAT in the stream version only determines
     442             :             // whether V2 is chosen/permitted at all.
     443      152176 :             uint32_t stored_format_version = DISK_VERSION_INIT;
     444      152176 :             if (s.GetVersion() & ADDRV2_FORMAT) stored_format_version |= DISK_VERSION_ADDRV2;
     445      152176 :             READWRITE(stored_format_version);
     446      152176 :             stored_format_version &= ~DISK_VERSION_IGNORE_MASK; // ignore low bits
     447      152176 :             if (stored_format_version == 0) {
     448           4 :                 use_v2 = false;
     449      152176 :             } else if (stored_format_version == DISK_VERSION_ADDRV2 && (s.GetVersion() & ADDRV2_FORMAT)) {
     450             :                 // Only support v2 deserialization if ADDRV2_FORMAT is set.
     451      152170 :                 use_v2 = true;
     452      152170 :             } else {
     453           2 :                 throw std::ios_base::failure("Unsupported CAddress disk format version");
     454             :             }
     455      152174 :         } else {
     456             :             // In the network serialization format, the encoding (v1 or v2) is determined directly by
     457             :             // the value of ADDRV2_FORMAT in the stream version, as no explicitly encoded version
     458             :             // exists in the stream.
     459       51793 :             assert(s.GetType() & SER_NETWORK);
     460       51793 :             use_v2 = s.GetVersion() & ADDRV2_FORMAT;
     461             :         }
     462             : 
     463      203967 :         READWRITE(Using<LossyChronoFormatter<uint32_t>>(obj.nTime));
     464             :         // nServices is serialized as CompactSize in V2; as uint64_t in V1.
     465      203967 :         if (use_v2) {
     466             :             uint64_t services_tmp;
     467      265783 :             SER_WRITE(obj, services_tmp = obj.nServices);
     468      154254 :             READWRITE(Using<CompactSizeFormatter<false>>(services_tmp));
     469      196979 :             SER_READ(obj, obj.nServices = static_cast<ServiceFlags>(services_tmp));
     470      154254 :         } else {
     471       49713 :             READWRITE(Using<CustomUintFormatter<8>>(obj.nServices));
     472             :         }
     473             :         // Invoke V1/V2 serializer for CService parent object.
     474      203967 :         OverrideStream<Stream> os(&s, s.GetType(), use_v2 ? ADDRV2_FORMAT : 0);
     475      203967 :         SerReadWriteMany(os, ser_action, ReadWriteAsHelper<CService>(obj));
     476      203967 :     }
     477             : 
     478             :     //! Always included in serialization. The behavior is unspecified if the value is not representable as uint32_t.
     479      641629 :     NodeSeconds nTime{TIME_INIT};
     480             :     //! Serialized as uint64_t in V1, and as CompactSize in V2.
     481      551686 :     ServiceFlags nServices{NODE_NONE};
     482             : 
     483          18 :     friend bool operator==(const CAddress& a, const CAddress& b)
     484             :     {
     485          36 :         return a.nTime == b.nTime &&
     486          18 :                a.nServices == b.nServices &&
     487          18 :                static_cast<const CService&>(a) == static_cast<const CService&>(b);
     488             :     }
     489             : };
     490             : 
     491             : /** getdata / inv message types.
     492             :  * These numbers are defined by the protocol. When adding a new value, be sure
     493             :  * to mention it in the respective BIP.
     494             :  */
     495             : enum GetDataMsg : uint32_t {
     496             :     UNDEFINED = 0,
     497             :     MSG_TX = 1,
     498             :     MSG_BLOCK = 2,
     499             :     // The following can only occur in getdata. Invs always use TX or BLOCK.
     500             :     MSG_FILTERED_BLOCK = 3,                           //!< Defined in BIP37
     501             :     // Dash message types
     502             :     // NOTE: we must keep this enum consistent and backwards compatible
     503             :     /* MSG_LEGACY_TXLOCK_REQUEST = 4, */              // Legacy InstantSend and not used anymore
     504             :     /* MSG_TXLOCK_VOTE = 5, */                        // Legacy InstantSend and not used anymore
     505             :     MSG_SPORK = 6,
     506             :     /* 7 - 15 were used in old Dash versions and were mainly budget and MN broadcast/ping related*/
     507             :     MSG_DSTX = 16,
     508             :     MSG_GOVERNANCE_OBJECT = 17,
     509             :     MSG_GOVERNANCE_OBJECT_VOTE = 18,
     510             :     /* 19 was used for MSG_MASTERNODE_VERIFY and is not supported anymore */
     511             :     // Nodes may always request a MSG_CMPCT_BLOCK in a getdata, however,
     512             :     // MSG_CMPCT_BLOCK should not appear in any invs except as a part of getdata.
     513             :     MSG_CMPCT_BLOCK = 20,                             //!< Defined in BIP152
     514             :     MSG_QUORUM_FINAL_COMMITMENT = 21,
     515             :     /* MSG_QUORUM_DUMMY_COMMITMENT = 22, */           // was shortly used on testnet/devnet/regtest
     516             :     MSG_QUORUM_CONTRIB = 23,
     517             :     MSG_QUORUM_COMPLAINT = 24,
     518             :     MSG_QUORUM_JUSTIFICATION = 25,
     519             :     MSG_QUORUM_PREMATURE_COMMITMENT = 26,
     520             :     /* MSG_QUORUM_DEBUG_STATUS = 27, */               // was shortly used on testnet/devnet/regtest
     521             :     MSG_QUORUM_RECOVERED_SIG = 28,
     522             :     MSG_CLSIG = 29,
     523             :     /* MSG_ISLOCK = 30, */                            // Non-deterministic InstantSend and not used anymore
     524             :     MSG_ISDLOCK = 31,
     525             :     MSG_DSQ = 32,
     526             :     MSG_PLATFORM_BAN = 33,                            // Platform service ban (DIP-0031)
     527             : };
     528             : 
     529             : /** inv message data */
     530             : class CInv
     531             : {
     532             : public:
     533             :     CInv();
     534             :     CInv(uint32_t typeIn, const uint256& hashIn);
     535             : 
     536     2427483 :     SERIALIZE_METHODS(CInv, obj) { READWRITE(obj.type, obj.hash); }
     537             : 
     538             :     friend bool operator<(const CInv& a, const CInv& b);
     539             : 
     540             :     bool IsKnownType() const;
     541             :     std::string GetCommand() const;
     542             :     std::string ToString() const;
     543             : 
     544             :     // Single-message helper methods
     545       84410 :     bool IsMsgTx()        const { return type == MSG_TX; }
     546      242231 :     bool IsMsgBlk() const { return type == MSG_BLOCK; }
     547      169506 :     bool IsMsgDstx()       const { return type == MSG_DSTX; }
     548        2688 :     bool IsMsgFilteredBlk() const { return type == MSG_FILTERED_BLOCK; }
     549        2014 :     bool IsMsgCmpctBlk() const { return type == MSG_CMPCT_BLOCK; }
     550             : 
     551             :     // Combined-message helper methods
     552       52274 :     bool IsGenTxMsg() const
     553             :     {
     554       52274 :         return type == MSG_TX || type == MSG_DSTX;
     555             :     }
     556       54735 :     bool IsGenBlkMsg() const
     557             :     {
     558       54735 :         return type == MSG_BLOCK || type == MSG_FILTERED_BLOCK || type == MSG_CMPCT_BLOCK;
     559             :     }
     560             : 
     561             : private:
     562             :     const char* GetCommandInternal() const;
     563             : 
     564             : public:
     565             :     uint32_t type;
     566             :     uint256 hash;
     567             : };
     568             : 
     569             : #endif // BITCOIN_PROTOCOL_H

Generated by: LCOV version 1.16