Distributed Consensus So we've talked in a generic manner about centralization and decentralization. Let's now talk, at a bit more technical level, about Bitcoin and decentralization. And a key word that'sgonna come up again and again here is consensus, specifically distributed consensus. Sowhat am I talking about here? At a technical level, the key challenge that you have to solveto build a distributed e-cash system is called distributed consensus. And this is a class ofprotocols that's been studied for decades in the computer science literature. So, butintuitively, you can think of it as our goal being to decentralize ScroogeCoin, which is thehypothetical currency that we saw in the first lecture. So as I said, there's decades of research in computer science on these consensus protocols. And the traditional motivating application for this is reliability in distributedsystems. What do I mean by that? Imagine you're in charge of the backend for a companylike Google or Facebook. These companies typically have thousands, or even millions ofservers, which form a massive distributive database that records all of the actions thathappen on the system, like users' comments and likes and posts, and so on. So when a new comment, let's say, comes in, the way it'll be recorded is that there might be 10 or 15 different nodes, in that massive backend, that might contain copies of this action. The server must now ensure that either every copy of that database contains that comment or none of them do. If for some reason, because some of these nodes might be faulty, the action gets recorded in none of the databases, it's okay. You can go back to the user and say, there was aproblem saving your post, would you please try again? On the other hand, if some of thecopies of the database saved it and others didn't, then you'd be in a lot of trouble, becauseyou'd have an inconsistent database. So this is the key problem that motivated the traditionalresearch on distributed consensus. And you can sort of see the similarities to Bitcoin here.But we're gonna talk in a bit more detail about the similarities and differences. So that wasthe traditional motivating application. But we can also imagine that if we achieved adistributed consensus protocol, and we were able to use that to build a massive, global scaledistributed key value store that maps arbitrary keys or names to arbitrary values, then thatwill enable a lot of applications. For example, a distributed domain name system, which issimply a mapping between human understandable domain names to IP addresses. Or apublic key directory, which is a mapping between user email addresses, let's say, to theirpublic keys. Or even things like stock trades. Because this distributed database, instead ofkeeping track of who's paid whom how much money, would keep track of who's transferredwhat units of which stock to whom. And the cool thing about this is that now that Bitcoin has solved the distributed consensus problem, in a certain sense that we'll try to understand in this lecture. We can also go aheadand try to think about solutions to all of these other related problems. And in fact, there aremany Altcoins. And Altcoins, we'll have several more lectures about Altcoins. But very briefly,
Altcoins are systems built on Bitcoin-like principles to achieve, perhaps, slightly differentgoals. Sometimes currency systems, sometimes not currency systems, such as one of theseapplications. And so, given that we can solve distributed consensus now. And given that wecan build a global distributed key value store. It enables a lot of these other cool applications. Now, let's proceed to a technical definition now. In reality, distributed consensus has a very straightforward technical definition. Suppose that there are n nodes or processes, where n isa fixed number. And each of these nodes has a value that may be input. And then a consensus protocol happens. And the two requirements on this consensus protocol are that the protocol should terminate, and all correct nodes should decide on somevalue, the consensus value, all right? And I say correct nodes, because some of the nodesmight be faulty, or even outright malicious. The second stipulation is that the value they decide upon cannot be chosen at random. But it must be a value that at least one of these reliable nodes suggested as input. So, it really isthat easy. Let's attempt to interpret this in the perspective of Bitcoin, though. So, to understand how distributed consensus could work in Bitcoin, let's start with a reminder that Bitcoin is a peer-to-peer system, all right? So, what I mean when I say Bitcoinis a peer to peer system is that when Alice wants to pay Bob, what she does is she's going tobroadcast the transaction to all of the Bitcoin nodes that comprise the peer-to-peer network.And you can see here the structure of the transaction. This is similar to GoofyCoin, that wesaw in the first lecture. And what a transaction is going to have is it's going to have Alice'ssignature. Which the other nodes need in order to know that it really, in fact, came from Alice.It's going to have Bob's public key, which also accesses his address at which he wants toreceive bitcoins. Moreover, it includes a hash. What is hash, exactly? Remember the idea of hash pointers from the first lesson. So this hash is a means for Alice to connect this transaction or thiscurrency to the coin she previously received from someone else, correct? These thus are theelements that make up the data structure that we refer to as a transaction. And she willbroadcast that information to all Bitcoin P2P nodes. And notice something funny here. Bob's computer is nowhere in thispicture. Now Bob, if he wants to be notified that this transaction did in fact happen and that he got paid, he might wanna run a Bitcoin node that's one of these peer-to-peer nodes, in order tolisten in on the network and be sure that he's received that transaction. But his listening isnot, in fact, necessary for him to receive the funds. The bitcoins will be his whether or nothe's running a node on the network. So, given this peer-to-peer system, what is it exactly thatthe nodes might want to reach consensus on? Well, given that a variety of users arebroadcasting these transactions to the network. What everybody wants to reach consensuson is exactly which transactions were broadcasted, and the order in which these transactionshappened.
So what does that mean, specifically? How consensus could work in Bitcoin is that at any given time, all the nodes in the peer-to-peer network would have a sequence of blocks oftransactions that they've reached consensus on. So recall that in ScroogeCoin, foroptimization purposes, for efficiency, we put transactions into blocks. And we link theseblocks together on a block chain. So we're utilizing a similar principle here. We could doconsensus on transactions one by one, that would be okay. It would just be inefficient. Soinstead, we do consensus on a block by block basis. So at any given point, all these nodes inthe peer-to-peer network would have the sequence of blocks that they have agreed uponalready. And each node would then have a set of outstanding transactions that it has heardabout. So recall that for these transactions, consensus has not yet happened. And so, almostby definition, each node might have a slightly different version of the outstandingtransactions thats it's heard about. The peer-to-peer network is not perfect, so some nodemay have heard about a transaction, but not other nodes. So given that we the setup, whatcould happen is that you have the sequence of blocks that everybody has agreed upon. Ablock is just a series of transactions. Why Bitcoin's Consensus Protocol Is a Technical Challenge The consensus protocol for Bitcoin is a peer-to-peer, decentralized network. The protocol's goal is to make sure that everyone on the network agrees to use the same version of theblockchain. But creating a consensus protocol that can function in a decentralized setting likeBitcoin is a difficult technological challenge. This essay will examine the difficulties theBitcoin consensus mechanism encounters and the reasons why it is a challenging technicalissue. The Basics of Bitcoin's Consensus Protocol To understand why Bitcoin's consensus protocol is a technical challenge, it's essential to understand how it works. The consensus protocol allows nodes in the network to agree on asingle version of the blockchain. Nodes in the network can propose blocks of transactions,which are then verified by other nodes in the network. Once a block of transactions isverified, it becomes part of the blockchain, and the consensus protocol moves to the nextblock. The consensus protocol is crucial to Bitcoin's success because it ensures that all transactions are valid, and no one can spend the same bitcoins twice. However, designing aconsensus protocol that can work in a decentralized environment like Bitcoin is a challengingtechnical problem. Challenges Faced by the Bitcoin Consensus Protocol
There are several reasons why designing a consensus protocol that can work in a decentralized environment like Bitcoin is a challenging technical problem. The following aresome of the most significant challenges faced by the Bitcoin consensus protocol: Node Failure: Nodes in the network might fail, and some nodes might be malicious. In either case, the consensus protocol must be designed to handle these situations. Imperfect Network: The Bitcoin network is highly imperfect. Not all nodes are connected toeach other, and there can be faults in the network due to poor internet connectivity. High Latency: There is a lot of latency in the Bitcoin network because all transactions happen over the internet. There is no notion of global time, so not all nodes can agree to acommon ordering of events based on observing timestamps. Pessimistic Literature: Many impossibility results have been proved in the literature on distributed consensus, which has made the design of consensus protocols more challenging. The Byzantine Generals Problem: The Byzantine Generals Problem is a well-known impossibility result that proves that consensus is impossible, even with a single faultyprocess. The Fischer-Lynch-Paterson Impossibility Result: Under certain conditions, consensus is impossible, even with a single faulty process. Despite these challenges, there are a few well-known protocols, and Paxos is probably one of the better known. What Paxos does is it makes certain compromises. It never produces aninconsistent result, but it accepts the tradeoff that, under certain conditions, the protocol canget stuck and fail to make any progress. Why Bitcoin's Consensus Protocol Is a Hard Technical Problem Because of the difficulties mentioned above, creating a consensus mechanism that can function in a decentralized setting like Bitcoin is a difficult technological problem. Thenetwork is quite unreliable, there is a lot of latency, and nodes could malfunction or bemalicious. In addition, there is no concept of global time, which makes it difficult to createalgorithms that can manage event ordering. The literature on distributed consensus is also somewhat pessimistic, with many impossibility results having been proved. These results have made the design of consensusprotocols even more challenging. While some well-known protocols, such as Paxos, havebeen designed to handle these challenges, they still make certain compromises and may notbe perfect in all situations. Conclusion
It's a challenging technological challenge to create a consensus mechanism that can function in a decentralized setting like Bitcoin. Inadequate networks, high latency, no conceptof global time, and node failure must all be taken into account when developing the Bitcoinconsensus process.