TeachMeBitcoin

The Missing Transaction Hunt: The `GETBLOCKTXN` and `BLOCKTXN` handshake

From TeachMeBitcoin, the free encyclopedia Reading time: 3 min

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

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."


☕ Help support TeachMeBitcoin

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:

Ethereum: 0x578417C51783663D8A6A811B3544E1f779D39A85
Bitcoin: bc1q77k9e95rn669kpzyjr8ke9w95zhk7pa5s63qzz
Solana: 4ycT2ayqeMucixj3wS8Ay8Tq9NRDYRPKYbj3UGESyQ4J
Address copied to clipboard!