Post
Topic
Board Development & Technical Discussion
Merits 1 from 1 user
Re: Generate coinbase from to send to miner (ckpool source code question)
by
nQuant
on 07/02/2018, 04:51:56 UTC
⭐ Merited by achow101 (1)
You are awesome. Thanks for taking time and explain each parts.
I highly suggest that you read Bitcoin.org's documentation on the raw transaction format as that is basically what you are being given by the stratum protocol. All it is giving you is the entire coinbase transaction with some parts missing that the miner needs to fill out. Those are the nonce and extra nonce which are part of the coinbase.

Coinbase1
----------------
Header               |   01000000010000000000000000000000000000000000000000000000000000000000000000fffff fff
This is not a header. This consists of 4 different fields. The first 4 bytes are the transaction version number, the next byte is the number of inputs. The next 32 bytes are the transaction id of the transaction the input spends from. The 4 bytes after that are the index of the output that is being spent. In a coinbase transaction, the previous txid must be all 0's, and the output index must be 0xffffffff.

Length               |   35 (<= this is 53 decimal length counts till signature part Huh )
Yes, that is the length. It is the length of the scriptSig, which in a coinbase transaction, is known as the coinbase.

Height               |   0371bb07
The first byte is a length specifier. The next 3 bytes are the block height. This is pursuant to BIP 34

                  |   ffffffff (<= is this separator between tx in and tx out ?)
No, this is not a separator. It is the sequence number. Every input has a 4 byte sequence number.

end                       |   00000000
That's the transaction lock time, not "end".

Thanks my friend, actually I'm aware of first part of coinbase1, I'm just calling it header because cgminer has it as static variable name sigheader something. I'm now able to construct entire coinbase but it fails to decode. I'll look try read the document in depth and see if I can figure out what I'm doing wrong. On one look everything looks simple to put together But man so many concepts to go wrong Sad  crazy architecture Smiley

For now I'm putting it on side to study, but now caught into something I though I have solved about stratum header.. This should be separate question but just wanted to put short question in case you have pretty simple explanation.

cgminer log shows stratum header constructed as below
20000000da780ff935f3917ed99a7b616cb98ebb3104b3fa000b7acd0000000000000000854e4bd db4eeb7c1841b651ceb26f4d12116bfcc2c41ed18220fd701571914ba5a6fdbfa176c2146000000 00

Look at version, time, difficulty part. Shouldn't it be flipped as big endian ?

And at the calculation of midsate its flipping all 4 bytes.. meaning 00000020f90f78da7e91f335617b9ad9bb8eb96cfab30431cd7a0b000000000000000000dd4b4e8 5c1b7eeb41c651b84d1f426ebccbf162118ed412c01d70f22

When submitblock is called, what should be sent as block header ?