The Missing Transaction Hunt: The `GETBLOCKTXN` and `BLOCKTXN` handshake
11. The Missing Transaction Hunt: The GETBLOCKTXN and BLOCKTXN handshake
In the previous chapter, we saw how the node uses a "Sketch" (the Compact Block) to reconstruct a block from its own mempool. But what happens when the "Jigsaw Puzzle" is missing pieces? What if a miner included a transaction that your node never saw in the gossip? To solve this, the Diplomat performs the Missing Transaction Hunt. This is a secondary handshake that ensures no block is left unfinished.
For the Sovereign Architect, the Hunt is the "Resilience of the Assembly." It is the proof that the node doesn't give up if the first attempt at reconstruction fails. It simply asks for the specific pieces it needs.
Analyzing the Hunt: GETBLOCKTXN
In the source code (src/net_processing.cpp), we see the logic that triggers when a reconstruction is incomplete.
/**
* PEDAGOGICAL ANALYSIS: THE SPECIFIC REQUEST
* This logic identifies exactly which transactions are missing
* from a compact block and asks the peer for them.
*/
if (status == READ_STATUS_INCOMPLETE) {
// 1. Create a "Request" message.
BlockTransactionsRequest req;
req.blockhash = hash;
// 2. Add the "Indices" (the numbers) of the missing transactions.
for (size_t i = 0; i < missing_indices.size(); i++) {
req.indexes.push_back(missing_indices[i]);
}
// 3. Send the "GETBLOCKTXN" message to the peer.
MakeAndPushMessage(pfrom, NetMsgType::GETBLOCKTXN, req);
}
Explaining the Hunt: The Targeted Question
-
READ_STATUS_INCOMPLETE: The node has tried to build the block using its mempool but failed. It now enters "Recovery Mode." It doesn't ask for the whole 1MB block again; that would be a waste of bandwidth. It only asks for the "Gaps." It is the Precision of the Machine. -
BlockTransactionsRequest: This is the "Shopping List." It contains the block's hash and a list of numbers (indices). If transactions 5, 10, and 50 were missing, the list will simply be[5, 10, 50]. It is the Efficiency of the Sovereign. -
GETBLOCKTXN: This is the "Request" message. It tells the peer: "I have your sketch, but I'm missing these three transactions. Please send them now." It is the Communication of the Protocol. -
BLOCKTXN(The Response): The peer receives your request, looks at the block in their memory, and sends back aBLOCKTXNmessage containing the full bytes of those specific transactions. Your node then "Inserts" them into the empty slots and completes the assembly. It is the Conclusion of the Hunt.
The Sovereignty of the Hunt
The Missing Transaction Hunt is the "Safety Net" of the Compact Block system. It ensures that your node can always reach the truth, even if its mempool is slightly out of sync with the miner's. As a Sovereign Architect, you know that "Perfection is not required for Progress." By having a protocol that can recover from missing data, you are ensuring your node remains "Synced" even in a chaotic and imperfect network. You are the "Master of the Hunt."
TeachMeBitcoin is an ad-free, open-source educational repository curated by a passionate team of Bitcoin researchers and educators for public benefit. If you found our articles helpful, please consider supporting our hosting and ongoing content updates with a clean donation: