Block Construction in Bitcoin: How it works
Tags: bitcoin, blocks
Published: 2024-02-16 14:06:25

Let's talk about how blocks are constructed on the Bitcoin network. In Bitcoin, Blocks serve as a Data structure where valid transactions(Basically confirmed exchange of bitcoin between addresses). These Blocks are "Chained" together using a set of Cryptographic principles that make each block more inseparable from it's direct Subsequent block. 

Transactions are added to blocks by miners who compete to solve a Mathematical problem. The miner who is able to solve this Problem earns a reward for solving that problem, firstly from the block reward which is the reward for mining a new block and secondly from the accumulated transaction fees in that block

## WHAT MAKES A VALID BLOCK?
When selecting transactions to form a block, Miners select blocks in a way that would result in them having maximum profit. This would mean that transactions with the Highest transaction fees are given priority and transactions with the lowest fees linger and are sometimes never confirmed. These blocks however, have to abide by the Bitcoin Network's consensus rules. Some of the factors considered when constructing a block include:

### 1. TRANSACTIONS SHOULD NOT EXCEED THE A RECOMMENDED COMBINED WEIGHT OF 4 MILLION.
Transaction Weight is a unit of measurement adopted in Bitoin to measure the amount of space occupied by a single transaction, with the single smallest unit of measurement being referred to as a _Weight Unit_. Weight units typically have a 4:1 ratio when converting to bytes i.e. 4 weight units = 1 byte. However, this is only the case when dealing with Legacy transactions. Legacy transactions as the name suggests, are the first version of transactions used in Bitcoin and are normal transactions that do not offer any extra features. When dealing with other types of transactions such as Multisig transactions. Weight units to bytes have a 1:1 ratio which means, 1 weight unit = 1 bytes. This means that multisig transactions weigh less, and as such occupy less space. 

### 2.TRANSACTIONS IN A BLOCK MUST NOT OCCUR TWICE
This is perhaps the golden and most obvious rule when including transactions in a block. The same transaction occurring twice would mean that Bitcoin has been double-spent i.e. The same value of currency has been present in a transfer twice. This would annul Bitcoin's validity as a means of exchanging value 

### 3.PARENT TRANSACTIONS MUST APPEAR BEFORE CHILD TRANSACTIONS
The terms Parent and Child transactions came to be in Bitcoin as a result of a Fee bumping Method known as _Child Pays For Parent (CPFP)_. This Method is useful in helping to confirm transactions that were broadcast with a low fee and as such are not likely to be confirmed due to their low incentive for miners. 
_Child Pays For Parent (CPFP)_ can be explained as follows with a simple analogy; I'm shopping on AliExpress and I buy cheap s from a smartwatch from a particular vendor, one that has a free shipping tag attached. This item would normally take a while to deliver because well, it's free and as such wouldn't take priority. I now buy a really expensive item say, A gaming rig that has paid delivery. I then contacted the seller of the item and instructed him to ship my cheap necklace to my second order, the one with paid delivery which would be delivered in normal time. This is a typical example of what happens in _Child Pays For Parent (CPFP)_, where a second transaction is broadcasted referencing one of the inputs of the previously broadcasted transactions with a low fee. This would incentivize the miner to confirm the transaction with a low fee that would have otherwise been left hanging in order the confirm the transaction with a high fee


## CONCLUSION
Block construction is an integral step in the working flow of the Bitcoin network and as such, Will likely not require you to write custom code as most mining software have already implemented this. However, hopefully this article helps you understand how the selection process occurred, the factors considered and the reason(s) behind it's mode of operation