1

I was reviewing the PR #25720. This is part of description for the PR:

However, if an INV for a block is received before our headers chain is caught up, we'll then start to sync headers from each peer announcing the block. This can result in doing a big headers sync with many (if not all) of our peers simultaneously, which wastes bandwidth.

What is an INV message? I tried to figure it out by searching it but found nothing useful. This link had a small information about it but it is still not clear for me what it is.

2 Answers 2

4

inv is short for inventory. As the Bitcoin wiki says:

Inventory vectors are used for notifying other nodes about objects they have or data which is being requested.

Inventory vectors consist of the following data format:

enter image description here

The inv message (for transactions) was explained in the notes of this PR review club in Feb 2021 hosted by Elle Mouton.

Transaction relay is a three step process: inv -> getdata -> tx:

  1. the relaying node sends an inv message to the receiving node to announce a new transaction.
  2. if the receiving node wants to retrieve the transaction that it learned about in the inv message then it will send a getdata message to the relaying node to request the full transaction. (The receiving node won't send a getdata message to a peer for transactions that it has already seen or if it has already sent a getdata message for the transaction to a different peer.)
  3. the relaying node delivers a tx message to the receiving node. If the relaying node is no longer able to deliver the transaction, it responds with notfound instead of the tx.
1

Michael's answer was very helpful for me, but I think it is also helpful to take a look at the source code and implementation of inv messages while the question is tagged bitcoin-core-development.

This is the source code for inv messages. Link:

/** inv message data */
class CInv
{
public:
    CInv();
    CInv(uint32_t typeIn, const uint256& hashIn);

    SERIALIZE_METHODS(CInv, obj) { READWRITE(obj.type, obj.hash); }

    friend bool operator<(const CInv& a, const CInv& b);

    std::string GetCommand() const;
    std::string ToString() const;

    // Single-message helper methods
    bool IsMsgTx() const { return type == MSG_TX; }
    bool IsMsgBlk() const { return type == MSG_BLOCK; }
    bool IsMsgWtx() const { return type == MSG_WTX; }
    bool IsMsgFilteredBlk() const { return type == MSG_FILTERED_BLOCK; }
    bool IsMsgCmpctBlk() const { return type == MSG_CMPCT_BLOCK; }
    bool IsMsgWitnessBlk() const { return type == MSG_WITNESS_BLOCK; }

    // Combined-message helper methods
    bool IsGenTxMsg() const
    {
        return type == MSG_TX || type == MSG_WTX || type == MSG_WITNESS_TX;
    }
    bool IsGenBlkMsg() const
    {
        return type == MSG_BLOCK || type == MSG_FILTERED_BLOCK || type == MSG_CMPCT_BLOCK || type == MSG_WITNESS_BLOCK;
    }

    uint32_t type;
    uint256 hash;
};

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.