Blockchain 101 Part 2: How Blockchain Works

in blockchain •  7 years ago 

Per the definition outlined in part 1, Blockchain is defined as a peer-to-peer digital ledger of immutable transactions organized into timestamped blocks that can only be confirmed by network consensus. Each block that is created contains a reference to the previous block, forming a chain of blocks called the blockchain. On this blockchain, these transactions represent the transfer of value, either tangible (a product) or intangible (currency). The network “consensus” that is so often name-dropped in every article related to blockchain is often the least understood part of blockchain, and sometimes it is overlooked completely for lack of a reasonable explanation of how it works (gasp!). Never fear! I have you covered.

First things first, let’s briefly touch on what a transaction looks like on the blockchain. Keep in mind that each node is represented by a key pair, a public key (the wallet address to which transactions are sent) and a private key (used to access the wallet and sign outgoing transactions). The public key value is really an address for a digital wallet that holds a node’s transaction records. You can think of this wallet as a locked glass box; the contents are relatively easy to find, but only the holder of the private key pertaining to that public key glass box can open it and change the contents. When a transaction is created on the blockchain, the public key of the recipient is used as the address to send to and encrypt the data, and the private key of the sender is used to sign the transaction. Each transaction has both inputs and outputs that determine the balance one holds. Let’s use an example to illustrate this:

Let's imagine Alice wants to send 1 BTC to Bob.

A couple really important points here; a node’s wallet balance is determined by the reconciliation of the entire history inputs and outputs for their wallet. For example, if Bob’s wallet has transactions as follows: [-1 BTC, +1 BTC, -.5 BTC, +2 BTC], his wallet balance will be 1.5 BTC, but it is not settled into one single record, it is rather calculated in real time whenever a balance is requested. This differs from a bank’s way of keeping balance, where there is a monthly statement with debits and credits for a period of time that result in a carried balance. Furthermore, when a node creates a transaction, the protocol can only send the entire balance of one of the transactions in the node’s wallet, meaning it cannot split the balance of transactions up into smaller amounts in order to send exact change. For example, with the wallet balances above, if Bob wants to send a transaction to Alice for 1.5 BTC, the protocol will take the +2 BTC transaction in his wallet and issues that as a transaction with an output of 1.5 BTC to Alice’s address and then .5 BTC back to Bob’s address as change (it uses the entire balance of that +2 BTC transaction). Note the difference between this process and the debit and credit style that banks use! When you send money to someone else through a bank, their balance goes up, yours goes down and it is reconciled by the bank in exact change. Banks do not issue a transaction that sends $100 to your friend and then $25 back to yourself in order to send your friend $75. I know that this can get a bit confusing, so feel free to leave a comment if you need anything cleared up.

Now that you understand transactions and wallet balances, back to consensus. There are a few key requirements that the consensus process addresses:

The work required and the reward involved incentivizes miners to do that work to verify transactions and drive the network forward, and dis-incentivizes cheating the system

The verification that transactions are valid is completed effectively, i.e. prevents double spend, sending more funds than you own, etc.

The process effectively eliminates the need for a trusted 3rd party or intermediary to perform the action of verifying transactions and maintaining a copy of the ledger

How it works:

As you can see in the graphic above, as a general rule of thumb, the process goes as follows in a never ending cycle:

  1. As transactions are issued by nodes on the network, those transactions are broadcast to everyone on the network and put in queue to be verified

  2. Miners pull transactions from the queue into prospective blocks, checking their validity, while simultaneously competing with other miners to solve a complex cryptographic puzzle

  3. When a miner finds the answer to the cryptographic puzzle, they broadcast the “proof-of-work” to the rest of the network

  4. The network can easily verify that the answer is correct (think about math class, when you have the answers, it’s plug and play)

  5. Finally, the miner appends their block of transactions to the previous block and they are rewarded with cryptocurrency for their work

In a future post, I will go into more technical detail about the mathematics behind proof-of-work consensus. For the sake of keeping this oriented to a 101 reader, I will leave that for a later time. So what is the “proof-of-work” for these miners, you may ask? In the case of protocols like Bitcoin, Ethereum and the like, the proof-of-work is rapid iteration and trial and error to find a target solution to a complex cryptographic puzzle. Essentially, the input from miners is time and energy from their computer’s processing power and the output is guesses at the solution to the cryptographic puzzle. One crucial thing is missing here: what if tons of miners join and add their processing power? Wouldn’t the problem be solved much faster as more miners join in? In short, yes, so the blockchain protocol automatically adjusts the difficulty of the math problem based on the amount of processing power on the network to combat massive fluctuations in block creation time. Remember: proof-of-work is a piece of data that is difficult or costly to obtain, in this case it costs time and electricity/processing power, but very easy to verify (think having the equation and the answer for a math problem, plug and play). In order for consensus to work, the cryptographic puzzle needs to be difficult to solve but very easy to verify by the rest of the network. In this case, when the miner broadcasts the answer to the puzzle to the network, it takes a fraction of a second to verify its correctness and grant the miner rights to append the latest block to the chain. The process of consensus is the only way that blocks can be created, and the only way that new tokens (cryptocurrency) can be created; the reward for mining a new block is the only way more tokens can be created on the network! The consensus process effectively replaces intermediaries like banks with peers on the network (in this case, miners), and the level of distrust between individuals transacting with one another on the network is mitigated by trust in the protocol to verify transactions accurately. In a future series I will discuss the concept of trust and how it relates to blockchain.

It should be fairly obvious now that blockchain in and of itself is an extremely intricate and carefully thought out technology and protocol that relies as much on game theory and economics as it does computers and software! That is what makes it so fascinating; there is something for everyone in the study of blockchain.

I know I have shared quite a bit of information here, and some of the topics may have been confusing. Not to worry! If you still find yourself confused, feel free to leave a comment and I will address your questions. The final part of this trilogy entitled “Blockchain for Dummies” will be all about how blockchain is being used and implemented on the market today, and will introduce the next series of posts and videos that will be coming soon!

Authors get paid when people like you upvote their post.
If you enjoyed what you read here, create your account today and start earning FREE STEEM!