LCOV - code coverage report
Current view: top level - src - protocol.h (source / functions) Hit Total Coverage
Test: coverage.lcov Lines: 44 44 100.0 %
Date: 2021-06-29 14:35:33 Functions: 31 190 16.3 %
Legend: Modified by patch:
Lines: hit not hit | Branches: + taken - not taken # not executed

Not modified by patch:
Lines: hit not hit | Branches: + taken - not taken # not executed
Branches: 75 142 52.8 %

           Branch data     Line data    Source code
#       1                 :            : // Copyright (c) 2009-2010 Satoshi Nakamoto
#       2                 :            : // Copyright (c) 2009-2020 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 __cplusplus
#       7                 :            : #error This header can only be compiled as C++.
#       8                 :            : #endif
#       9                 :            : 
#      10                 :            : #ifndef BITCOIN_PROTOCOL_H
#      11                 :            : #define BITCOIN_PROTOCOL_H
#      12                 :            : 
#      13                 :            : #include <netaddress.h>
#      14                 :            : #include <primitives/transaction.h>
#      15                 :            : #include <serialize.h>
#      16                 :            : #include <uint256.h>
#      17                 :            : #include <version.h>
#      18                 :            : 
#      19                 :            : #include <limits>
#      20                 :            : #include <stdint.h>
#      21                 :            : #include <string>
#      22                 :            : 
#      23                 :            : /** Message header.
#      24                 :            :  * (4) message start.
#      25                 :            :  * (12) command.
#      26                 :            :  * (4) size.
#      27                 :            :  * (4) checksum.
#      28                 :            :  */
#      29                 :            : class CMessageHeader
#      30                 :            : {
#      31                 :            : public:
#      32                 :            :     static constexpr size_t MESSAGE_START_SIZE = 4;
#      33                 :            :     static constexpr size_t COMMAND_SIZE = 12;
#      34                 :            :     static constexpr size_t MESSAGE_SIZE_SIZE = 4;
#      35                 :            :     static constexpr size_t CHECKSUM_SIZE = 4;
#      36                 :            :     static constexpr size_t MESSAGE_SIZE_OFFSET = MESSAGE_START_SIZE + COMMAND_SIZE;
#      37                 :            :     static constexpr size_t CHECKSUM_OFFSET = MESSAGE_SIZE_OFFSET + MESSAGE_SIZE_SIZE;
#      38                 :            :     static constexpr size_t HEADER_SIZE = MESSAGE_START_SIZE + COMMAND_SIZE + MESSAGE_SIZE_SIZE + CHECKSUM_SIZE;
#      39                 :            :     typedef unsigned char MessageStartChars[MESSAGE_START_SIZE];
#      40                 :            : 
#      41                 :       1014 :     explicit CMessageHeader() = default;
#      42                 :            : 
#      43                 :            :     /** Construct a P2P message header from message-start characters, a command and the size of the message.
#      44                 :            :      * @note Passing in a `pszCommand` longer than COMMAND_SIZE will result in a run-time assertion error.
#      45                 :            :      */
#      46                 :            :     CMessageHeader(const MessageStartChars& pchMessageStartIn, const char* pszCommand, unsigned int nMessageSizeIn);
#      47                 :            : 
#      48                 :            :     std::string GetCommand() const;
#      49                 :            :     bool IsCommandValid() const;
#      50                 :            : 
#      51                 :     229279 :     SERIALIZE_METHODS(CMessageHeader, obj) { READWRITE(obj.pchMessageStart, obj.pchCommand, obj.nMessageSize, obj.pchChecksum); }
#      52                 :            : 
#      53                 :            :     char pchMessageStart[MESSAGE_START_SIZE]{};
#      54                 :            :     char pchCommand[COMMAND_SIZE]{};
#      55                 :            :     uint32_t nMessageSize{std::numeric_limits<uint32_t>::max()};
#      56                 :            :     uint8_t pchChecksum[CHECKSUM_SIZE]{};
#      57                 :            : };
#      58                 :            : 
#      59                 :            : /**
#      60                 :            :  * Bitcoin protocol message types. When adding new message types, don't forget
#      61                 :            :  * to update allNetMessageTypes in protocol.cpp.
#      62                 :            :  */
#      63                 :            : namespace NetMsgType {
#      64                 :            : 
#      65                 :            : /**
#      66                 :            :  * The version message provides information about the transmitting node to the
#      67                 :            :  * receiving node at the beginning of a connection.
#      68                 :            :  */
#      69                 :            : extern const char* VERSION;
#      70                 :            : /**
#      71                 :            :  * The verack message acknowledges a previously-received version message,
#      72                 :            :  * informing the connecting node that it can begin to send other messages.
#      73                 :            :  */
#      74                 :            : extern const char* VERACK;
#      75                 :            : /**
#      76                 :            :  * The addr (IP address) message relays connection information for peers on the
#      77                 :            :  * network.
#      78                 :            :  */
#      79                 :            : extern const char* ADDR;
#      80                 :            : /**
#      81                 :            :  * The addrv2 message relays connection information for peers on the network just
#      82                 :            :  * like the addr message, but is extended to allow gossiping of longer node
#      83                 :            :  * addresses (see BIP155).
#      84                 :            :  */
#      85                 :            : extern const char *ADDRV2;
#      86                 :            : /**
#      87                 :            :  * The sendaddrv2 message signals support for receiving ADDRV2 messages (BIP155).
#      88                 :            :  * It also implies that its sender can encode as ADDRV2 and would send ADDRV2
#      89                 :            :  * instead of ADDR to a peer that has signaled ADDRV2 support by sending SENDADDRV2.
#      90                 :            :  */
#      91                 :            : extern const char *SENDADDRV2;
#      92                 :            : /**
#      93                 :            :  * The inv message (inventory message) transmits one or more inventories of
#      94                 :            :  * objects known to the transmitting peer.
#      95                 :            :  */
#      96                 :            : extern const char* INV;
#      97                 :            : /**
#      98                 :            :  * The getdata message requests one or more data objects from another node.
#      99                 :            :  */
#     100                 :            : extern const char* GETDATA;
#     101                 :            : /**
#     102                 :            :  * The merkleblock message is a reply to a getdata message which requested a
#     103                 :            :  * block using the inventory type MSG_MERKLEBLOCK.
#     104                 :            :  * @since protocol version 70001 as described by BIP37.
#     105                 :            :  */
#     106                 :            : extern const char* MERKLEBLOCK;
#     107                 :            : /**
#     108                 :            :  * The getblocks message requests an inv message that provides block header
#     109                 :            :  * hashes starting from a particular point in the block chain.
#     110                 :            :  */
#     111                 :            : extern const char* GETBLOCKS;
#     112                 :            : /**
#     113                 :            :  * The getheaders message requests a headers message that provides block
#     114                 :            :  * headers starting from a particular point in the block chain.
#     115                 :            :  * @since protocol version 31800.
#     116                 :            :  */
#     117                 :            : extern const char* GETHEADERS;
#     118                 :            : /**
#     119                 :            :  * The tx message transmits a single transaction.
#     120                 :            :  */
#     121                 :            : extern const char* TX;
#     122                 :            : /**
#     123                 :            :  * The headers message sends one or more block headers to a node which
#     124                 :            :  * previously requested certain headers with a getheaders message.
#     125                 :            :  * @since protocol version 31800.
#     126                 :            :  */
#     127                 :            : extern const char* HEADERS;
#     128                 :            : /**
#     129                 :            :  * The block message transmits a single serialized block.
#     130                 :            :  */
#     131                 :            : extern const char* BLOCK;
#     132                 :            : /**
#     133                 :            :  * The getaddr message requests an addr message from the receiving node,
#     134                 :            :  * preferably one with lots of IP addresses of other receiving nodes.
#     135                 :            :  */
#     136                 :            : extern const char* GETADDR;
#     137                 :            : /**
#     138                 :            :  * The mempool message requests the TXIDs of transactions that the receiving
#     139                 :            :  * node has verified as valid but which have not yet appeared in a block.
#     140                 :            :  * @since protocol version 60002.
#     141                 :            :  */
#     142                 :            : extern const char* MEMPOOL;
#     143                 :            : /**
#     144                 :            :  * The ping message is sent periodically to help confirm that the receiving
#     145                 :            :  * peer is still connected.
#     146                 :            :  */
#     147                 :            : extern const char* PING;
#     148                 :            : /**
#     149                 :            :  * The pong message replies to a ping message, proving to the pinging node that
#     150                 :            :  * the ponging node is still alive.
#     151                 :            :  * @since protocol version 60001 as described by BIP31.
#     152                 :            :  */
#     153                 :            : extern const char* PONG;
#     154                 :            : /**
#     155                 :            :  * The notfound message is a reply to a getdata message which requested an
#     156                 :            :  * object the receiving node does not have available for relay.
#     157                 :            :  * @since protocol version 70001.
#     158                 :            :  */
#     159                 :            : extern const char* NOTFOUND;
#     160                 :            : /**
#     161                 :            :  * The filterload message tells the receiving peer to filter all relayed
#     162                 :            :  * transactions and requested merkle blocks through the provided filter.
#     163                 :            :  * @since protocol version 70001 as described by BIP37.
#     164                 :            :  *   Only available with service bit NODE_BLOOM since protocol version
#     165                 :            :  *   70011 as described by BIP111.
#     166                 :            :  */
#     167                 :            : extern const char* FILTERLOAD;
#     168                 :            : /**
#     169                 :            :  * The filteradd message tells the receiving peer to add a single element to a
#     170                 :            :  * previously-set bloom filter, such as a new public key.
#     171                 :            :  * @since protocol version 70001 as described by BIP37.
#     172                 :            :  *   Only available with service bit NODE_BLOOM since protocol version
#     173                 :            :  *   70011 as described by BIP111.
#     174                 :            :  */
#     175                 :            : extern const char* FILTERADD;
#     176                 :            : /**
#     177                 :            :  * The filterclear message tells the receiving peer to remove a previously-set
#     178                 :            :  * bloom filter.
#     179                 :            :  * @since protocol version 70001 as described by BIP37.
#     180                 :            :  *   Only available with service bit NODE_BLOOM since protocol version
#     181                 :            :  *   70011 as described by BIP111.
#     182                 :            :  */
#     183                 :            : extern const char* FILTERCLEAR;
#     184                 :            : /**
#     185                 :            :  * Indicates that a node prefers to receive new block announcements via a
#     186                 :            :  * "headers" message rather than an "inv".
#     187                 :            :  * @since protocol version 70012 as described by BIP130.
#     188                 :            :  */
#     189                 :            : extern const char* SENDHEADERS;
#     190                 :            : /**
#     191                 :            :  * The feefilter message tells the receiving peer not to inv us any txs
#     192                 :            :  * which do not meet the specified min fee rate.
#     193                 :            :  * @since protocol version 70013 as described by BIP133
#     194                 :            :  */
#     195                 :            : extern const char* FEEFILTER;
#     196                 :            : /**
#     197                 :            :  * Contains a 1-byte bool and 8-byte LE version number.
#     198                 :            :  * Indicates that a node is willing to provide blocks via "cmpctblock" messages.
#     199                 :            :  * May indicate that a node prefers to receive new block announcements via a
#     200                 :            :  * "cmpctblock" message rather than an "inv", depending on message contents.
#     201                 :            :  * @since protocol version 70014 as described by BIP 152
#     202                 :            :  */
#     203                 :            : extern const char* SENDCMPCT;
#     204                 :            : /**
#     205                 :            :  * Contains a CBlockHeaderAndShortTxIDs object - providing a header and
#     206                 :            :  * list of "short txids".
#     207                 :            :  * @since protocol version 70014 as described by BIP 152
#     208                 :            :  */
#     209                 :            : extern const char* CMPCTBLOCK;
#     210                 :            : /**
#     211                 :            :  * Contains a BlockTransactionsRequest
#     212                 :            :  * Peer should respond with "blocktxn" message.
#     213                 :            :  * @since protocol version 70014 as described by BIP 152
#     214                 :            :  */
#     215                 :            : extern const char* GETBLOCKTXN;
#     216                 :            : /**
#     217                 :            :  * Contains a BlockTransactions.
#     218                 :            :  * Sent in response to a "getblocktxn" message.
#     219                 :            :  * @since protocol version 70014 as described by BIP 152
#     220                 :            :  */
#     221                 :            : extern const char* BLOCKTXN;
#     222                 :            : /**
#     223                 :            :  * getcfilters requests compact filters for a range of blocks.
#     224                 :            :  * Only available with service bit NODE_COMPACT_FILTERS as described by
#     225                 :            :  * BIP 157 & 158.
#     226                 :            :  */
#     227                 :            : extern const char* GETCFILTERS;
#     228                 :            : /**
#     229                 :            :  * cfilter is a response to a getcfilters request containing a single compact
#     230                 :            :  * filter.
#     231                 :            :  */
#     232                 :            : extern const char* CFILTER;
#     233                 :            : /**
#     234                 :            :  * getcfheaders requests a compact filter header and the filter hashes for a
#     235                 :            :  * range of blocks, which can then be used to reconstruct the filter headers
#     236                 :            :  * for those blocks.
#     237                 :            :  * Only available with service bit NODE_COMPACT_FILTERS as described by
#     238                 :            :  * BIP 157 & 158.
#     239                 :            :  */
#     240                 :            : extern const char* GETCFHEADERS;
#     241                 :            : /**
#     242                 :            :  * cfheaders is a response to a getcfheaders request containing a filter header
#     243                 :            :  * and a vector of filter hashes for each subsequent block in the requested range.
#     244                 :            :  */
#     245                 :            : extern const char* CFHEADERS;
#     246                 :            : /**
#     247                 :            :  * getcfcheckpt requests evenly spaced compact filter headers, enabling
#     248                 :            :  * parallelized download and validation of the headers between them.
#     249                 :            :  * Only available with service bit NODE_COMPACT_FILTERS as described by
#     250                 :            :  * BIP 157 & 158.
#     251                 :            :  */
#     252                 :            : extern const char* GETCFCHECKPT;
#     253                 :            : /**
#     254                 :            :  * cfcheckpt is a response to a getcfcheckpt request containing a vector of
#     255                 :            :  * evenly spaced filter headers for blocks on the requested chain.
#     256                 :            :  */
#     257                 :            : extern const char* CFCHECKPT;
#     258                 :            : /**
#     259                 :            :  * Indicates that a node prefers to relay transactions via wtxid, rather than
#     260                 :            :  * txid.
#     261                 :            :  * @since protocol version 70016 as described by BIP 339.
#     262                 :            :  */
#     263                 :            : extern const char* WTXIDRELAY;
#     264                 :            : }; // namespace NetMsgType
#     265                 :            : 
#     266                 :            : /* Get a vector of all valid message types (see above) */
#     267                 :            : const std::vector<std::string>& getAllNetMessageTypes();
#     268                 :            : 
#     269                 :            : /** nServices flags */
#     270                 :            : enum ServiceFlags : uint64_t {
#     271                 :            :     // NOTE: When adding here, be sure to update serviceFlagToStr too
#     272                 :            :     // Nothing
#     273                 :            :     NODE_NONE = 0,
#     274                 :            :     // NODE_NETWORK means that the node is capable of serving the complete block chain. It is currently
#     275                 :            :     // set by all Bitcoin Core non pruned nodes, and is unset by SPV clients or other light clients.
#     276                 :            :     NODE_NETWORK = (1 << 0),
#     277                 :            :     // NODE_BLOOM means the node is capable and willing to handle bloom-filtered connections.
#     278                 :            :     // Bitcoin Core nodes used to support this by default, without advertising this bit,
#     279                 :            :     // but no longer do as of protocol version 70011 (= NO_BLOOM_VERSION)
#     280                 :            :     NODE_BLOOM = (1 << 2),
#     281                 :            :     // NODE_WITNESS indicates that a node can be asked for blocks and transactions including
#     282                 :            :     // witness data.
#     283                 :            :     NODE_WITNESS = (1 << 3),
#     284                 :            :     // NODE_COMPACT_FILTERS means the node will service basic block filter requests.
#     285                 :            :     // See BIP157 and BIP158 for details on how this is implemented.
#     286                 :            :     NODE_COMPACT_FILTERS = (1 << 6),
#     287                 :            :     // NODE_NETWORK_LIMITED means the same as NODE_NETWORK with the limitation of only
#     288                 :            :     // serving the last 288 (2 day) blocks
#     289                 :            :     // See BIP159 for details on how this is implemented.
#     290                 :            :     NODE_NETWORK_LIMITED = (1 << 10),
#     291                 :            : 
#     292                 :            :     // Bits 24-31 are reserved for temporary experiments. Just pick a bit that
#     293                 :            :     // isn't getting used, or one not being used much, and notify the
#     294                 :            :     // bitcoin-development mailing list. Remember that service bits are just
#     295                 :            :     // unauthenticated advertisements, so your code must be robust against
#     296                 :            :     // collisions and other cases where nodes may be advertising a service they
#     297                 :            :     // do not actually support. Other service bits should be allocated via the
#     298                 :            :     // BIP process.
#     299                 :            : };
#     300                 :            : 
#     301                 :            : /**
#     302                 :            :  * Convert service flags (a bitmask of NODE_*) to human readable strings.
#     303                 :            :  * It supports unknown service flags which will be returned as "UNKNOWN[...]".
#     304                 :            :  * @param[in] flags multiple NODE_* bitwise-OR-ed together
#     305                 :            :  */
#     306                 :            : std::vector<std::string> serviceFlagsToStr(uint64_t flags);
#     307                 :            : 
#     308                 :            : /**
#     309                 :            :  * Gets the set of service flags which are "desirable" for a given peer.
#     310                 :            :  *
#     311                 :            :  * These are the flags which are required for a peer to support for them
#     312                 :            :  * to be "interesting" to us, ie for us to wish to use one of our few
#     313                 :            :  * outbound connection slots for or for us to wish to prioritize keeping
#     314                 :            :  * their connection around.
#     315                 :            :  *
#     316                 :            :  * Relevant service flags may be peer- and state-specific in that the
#     317                 :            :  * version of the peer may determine which flags are required (eg in the
#     318                 :            :  * case of NODE_NETWORK_LIMITED where we seek out NODE_NETWORK peers
#     319                 :            :  * unless they set NODE_NETWORK_LIMITED and we are out of IBD, in which
#     320                 :            :  * case NODE_NETWORK_LIMITED suffices).
#     321                 :            :  *
#     322                 :            :  * Thus, generally, avoid calling with peerServices == NODE_NONE, unless
#     323                 :            :  * state-specific flags must absolutely be avoided. When called with
#     324                 :            :  * peerServices == NODE_NONE, the returned desirable service flags are
#     325                 :            :  * guaranteed to not change dependent on state - ie they are suitable for
#     326                 :            :  * use when describing peers which we know to be desirable, but for which
#     327                 :            :  * we do not have a confirmed set of service flags.
#     328                 :            :  *
#     329                 :            :  * If the NODE_NONE return value is changed, contrib/seeds/makeseeds.py
#     330                 :            :  * should be updated appropriately to filter for the same nodes.
#     331                 :            :  */
#     332                 :            : ServiceFlags GetDesirableServiceFlags(ServiceFlags services);
#     333                 :            : 
#     334                 :            : /** Set the current IBD status in order to figure out the desirable service flags */
#     335                 :            : void SetServiceFlagsIBDCache(bool status);
#     336                 :            : 
#     337                 :            : /**
#     338                 :            :  * A shortcut for (services & GetDesirableServiceFlags(services))
#     339                 :            :  * == GetDesirableServiceFlags(services), ie determines whether the given
#     340                 :            :  * set of service flags are sufficient for a peer to be "relevant".
#     341                 :            :  */
#     342                 :            : static inline bool HasAllDesirableServiceFlags(ServiceFlags services)
#     343                 :      12723 : {
#     344                 :      12723 :     return !(GetDesirableServiceFlags(services) & (~services));
#     345                 :      12723 : }
#     346                 :            : 
#     347                 :            : /**
#     348                 :            :  * Checks if a peer with the given service flags may be capable of having a
#     349                 :            :  * robust address-storage DB.
#     350                 :            :  */
#     351                 :            : static inline bool MayHaveUsefulAddressDB(ServiceFlags services)
#     352                 :         32 : {
#     353 [ +  + ][ #  # ]:         32 :     return (services & NODE_NETWORK) || (services & NODE_NETWORK_LIMITED);
#         [ +  - ][ #  # ]
#     354                 :         32 : }
#     355                 :            : 
#     356                 :            : /** A CService with information about it as peer */
#     357                 :            : class CAddress : public CService
#     358                 :            : {
#     359                 :            :     static constexpr uint32_t TIME_INIT{100000000};
#     360                 :            : 
#     361                 :            : public:
#     362                 :     152946 :     CAddress() : CService{} {};
#     363                 :      37840 :     CAddress(CService ipIn, ServiceFlags nServicesIn) : CService{ipIn}, nServices{nServicesIn} {};
#     364                 :         26 :     CAddress(CService ipIn, ServiceFlags nServicesIn, uint32_t nTimeIn) : CService{ipIn}, nTime{nTimeIn}, nServices{nServicesIn} {};
#     365                 :            : 
#     366                 :            :     SERIALIZE_METHODS(CAddress, obj)
#     367                 :      77576 :     {
#     368                 :      77576 :         SER_READ(obj, obj.nTime = TIME_INIT);
#     369                 :      77576 :         int nVersion = s.GetVersion();
#     370 [ +  + ][ +  + ]:      77576 :         if (s.GetType() & SER_DISK) {
#         [ -  + ][ +  - ]
#         [ +  - ][ +  - ]
#         [ +  - ][ +  - ]
#         [ +  - ][ +  - ]
#         [ -  + ][ +  + ]
#     371                 :      65338 :             READWRITE(nVersion);
#     372                 :      65338 :         }
#     373 [ +  - ][ +  + ]:      77576 :         if ((s.GetType() & SER_DISK) ||
#         [ +  + ][ -  + ]
#         [ -  + ][ +  + ]
#         [ +  - ][ +  - ]
#         [ +  - ][ +  - ]
#         [ +  - ][ +  - ]
#     374 [ #  # ][ +  - ]:      77576 :             (nVersion != INIT_PROTO_VERSION && !(s.GetType() & SER_GETHASH))) {
#         [ +  + ][ +  + ]
#         [ +  - ][ #  # ]
#         [ #  # ][ +  - ]
#         [ #  # ][ #  # ]
#         [ #  # ][ #  # ]
#         [ #  # ][ #  # ]
#         [ #  # ][ #  # ]
#         [ +  - ][ #  # ]
#         [ #  # ][ #  # ]
#         [ +  - ][ +  - ]
#         [ +  - ][ +  - ]
#     375                 :            :             // The only time we serialize a CAddress object without nTime is in
#     376                 :            :             // the initial VERSION messages which contain two CAddress records.
#     377                 :            :             // At that point, the serialization version is INIT_PROTO_VERSION.
#     378                 :            :             // After the version handshake, serialization version is >=
#     379                 :            :             // MIN_PEER_PROTO_VERSION and all ADDR messages are serialized with
#     380                 :            :             // nTime.
#     381                 :      73683 :             READWRITE(obj.nTime);
#     382                 :      73683 :         }
#     383 [ +  - ][ +  + ]:      77576 :         if (nVersion & ADDRV2_FORMAT) {
#         [ +  + ][ +  - ]
#         [ -  + ][ +  - ]
#         [ -  + ][ +  - ]
#         [ -  + ][ +  + ]
#         [ +  + ][ +  + ]
#     384                 :      66410 :             uint64_t services_tmp;
#     385                 :      66410 :             SER_WRITE(obj, services_tmp = obj.nServices);
#     386                 :      66410 :             READWRITE(Using<CompactSizeFormatter<false>>(services_tmp));
#     387                 :      66410 :             SER_READ(obj, obj.nServices = static_cast<ServiceFlags>(services_tmp));
#     388                 :      66410 :         } else {
#     389                 :      11166 :             READWRITE(Using<CustomUintFormatter<8>>(obj.nServices));
#     390                 :      11166 :         }
#     391                 :      77576 :         READWRITEAS(CService, obj);
#     392                 :      77576 :     }
#     393                 :            : 
#     394                 :            :     // disk and network only
#     395                 :            :     uint32_t nTime{TIME_INIT};
#     396                 :            : 
#     397                 :            :     ServiceFlags nServices{NODE_NONE};
#     398                 :            : };
#     399                 :            : 
#     400                 :            : /** getdata message type flags */
#     401                 :            : const uint32_t MSG_WITNESS_FLAG = 1 << 30;
#     402                 :            : const uint32_t MSG_TYPE_MASK = 0xffffffff >> 2;
#     403                 :            : 
#     404                 :            : /** getdata / inv message types.
#     405                 :            :  * These numbers are defined by the protocol. When adding a new value, be sure
#     406                 :            :  * to mention it in the respective BIP.
#     407                 :            :  */
#     408                 :            : enum GetDataMsg : uint32_t {
#     409                 :            :     UNDEFINED = 0,
#     410                 :            :     MSG_TX = 1,
#     411                 :            :     MSG_BLOCK = 2,
#     412                 :            :     MSG_WTX = 5,                                      //!< Defined in BIP 339
#     413                 :            :     // The following can only occur in getdata. Invs always use TX/WTX or BLOCK.
#     414                 :            :     MSG_FILTERED_BLOCK = 3,                           //!< Defined in BIP37
#     415                 :            :     MSG_CMPCT_BLOCK = 4,                              //!< Defined in BIP152
#     416                 :            :     MSG_WITNESS_BLOCK = MSG_BLOCK | MSG_WITNESS_FLAG, //!< Defined in BIP144
#     417                 :            :     MSG_WITNESS_TX = MSG_TX | MSG_WITNESS_FLAG,       //!< Defined in BIP144
#     418                 :            :     // MSG_FILTERED_WITNESS_BLOCK is defined in BIP144 as reserved for future
#     419                 :            :     // use and remains unused.
#     420                 :            :     // MSG_FILTERED_WITNESS_BLOCK = MSG_FILTERED_BLOCK | MSG_WITNESS_FLAG,
#     421                 :            : };
#     422                 :            : 
#     423                 :            : /** inv message data */
#     424                 :            : class CInv
#     425                 :            : {
#     426                 :            : public:
#     427                 :            :     CInv();
#     428                 :            :     CInv(uint32_t typeIn, const uint256& hashIn);
#     429                 :            : 
#     430                 :     214794 :     SERIALIZE_METHODS(CInv, obj) { READWRITE(obj.type, obj.hash); }
#     431                 :            : 
#     432                 :            :     friend bool operator<(const CInv& a, const CInv& b);
#     433                 :            : 
#     434                 :            :     std::string GetCommand() const;
#     435                 :            :     std::string ToString() const;
#     436                 :            : 
#     437                 :            :     // Single-message helper methods
#     438                 :      34672 :     bool IsMsgTx() const { return type == MSG_TX; }
#     439                 :      33846 :     bool IsMsgBlk() const { return type == MSG_BLOCK; }
#     440                 :      51209 :     bool IsMsgWtx() const { return type == MSG_WTX; }
#     441                 :       1032 :     bool IsMsgFilteredBlk() const { return type == MSG_FILTERED_BLOCK; }
#     442                 :        205 :     bool IsMsgCmpctBlk() const { return type == MSG_CMPCT_BLOCK; }
#     443                 :      17609 :     bool IsMsgWitnessBlk() const { return type == MSG_WITNESS_BLOCK; }
#     444                 :            : 
#     445                 :            :     // Combined-message helper methods
#     446                 :            :     bool IsGenTxMsg() const
#     447                 :     104955 :     {
#     448 [ +  + ][ +  + ]:     104955 :         return type == MSG_TX || type == MSG_WTX || type == MSG_WITNESS_TX;
#                 [ -  + ]
#     449                 :     104955 :     }
#     450                 :            :     bool IsGenBlkMsg() const
#     451                 :      19399 :     {
#     452 [ +  + ][ +  + ]:      19399 :         return type == MSG_BLOCK || type == MSG_FILTERED_BLOCK || type == MSG_CMPCT_BLOCK || type == MSG_WITNESS_BLOCK;
#         [ +  + ][ +  + ]
#     453                 :      19399 :     }
#     454                 :            : 
#     455                 :            :     uint32_t type;
#     456                 :            :     uint256 hash;
#     457                 :            : };
#     458                 :            : 
#     459                 :            : /** Convert a TX/WITNESS_TX/WTX CInv to a GenTxid. */
#     460                 :            : GenTxid ToGenTxid(const CInv& inv);
#     461                 :            : 
#     462                 :            : #endif // BITCOIN_PROTOCOL_H

Generated by: LCOV version 1.14