# How blocks are created and broadcast?

Followings are some of my understandings about how bitcoin blockchain works, and want to confirm. Appreciate your comments and thoughts.

In the blockchain, every peer receives both transactions and blocks. A peer will store the transactions they received into a local buffer, keep them ordered, and organize them into blocks. Then, if this peer successfully solves the mathematical puzzle, it will broadcast the block it has. Otherwise, if this peer receives a block, it will update the existing transactions in its buffer according to the transactions in that newly received block. Please correct me if I am wrong.

If the above process is correct, does a peer broadcast only 1 block each time when it solves the mathematical puzzle, or it can broadcast multiple blocks? If a peer can only broadcast 1 block, what if the peer has created multiple blocks since last time it has received or broadcast any block?

It would first have to broadcast the first block. The way it works, the hash of the first block (including the nonce that is needed to solve the puzzle) would included in the second block. So the miner can't create the next block without first solving the puzzle for the first block because that's the only way to get that nonce.

So you can't work on two blocks and broadcast them simultaneously. The blockchain defeats that (that nonce which you can't tell till you have actually solved the block). You can work on two blocks to find the next block faster (although I doubt it's really reasonable since you have two split your hashing power between the workloads).

Now it's possible to broadcast the first block and find the next one or two in quick succession. This happens. Finding the hash is brute force. It's a game of probability, which is basically just a fancy word for chance.

A miner can only create a new valid block by solving the 'puzzle' (Proof of work) for that particular block. To broadcast more than one at once, it would have to have found a valid hash for both blocks, otherwise one of them would be invalid. The difficulty of the puzzle is chosen so that a block will roughly be found once every 10 minutes in the entire network.

I believe the 'buffer' you are talking about is the mempool. This holds all transactions that a node has seen which haven't been mined into a block (they are the unconfirmed transactions). Once a node receives a valid block from a miner, those transactions are no longer kept in the mempool.

If a 'miner' wants to solve two blocks then this has to be done one after the other. Indeed, solving a block implies that you find the hash-vale for that block that fulfils the condition of being smaller than a certain threshold (or, equivalently that the hash starts with a pre-specified number of zeroes). This is the 'proof of work'.

But, every solved block contains not only the transactions and a nonce, but it also contains the hash of the previous block in the chain. So if a minder wants to solve two consecutive blocks it must first solve the first block, put the ('valid') hash of that block in the next block (this can not be done before solving the first block because else you do not know this) and then solve this next block (that includes the valid hash of the previous block).

So the miner can only start solving the second block after it solved the first one.

Of course a miner could decide to do so and try to find to consecutive blocks and then broadcast them (in the right order, because else they are invalid) to the network, but if in the meantime another miner solves a block, then these two blocks arrive 'too late' and will not be appended at the end of the blockchain.

The risk of arriving 'too late'' is significant because - by the above- that particular minor has to solve two blocks before any other minor solves one block.

Importantly it is generating a random solution to an insolvable "problem" that creates the non-deterministic authorization for a single node to publish a block that is acceptable to the rest of the network (ie. the lottery). "Mining" is a misnomer.

Some methods of attempting to exploit this have been discussed, but most prove impractical or inefficient. Some of these methods require winning nodes to hold back the winning block in an attempt to publish a valid fork of the blockchain unknowingly to the rest of the network. So what you describe is possible, theoretically.

https://bitcoin.org/en/glossary/51-percent-attack

https://btc-hijack.ethz.ch/

In the blockchain, every peer receives both transactions and blocks.

Yes, nodes receive transactions and blocks from peers on request.

A peer will store the transactions they received into a local buffer, keep them ordered, and organize them into blocks.

Yes. A node stores unconfirmed transactions in the memory pool.

Then, if this peer successfully solves the mathematical puzzle, it will broadcast the block it has.

Yes. A node that finds a nonce yielding a block with a hash value within the target range will send it to connected peers, and they will relay the block further.

Otherwise, if this peer receives a block, it will update the existing transactions in its buffer according to the transactions in that newly received block.

Yes. If a block with sufficient proof-of-work is received, it will be accepted and a new round of hashing will begin to extend the new block.

If the above process is correct, does a peer broadcast only 1 block each time when it solves the mathematical puzzle, or it can broadcast multiple blocks?

A node will publish any number of blocks that extend the tip of the active chain. For example, if a node gets lucky and finds a block immediately after the last one, it will publish two blocks - a parent and a child.

If a peer can only broadcast 1 block, what if the peer has created multiple blocks since last time it has received or broadcast any block?

A node can publish any block at any time. Whether or not peers accept the block is a different question around which the topic of "consensus" revolves.