Mining the Blockchain, Part II

A couple of weeks ago, Jeff Harris wrote the first of a series of blogs on Blockchain. In this second installment, I build on his overview and explore the methods used to create a trusted distributed ledger. To develop this understanding, I am going to use the example of a checkbook to explore one of the first blockchain implementations: cryptocurrency. I’ll provide an overview of:

The parts of a checkbook: the ledger, the checkbook, the check, and the bank

1. The ledger

Blockchain technology is a distributed ledger with no centralized storage. All cryptocurrencies are built on blockchain. You can think of blockchain like a checkbook ledger. When you write a check to someone, you enter the transaction into the ledger. When someone sends you a check, you deposit it and that transaction is also recorded in the ledger. In a cryptocurrency system, blockchain is the ledger, but unlike your checkbook ledger, it is a public file and it contains copies of every account and every transaction extending back to the beginning of time for the currency.

2. The check

When we want to pay a debt or transfer funds, we pull out our checkbook and write a check. The check records the parameters of the transaction and provides a physical form of proof, including our signature. When we take the check to the bank, the bank transforms that paper record into a digital transaction conducted on a centralized compute system. Blockchain eliminates the check and the central compute system, replacing it with a distributed system.

3. The checkbook

In bitcoin and other cryptocurrencies, the checkbook is replaced by a computer client called a “wallet.” The wallet client lets the end-user submit transactions to the cryptocurrency network. It also transforms the client into a node that can validate and process transactions coming from other places on the network. This latter functionality is called mining, and it is critical to building trust and consensus on the blockchain. Individuals are incentivized to participate in mining via rewards given for finding solutions to extremely difficult mathematical problems.

4. Writing a check

The act of writing a check is executed through the wallet client or an API which communicates to the wallet client. Each currency is different, but in general a transaction includes the sender wallet ID, the receiver or receivers, the amount to be transferred, and any fees associated with the transaction. Some currencies include other fields as well. Once this information is entered, the node announces the transaction to its peers. As an example, in a Bitcoin network, a node will typically establish at least 8 peer-to-peer connections.

5. Processing the check

Banks process checks centrally. They verify the integrity of the check (signature, anti-counterfeiting measures, account numbers, etc). Once validated, they create a digital transaction in a central computer system. The central system applies debits and credits to the accounts in question, and money is exchanged.

In a cryptocurrency transaction, the blockchain replaces the central computer system and the accounts. The blockchain is the ledger of all accounts. It is distributed, open, and pseudo-anonymous: Anyone can inspect the blockchain and see all the transactions, and which accounts they went to, but there is no personally identifying information to connect an account to a person. It is possible to walk through the blockchain just like you can walk back through your checkbook ledger to the beginning of time when you opened the account.

6. Validating and recording the transaction

Validating a transaction in a cryptocurrency network works similarly to our checking example. Blockchain transactions are submitted to the network by a wallet node. The wallet node shares the transaction to its peers via a peer-to-peer mechanism. Receiving nodes immediately validate the transaction and, if valid, announce it to their peers. All peers in the network will repeat this process, ensuring the integrity of the blockchain.

Validation may include many checks, but two are critical: Verifying the authenticity of the sender, and verifying that funds exist to pay the debt in the transaction. The sender used private key cryptography to verify his or her identity when the transaction was submitted, thus that condition is already met. To verify that funds exist, each node searches the blockchain and determines if the sender has received or earned funds that have not yet been committed to any other transaction. To perform this validation, every full node maintains either a full copy of the blockchain, or a subset with all the relevant unspent prior transactions.

Once any node validates a received transaction, it forwards it to its peer nodes, and also stores it in a transaction queue for later recording into the blockchain. Through this process, the transaction propagates through the entire network.

7. Recording the transaction to the ledger

Up until this point, the transaction is only stored in a queue, waiting to be committed to the ledger. This last step is the equivalent of the bank actually moving money between accounts.

When enough transactions have accumulated, or enough time has passed, the transactions in queue will be assembled into a block. Each cryptocurrency has specific rules about how blocks are put together. These rules may cover details such as: What order can transactions be put it? What defines the priority? How many transactions are allowed per block? How often is a block committed to the chain? And so on. These details are important to the performance characteristics of the blockchain in question. As you think about other applications for blockchain technology, you will find parameters like time to resolution, latency, and number of transactions per second are important to different systems.

The blockchain network for the currency dictates the rules of how blocks are assembled. Once a client can meet those rules, it forms a block from the transaction queue, and then starts work on a very hard computational puzzle related to the block. The block is not committed to the blockchain until a valid solution to that puzzle is solved. Each cryptocurrency has its own puzzle. The process of finding the solution to the puzzle is called mining. We’ll take a deeper look at how mining works in the next chapter.

When a node finds the solution to a puzzle, it broadcasts that solution and associated block to the network. Remember, finding the solution to the puzzle is exceptionally difficult and time consuming. However, verifying a given solution is fast and easy. All receiving clients check the work, and confirm the solution is valid. Once they validate the block, they record the block to the local copy of the blockchain and forward on the new block to the network. The block is now committed to the blockchain. As a reward for the work, the owner of the lucky node that solved the puzzle gets a prize: cryptocurrency coins.

Integrity of the blockchain

At this point, the process repeats itself, with the next batch of transactions being formed into a new block. One last concept is crucial to understanding blockchain: The new block contains a permanent reference to the previous block. Because each block has a link to the previous block, if one block is changed, all blocks that reference it must have their work puzzle re-computed.

This chaining mechanism ensures the integrity of the blockchain by making it nearly impossible to change transactions once they are validated and recorded. The longer a transaction has been on the blockchain, the less likely it is to ever be changed. This is why the computationally expensive work function is integral: it is the mechanism that creates the trust necessary for a distributed, decentralized ledger.

While blockchain is a peer-to-peer technology, not all parts of the process require full peer-to-peer meshing. In particular, solving the puzzle may be done by a system of many computers that share the work. When this is implemented, the mining traffic will look more like client-server traffic than peer-to-peer. If you want to understand more about the network traffic of a blockchain transaction, watch for the fourth part in this series, where we look at this in greater depth.\

limit
3