TeachMeBitcoin

The Mining Pool Protocol: Stratum and Block Templates

From TeachMeBitcoin, the free encyclopedia Reading time: 2 min

The Mining Pool Protocol: Stratum and Block Templates

Even if you aren't a miner, your node knows how to "Build" a block. This is done through a protocol called Stratum. The node takes all the transactions in its Mempool, sorts them by fee, and creates a "Block Template." It then hands this template to a miner, who tries to find the "Winning Number" (the Nonce). Your node is the "Architect," and the miner is the "Builder." It is the "Blueprint of the Bit." It is the "Design of the Done." It is the "Plan of the Proof."

The getblocktemplate Logic

In src/rpc/mining.cpp, the node prepares the work for the miners. it ensures that every transaction in the block is valid and that the "Coinbase" transaction (the miner's reward) is correctly formatted. It is the "Preparation of the Prize."

/**
 * Creates a template for a new block to be mined.
 * This is the "Blueprint" that miners use to build the next piece of history.
 */
UniValue getblocktemplate(const JSONRPCRequest& request)
{
 // Selecting the "Best" transactions from the Mempool.
 // Adding the "Coinbase" reward for the miner.
 return CreateNewBlock(node.chainman->ActiveChainstate());
}

Explaining the Code: The Architect's Plan

  1. CreateNewBlock: This is the "Brain" of the mining process. It decides which transactions deserve to be in the next block. It prioritizes the ones that pay the most, ensuring that the network remains economically efficient. It is the "Market of the Mine." It is the "Justice of the Job."

  2. ActiveChainstate: The node makes sure the new block is built on top of the current state of the world. It doesn't want the miner to waste energy building on an old, dead branch of history. It is the "Guidance of the Now." It is the "Path of the True."


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