A blockchain is a data structure that contains records, called blocks, which are linked together in a cryptographically secure way. It's a distributed, publicly agreed upon ledger of transactions, and the fundamental technology of cryptocurrencies like Bitcoin.
How blockchain works
A blockchain is a special type of linked list. Each item in the list contains its own information and a pointer to the next item in the list. If you start looking for an item in a linked list, you traverse it one item at a time, using that item's information to find the next item, then repeating the process. This process can be a useful way to structure data, partly because you can splice two lists together by changing a single pointer.
Blockchains are a little different because they link backward rather than forward. When a new block is created, it points to the preceding block.
Other characteristics of a blockchain:
- A block contains a set of transactions. A "transaction" is an agreed upon change of data from one state to another. The data may be conventional file data or specialized data such as ownership of currency.
- The transactions in a block are "atomic," meaning they cannot be divided into smaller sets. Either all the transactions occurred, or nothing at all.
- The first block created is called the genesis block. The genesis block is the only block with no predecessor — every other block eventually links back to the genesis block. A block's distance from the genesis block is called its "block height," because blockchains are often visualized as being constructed vertically, from the bottom up.
- Every block after the genesis block contains a pointer to its previous ("parent") block and a hash of that block's header. This hash has cryptographic properties that make it unpredictable and unique. Its mathematical qualities are what make the blockchain secure from forgery.
- To traverse the chain, you must start at the newest block, called the "tip," "head," or "top" of the chain. Then you traverse backward, "down" the chain, one block at a time.
- A block can point to only one previous "parent" block. However, multiple blocks may point to the same parent, which creates a branch in the chain, called a fork.
- New blocks are added to the top of the chain or the tip of a fork.
Why blockchain is useful
Blockchain is effective as a distributed ledger technology, or DLT. A distributed ledger is openly shared with all participants — there are no private transactions. The cryptographic verification from block to block creates a chain of trust in these transactions.
These properties make the blockchain a decentralized, authoritative record of information. For a cryptocurrency, a blockchain permits owners to transfer value to each other without needing a centralized banking institution to broker the transfer.
What's in a block
In general, a block contains:
- A block header that contains identifying information about the block.
- A transaction counter, representing the number of unique transactions in the block.
- The transactions.
A block header generally contains:
- A version number of the software, or rules, which govern the blockchain.
- A cryptographic hash of the previous block's header.
- A cryptographic hash of the root (Merkle tree root) of the block's transactions. The transactions themselves are not stored in the header, but this root is unique to those transactions, and is required to reconstruct them.
- A difficulty target, used in generating provable cryptographic work (proof of work) for that block.
- A timestamp.
- A nonce — a number which may be used only once.
A fork may be created because a different set of rules is being applied to future transactions, or because new features have been added to the blockchain. It's like a fork in the road: the record of transactions proceeds in two different directions.
A fork may also be created retroactively if transaction validity is in question, to proceed from a known valid point in the blockchain.
Temporary forks are a natural side effect of the distributed processing performed on a blockchain. Such a fork may occur when two or more miners finish mining a block at approximately the same time.
When the rules that govern transactions change, a "hard" or "soft" fork may be created. In a soft fork, the new rules are backward-compatible, so new rule blocks are seen as valid by old-rule blocks. In a hard fork, the old and new rules are not compatible, and neither fork sees the other's blocks as valid.
Establishing trust in the blockchain takes a lot of work. To create the chain of trust, participants called "miners" perform the cryptographic "work" to verify transactions in the chain. Miners use their computer's CPU and GPU power to compute complex, repetitive cryptographic hashing functions. The process is called mining because it requires a large amount of distributed work, in the search for something valuable.
Mining requires a powerful computer and a lot of electricity, so there is a significant real-world expense to mine a blockchain. To encourage mining, the system rewards the individual whose computer successfully "mines a block." Miners compete with one another to claim this reward.
What constitutes a reward, varies according to the purpose of the blockchain. In a cryptocurrency blockchain, the miner who solves a block is rewarded with a set amount of the currency. For instance, the bounty for successfully mining a Bitcoin block is 25 Bitcoins.