Inventory Vector
An inventory vector is a 36-byte data structure in Bitcoin's P2P protocol that identifies a specific network object by type and hash, used in inv, getdata, and notfound messages.
Key Takeaways
- An inventory vector is a 36-byte structure consisting of a 4-byte type field and a 32-byte hash that uniquely identifies an object (such as a transaction or block) on the Bitcoin P2P network.
- Bitcoin nodes exchange inventory vectors in inv, getdata, and notfound messages to coordinate which transactions and blocks need to be transferred, avoiding redundant data transmission.
- Type constants like MSG_TX, MSG_BLOCK, and MSG_CMPCT_BLOCK tell the receiving peer what kind of object is being referenced and how it should be serialized, with witness-flag variants added by SegWit (BIP 144).
What Is an Inventory Vector?
An inventory vector (sometimes abbreviated inv_vect) is the fundamental data structure that Bitcoin nodes use to identify objects on the network. When one node wants to tell another about a transaction it has seen or a block it has validated, it does not send the full object immediately. Instead, it sends a compact reference: the inventory vector. This keeps the gossip protocol efficient by letting peers decide whether they actually need the data before requesting it.
Each inventory vector is exactly 36 bytes: a 4-byte unsigned integer specifying the object type, followed by a 32-byte hash that uniquely identifies the object. The type field tells the receiving node what kind of object the hash refers to (a transaction, a block, a compact block, and so on), while the hash lets the node check whether it already has that object in its local storage.
Inventory vectors appear in three P2P messages: inv (announcing objects), getdata (requesting objects), and notfound (indicating unavailable objects). Together, these messages form the core of Bitcoin's data exchange protocol.
How It Works
When a node receives or validates a new object, it broadcasts an inv message to its connected peers. The inv message contains one or more inventory vectors listing the objects the sender has available. Each receiving peer checks the inventory vectors against its own data:
- A node validates a new transaction or block
- The node constructs inventory vectors for each new object (type + hash)
- The node sends an inv message containing these vectors to its peers
- Each peer checks whether it already has the referenced objects
- For unknown objects, the peer sends a getdata message with the same inventory vectors
- The original node responds with the full object (a tx or block message)
- If the object is unavailable, the node replies with a notfound message
This request-response pattern prevents unnecessary data transfer. A node with 100 peers does not send each of them a full 1 MB block: it sends a 36-byte inventory vector, and only the peers that need the block request it. The inv message itself is limited to 50,000 inventory vectors per message.
Byte Layout
All multi-byte integers in Bitcoin's P2P protocol are serialized in little-endian byte order. The inventory vector layout is:
Inventory Vector (36 bytes)
├── type (4 bytes, uint32_t, little-endian)
└── hash (32 bytes, char[32])
Example: MSG_TX inventory vector
01 00 00 00 # type = 1 (MSG_TX)
a1 b2 c3 d4 ... (32 bytes) # transaction hash (txid)Type Constants
The type field determines what kind of object the hash identifies and how the responding node should serialize the data. Bitcoin Core defines the following type constants:
| Value | Name | Description |
|---|---|---|
| 0 | ERROR | Data can be ignored; typically used as a placeholder |
| 1 | MSG_TX | Hash is a txid; response is a tx message |
| 2 | MSG_BLOCK | Hash is a block hash; response is a block message |
| 3 | MSG_FILTERED_BLOCK | Hash is a block hash; response is a merkleblock message (used with Bloom filters) |
| 4 | MSG_CMPCT_BLOCK | Hash is a block hash; response is a cmpctblock message (see compact blocks) |
| 5 | MSG_WTX | Hash is a wtxid (BIP 339); response includes witness data |
Witness-Flag Variants
BIP 144 introduced witness-flag variants for use in getdata requests. These variants signal that the requesting node wants the object serialized with witness data. The witness flag is bit 30 of the type field (0x40000000):
MSG_WITNESS_FLAG = 0x40000000 (1 << 30)
MSG_WITNESS_TX = 0x40000001 (MSG_TX | MSG_WITNESS_FLAG)
MSG_WITNESS_BLOCK = 0x40000002 (MSG_BLOCK | MSG_WITNESS_FLAG)These witness types are used exclusively in getdata requests, not in inv announcements. When a node requests MSG_WITNESS_TX, the responding peer returns the transaction serialized with its full witness structure. This distinction matters because a transaction's witness data can be significantly larger than its base data.
WTXID Relay (BIP 339)
BIP 339 introduced MSG_WTX (type 5) to solve a transaction malleability problem in relay. Traditional txids exclude witness data, so a third party could malleate a transaction's witness and announce an invalid version under the same txid, potentially blocking relay of the valid transaction.
With MSG_WTX, the inventory vector's hash is the wtxid (a hash covering both the transaction and its witness data). Two peers negotiate wtxid relay by exchanging a wtxidrelay message during the version handshake. After negotiation, the node must use MSG_WTX when announcing transactions to that peer. Bitcoin Core has supported wtxid relay since version 0.21.0.
Use Cases
Transaction Relay
When a node's mempool accepts a new transaction, it announces the transaction to its peers using an inv message with a MSG_TX (or MSG_WTX) inventory vector. Peers that do not yet have the transaction respond with getdata, and the announcing node sends the full transaction. This selective relay ensures each transaction traverses each network link at most once, keeping bandwidth usage proportional to the number of unique transactions rather than the number of peers. For a deeper look at this process, see the transaction lifecycle explainer.
Block Relay
Block relay relies heavily on inventory vectors. When a miner finds a new block, it propagates through the network via inv/getdata exchanges. The MSG_BLOCK type requests the full block, while MSG_CMPCT_BLOCK triggers the compact block relay protocol (BIP 152), which dramatically reduces bandwidth by sending only short transaction IDs for transactions the peer likely already has. For details on how this impacts propagation times, see the compact block relay deep dive.
Light Client Filtering
MSG_FILTERED_BLOCK allows Bloom filter-based light clients (BIP 37) to request only the transactions relevant to their wallet. The peer responds with a merkleblock message containing a Merkle proof for the matched transactions. Modern light clients typically use compact block filters (BIP 157/158) instead, which offer better privacy properties.
Initial Block Download
During initial block download, a syncing node uses getdata messages with MSG_BLOCK inventory vectors to request blocks from peers. The node identifies which blocks it needs by processing block headers first (via the headers-first sync strategy), then constructs inventory vectors for each missing block and batches them into getdata requests.
Risks and Considerations
Fingerprinting and Privacy
The order and timing of inventory vectors in inv messages can leak information. A network observer monitoring multiple nodes can correlate which node first announced a transaction, potentially linking transactions to their origin IP address. Protocols like Dandelion and Erlay aim to mitigate this by changing how nodes propagate inventory announcements.
Inv Flooding
A malicious peer could send inv messages with large numbers of inventory vectors for nonexistent objects, causing the receiving node to waste bandwidth on futile getdata requests. Bitcoin Core mitigates this through rate limiting, peer scoring, and the 50,000 inventory vector cap per inv message. Nodes that consistently announce invalid objects get deprioritized or disconnected.
Eclipse Attacks
If an attacker controls all of a victim's peer connections (an eclipse attack), they can selectively withhold inventory vectors for new blocks or transactions. The victim node would not know about objects it has never been told about. Running multiple diverse peer connections, using anchor connections to known-good nodes, and monitoring for suspicious peer behavior help defend against this. For more on network-level defenses, see the P2P network topology and resilience analysis.
Unknown Type Handling
Type values of 0 and values greater than the highest defined constant are reserved for future use. Bitcoin Core ignores inventory vectors with unknown types. This forward-compatible design allows new object types to be introduced without breaking older nodes, though those older nodes will simply skip the unfamiliar inventory entries.
This glossary entry is for informational purposes only and does not constitute financial or investment advice. Always do your own research before using any protocol or technology.