How to build a Block Header from pool data?

and thanks in advance for your help!

I'm new to the forum, but I've read quite a bit of documentation, and I still can't figure out how to properly construct the block header from the data provided by a mining pool. I'm really interested in mining lately and would like to understand the process in detail.

Let's go through a practical example:

1. Subscribing to the Pool

When I send mining.subscribe, I receive:

[[["mining.set_difficulty","0HN9B1NBLO9DQ"],["mining.notify","0HN9B1NBLO9DQ"]],"2006be21",4]

From this, I get:

  • Extranonce1 = "2006be21"
  • Extranonce2 must be 4 bytes (e.g., "c95fc1a9").

2. Receiving Work from the Pool

After mining.authorize, I receive a mining.notify message:

["00059c50","cd6f21657c8eb8301949442a3fff2e78a9cb857e01b2a0120000000000000000",
"01000000010000000000000000000000000000000000000000000000000000000000000000ffffffff1503e4810d0474d9ad6700",
"027a690000000001bae6a212000000001976a9143e5509507b08938f58bdb9d9d8e860e0d0d084dc88ac00000000",
["6cffdce483ddf6d154b90eaa262e63e0f4fddd17bea7730af0cb070a2482e800",
"11f5139edbd86f6497e8341b195d435694c0b482babf9e6ff9c68f3d2cfd9cc8",
"879bf96a7f01f34dd6f9e14e91cd4153da922e136ded76c4d76376dc4aa2bffb",
"579a25a2a4e4844aca8d357d0ef3ab4269cb06aeba874e3a7945ec04b6a207eb",
"4f4cd551e8ab18716ac53a1460c77f795c1999dd983a98f030500ca646790f86",
"2806126621f7fe529e08b0cdf7f502ccae77a27d2f9c9f1c3f39d5849f885c70",
"d1a498f3adc3db8f7b3bca34427d7d5e22caee7ef8ef63e681f92e64bd9bc0c4"],
"20000000","1802b50e","67add974",false]

From this, I extract the following:

  • jobID: "00059c50"
  • previous hash: "cd6f21657c8eb8301949442a3fff2e78a9cb857e01b2a0120000000000000000"
  • Coinbase1: "01000000010000000000000000000000000000000000000000000000000000000000000000ffffffff1503e4810d0474d9ad6700"
  • Coinbase2: "027a690000000001bae6a212000000001976a9143e5509507b08938f58bdb9d9d8e860e0d0d084dc88ac00000000"
  • Merkle branch: [...]
  • Version: "20000000"
  • nBits: "1802b50e"
  • nTime: "67add974"

3. Constructing the Coinbase Transaction

I concatenate:

Coinbase1 + Extranonce1 + Extranonce2 + Coinbase2

Resulting in:

"01000000010000000000000000000000000000000000000000000000000000000000000000ffffffff1503e4810d0474d9ad67002006be21c95fc1a9027a690000000001bae6a212000000001976a9143e5509507b08938f58bdb9d9d8e860e0d0d084dc88ac00000000"

4. Computing the Merkle Root

I compute sha256(sha256(CoinbaseTransaction)), then hash it with the Merkle branch using:

DoubleSha256(merkleBranch[i] + merkleBranch[i + 1])

This results in the Merkle root:

"6e7770d16e88b3effd401a58e47a22ac1eaba562543620bf673ff8d40548ae56"

5. Constructing the Block Header

I format the block header as:

"00000020" + previousHash + merkleRoot + nTime + nBits + nonce

Example with nonce d1002500 (- are added to make it more readable):

"00000020-cd6f21657c8eb8301949442a3fff2e78a9cb857e01b2a0120000000000000000-56ae4805d4f83f67bf20365462a5ab1eac227ae4581a40fdefb3886ed170776e-74d9ad67-0eb50218-d1002500"

Computing the double SHA-256:

cc8c028e85d85cdfd07541cc50d7e5c7e10fa708c39a3c942d0083238e020000

6. Submitting the Work

I send a mining.submit with:

jobID: "00059c50"
ExtraNonce2: "c95fc1a9"
nTime: "67add974"
nOnce: "d1002500"

Issue

Even when I submit a hash with a higher difficulty, the pool eventually returns a "low difficulty" error (e.g., E-10, E-9). This suggests I'm incorrectly constructing the block header or calculating the Merkle root incorrectly.

Can anyone help me figure out what I’m doing wrong?

Thanks a lot! 😊



from Recent Questions - Bitcoin Stack Exchange https://ift.tt/7OfhXQo
via IFTTT

Popular posts from this blog

Bitcoin Mining Could Be Strengthening The Ruble, Russian Central Bank Says

Crypto Exec Warns Tokenization Is Moving Faster Than Expected

Bitwise Clients Pour $69M Into Solana as Bulls Fight to Reclaim $200 Resistance Zone