Thursday, February 13, 2025
HomeBitcoinblockchain - How one can construct a Block Header from pool knowledge?

blockchain – How one can construct a Block Header from pool knowledge?


and thanks prematurely in your assist!

I am new to the discussion board, however I’ve learn fairly a little bit of documentation, and I nonetheless cannot determine how one can correctly assemble the block header from the information offered by a mining pool. I am actually interested by mining recently and wish to perceive the method intimately.

Let’s undergo a sensible instance:

1. Subscribing to the Pool

Once I ship mining.subscribe, I obtain:

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

From this, I get:

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

2. Receiving Work from the Pool

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

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

From this, I extract the next:

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

3. Setting up the Coinbase Transaction

I concatenate:

Coinbase1 + Extranonce1 + Extranonce2 + Coinbase2

Leading to:

"01000000010000000000000000000000000000000000000000000000000000000000000000ffffffff1503e4810d0474d9ad67002006be21c95fc1a9027a690000000001bae6a212000000001976a9143e5509507b08938f58bdb9d9d8e860e0d0d084dc88ac00000000"

4. Computing the Merkle Root

I compute sha256(sha256(CoinbaseTransaction)), then hash it with the Merkle department utilizing:

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

This ends in the Merkle root:

"6e7770d16e88b3effd401a58e47a22ac1eaba562543620bf673ff8d40548ae56"

5. Setting up the Block Header

I format the block header as:

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

Instance with nonce d1002500 (- are added to make it extra readable):

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

Computing the double SHA-256:

cc8c028e85d85cdfd07541cc50d7e5c7e10fa708c39a3c942d0083238e020000

6. Submitting the Work

I ship a mining.submit with:

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

Concern

Even once I submit a hash with a better issue, the pool finally returns a “low issue” error (e.g., E-10, E-9). This means I am incorrectly setting up the block header or calculating the Merkle root incorrectly.

Can anybody assist me determine what I’m doing mistaken?

Thanks lots! 😊

RELATED ARTICLES

LEAVE A REPLY

Please enter your comment!
Please enter your name here

Most Popular

Recent Comments