Sunday, December 22, 2024

stratum – How ought to I order the block header knowledge in messages with the pool?

First i’m creating this put up to learn all of you who’re actually into understanding and constructing your personal miner from the scratch. There’s so many supplies however not often have something in widespread.

I need assistance validating if the order of issues is right in my Block header for mining. I’m constructing my very own miner as a problem and nonetheless wrestle with the correct codecs. There are a lot of examples on the net however actually even the pool would not state through which order the info is being despatched out for the shoppers. So only for an absolute readability i assumed we may have a definitive reply on the query right here.

A few of the builders reverse the pool hash and even flip the bytes:

hex2byte(ph, bp);
 revFlip(bp);

Others simply merely copy paste Bitcoin wiki answer, with out noticing that the prev hash for instance is reversed to what the mining pool gives.

 $prevBlockHash = SwapOrder('00000000000008a3a41b85b8b29ad444def299fee21793cd8b9e567eab02cd81');
  $rootHash = SwapOrder('2b12fcf1b09288fcaff797d71e950e71ae42b91e8bdb2304758dfcffc2b620e3');
  $

Some inform, that we must always reverse the nbits,ntime, model – however that is already reversed from the pool proper?

So the query is :

When speaking with the pool, how ought to i organize my knowledge for the block header, to be prepared for comparability with the goal after hashing?

That is so essential, that any mistake made right here will lead miner(s) to compute hashes for issues which are irrelevant thus by no means discovering a sound ‘nonce’ – its so wasteful and will actually be clarified.

Since i’m speaking about pool right here, i’ll base this on using solo.ckpool.org instance.

So let’s begin from the start by connecting to the pool, and retrieving knowledge that must be used to compose a block header.

Right here we go, the info being despatched to me from solo.ckpool.org is:

{"outcome":[[["mining.notify","71ae8ae6"]],"5324fa6e",8],"id":1,"error":null}

{"params":["64851638000ea04d","6a2be50e9bfb43f4973d1b2a84fc5fa27a11730b000209b00000000000000000","01000000010000000000000000000000000000000000000000000000000000000000000000ffffffff3503a9d20c0004b8852666047a773e130c","0a636b706f6f6c112f736f6c6f2e636b706f6f6c2e6f72672fffffffff03c432eb1b000000001976a914c987a18977a2139835193b3df2eea097f834966888ac76dc91000000000016001451ed61d2f6aa260cc72cdf743e4e436a82c010270000000000000000266a24aa21a9ed5c2c1c347c20b2c0818daeda78f4d407f55b405e5652265bbc0b5ab948c615cb00000000",["3d14cb3882afe1cdb6121b77a1c6fe1ace1cfb4f56796875c0e5dc7475d794e5","90107e0ab73bfb0cb540cf129823a3fdd4d2df2d1cfb8a50f2ec4f10da6e4e3f","ce46e565beea4882ea532dfaecb83cc879a60c36a298ab40ec2a3c4e5ae42d65","afbead8f037a81818082f0d276e4a438a3456f0dfcce87255c349264a77ffdf1","67dcbd833c2676450e1f388da5781f902c6c4ca423a88fac6cf2a16827ebd567","7ffff8567be6efa8acd37a27b3c60bd194ca990bca74c9e71dd673d3e0c3f621","53514468979f077ace9ba497d3fa44e5091150188d29ed3dcb80a89f36662839","ff0c843842dde895d2ee8e698d35240517de66bdd839ec3f88d7c3a2b2337724","81a08847bb764ec45481a3e491640d5557fc78276091b69534af71267d1610a5","fb60c793ec790c71bb5b54e93cd8db5f134d9730754ec7c88f71862e07151d7f","bcd9c2f483e5a422e735f23610a40d07790f0ef47bea1218a4fbc1489865202c","b9a275e502fab0f76cb10e9d791a16ef18cf8addbf2ebdc92ede9a07a62dee84"],"20000000","17034219","662685b8",true],"id":null,"methodology":"mining.notify"}

The pool is sending prev hash as 6a2be50e9bfb43f4973d1b2a84fc5fa27a11730b000209b00000000000000000 so some elements are already reversed (however it would not state wherever, what’s reversed and could possibly be used as is).

So based mostly on the main points above, let’s head to my mind-set about learn how to correctly assemble the header.

CONSTRUCTING (CONCATENATING)

  1. Don’t reverse Model from the pool 20000000
  2. Don’t reverse the prev hash (seems reversed when in comparison with https://en.bitcoin.it/wiki/Block_hashing_algorithm) 6a2be50e9bfb43f4973d1b2a84fc5fa27a11730b000209b00000000000000000
  3. Dhash the merkle and reverse it
  4. Don’t reverse ntime from the pool 662685b8
  5. Don’t reverse nbits from the pool 17034219
  6. Generate a random nonce and don’t reverse it (as a result of we’re engaged on Little Endian machine)

Append all as regular:
model+prev_block_hash+merkle_hash+ntime+nbits+nonce

For readability: model+prev_block_hash+reverse(merkle_hash)+ntime+nbits+nonce

And the output i generate is:

Coinbase1           : 01000000010000000000000000000000000000000000000000000000000000000000000000ffffffff3503a9d20c0004b8852666047a773e130c
Coinbase2           : 0a636b706f6f6c112f736f6c6f2e636b706f6f6c2e6f72672fffffffff03c432eb1b000000001976a914c987a18977a2139835193b3df2eea097f834966888ac76dc91000000000016001451ed61d2f6aa260cc72cdf743e4e436a82c010270000000000000000266a24aa21a9ed5c2c1c347c20b2c0818daeda78f4d407f55b405e5652265bbc0b5ab948c615cb00000000
Extranonce1         : 5324fa6e
Extranonce2         : 000000008f6bc892
Extranonce2 measurement    : 8
Merkle 0            :3d14cb3882afe1cdb6121b77a1c6fe1ace1cfb4f56796875c0e5dc7475d794e5
Merkle 1            :90107e0ab73bfb0cb540cf129823a3fdd4d2df2d1cfb8a50f2ec4f10da6e4e3f
Merkle 2            :ce46e565beea4882ea532dfaecb83cc879a60c36a298ab40ec2a3c4e5ae42d65
Merkle 3            :afbead8f037a81818082f0d276e4a438a3456f0dfcce87255c349264a77ffdf1
Merkle 4            :67dcbd833c2676450e1f388da5781f902c6c4ca423a88fac6cf2a16827ebd567
Merkle 5            :7ffff8567be6efa8acd37a27b3c60bd194ca990bca74c9e71dd673d3e0c3f621
Merkle 6            :53514468979f077ace9ba497d3fa44e5091150188d29ed3dcb80a89f36662839
Merkle 7            :ff0c843842dde895d2ee8e698d35240517de66bdd839ec3f88d7c3a2b2337724
Merkle 8            :81a08847bb764ec45481a3e491640d5557fc78276091b69534af71267d1610a5
Merkle 9            :fb60c793ec790c71bb5b54e93cd8db5f134d9730754ec7c88f71862e07151d7f
Merkle 10            :bcd9c2f483e5a422e735f23610a40d07790f0ef47bea1218a4fbc1489865202c
Merkle 11            :b9a275e502fab0f76cb10e9d791a16ef18cf8addbf2ebdc92ede9a07a62dee84
Model             : 536870912 / 20000000
Merklehash          : bc65e13b5f7c69e9ce91adbb063d46b9be2445805e6a2498e13863708d57392c
ntime               : 662685b8 / 662685b8
nbits               : 17034219 / 17034219
Nonce               : 00
Block prevhash      : 6a2be50e9bfb43f4973d1b2a84fc5fa27a11730b000209b00000000000000000
Block Header        : 000000206a2be50e9bfb43f4973d1b2a84fc5fa27a11730b000209b000000000000000002c39578d706338e198246a5e804524beb9463d06bbad91cee9697c5f3be165bcb88526661942031700000000
Block hash(reversed): 03752b55669564dccb91e47cb1d5fe421fac014e1e9fb2d563d1bd8fe44c86f2
Goal(reversed)    : 0000000000000000000000000000000000000000194203000000000000000000

Then we have to double hash merkle and block header with SHA256, and so far as i do know SHA256 is at all times represented BE, so now we have to reverse the hash after finishing the double hash.

HASHING

  1. Calculate merkle, double hash it and reverse (as a result of we’re doing SHA256)

  2. After DHashing the header, reverse it (as a result of we’re doing SHA256)

COMPARE
However that could be a totally different story.

Thanks upfront, any assist right here is appreciated since i’ve seen many implementations of various miners, and severely majority of them do issues otherwise – even when working with the identical pool.

Related Articles

LEAVE A REPLY

Please enter your comment!
Please enter your name here

Latest Articles