The question is not about the block being included on the block chain, but who actually creates a block? Like what is the process here. Can someone walk me through this? I do know that blocks are summarized in form of a block header and contain a list of transactions.

  1. Who selects the transactions to go into this block? If not a person, where in the Core is this included
  2. How do they then get bundled as a block?
  3. How do they get passed on then to the miners?

1 Answer 1

  1. Who selects the transactions to go into this block? If not a person, where in the Core is this included

Miner select them. More specifically, node software that miners run select the transactions. Most miners use Bitcoin Core or some variation of it.

  1. How do they then get bundled as a block?
  2. How do they get passed on then to the miners?

When the node software selects transactions, it creates a hexadecimal string for each transaction that represents each of the fields. That hex string follows the same format used for serializing transactions for sending over the network, just as the hex representation of the bytes instead of the bytes themselves. This is then packaged together with some other information into a JSON object in the getblocktemplate format and provided over a JSON-RPC interface to mining software.

The mining software then takes the information provided by getblocktemplate, adds their own additional information (e.g. the nonce) and constructs a serialized block. Serialized blocks are byte arrays containing all of the information in a block and are the same format as sent over the network. If the block is valid, the miner sends the serialized block back to the node which then sends it to the rest of the Bitcoin network.

Here is a step by step example of how a miner Alice mines a block.

  1. Alice runs Bitcoin Core which constantly receives, validates, and relays transactions and other blocks.
  2. Alice runs a mining software (such as cgminer) and connects here hashing machines (e.g. an Antminer S9) to that.
  3. Alice also provides to her instance of cgminer the credentials to the JSON-RPC interface for her Bitcoin Core node.
  4. cgminer will use getblocktemplate and send a request for a block template to Bitcoin Core.
  5. Bitcoin Core receives the getblocktemplate request and chooses transactions from its pool of valid and unconfirmed transactions that it has stored in memory. The transactions are typically selected by their fee rates, highest fee rate being selected first.
  6. Bitcoin Core constructs a block template using the selected transactions and adds any additional information required.
  7. Bitcoin Core responds back to cgminer over the JSON-RPC interface with the completed block template.
  8. cgminer receives the block template and uses it to construct a serialized block header in a form that is acceptable to the hashing hardware
  9. cgminer sends whatever data it has serialized to the hashing hardware and the hardware computes SHA256 hashes on it while incrementing some data in the data.
  10. The hashing hardware (or cgminer) checks whether a hash has a valid proof of work. If it does, skip to step 14.
  11. Once the hardware exhausts all possible combinations it can try using the data given and responds back to cgminer
  12. cgminer, when the hashing hardware can no longer continue with its data, sends another getblocktemplate request to Bitcoin Core for a new set of transactions and block data to try.
  13. Repeat steps 4 through 12 until the hashing hardware finds a hash with a valid proof of work in setp 10.
  14. Once a hash with a valid proof of work has been found, cgminer takes the data that was hashed for that valid proof of work and combines it with the serialized transactions.
  15. The serialized block is converted into a hexadecimal string and sent to Bitcoin Core using the submitblock RPC command.
  16. Bitcoin Core takes the hexadecimal string representing the block, converts it into a byte array, checks that the block is valid, and if it is, sends the block to the nodes that it is connected to.
  • +1 for extensive. you seem to know more than you should. But one more thing. How do these bundled blocks get propagated throughout the network to other miners ? how is it made sure that some of the transactions aren't part of other blocks ?
    – Frank L
    Jun 8, 2018 at 15:45
  • @FrankL The block gets propagated through the network in a peer-to-peer fashion. Eventually they will get to the miners. When a miner receives the block it will place it to the top of his chain. After that he would exclude the transactions already included to the new block when he tries to mine the next block because otherwise it would constitute a double spend and the block would be invalid (other nodes would reject it)
    – Mike D
    Jun 8, 2018 at 21:07

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.