Book Image

Blockchain across Oracle

By : Robert van Molken
Book Image

Blockchain across Oracle

By: Robert van Molken

Overview of this book

Blockchain across Oracle gives you the professional orientation to Blockchain that you need as an Oracle developer in today’s changing world. Written and prepared for you by Oracle Developer Champion Robert van Mölken, this book gets you up to speed with the details of the Blockchain - core concepts, how to implement Oracle’s Blockchain Cloud Service, industry implications for the Blockchain, and how the Blockchain will affect your Oracle customers. Robert van Mölken introduces you to the history and concepts of the Blockchain. You’ll really get to understand the Blockchain inside and out, as an Oracle developer or solution architect. You’ll understand the Blockchain flow, and how the hashes and chains create a new decentralised paradigm for you as an Oracle developer. You’ll gain insights into how the Blockchain affects Oracle developers and customers in this modern and disruptive era. You’ll see how the Blockchain concepts work in this new world where Assets, Transactions, Security, and Privacy, can all be sustained across a decentralized system for your customers. Then you'll find a detailed look at the cutting-edge Oracle middleware solutions. You’ll learn about Hyperledger Fabric, the opensource Blockchain framework used by Oracle as its core, and how to set up your own Oracle Blockchain Network. You’ll design and develop a smart contract, and learn how to run it on the Oracle Blockchain Cloud Service. The final part of the book looks at how the Blockchain will affect your customers across various industry sectors. By studying industry trends in the financial services sector, healthcare industry, and the transport industry, you’ll discover how the options and possibilities for you and your clients are being transformed by the Blockchain across Oracle. You’ll complete this professional orientation by looking at Blockchain trends and future directions.
Table of Contents (24 chapters)
Title Page
Packt Upsell
Contributors
Preface
3
Blockchain 101 - Assets, Transactions, and Hashes
4
Blockchain 101 - Blocks, Chains, and Consensus
Index

What is the architecture behind the blockchain?


As I mentioned earlier, the blockchain is not just a distributed database; it includes advanced software and security techniques to create a network of nodes (peers) that are always in sync, where each node validates and verifies transactions and blocks redundantly in order to reach consensus, and it provides a platform to run decentralized applications. To achieve this, the blockchain or digital ledger technology is built upon a layered architecture. In most cases, this contains four or five layers, namely the data layer, network layer, consensus layer, incentive layer, and application layer.

The data layer

At the bottom layer of the stack is the data layer, which deals with the data structure and the physical storage of data in the blockchain.

 

The following diagram shows the common capabilities that are part of this layer:

The capabilities of the data layer, such as cryptographic protocols, hash functions, digital signatures, and others

The data layer includes capabilities that describe the transaction and data model, the type of participants that can connect and use the blockchain (that is, the permissions model), the structure of the chain and its blocks, and the cryptography and hash functions to secure data and generate digital signatures.

Data model, transactions, and chain structure

The first two capabilities, data model and transactions, are closely related to each other. This is where the data model describes the type of assets available on the network and its data structure. Transactions trigger actions to modify asset data and transact assets between participants. The data model can be very simple and contain just one asset, such as a cryptocurrency like Bitcoin, or a more complex model with multiple assets that can even have relationships between them. The same applies to the transactions available on the network.

An asset(s) can be created or referenced in a transaction, which in essence transfers the asset(s) between two parties who wish to exchange the data, for example, processing a payment between two parties, placing an order on an online store, registering an automobile, tracking diamonds around the world, or sharing your digital identity. More background will be provided on these two capabilities in Chapter 3, Blockchain 101 - Assets, Transactions, and Hashes.

The chain structure is also related to transaction data. It describes the data structure in which individual transactions are combined into a block and how these blocks are chained to each other. The structure is usually different across blockchain platforms, since it is used to run on a specific platform. When comparing blockchains, you will notice that more advanced platforms have more complex structures; that is, they contain more information. For reference, the minimum size of a block on the Bitcoin blockchain is around 100 bytes, whereas the minimum size of a block on the Ethereum blockchain is around 525 bytes. The chain structure also describes the maximum size of a block, how blocks are chained together, and how incentives are paid out to participants. More information will be provided about this capability in Chapter 4, Blockchain 101 - Blocks, Chains, and Consensus.

Cryptographic protocol, hash functions, and digital signatures

These three capabilities—cryptographic protocols, hash functions, and digital signatures—secure and digitally sign the data in the blockchain. A cryptographic protocol performs a security-related function by applying cryptographic methods, and it describes the algorithms such as hash functions should be used. The protocol used by a blockchain usually incorporates at least these aspects:

  • Entity authentication
  • Public/private key cryptography
  • Secured application-level data transport
  • Fingerprint/signature generation
  • Data encryption methods

To prove that the data on the blockchain has not been tampered with, transactions, blocks, and participating nodes are signed by generating digital signatures (or fingerprints) on the content of the data using hash functions. A hash function takes any input data and produces an output, which, based on the algorithm in use, has a different fixed length. The output of a hash function is always a string, for example, an SHA256 hash is a 256-bit (32 byte) string of the input data. However, the input could be a list of transactions, and the output would be the digital signature that is placed on the block so that the content of the block (transactions) can be easily validated by others. In the given example, SHA stands for Secure Hash Algorithms, which are a family of cryptographic hash functions published by the National Institute of Standards and Technology. 

Merkle tree

In the cryptography used in a blockchain, there is a fourth capability that ensures that the data is still valid, and that is a Merkle tree. The Merkle tree, or hash tree, is a tree of data blocks in which every leaf node is labeled by a hash or digital signature, and every non-leaf node (for example, the top of the tree) is labelled with the cryptographic hash of all of the digital signatures of its child nodes as its input. The hash tree is used by the blockchain to verify all data that is stored, processed, and transferred between nodes in the network. It can ensure that the blocks received from other nodes (peers) in the network are undamaged and unaltered, and it can verify that other peers do not send malicious data blocks and lie about their content. More details about these capabilities will be presented in Chapter 3, Blockchain 101 - Assets, Transactions, and Hashes.

Participants

A blockchain network is nothing without its participants. A public blockchain can have an infinite number of participants, since anyone can join the network. On the other hand, a blockchain network for business is a collectively-owned, peer-to-peer network operated by a group of identifiable participants. With either network, participants can be individuals or legal entities, such as a business, university, or hospital. The data layer describes the rules for joining the network and the permissions model for accessing and writing the data.

As the blockchain will become more relevant, powerful, and useful in direct proportion to the number of participants, this paradoxically raises one of the biggest concerns, which is the processing power needed to maintain and operate a huge blockchain over time. Solving this challenge is paramount from an architectural perspective and probably key for blockchain applications to become 100% viable in relation to a ton of use cases and eventually positioning themselves as mainstream technology.

The network layer

The second layer up on the stack, just above the data layer, is the network layer. This layer deals with the propagation or broadcast of transactions and block data among available peers in the network, the reliability of the network, and local validation of data. The following diagram shows the common capabilities that are part of this layer:

The capabilities of the network layer include a peer-to-peer network to broadcast transactions

Peer-to-peer network and broadcast of data

You may have heard of BitTorrent, a peer-to-peer network where users share files among each other without a central server having control over the data. The network layer of a blockchain is similar to this, and it is also managed by a peer-to-peer network, which is an architecture for distributing data in a network. In the case of blockchain, it is a network in which nodes (peers) are interconnected and share data or tasks (resources) among each other. This is different to a traditional client-server model, where the centralized server holds 100% of the data and the client needs to trust that the data is legitimate.

A peer-to-peer network runs without the use of a centralized administration system to coordinate transactions. Rather, it sends or broadcasts transactions to each connected party in the network. Nodes can join or leave when they want. When a node joins or rejoins the network, all active nodes will then share all of the updates required to be in sync. These peers commonly find each other through a central index server, or by seeking other participants that use the same software through the internet. When a transaction is published to one of the peers in the network, that peer broadcasts the transaction and its data to all connected nodes in order to ensure that everyone is in sync with each other. Besides transactions, peers periodically generate blocks of verified transactions, which is part of the consensus mechanism, and they are broadcast in the same way.

A peer-to-peer network is, in some ways, less efficient than the client-server model, as the data is distributed and redundantly processed. However, each peer can operate independently, which makes the peer-to-peer network more scalable and robust. Since no central server controls the flow of data, it is harder to close down the network. Additional detail regarding this capability is presented in Chapter 3, Blockchain 101 – Assets, Transactions, and Hashes.

Relay network

When running a big-scale blockchain across multiple continents, it is sometimes required, due to legal or performance reasons, for example, that these continents' systems can run separately for each other. Each continent can have its own network of nodes running independently, but they are all connected to each other through trusted node(s) that relay validated blocks of transactions to and from each continent's network. More information about this capability is presented in Chapter 4, Blockchain 101 - Blocks, Chains, and Consensus.

Local validation

Platforms that support smart contracts often support local validation. As the name suggests, this capability allows a peer to validate a transaction locally before it broadcasts the transaction to the rest of the network. The peer to which the transaction is submitted will validate and execute the transaction and smart contract rules. Only if no exceptions occur will the transaction be broadcast, else the transaction is canceled. More information regarding this capability is presented in Chapter 6Understanding the Blockchain Data Flow.

 

The consensus layer

The third layer of the stack is the consensus layer. This layer deals with the enforcement of network rules that describe what nodes within the network should do to reach consensus about the broadcasted transactions. It also deals with the generation and verification of blocks. The following diagram shows the common capabilities that are part of this layer:

The capabilities of the consensus layer include the different consensus mechanisms that are available

The consensus layer includes capabilities that describe the rules for reaching consensus. The rules that need to be enforced depend on the consensus mechanism that is chosen when the network is initially set up.

When we speak about consensus, we mean the collaborative process that participating nodes of the network use to agree that a transaction is valid and to keep the distributed ledger synchronized at all times. These consensus mechanisms lower the risk of malicious (or fraudulent) transactions because they would have to occur (or be executed) across many locations at the same time, or else the tampering will be noticed almost immediately by other nodes. To reach consensus, the majority of the participants need to agree that the transaction is valid before it is permanently recorded in the ledger.

Once a transaction is permanent, no one, not even a system administrator, can delete the transaction from the ledger. The cost and time needed to reach consensus depends on the mechanism in place and the number of nodes participating in the consensus. A permissionless, or public, blockchain has relatively higher costs as compared to a trusted network of participants (permissioned or private blockchain). A wide variety of consensus mechanisms exist and are available to choose from in order to run an enterprise blockchain. When trust is high between nodes, a simple consensus mechanism, such as a majority vote, may be all that is needed. Alternatively, the network may choose to use a more hardened method.

The following example mechanisms and capabilities demonstrate how a network can reach consensus. The available consensus mechanisms can be categorized in to two groups: sophisticated and lightweight consensus mechanisms. Where the trust between participants is limited or non-existent, you will usually see one of the following more advanced consensus methods being used.

Sophisticated consensus mechanisms

In the world of Bitcoins and Altcoins (cryptocurrencies based on the blockchain developed by the Bitcoin core team), the Proof of Work (PoW) mechanism is used for consensus. PoW was originally a protocol developed with the primary goal of preventing cyber attacks, such as a DDOS attack. The idea behind PoW was first published in 1993 by Cynthia Dwork and Moni Naor, and used in the Bitcoin white paper as it allows for trustless and distributed consensus. This protocol requires participating nodes to perform an intensive form of calculations (also called mining) in order to create a new group (or block) of trustless transactions on the blockchain. The mining of transactions is necessary for two reasons:

  1. Verifying the legitimacy of transactions
  2. Creating new digital currency to reward miners for executing the first reason

To verify these transactions, the miners need to solve a mathematical problem (or puzzle). The first miner that solves this puzzle gets the reward (in the form of new cryptocurrency) and a transaction fee amount supplied by the transaction owners. Verified blocks of transactions are permanently added to the public blockchain ledger, and with every new block, the puzzle gets a bit more difficult. This requires miners to work more efficiently over time. Miners who can deliver more computing power are usually the ones that solve the puzzle the quickest.

Luckily, there are other ways to verify transactions. A mechanism known as Proof of Stake (PoS) is an algorithm with the same end goal as PoW. However, the way it achieves the objective is different. The main difference between PoW and PoS is that with the latter, participation is restricted to the participants that have a legitimate stake (wealth) in the blockchain. Instead of all participants (or stakeholders) trying to confirm the validity of the information submitted, this consensus method chooses an individual to approve it by running a type a lottery. The chance of your being chosen is calculated based on your proportional stake (wealth) in the network. For each X amount of stake a participant holds, they get a lottery ticket. When it is time to verify and create a new block of transactions, the network chooses a lucky winner to announce their conclusions. Where a PoW-based blockchain rewards a miner for solving (mining) the mathematical puzzle to create a new block, a PoS-based blockchain does not reward an individual for creating a new block. Rather, the individual receives compensation (in the form of collected transaction fees). Thus, the term mining is replaced with the term forging, where a block is forged rather than mined.

This is demonstrated in the following diagram:

PoW requires expensive computer calculations to create a new block of transactions, which can be done by anyone.  With PoS, the creator of a new block of transactions is chosen based on their stake (wealth).

The preceding diagram shows the main difference between the two consensus methods. The PoS consensus method has advantages over the PoW method, as it does not perform useless calculations in order to create a block. This prevents a lot of energy from being wasted and is more cost efficient. Also, the PoW protocol is sensitive to a 51% attack, where an individual controls a minimum of 51 percent of the total computational power available in the entire network. With the PoS protocol in place, it is much harder to execute this type of attack because an individual needs to own 51 percent of the total amount of wealth (assets/coins), which is very unlikely.

The PoS protocol also has a variant called the delegated proof of stake (DPoS). The main difference between the two is analogous to the difference between a direct democracy, where you vote for a specific person, and a representative democracy, where you select a group of voters who then collectively vote on a specific person. With a DPoS, the participants choose an entity to represent their collective stake in the blockchain. Thus, you decide which entity, also called a delegate node, will represent your stake in the blockchain. This allows you to join a team in order to magnify your stake. This helps balance out the power of large stakeholders. In Chapter 4Blockchain 101 - Blocks, Chains, and Consensus, I will address these protocols in more detail.

Lightweight consensus mechanisms

In a business environment, where trust between participants is high or at least partially present, you can come across one of the following more lightweight consensus methods. One of the most well-known consensus mechanisms, besides PoW and (delegated) PoS, is the practical byzantine fault tolerance (PBFT) method. It is used by many enterprise blockchain providers.

The difference between the previously-discussed sophisticated methods and PBFT is that this protocol is much more lightweight, since it does not require nodes to perform computations in order to create and verify blocks of transactions. With PBFT, every peer in the network maintains its own internal state, or their view on the current plan of actions. Transactions that are submitted to the network reach the validating peers at different times, so the order of transactions received doesn't have to be the same. In a given time period, peers that are fully in sync vote for a validating leader who chooses the sequence of transactions. The other peers use this sequence, in conjunction with their internal state, to perform a computation until they have the same sequence and consensus.

The following diagram shows you visually how this consensus mechanism works:

With PBFT, each peer might receive the same transactions in a different order, but broadcast their sequence to all other peers in order for validating peers to vote regarding the correct order

With PBFT, a consensus is reached based on the total number of decisions submitted by all peers. The consensus does not operate on the principle requiring that the majority of peers agree on a single decision submitted by a validating peer, but every decision that is sent. For every block, one of the validating pears is chosen as the leader, which will ultimately decide the final order of the transactions. So, if participant A sends one result sequence to participant B, and a different result sequence to participant C, then participant C would send this different result to participant B, who concludes that participant A has sent two different sequences. I will discuss the PBFT in more detail in Chapter 4, Blockchain 101 - Blocks, Chains, and Consensus.

Another similar consensus mechanism is the federated Byzantine agreement (FBA). It assumes that participants in a network know each other, and they can distinguish which participants are important to them and which are not. In contrast to PBFT, instead of listening to all votes coming in for a certain sequence, a validating peer waits for the majority of the nodes it considers to be important to agree on a transaction before it agrees to the transaction. The same goes for the other validating peers in the network. A transaction is considered verified once enough peers considered important by enough nodes have agreed on its legality.

Another up-and-coming consensus mechanism is called the Tangle protocol. It works a bit differently than the ones I have explained up until now, and it is not considered a blockchain. When you submit a transaction with the Tangle protocol, it is confirmed by the network if and when two other peers in the network have proofed your transaction. Therefore, it is different from the others since, at any given time, no single node helps maintain the entire ledger. Each node helps by adding or editing two transactions at a time. The protocol also stores the transactions on a directed acyclic graph (DAG) (https://en.wikipedia.org/wiki/Directed_acyclic_graph) rather than on a linked list. In short, a DAG is a graph without a directed cycle, such that there is no way to start at any vertex v and follow a consistently-directed sequence of edges that eventually loops back to v again, as shown in the following diagram:

Transactions connected into a DAG. Arrows are drawn from the child to the parent. G is the genesis transaction.

The Tangle protocol does not know the concept of miners either. Since each edge holds only one transaction, other users can easily perform validation and PoW. Thus, there are no fees or rewards for confirming transactions in the ledger, but in order to submit your own transaction, you need to proof two other transactions first.

Permissioned consensus

When setting up a private or consortium blockchain between well-trusted entities, you might not need a full-blown consensus protocol.

It might be sufficient to work with a permissions-only consensus. This capability describes a consensus method in which there is no PoW to be done to verify transactions. Rather, it is based on the authorization and granted permissions that a user has on the data. If a user has write privileges on a certain entity, then they are allowed to modify that entity's data. Some users might have all permissions on a system, whereas others only have read permissions on a specific type of entity. This consensus model is more in line with permission models used by a traditional database or web application.

Sharding consensus

A number of blockchain platforms currently available support a capability called sharding consensus. Sharding is a type of data partitioning that separates large databases into smaller, faster, and more manageable parts called shards. Some blockchains try to use sharding consensus to make the blockchain faster and more efficient by not having every validating peer validate the same data blocks. With sharding consensus, a validating peer is assigned to one of the partitions and is only responsible for validating transactions that are part of that partition. Other blockchains implement this capability by allowing participants to create private channels or subnets between specific peers in the network for the purpose of conducting private and confidential transactions, meaning peers can exchange transactions on a global ledger and exchange private transactions with other peers on a private channel. Participants who want to form a channel must be explicitly authenticated and authorized on that channel to transact and share updates on the ledger. Each channel has its own shared digital ledger and transactions log, and it must coexist in the same blockchain.

The incentive layer

The fourth layer of the stack is the optional incentive layer. This layer deals with the distribution of rewards that are earned by nodes in the network for the work they do to reach consensus. Whether this layer is implemented or not depends on the consensus mechanism in use. The following diagram shows the common capabilities that are part of this layer:

The capabilities of the incentive layer, including the distribution of rewards and transaction fees

The incentive layer include capabilities that describe what kinds of incentives are given by the network, when and how incentives can be earned by nodes, and the minimum amount of transaction fees needed to perform actions on the blockchain.

Rewards distribution and transaction fees

To run a successful public blockchain, there needs to be some kind of incentive program for individuals to join the network and to participate in the validation of transactions. As explained in the section on the consensus layer, what kind of work needs to be performed to reach consensus depends on the mechanism chosen by the network originator: the more difficult the PoW, the more elaborate the rewards distribution system.

A blockchain that uses PoW rewards the node (or miner) who solves the mathematical puzzle first when creating a new block. The node receives an amount of cryptocurrency in return. For example, Bitcoin currently has a block rewards of 12.5 coins, which halves every 210,000 blocks. With 144 blocks mined each day, it halves on average every four years. The miner that mines the block also receives all of the transaction fees. The total amount of transaction fees that the miner receives depends on the kind of transactions included in the block. The individual fee of a transaction is based on its size (in bytes), the age of its inputs (how long ago the coins spent were received), and the speed at which you want your transaction to be validated and verified. Thus, to submit a transaction successfully, you need to calculate the amount of the fee you need to pay in order for your transaction to be included by a miner in one of the next blocks. The higher the fee you must pay, the quicker your transaction is validated and verified. For example, in Bitcoin, the transaction fee for the next block can range between $5 and $35 USD.

A blockchain that uses PoS does not have a reward system for mining, or, in this case, forging a block of transactions. All of the digital currency is created in the beginning and can, for example, be bought and sold through exchanges and may also distributed as transaction fees. The node that does the proofing of the transactions will only receive the transaction fees included by the original submitters of the transactions. The amount of transaction fee the forger receives depends on the complexity of each individual transaction and the fuel needed to execute it. So, to submit a transaction successfully, once again you need to calculate the amount of the fee you need to pay in order for your transaction to be validated and verified in one of the upcoming blocks. When the amount is too low, it is possible that your transaction will remain in a pending status for a long time. You can then choose whether to resend it with a higher fee. Some blockchains, such as Ethereum, in addition to the transaction fee, also use a gas fee for the execution of the transaction, and when this is too low, your transaction will fail and you will lose the gas fee to the forger.

There are also consensus mechanisms that combine the two systems, such as Proof of Activity (PoA). With PoA, miners first have to solve a cryptographic puzzle to create a block. The winner then receives a block reward. This block, however, does not contain transactions—it only contains the address of the winner. Next, a group of validating nodes (forgers) is chosen to verify the transaction that will be added, and they receive a reward for validating transactions.

The application layer

The fifth and final (top) layer of the stack is called the application layer. This layer deals with providing the interfaces to access, program, and use the blockchain. The following diagram shows the common capabilities that are part of this layer:

The capabilities of the application layer, including the programmable smart contracts and APIs

The application layer includes capabilities that provide application interfaces on top of the blockchain, both out-of-the-box functionality and custom implementations. The capabilities describe how the digital ledger is implemented and exposed to the world, how smart contracts can be built and run on the blockchain, and how third-party applications can interact with the digital ledger and smart contracts.

Digital ledger

One of the core capabilities of the blockchain is the digital ledger, a type of database or system of records, which is distributed (shared, replicated, and synchronized) by the network layer among the participants in the network. The digital ledger records the transactions, such as the transfer of assets or data, from one participant to another, or among multiple participants in the network. Commonly, a key/value data structure is used to record these transactions and its assets. More advanced digital ledgers, such as the one used by Ethereum, NEO, and Hyperledger, also record smart contract code in the ledger as its own asset. Some digital ledgers have the ability to save the current state separately from the transactions log, which allows third-party applications to query the data easily without needing to replay the entire transaction log.

 

Smart contract

Another capability that is indispensable in a modern blockchain is smart contracts. A smart contract, also known as a cryptographic contract, governs interactions with the digital ledger, and it allows agreements between network participants to be executed automatically. Smart contracts can act as a complement, or substitute, for legal agreements. It is computer code that directly controls certain aspects of transactions under certain conditions. A smart contract not only defines the terms and conditions (rules and penalties) of an agreement, but it is also capable of automatically facilitating, executing, and enforcing the negotiation or performance of an agreement. A smart contract does this by taking the input, putting that input through the rules set out in the smart contract, and executing the required actions defined by those contractual clauses. For example, a smart contract could stipulate the pay-out on a shipping of perishables depending on when the shipment arrives. Shipments that arrive later than agreed to by both parties are free; otherwise, the importer automatically pays the grower the unit price × the number of units in the shipment.

RESTful and command-line APIs

For external clients and applications to interact with the blockchain, its ledger, and smart contracts, most platforms offer both a CLI (command-line interface) and a RESTful API (application programming interface). Such interfaces define a set of functions that developers can use to perform certain actions on the blockchain and receive responses via the HTTP protocol using the GET and POST method. The two interfaces differ in terms of functions supported. For example, you can use the command-line interface to control the settings of your node, whereas RESTful APIs can be used to invoke and query data on the blockchain. More advanced blockchain platforms also offer SDKs (Software Development Kits) for specific programming languages that are an abstraction layer on top of these APIs.

Decentralized applications

A capability that is still a very new concept is a decentralized application. A decentralized application (dApp) is a blockchain-enabled website that runs independently on every node of the peer-to-peer network, rather than on a single serve. They are comprised of both a frontend (web) application and a backend application, where the smart contract (backend application) allows it to connect to the blockchain. For example, a decentralized application includes the data model it uses (participants, assets, and transactions), an authorization and permissions model, smart contracts (backend), and a frontend web application. One public blockchain platform that supports this capability is Blockstack (http://blockstack.org).