4

I'm trying to understand how mining works. For learning purpose I'm using Bitcoin Core as solo mining pool. Getblocktemplate will return data that is enough to start mining witch is simple founding correct nonce. But what is next step?

I found in bitcoin core method submitblock that have one argument / block data. I didn't found any example how that data should be build. Please give me some advice.

morsecoder
  • 14,168
  • 2
  • 42
  • 94
Robert
  • 171
  • 1
  • 6

2 Answers2

3

The submitblock method takes a raw serialized block as its only parameter. You can find detailed documentation on these here and here.

For example, this is the raw genesis block in bitcoin:

0100000000000000000000000000000000000000000000000000000000000000000000003BA3EDFD7A7B12B27AC72C3E67768F617FC81BC3888A51323A9FB8AA4B1E5E4A29AB5F49FFFF001D1DAC2B7C0101000000010000000000000000000000000000000000000000000000000000000000000000FFFFFFFF4D04FFFF001D0104455468652054696D65732030332F4A616E2F32303039204368616E63656C6C6F72206F6E206272696E6B206F66207365636F6E64206261696C6F757420666F722062616E6B73FFFFFFFF0100F2052A01000000434104678AFDB0FE5548271967F1A67130B7105CD6A828E03909A67962E0EA1F61DEB649F6BC3F4CEF38C4F35504E51EC112DE5C384DF7BA0B8D578A4C702B6BF11D5FAC00000000

And when you split is apart into its pieces:

version:     01000000
prev block:  0000000000000000000000000000000000000000000000000000000000000000 
merkle root: 3BA3EDFD7A7B12B27AC72C3E67768F617FC81BC3888A51323A9FB8AA4B1E5E4A
timestamp:   29AB5F49
bits:        FFFF001D
nonce        1DAC2B7C
num txs:     01
tx1:         01000000010000000000000000000000000000000000000000000000000000000000000000FFFFFFFF4D04FFFF001D0104455468652054696D65732030332F4A616E2F32303039204368616E63656C6C6F72206F6E206272696E6B206F66207365636F6E64206261696C6F757420666F722062616E6B73FFFFFFFF0100F2052A01000000434104678AFDB0FE5548271967F1A67130B7105CD6A828E03909A67962E0EA1F61DEB649F6BC3F4CEF38C4F35504E51EC112DE5C384DF7BA0B8D578A4C702B6BF11D5FAC00000000
morsecoder
  • 14,168
  • 2
  • 42
  • 94
  • And, according to BIP 22 if the server provided a workid, it MUST be included with submissions as the second parameter. Currently, Bitcoin Core states that this value is ignored. – Willtech Feb 11 '18 at 04:56
0

The input to submitblock is a "serialized" raw block in HEX. The format for a "serialized" block is here (hard to find!)....

https://developer.bitcoin.org/reference/block_chain.html#serialized-blocks

The raw transactions included at the end of the "serialized" block format are themselves formatted like this...

https://developer.bitcoin.org/reference/transactions.html#raw-transaction-format

bigjosh
  • 317
  • 1
  • 9