In both solo and pool mining, the mining software needs to get the information necessary to construct block headers. This subsection describes, in a linear way, how that information is transmitted and used. However, in actual implementations, parallel threads and queuing are used to keep ASIC hashers working at maximum capacity,
The simplest and earliest method was the now-deprecated Dash Core
getwork RPC, which constructed a headerheader - An 80-byte header belonging to a single block which is hashed repeatedly to create proof of work. for the miner directly. Since a header only contains a single 4-byte nonce good for about 4 gigahashes, many modern miners need to make dozens or hundreds of
getwork requests a second.
An improved method is the Dash Core
getblocktemplate RPC. This provides the mining software with much more information:
The information necessary to construct a coinbase transactioncoinbase transaction - The first transaction in a block. Always created by a miner, it includes a single coinbase. paying the pool or the solo miner's
A complete dump of the transactionstransactions - A transaction spending satoshis.
dashdor the mining pool suggests including in the block, allowing the mining software to inspect the transactions, optionally add additional transactions, and optionally remove non-required transactions.
Other information necessary to construct a block headerblock header - An 80-byte header belonging to a single block which is hashed repeatedly to create proof of work. for the next blockblock - One or more transactions prefaced by a block header and protected by proof of work. Blocks are the data stored on the block chain.: the block version, previous block hash, and bits (target).
The mining pool's current target thresholdtarget threshold - The target is the threshold below which a block header hash must be in order for the block to be valid, and nBits is the encoded form of the target threshold as it appears in the block header. for accepting shares. (For solo miners, this is the network target.)
Using the transactions received, the mining software adds a nonce to the coinbase extra nonce field and then converts all the transactions into a merkle treemerkle tree - A tree constructed by hashing paired data (the leaves), then pairing and hashing the results until a single hash remains, the merkle root. In Dash, the leaves are almost always transactions from a single block. to derive a merkle rootmerkle root - The root node of a merkle tree, a descendant of all the hashed pairs in the tree. Block headers must include a valid merkle root descended from all transactions in that block. it can use in a block header. Whenever the extra nonce field needs to be changed, the mining software rebuilds the necessary parts of the merkle tree and updates the time and merkle root fields in the block header.
getblocktemplate is sent over HTTP. To ensure they get the most recent work, most miners use HTTP longpoll to leave a
getblocktemplate request open at all times. This allows the mining pool to push a new
getblocktemplate to the miner as soon as any minerminer - Mining is the act of creating valid Dash blocks, which requires demonstrating proof of work, and miners are devices that mine or people who own those devices. on the peer-to-peer networknetwork - The Dash P2P network which broadcasts transactions and blocks. publishes a new block or the pool wants to send more transactions to the mining software.
A widely used alternative to
getblocktemplate is the Stratum mining protocol. Stratum focuses on giving miners the minimal information they need to construct block headers on their own:
The information necessary to construct a coinbase transaction paying the pool.
The parts of the merkle tree which need to be re-hashed to create a new merkle root when the coinbase transaction is updated with a new extra nonce. The other parts of the merkle tree, if any, are not sent, effectively limiting the amount of data which needs to be sent to (at most) about a kilobyte at current transaction volume.
All of the other non-merkle root information necessary to construct a block header for the next block.
The mining pool's current target threshold for accepting shares.
Using the coinbase transaction received, the mining software adds a nonce to the coinbase extra nonce field, hashes the coinbase transaction, and adds the hash to the received parts of the merkle tree. The tree is hashed as necessary to create a merkle root, which is added to the block header information received. Whenever the extra nonce field needs to be changed, the mining software updates and re-hashes the coinbase transaction, rebuilds the merkle root, and updates the header merkle root field.
getblocktemplate, miners using Stratum cannot inspect or add transactions to the block they're currently mining. Also unlike
getblocktemplate, the Stratum protocol uses a two-way TCP socket directly, so miners don't need to use HTTP longpoll to ensure they receive immediate updates from mining pools when a new block is broadcast to the peer-to-peer network.
Resources: The GPLv3 BFGMiner mining software and AGPLv3 Eloipool mining pool software are widely-used among Bitcoin miners and pools. The libblkmaker C library and python-blkmaker library, both MIT licensed, can interpret GetBlockTemplate for your programs.
Updated almost 2 years ago