An introduction to Blockchain
Still not sure about blockchain? Robert van Mölken explores the basics of distributed ledger technologies and shows how they can be a solid foundation for future success. Here, we dive deeper into the architectural intricacies that make up blockchain.
The following is an excerpt from the book, Blockchain across Oracle by Robert van Mölken and published by Packt. Blockchain across Oracle gives you the professional orientation to Blockchain that you need as an Oracle developer in today’s changing world.
This article serves as an introduction to the blockchain. In this article, I will explain what is the blockchain technology on a more architectural level. When you ask 10 people what they think the term blockchain means, you might not be surprised to get 10 different and conflicting answers, as use of the term blockchain can be a bit confusing. A lot of people connect it to bitcoin or other virtual (crypto-) currencies. Some people talk about the Ethereum Application Platform, some about smart contracts (executable code), but most of the time blockchain is explained as a distributed, shared ledger.
In essence, a blockchain is a system of maintaining digitally-distributed ledgers in a way that allows individuals who do not fully trust each other to agree on the updates to the shared ledger. Blockchains use peer-to-peer protocols rather than a central authority or third party to distribute and verify transactions between entities. There is no single point of failure, so entities can appear, disappear, or malfunction without affecting the group.
What is a blockchain?
When talking about blockchain, we always refer it as a distributed ledger technology (DLT) that formed the underlying, open-source technology behind bitcoin. A blockchain is a digital system of recording transactions of assets in a list that is replicated across available nodes in a network, rather than being stored in a central data store as is the case with traditional databases.
In a distributed ledger such as a blockchain, the data is distributed to all nodes in a trustless manner (meaning without a trusted third party like VISA, MasterCard, or your bank) using a peer-to-peer protocol in near real-time. Each node individually processes and verifies every transaction redundantly, bundles the verified transactions into a block, and broadcasts them to all other nodes in the network. Through a consensus mechanism, the block of transactions is validated by other nodes in which the majority has to approve the block before it becomes final and is added to the blockchain.
The blockchain uses a combination of digital signatures and cryptography to prove your identity and authenticity and to enforce read/write and execute permissions (access rights). This makes it possible to permit write access for certain participants and read access to other participants, or even to a wider audience; that is, everybody. If you loosely compare a blockchain to a traditional database, a blockchain is a system that contains an ordinary database and some extra software which validates that submitted records conform to previously agreed-upon rules before adding the new records into the database. This extra software listens and broadcasts new records to all nodes, or peers, participating in the network, ensuring that each peer has the same data in its database.
The following diagram is an overview of the capabilities that make up blockchain technology:
Technically, a blockchain is a new method of data storage. It is actually just a file with a predefined data structure (that is, how the data is logically put together). It can be compared with other data structures, such as relational databases (tables, columns, and rows), XML files, comma-separated values (csv), Excel database files, and binary files (images and videos). An analogy that I often use is that blocks in a chain are the same as pages in a book. Each page in a book just like the following one has a bunch of text structured in paragraphs, and information about its context (also called metadata), such as the article number, article title, and page number.
Similarly, in a blockchain, each block consists of a collection of content, for example the list of transactions, and a header, which contains technical information about the block, a reference to the previous block, and a digital signature (hash) of the data contained in the block. A blockchain, where blocks are linked to each other to make a chain, is analogous to pages in a book. Pages use sequential numbering that makes it easy to know their order. If pages were to be pulled out of the book and thrown into a pile, it would be easy to put them back in order. A blockchain, though, is more clever.
The following diagram shows that each block links back to the previous block via the block’s fingerprint. The fingerprint is determined by the individual block’s content and the fingerprint of the previous block:
In a book, the ordering of pages is implicitly built on a page whose number is one less; that is, page 13 follows page 12 (13 – 1), whereas blocks are represented by fingerprints or hashes that are built upon each other. For example, block 3 with hash 8ec6cc0 is determined by hashing its data together with hash 9a59c5f of the previous block. By using a fingerprint that is determined based on the previous one, it can be used for validating the internal consistency of the data. This scenario is shown in the following screenshot:
You can check whether the data is consistent within a block by generating the fingerprint yourself and comparing it to the one that is part of the block’s header. If someone wants to change the information stored in one of the earlier blocks, they need to regenerate all of the fingerprints from that point until the end of the chain. However, the blockchain will appear to be altered, and it is instantly noticeable by others.
Depending on the consensus method used, the creation of these fingerprints can be a very difficult and slow process, which makes it very problematic to rewrite the blockchain. Furthermore, the number of blocks already present in the blockchain can be huge, for example, for bitcoin (06.03.2018: 512253 blocks with a size of 156 GB). The following screenshot shows that when changing the data, the hash is also changed and the block becomes invalid:
How does a blockchain work?
The technology (that is, the architecture, mechanisms, security, and so forth) behind the blockchain can be seen both as the backbone for future accounting and an engine for a modern message transport system. So how does a blockchain actually work during runtime?
The following diagram shows how blockchain systems must follow a specific flow of actions in order to consistently maintain a distributed ledger of facts (a key-value database with the current state of assets) and a separate history of their updates (distributed transaction log). The transactions that you submit are stored and verified without the involvement of a governing central authority using advanced mathematics and computer science, that is, cryptographic hash functions. The blockchain not only secures these transactions but also protects their integrity (and anonymity).
A typical blockchain provides client APIs to interact with the transaction, but generally you would use a web application that calls the API with which you would submit your transaction to one of the active nodes (peers) in the network. Depending on the network’s capabilities, the transaction is either locally validated or directly broadcast to all active nodes in the network using the peer-to-peer (P2P) network. When locally validated, your transaction is only broadcast after validation based on a set of network rules. Each node that receives your transaction will, depending on network rules, either verify it instantly or transcribe it into a secure record and place it in a queue of pending transactions. In this case, nodes; that is, the participating computers or servers in the network, verify if your transaction is valid based on a set of rules to which the network has agreed. For example, your transaction can trigger participating nodes to execute business logic (such as a smart contract) and follow the consensus protocol to verify the results.
SEE ALSO: “For blockchain to be really successful, we have to understand where and why to deploy it”
Some consensus protocols require you to pay a transaction fee to get your transaction verified. The amount you pay is part of your transaction, and it determines the time it takes to get verified. Some nodes that create blocks only verify transactions that have a higher reward. Depending on the rules defined by the network’ protocol, validating nodes combine transactions into a block and digitally fingerprint the result so that they can be validated by other nodes in the network. Just like transactions, blocks are broadcast to all active nodes using the peer-to-peer network.
When consensus is reached, depending on the network’s rules, participating nodes either batch the transactions and store the results as a cryptographically secured, immutable data block, or they take the approved block and append it to their ledger. Consensus protocols may include a reward system for nodes that create a block or require you to pay a transaction fee to distribute the currency to the rightful recipient.
Following the consensus mechanisms and network rules, it may take several blocks until you can be certain that your transaction is verified and not part of an orphaned chain. It is possible for multiple peers to create a block at the same time or just a few seconds apart from each other. This can produce a fork in the chain. Both blocks are initially accepted by the majority of the network, creating two chains. For any block of transactions, however, there is only one way to the genesis block (that is, first created in the chain), and blocks that are part of the smaller chain are eventually rejected.
In the following diagram, you can see that the longest chain survives and that smaller chains are rejected:
Those transactions that are part of the rejected block(s) are added back to the pool of queued transactions and will eventually be included in another block. With blockchains that use an incentive model, the reward that someone receives for solving an orphaned block is practically lost.
SEE ALSO: “If you make the right choices, blockchain will help you, otherwise it’s going to be a nightmare for you to manage”
This article served as an introduction to the technology behind blockchain. The article started by explaining that a blockchain is a digital system of recording transactions of assets in a list that is replicated across available nodes in the network. A block in the chain is somewhat analogous to pages in a book.
The article continued by answering the question of how a blockchain works, and it described the flow of data in a blockchain once a transaction is submitted, from the broadcast of transactions to all other nodes using a peer-to-peer network to the verification steps in the consensus protocol. I reviewed each step in the flow of data, its purpose, and the changes that occur to the data.
You have just read an excerpt from the book, Blockchain across Oracle by Oracle Developer Champion Robert van Mölken and published by Packt. This book gets you up to speed with the details of the Blockchain – core concepts, how to implement Oracles Blockchain Cloud Service, industry implications for the Blockchain, and how the Blockchain will affect your Oracle customers.