Getdata Message
A getdata message is a Bitcoin P2P request for the full content of transactions or blocks advertised by a peer.
Key Takeaways
- A getdata message is a Bitcoin P2P network request that asks a peer to send the full content of transactions, blocks, or other objects previously advertised via an inv message.
- Getdata uses inventory vectors with type codes to specify what data is needed: raw transactions, full blocks, compact blocks, or witness-serialized variants introduced by SegWit.
- Bitcoin Core enforces rate limits, download timeouts, and per-peer caps to prevent nodes from stalling the network or monopolizing bandwidth during data retrieval.
What Is a Getdata Message?
A getdata message is a command in the Bitcoin peer-to-peer protocol that requests the full content of one or more data objects from a connected peer. When a node learns about new transactions or blocks through an inv (inventory) message, it responds with a getdata message listing the specific items it wants to download. The peer then sends the requested data: a tx message for transactions, a block message for full blocks, or a cmpctblock message for compact blocks.
This request-response pattern is central to how the Bitcoin network propagates information. Rather than flooding every node with every piece of data, the gossip protocol uses a two-step process: first announce what you have (inv), then let peers ask for what they need (getdata). This design conserves bandwidth by ensuring nodes only download data they do not already possess.
How It Works
The getdata message shares the same binary format as the inv message. It contains a count followed by a list of inventory vectors, where each vector is a 4-byte type field and a 32-byte hash identifying the requested object. The type field tells the responding peer what format to use when sending the data.
Inventory Type Codes
Each inventory vector carries a type code that specifies the kind of data requested:
| Type | Value | Description |
|---|---|---|
| MSG_TX | 1 | Request a transaction by its txid |
| MSG_BLOCK | 2 | Request a full block |
| MSG_FILTERED_BLOCK | 3 | Request a Merkle block (BIP 37) |
| MSG_CMPCT_BLOCK | 4 | Request a compact block (BIP 152) |
| MSG_WTX | 5 | Request a transaction by its wtxid (BIP 339) |
After the activation of SegWit, witness-serialized variants were introduced by setting bit 30 (the witness flag). For example, MSG_WITNESS_TX (0x40000001) requests a transaction including its witness data, while MSG_WITNESS_BLOCK (0x40000002) requests a block with full witness serialization. Type 0 and types above 7 are reserved, and Bitcoin Core ignores inventory vectors with unknown type codes.
Message Structure
The binary layout of a getdata message is straightforward:
// Getdata message format
// Field Size Description
// count 1-9 bytes Number of inventory vectors (CompactSize)
// inventory 36 bytes Type (4 bytes, little-endian) + Hash (32 bytes)
// each Repeated for each requested object
// Example: requesting one transaction
// count: 01
// type: 01000000 (MSG_TX = 1)
// hash: a1b2c3... (32-byte txid)A single getdata message can request multiple objects of different types. The Bitcoin protocol allows up to 50,000 inventory entries per message, though in practice most getdata messages contain far fewer items.
Transaction Download Flow
When a node receives a new transaction from a wallet or via the relay network, it announces it to peers using an inv message. The download sequence proceeds as follows:
- Node A broadcasts an inv message containing the txid of the new transaction
- Node B receives the inv and checks whether it already has the transaction in its mempool
- If Node B does not have the transaction, it sends a getdata message requesting MSG_TX (or MSG_WITNESS_TX for witness-serialized data)
- Node A responds with a tx message containing the full transaction data
- Node B validates the transaction and, if valid, adds it to its mempool and announces it to its own peers
Block Download Flow
Block downloads follow a similar pattern but with additional options depending on how the node has negotiated compact block relay with its peers.
In low-bandwidth compact block mode, the peer first announces the block via an inv or headers message. The receiving node then sends a getdata with type MSG_CMPCT_BLOCK (4). The peer responds with a cmpctblock message containing the block header and short transaction IDs. If the receiver is missing any transactions, it sends a getblocktxn request and the peer replies with the missing transactions in a blocktxn message:
- Peer sends inv or headers announcing a new block
- Node sends getdata with MSG_CMPCT_BLOCK
- Peer responds with cmpctblock (header + short transaction IDs)
- Node reconstructs the block from its mempool
- If transactions are missing: node sends getblocktxn, peer replies with blocktxn
In high-bandwidth compact block mode, the peer pushes the cmpctblock message immediately without waiting for a getdata request. This skips a round trip but may deliver blocks the node already has. For a deeper look at compact block relay, see the compact block relay research article.
Legacy block downloads (without compact blocks) use the simpler flow: inv, getdata with MSG_BLOCK, and a full block message in response.
Rate Limiting and Download Protection
Bitcoin Core implements several safeguards to prevent peers from abusing the getdata mechanism or stalling block downloads. These protections are critical for maintaining network health and preventing denial-of-service attacks.
Per-Peer Block Limits
A node will request at most 16 blocks in-flight from any single peer at a time (MAX_BLOCKS_IN_TRANSIT_PER_PEER). This prevents a slow or malicious peer from monopolizing the download pipeline. If additional blocks are needed, the node distributes requests across multiple peers.
Block Download Window
During initial block download (IBD), the node fetches blocks within a moving window of 1,024 blocks ahead of its current validated tip. This prevents memory exhaustion from requesting too many out-of-order blocks and ensures that blocks arrive in a roughly sequential order for efficient validation.
Stall Detection and Timeouts
If a peer fails to deliver a requested block within the stall timeout (starting at 2 seconds, with a maximum of 64 seconds), the node may disconnect the peer and re-request the block from someone else. The overall block download timeout is approximately one block interval (about 10 minutes) plus an additional period for each parallel downloading peer (about 5 minutes per peer).
Transaction Request Scheduling
For transactions, Bitcoin Core uses a 60-second interval (GETDATA_TX_INTERVAL) before trying to fetch a transaction from an additional peer. If the first peer does not deliver, the node sends a getdata to a different peer. This prevents a single unresponsive peer from blocking transaction propagation while also avoiding unnecessary duplicate requests across the network.
Avoiding Duplicate Requests
A well-behaved node avoids requesting the same data from multiple peers simultaneously. When a node receives multiple inv messages for the same transaction from different peers, it selects one peer to request from and tracks the in-flight request. If that peer fails to respond within the timeout, the node retries with a different peer.
This logic evolved significantly over Bitcoin Core's history. Early versions used a structure called mapAlreadyAskedFor that tracked recently requested items, but its bounded size created a vulnerability where attackers could flush entries and delay transaction relay. Modern Bitcoin Core uses more robust per-peer request tracking to ensure that every announced transaction eventually gets downloaded, even if the first peer stalls.
For blocks, duplicate avoidance is simpler: a node typically downloads each block from one peer at a time and only retries with another peer if the first stalls or disconnects. The compact block mechanism further reduces redundancy by allowing nodes to reconstruct blocks from transactions they already have in their mempool.
Use Cases
Transaction Propagation
The primary use of getdata is in the transaction relay pipeline. When a user broadcasts a transaction, it propagates across the network through repeated inv/getdata/tx cycles until every full node has a copy in its mempool. This ensures that miners can include the transaction in a block.
Block Synchronization
During initial block download, a new node uses getdata extensively to fetch the entire blockchain from peers. It downloads headers first to identify the best chain, then systematically requests blocks via getdata to build its local copy of the blockchain.
Lightweight Client Support
Bloom filter-based lightweight clients (BIP 37) use getdata with MSG_FILTERED_BLOCK to request Merkle blocks containing only the transactions matching their filter. While this approach has privacy drawbacks, it demonstrates how getdata's type system supports different data retrieval modes. Modern alternatives like compact block filters (BIP 157/158) offer better privacy properties.
Network Efficiency with Erlay
The Erlay protocol proposes replacing the flood-based inv/getdata relay for transactions with set reconciliation. Under Erlay, nodes exchange summaries of their transaction sets and only use getdata to fetch the differences, reducing bandwidth consumption by roughly 40% compared to the current relay mechanism.
Risks and Considerations
Eclipse Attacks
If an attacker controls all of a victim's peer connections (an eclipse attack), they can manipulate which inv messages the victim receives and selectively withhold data in response to getdata requests. This can delay transaction propagation or feed the victim a false view of the blockchain. For more on these attack vectors, see the eclipse attack mitigation research.
Bandwidth Exhaustion
A malicious node could send a flood of inv messages to trigger excessive getdata requests from victims, consuming their bandwidth. Bitcoin Core mitigates this by rate-limiting outbound inv messages and capping the number of in-flight requests per peer. The peer scoring system can also penalize or disconnect misbehaving peers.
Transaction Censorship
A peer that advertises a transaction via inv but never responds to the corresponding getdata can delay that transaction's propagation. While Bitcoin Core's retry mechanism eventually fetches the transaction from another peer, repeated stalling across multiple colluding nodes could meaningfully delay relay. This is one motivation behind proposals like Erlay that change the fundamental relay topology.
Privacy Implications
The getdata message reveals which transactions and blocks a node is interested in. A surveillance node can analyze getdata timing across multiple connections to infer which node first broadcast a transaction, potentially linking transactions to IP addresses. The Dandelion protocol addresses this by adding a stem phase that obscures the transaction's origin before the standard inv/getdata relay begins.
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.