The Cryptonight PoW hash function (cns008) expects an input (a blob on which to mine a new block).
I know that a mining blob can easily be obtained via the monerod daemon's JSON-RPC interface by calling getblocktemplate. However, for a mining pool project I am investigating whether or not I can generate the blob myself and reproduce Monero project's logic.
From the Monero project's source, I traced the above RPC call to this:
blobdata get_block_hashing_blob(const block& b)
{
blobdata blob = t_serializable_object_to_blob(static_cast<block_header>(b));
crypto::hash tree_root_hash = get_tx_tree_hash(b);
blob.append(reinterpret_cast<const char*>(&tree_root_hash), sizeof(tree_root_hash));
blob.append(tools::get_varint_data(b.tx_hashes.size()+1));
return blob;
}
Here, they:
initialize a blob with a block header, then
append the root of some tree data-structure that stores transactions (presumably a Merkle tree) to the blob, and finally they
append the number of transactions in this tree to the blob.
Unfortunately, the rest of logic is refactored into so many fragments in their codebase that I gave up trying...
So once, again my question is how can I generate the blob needed, and more specifically could somebody explain in pseudo-code terms what get_block_hashing_blob
is doing under the hood?