Blockchain The file of bitcoin transactions.
It is called the “blockchain” because new transactions are added to the file in blocks, and these blocks are built on top of one another to create a chain of blocks. Hence, blockchain.
But ultimately, the blockchain is permanent storage for bitcoin transactions.
How do you get a copy of the blockchain?
When you run bitcoin, your node will download blocks from other nodes on the network until you have an up-to-date copy of the blockchain.
When nodes connect to each other, they tell each other the height of their chain (how many blocks they have) during the initial handshake. If another node has more blocks than you, your node will request these blocks from the other nodes until you have a full copy of the blockchain.
As a result, nodes are constantly communicating with each other to replicate the blockchain across every computer on the network.
Tip: There is no single or definitive version of “the blockchain”. Every node keeps their own local copy of the blockchain, and the these can vary from computer to computer at any given time.
How are new blocks added to the blockchain?
New blocks of transactions must be mined before they can be added on to the blockchain.
In short, the process of mining involves collecting transactions from the memory pool in to a candidate block, and then using processing power to produce a block hash that is below a specific target value. This means that any node on the network can mine a new block, but you need to expend energy to be able to do so.
When a node (or “miner”) successfully mines a new block, they will share it with the other nodes on the network. When other nodes receive this new block, they will add it to their blockchain, and miners will start trying to mine a new block on top of it.
As a result, miners are constantly working to extend the blockchain with brand new blocks of transactions.
Note: Due to the difficulty and processing power required to mine a block, new blocks are added to the blockchain once every 10 minutes (on average).
Note: A node doesn’t have to try and mine new blocks. Instead it can just keep a copy of the blockchain and relay new blocks to other nodes when it receives them.
Can two blocks be mined at the same time?
Yes, and this is perfectly normal.
In this situation, nodes will consider the first block they receive as part of their blockchain, but also keep the second block they receive just in case. However, the second block to arrive (and the transactions inside it) will not be considered as part of their active blockchain.
Consequently, nodes on the network will actually be in disagreement about which of these two blocks belongs at the top of the chain.
This disagreement is resolved when the next block is mined. The next block will build on top of one of these blocks, creating a new longest chain of blocks, and as a rule nodes will always adopt the longest known chain of blocks as their active blockchain.
As a result, some nodes will perform a chain reorganisation to move out blocks from an old active chain in favour of blocks that make up a new longer chain.
Therefore, although there may be disagreements at any given time about which block(s) belong at the top of the blockchain, the mining of new blocks and the adoption of the longest chain means that nodes will always end up in agreement.
Does this mean that blocks in the blockchain can be replaced?
Due to the fact that nodes always adopt the longest chain, you could always try and build a new longer chain of blocks to replace an existing one, and every node on the network will adopt it. In effect, this would allow you to “undo” or reverse a bitcoin transaction from the blockchain.
However, the problem is that all miners are incentivised to always be building on to the longest known chain. This means that the combined processing power of miners on the network will be focused on building one single chain, which will be built faster than any chain you could build on your own.
In other words, the combined processing power of the network working to build the blockchain helps to protect blocks (and transactions) that have already been mined on to the blockchain.
So the only way you could perform an intentional chain reorganisation (to “undo” a transaction in an existing block) would be to have more processing power than every other miner combined so that you could out-mine the network and build a longer chain for everyone to adopt.
This is referred to as a “51% Attack”.
Where is the blockchain?
The blockchain files can usually be found in the following locations:
Note: The blockchain is split in to multiple files named
blk00002.dat, and so on. This is because it’s generally easier to work with smaller files than it is to work with one giant file.1
The blockchain is permanent storage for bitcoin transactions. New transactions are added to the file in blocks, and these blocks are built on top of each other to create a chain.
New blocks are added to the blockchain through mining, which involves the use of computer processing power. This means that it takes energy to mine a block, but any node on the network can work to try and add the next block on to the chain.
When a new block is mined, it will be relayed across the network, which nodes will verify and add on to their chain. In this way the blockchain is a constantly growing ledger of transactions, which is distributed across multiple computers on the network.
Nodes always adopt the longest chain of blocks as the active version of the blockchain, which resolves disagreements about which blocks belong at the top of the chain. This also protects blocks that are already in the blockchain, as it would require large amounts of energy to build a chain that replaces existing blocks in the chain.
As a result, the blockchain is a regularly updated file of transactions. The system of mining blocks and adopting the longest chain allows multiple computers over a network to agree on the same set of blocks and transactions that are considered active, whilst also making it difficult for anyone to make historic changes to the blocks and transactions in the file.