TeachMeBitcoin

The Sketch Reconstruction: How `CMPCTBLOCK` is rebuilt in memory

From TeachMeBitcoin, the free encyclopedia Reading time: 3 min

10. The Sketch Reconstruction: How CMPCTBLOCK is rebuilt in memory

Once your node receives a CMPCTBLOCK message (the "Sketch" from Chapter 9), the Diplomat must perform the "Miracle" of reconstruction. This happens in the PartiallyDownloadedBlock class. The node takes the sketch, looks at its mempool, and tries to "Fill in the Blanks."

For the Sovereign Architect, Sketch Reconstruction is the "Final Assembly" of the truth. It is the moment where "Potential" becomes "Verified History."

Analyzing the Assembly: InitData

In the source code, we see the node "Matching" fingerprints to transactions.

/**
 * PEDAGOGICAL ANALYSIS: THE DIGITAL JIGSAW PUZZLE
 * This logic matches the "Fingerprints" in the sketch 
 * to the transactions in your RAM.
 */
ReadStatus PartiallyDownloadedBlock::InitData(const CBlockHeaderAndShortTxIDs& cmpctblock, ...)
{
    // 1. Loop through every "Short ID" in the sketch.
    for (size_t i = 0; i < cmpctblock.BlockTxCount(); i++) {
        // 2. Try to find the matching transaction in our MEMPOOL.
        uint256 txid = m_mempool.LookupByShortID(cmpctblock.GetShortID(i));

        if (txid) {
            // 3. We found it! Add the full transaction to our block.
            vtx[i] = m_mempool.get(txid);
        } else {
            // 4. We are missing this one. Mark it for later.
            missing_indices.push_back(i);
        }
    }

    // 5. If we have everything, the block is COMPLETE.
    if (missing_indices.empty()) return READ_STATUS_OK;
}

Explaining the Assembly: The Completion of the Puzzle

The Sovereignty of the Assembly

When your node reconstructs a block, it is performing a "Local Audit." It is proving that it already knew most of what the network was about to say. As a Sovereign Architect, you are the "Master of the Assembly," commanding a node that is so well-informed that it can "Predict" the future of the blockchain using the gossip of the present. You are the "Guardian of the Puzzle."


☕ 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!