<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DEV Community: Arnab Chatterjee</title>
    <description>The latest articles on DEV Community by Arnab Chatterjee (@arnabkaycee).</description>
    <link>https://dev.to/arnabkaycee</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F375168%2F5af8cf4b-1058-4b30-ba23-42fdb080b7ba.jpeg</url>
      <title>DEV Community: Arnab Chatterjee</title>
      <link>https://dev.to/arnabkaycee</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/arnabkaycee"/>
    <language>en</language>
    <item>
      <title>Ethereum vs Hyperledger Fabric - A Deep dive Comparison - Part 2</title>
      <dc:creator>Arnab Chatterjee</dc:creator>
      <pubDate>Sun, 14 Feb 2021 10:50:29 +0000</pubDate>
      <link>https://dev.to/arnabkaycee/ethereum-vs-hyperledger-fabric-a-deep-dive-comparison-part-2-4ed0</link>
      <guid>https://dev.to/arnabkaycee/ethereum-vs-hyperledger-fabric-a-deep-dive-comparison-part-2-4ed0</guid>
      <description>&lt;h2&gt;
  
  
  Introduction
&lt;/h2&gt;

&lt;p&gt;Thank you for the overwhelming response to the first blog post on the rationale exploration for Blockchain Platform Architecture. In the first part, I discussed the basics of Distributed systems and their unreliability. However, when dealing with any system, architectural characteristics play a vital role in determining the system's quality. The ISO 25010 sets the standards of the quality characteristics that a software exhibits.&lt;/p&gt;

&lt;p&gt;Performance and Scalability are two of the keystone qualities that make any large scale systems usable. Remember, if we had a large computer with infinite resources, there would not be any distributed systems. So, distributed systems, being so, must always be performant and should scale so as not run out of business.&lt;/p&gt;

&lt;p&gt;However, a performant and scalable distributed system is anything but easy. There is a myriad of techniques to imbibe Performance and Scalability, each one always costing you something. Hybrid approaches do work but at the cost of complexity and manageability.&lt;/p&gt;

&lt;h2&gt;
  
  
  Enter the Block
&lt;/h2&gt;

&lt;p&gt;Scale and Performance in a Blockchain no matter how complex and diverse a topic can always be started with the Block. Why?&lt;br&gt;
Because it is the fundamental unit in a Blockchain that packs transactions. Imagine it like a medium to perform State Machine Replication of the database. It is similar to the economics of flying in business class versus economy. The difference is in the number of round trips when transactions need to be synced across nodes. Lesser the round trips, the more economical it becomes. The Block can contain transactions in the form of state changes. Each state change can be thought of as a set of key-value pairs proposed by users packed into a logical entity called a transaction.&lt;/p&gt;

&lt;h2&gt;
  
  
  Stitch 'em in a Chain
&lt;/h2&gt;

&lt;p&gt;So why do we need a chain of Blocks? A chain of Blocks is a way to determine the integrity of the data on the network. We all are familiar with the dynamics of how a Merkle hash tree works. It works on the magic of trapdoors and randomness of Hash Functions. These characteristics are incredibly crucial in how we perceive the characteristics of Blockchain. In the real sense, the chain signifies the permanence of data built using a form of a singular thread of Blocks that is always growing outwards.&lt;/p&gt;

&lt;p&gt;Ultimately, the hash's purpose is to establish a singular path from the leaf with the root ever-growing outwards.&lt;/p&gt;

&lt;p&gt;To give Blockchain's its immutable essence, every Block should be immutable. The hash function captures that. We all know that every Block contains the hash of the previous Block and how difficult it is to alter the Block's hash. But wait; is that all? How do we take the hash? Just pile up all the data and transactions (concatenate them) and take the resultant hash?&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Option A - hash all the data concatenated together&lt;/li&gt;
&lt;li&gt;Option B - Use Merkle trees&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;While both seem feasible, but virtually all the Blockchain platforms use option B. You may be wondering why?&lt;/p&gt;

&lt;h2&gt;
  
  
  Merkle Trees...The name seems familiar.
&lt;/h2&gt;

&lt;p&gt;While Blockchains are disgraced for encumbering nodes with all data from inception, it is not always the case that Blockchains are purely fueled by full nodes. Like big brothers, full nodes carry the load of the network by downloading all data from the network and validating transactions. But light nodes (of Ethereum and Bitcoin) work on the mechanism of Merkle Proofs.&lt;/p&gt;

&lt;p&gt;While piling up all the data side by side may work for immutability, it is not efficient when it comes to light clients.&lt;br&gt;
Light clients work on a concept of Merkle Proofs that leverage incremental build-up of the hash of N elements' to determine the presence of a transaction inside a Block. Merkle proofs provide a lightweight mechanism that enables the light clients (who do not store the whole Blockchain data) to verify transactions with a tiny fraction of the actual Block data. This enables the light clients to run in-sync with the full nodes while verifying Blocks only with headers, obviating the need for full-scale verification.&lt;/p&gt;

&lt;p&gt;Merkle proofs are based on a neat scheme devised by the famous computer scientist &lt;a href="https://en.wikipedia.org/wiki/Ralph_Merkle"&gt;Ralph Merkle&lt;/a&gt;. The scheme involves creating a binary tree of data present at the leaf level, where each leaf is hashed to give the next level of nodes. Here onwards, a pair of data is concatenated and hashed to form its parent. This is carried on until there is a single root called the Merkle root. The Merkle root forms the single hash representing the entire data.&lt;/p&gt;

&lt;p&gt;To verify the presence of a single data element, one does not need all the leaf nodes to calculate the root. This mechanism enables lightweight verification of the element by selecting a unique path called the Merkle proof corresponding to a leaf node (or element in question to be verified). Just select all the non-leaf nodes: the ommer (parent's sibling) nodes starting with the element, and then recursively until you reach the root. The nodes that path followed is the Merkle Proof of the element to be verified.&lt;/p&gt;

&lt;p&gt;So imagine if there are N elements to be stored, the proof would be as long as the depth of the tree, i.e. log(N).&lt;/p&gt;

&lt;p&gt;Vitalik Buterin has explained this concept in &lt;a href="https://blog.ethereum.org/2015/11/15/merkling-in-ethereum/"&gt;this article&lt;/a&gt;. I recommend reading it highly.&lt;/p&gt;

&lt;p&gt;Although things in the Fabric world are not different in using Merkle Trees, Fabric does not have a concept of light clients. The reason Merkle Trees why Fabric adopts Merkle trees are for optimizing data storage on-chain. For example, range queries supported by fabric chaincode use Merkle trees to optimize storage of a range of keys read in a transaction.&lt;/p&gt;

&lt;p&gt;So, now that we have questioned a few fundamentals about Blockchain. Let us discuss State and why it is so crucial to the Blockchain.&lt;/p&gt;

&lt;h2&gt;
  
  
  Blockchain was enough. Now, why this State?
&lt;/h2&gt;

&lt;p&gt;The State is the snapshot of the Ledger from inception till now. Let us come back to the famous example of chess. The Ledger is the list of all the moves you and your friend made from the game's start. But the State is how the board looks since the last move was played. The State gives a way to interpret the present, considering all the transactions that happened since inception. Without the State, to know Alice's balance, one has to get the books rolling afresh. The State can be thought of as a set of key-value pairs at their latest condition; checkpointed using a version number.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--vG4tiN3U--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/i/6xh325iy1yhvvs00l6s5.jpg" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--vG4tiN3U--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/i/6xh325iy1yhvvs00l6s5.jpg" alt="Alt Text"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  The State Juxtaposition
&lt;/h2&gt;

&lt;p&gt;Before we probe further into why Blocks tick the Blockchain and contrast the ledger platforms' Block structure, let us tour the mystery on how and why the State of Ethereum differs from that of Hyperledger Fabric.&lt;/p&gt;

&lt;h3&gt;
  
  
  The &lt;em&gt;Merkle Patricia Trie&lt;/em&gt; - Magically storing State of Ethereum
&lt;/h3&gt;

&lt;p&gt;Let us again go back to the Design Philosophy of Ethereum and Hyperledger Fabric. Ethereum is a public ledger and must store all details of all transactions that happened since inception. But do we really need to know how the past looks like? Even if we had to, we could always replay the transactions that appeared in each Block. Right? So, does it make sense to store all the history as State again? &lt;br&gt;
Yes, and, Ethereum does store history State. The rationale is discussed later in this post. But think for a moment, it is a gargantuan task to store the history since inception - like recording every single moment of your life in a camcorder. How does Ethereum manage to store the entire history? 🧐&lt;/p&gt;

&lt;h4&gt;
  
  
  Ethereum... History of the State... 🤯 How?
&lt;/h4&gt;

&lt;p&gt;The State of any system can be represented as a set of key-value pairs. In simple terms, keys can be account addresses, and value can be the balance. There are numerous mechanisms to store key-value pairs persistently. But storing the History state means storing a part of the State which was identical in the last Block and didn't change in the current Block, N times over.  This is highly inefficient, and Ethereum researchers had a nifty trick up their sleeve. Most Blocks would only store redundant information that didn't change since the last Block. To ensure tamper resistance of the states, the researchers tied the &lt;a href="https://en.wikipedia.org/wiki/Trie"&gt;Trie&lt;/a&gt; structure and Merkle Tree into a hybrid structure called Merkle Patricia Trie.&lt;/p&gt;

&lt;p&gt;The &lt;strong&gt;Merkle Patricia Trie (MPT)&lt;/strong&gt; isn't ordinary data structure. It is meant to solve multiple challenges at once.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Save Space by reusing and referencing old state elements (KV pairs).&lt;/li&gt;
&lt;li&gt;Solve the problem of proving the non-existence of an element in the State - which is not possible with a regular Merkle Tree&lt;/li&gt;
&lt;li&gt;Quick search of keys. Max number of traversals is the tree's height (which is the length of the keys in this case).&lt;/li&gt;
&lt;li&gt;Establish provenance of state changes by hashing state elements into an N-ary tree (where N = 17) into a single root. (N is 17 is because each node can branch into 16 different hexadecimal elements, and one place is reserved for a value.)&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Although somewhat cryptic, I will reuse the fantastic original visual representation of the &lt;a href="https://ethereum.stackexchange.com/questions/268/ethereum-block-architecture/6413#6413"&gt;Merkle Patricia Trie from Stack Exchange&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--2iG20sh5--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/i/m1grteym0752xbcezzdc.jpg" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--2iG20sh5--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/i/m1grteym0752xbcezzdc.jpg" alt="Alt Text"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Although intimidating, the MPT is a relatively simple concept to understand. There are three essential components:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Keys&lt;/strong&gt; - The key is the reference to find the value. In Ethereum, Keys are User or Contract addresses. Addresses have specific values. But a lot of Keys(addresses) have the same prefix. To avoid too many branches, keys with the same prefix are grouped together like in a Trie.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Values&lt;/strong&gt; - A value can be a number like a balance, the code of a smart contract or transaction receipts. The smart contract internally maintains the State of contract in a separate Merkle Patricia Trie called the storage trie. We discuss the smart contract storage in a separate post.&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;&lt;strong&gt;Nodes&lt;/strong&gt; - The unit of the tree. Each node is either an &lt;strong&gt;Extension node&lt;/strong&gt;,&lt;strong&gt;Branch Node&lt;/strong&gt; or a &lt;strong&gt;Leaf node&lt;/strong&gt;.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Extension nodes&lt;/strong&gt; - This is the divergent path node when key prefixes do not match. Each nibble (four bits) that correspond to the hexadecimal characters that match the Key prefix are stored as shared nibbles. In the example, &lt;code&gt;a7&lt;/code&gt; is the shared prefix for all the keys. So two nibbles &lt;code&gt;a&lt;/code&gt; and &lt;code&gt;7&lt;/code&gt; are stored at the root node a type of extension node. The next node is again a reference to a node, which can be either of an Extension, Branch or Leaf node.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Branch Node&lt;/strong&gt; - This is where the nibbles start getting really wiggly and differ significantly. There are 16 references. Each of them points to a different node whose nibble matches the single corresponding sequence in the key.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Leaf Node&lt;/strong&gt; - The ultimate of the trie, which usually ends in one or more nibbles in the keys. It contains a value.&lt;/li&gt;
&lt;/ul&gt;


&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;The punchline is that if you follow each nibble in an extension node, each reference in a branch node, and the leaf node key-end nibbles - the path you trace is the Key nibble by nibble. The value is stored in the leaf node. You may end at an intermediate node - and if there is a value in any of them, then that corresponds to the key traced by the nibbles so far.&lt;/p&gt;

&lt;p&gt;When a new Block is mined, and the current State is changed by the transactions in the Block, a new state root is formed. The new trie is constructed with the keys that changed in the transactions and reconstructing the entire state trie is avoided. Only the keys that change fork off to create a new part of the trie with new nodes, while part of the trie corresponding to the nodes where the keys did not change still refers to the old trie. In each Block, the State of the trie is a snapshot using a &lt;code&gt;KECCAK256&lt;/code&gt; hash function and stored as the state root in the Block header. This makes a lot of sense since there are millions of accounts in Ethereum that can change and reconstructing the entire State would be inefficient in terms of storage and computation.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--PKvMeAiZ--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/i/38b2btntmjusy9870fnn.jpg" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--PKvMeAiZ--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/i/38b2btntmjusy9870fnn.jpg" alt="Alt Text"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;The above diagram shows how the Merkle Patricia Trie changes from Block 654 when Dorothy(&lt;code&gt;a77d379&lt;/code&gt;) transfer 0.01 ETH to Emily (&lt;code&gt;a7ff377&lt;/code&gt;) who has just joined the network.&lt;/p&gt;

&lt;h3&gt;
  
  
  Ethereum History State, but why 😲?
&lt;/h3&gt;

&lt;p&gt;In simple words, Ethereum faced vicissitudes of forks and understands the importance of decentralization. In case of a mishap (a fork), it would be a gigantic task to recompute the State of a historical state from inception. Keeping old states means that the chain can quickly switch back to a relatively sane State. But would it make sense to store all the State since its inception? Of course not, that would mean keeping the provision to rollback to the genesis Block in case of a catastrophe. 😅 Of course, this would not happen because that would mean Ethereum prices would crash overnight. There would be a mass exodus of believers of Ethereum. So, Ethereum stores the last 128 states as history and &lt;a href="https://ethereum.stackexchange.com/questions/1229/difference-between-a-pruned-and-unpruned-blockchain?noredirect=1&amp;amp;lq=1"&gt;prunes the rest of them&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;Can I query the history state?&lt;/p&gt;

&lt;p&gt;Technically, one cannot query history. Still, events emitted by the Ledger are also stored on the Ledger and can be queried through Web3 APIs. However, querying the history state inside the smart contract itself is not possible. Ethereum does not allow the querying of the smart contract state because it prunes all historical States but the latest 128 Blocks.&lt;/p&gt;

&lt;h3&gt;
  
  
  Relax with the &lt;em&gt;Couch State&lt;/em&gt; in Hyperledger Fabric
&lt;/h3&gt;

&lt;p&gt;Unlike Ethereum, Hyperledger Fabric's State is quite simple. It uses a Couch database to store its ledger state. Couch DB is a document database where each document can be uniquely referred to by a unique key. Hyperledger Fabric allows the Smart contract developer to store keys (user-defined). These keys themselves form the State of the Ledger. Fabric also keeps track of the changes to a key. The approach is straightforward. It maintains a separate database that keeps track of all the keys changed and in what Block. It is then possible to query the history of that key using a Smart Contract API. Note that it is not the history state but a track of where the key has changed over time.&lt;/p&gt;

&lt;p&gt;The Couch database, apart from offering a key value pairs also offer a rich NoSQL querying interface to query Key-Value pairs using Mango Queries. Those familiar with SQL like queries can relate and imagine life without them. Mango Queries helps you find the relevant documents (Key-Value pairs) of interest with a querying language. This speeds up the querying process without having to traverse through every key in the database.&lt;/p&gt;

&lt;h2&gt;
  
  
  The Block Recipe
&lt;/h2&gt;

&lt;p&gt;Now that we have grasped an overwhelming lot about the State, I thank you for your patience and support for still reading. Let us now explore the Block of the Ledger. When talking about the fundamental structure of a Block, there are a few basics that all Block based ledgers follow. The Block would essentially consist of three things:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;The list of transactions&lt;/li&gt;
&lt;li&gt;The hash of the previous Block&lt;/li&gt;
&lt;li&gt;The Block number&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;In addition to this basic structure, each Block holds unique information about accountability. Accountability metrics answer the WHO of the Block.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Who sent the transactions?&lt;/li&gt;
&lt;li&gt;Who proposed the Block or the Block creator?&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;These metrics for accountability play a key role in the security of the Blockchain. The sender of the transaction needs to be identified for obvious reasons. However, the Block proposer needs to be identified for incentivizing or penalizing the Block creator. In the last post, we discussed the need for stakes. In a Block creation mechanism, there needs to be a leader, identifying the leader is imperative to maintain the sanity and security of the network.&lt;/p&gt;

&lt;h2&gt;
  
  
  Block Structure Compared
&lt;/h2&gt;

&lt;p&gt;Now that we know the lifeblood of the Block, let us trek further to understand the fundamental elements of the Ethereum and the Fabric Block.&lt;/p&gt;

&lt;h3&gt;
  
  
  Ethereum Block Structure
&lt;/h3&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--K0QSR7mE--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/i/ojo44e1caayj1ay6gi3r.jpg" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--K0QSR7mE--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/i/ojo44e1caayj1ay6gi3r.jpg" alt="Alt Text"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;When it comes to Ethereum, being a public Blockchain platform has a lot of Block data. The &lt;strong&gt;header&lt;/strong&gt; of the Block in Ethereum contains three essential elements.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;the essentials&lt;/strong&gt; - This comprises what every Block in a Blockchain should have, i.e., the parent Block hash and the Block number.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Block creator data&lt;/strong&gt; - This contains the details about the Block creator, the reward information, the total gas expenditure, the total gas limit imposed on the Block, the total gas used and the timestamp at which the miner mined the Block. This is to essentially know who has mined the Block for its accountability and establish the traceability of the new ethers introduced into the Blockchain. Without this information, there would be no provenance of where the new ethers came from.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;proof-of-work data&lt;/strong&gt; - This section essentially contains the proof that the miner has indeed mined the Block. This is the endorsement of the miner's work to mine new ethers into the system. Proof of Work (PoW) enables anyone to verify quickly and with ease - that sufficient computational energy has been spent to find the nonce that when hashed with the Block header hash (without the nonce) yields a value lower than a target. In other words, the miner did not introduce new Ethers out of thin air into the system with negligible or zero cost. This mechanism is detailed in the &lt;a href="https://eth.wiki/en/concepts/ethash/ethash"&gt;EthHash&lt;/a&gt; documentation.&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;data related to possible alternate chains&lt;/strong&gt; - Since Ethereum rewards competing miners who have solved the PoW challenge unlike Bitcoin, it is also necessary to keep accountability and provenance of the money introduced through the route of alternate chains. However, there is a caveat that Blocks that are introduced by Ommers (or uncles) can be referenced only till six Blocks from the Block of introduction. The reason for this is simple.&lt;br&gt;
Since Ethereum chooses the main chain by using GHOST (Greedy Heaviest Observed Sub Tree) protocol, there can be multiple parallel chains. If these chains grow too long, it would be extremely inefficient for the Blockchain to search and reference data during validation time. Imagine the Blockchain turning into a giant tree with ever-growing depth. It would be inefficient in traversing an unbalanced tree which is too deep to search. Along with the GHOST protocol restriction, the six-Block reference imposes an incentive to mine only on the longest chain.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;&lt;strong&gt;state-related data&lt;/strong&gt; - Ethereum keeps track of the State as well to ensure that states are consistent and non-repudiated across all Blocks. There are types of states.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;State Root - This is the MPT root of all the state changes in the current Block. This includes changes in State of user and contract accounts.&lt;/li&gt;
&lt;li&gt;Transactions Root - The MPT root of the transactions that were confirmed in the Block. Again MPT to the rescue to optimize storage and depth of the Merkle Tree.&lt;/li&gt;
&lt;li&gt;Receipts Root - The MPT root of the transaction receipt (the receipt you get after every transaction in Ethereum).&lt;/li&gt;
&lt;/ul&gt;


&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;The rest of the blocks just contain signed and validated transactions that the miner has accumulated and proposed as the block content. Each transaction holds information about the sender and the receiver of the transaction. In all cases, the sender (&lt;code&gt;from&lt;/code&gt;) is the User address, the receiver (&lt;code&gt;to&lt;/code&gt;) is user in case of direct Ether transfer or a contract in case of a contract invoke or a call. Contract invokes write data on the ledger, while calls just read. The value is the amount of ethers the user wants to send, while the data is applicable for contract calls to store &lt;code&gt;calldata&lt;/code&gt;.&lt;/p&gt;

&lt;h3&gt;
  
  
  Hyperledger Block Structure
&lt;/h3&gt;

&lt;p&gt;The Hyperledger Fabric Block looks different but contains some similiar characteristics as that of Ethereum.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--2zi5fmud--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/i/nqhdbce34ymve9ng8wz1.jpg" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--2zi5fmud--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/i/nqhdbce34ymve9ng8wz1.jpg" alt="Alt Text"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Block Header&lt;/strong&gt; - Let us start with the Block Header. It contains the essentials - previous Block hash, the Block number and the data hash. The data hash is principally the hash of the transactions in the Block wrapped in an Envelope. The Envelope is an overarching concept of the transaction that we will explore soon.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Block Data&lt;/strong&gt; - The Block data is a collection of Envelope; each wrapping a transaction. An Envelope contains more than the transaction proposed. But why enclose more data? Remember Part 1 of the article and how Fabric doesn't need to vet the transaction with all the participants in the network. To guarantee accountability and correctness, the transaction is send first as a proposal to interested parties in a &lt;em&gt;channel&lt;/em&gt; for verification. And these participants are a part &lt;em&gt;channels&lt;/em&gt;, the channel information is stored as well. So in a nutshell, the &lt;em&gt;Envelope&lt;/em&gt; contains.

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Header&lt;/strong&gt; - Information about the &lt;em&gt;channel&lt;/em&gt; and the creator of the transaction along with the signature.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Data&lt;/strong&gt; - Information about the transaction proposal, the endorsed response, along with the endorsements (signatures) of the stakeholders who endorsed the transaction proposal response.&lt;/li&gt;
&lt;/ul&gt;


&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;The endorsements capture the consent of the stakeholders in the transaction's outcome (validation). This furthers the accountability of the stakeholders in the transaction. We will discuss the details on Transaction flow including endorsements in a future article.&lt;/p&gt;

&lt;p&gt;Well, that is all. Thank you for reading so far in the journey to explore the Architectural rationale of Blockchain Platforms. We discuss Identity management of Blockchain Platforms and the rationale behind decisions in the next article. Thanks again and stay tuned.&lt;/p&gt;

</description>
      <category>ethereum</category>
      <category>hyperledger</category>
      <category>block</category>
      <category>architecture</category>
    </item>
    <item>
      <title>Ethereum vs Hyperledger Fabric - A Deep dive Comparison - Part 1</title>
      <dc:creator>Arnab Chatterjee</dc:creator>
      <pubDate>Thu, 29 Oct 2020 17:33:32 +0000</pubDate>
      <link>https://dev.to/arnabkaycee/ethereum-vs-hyperledger-fabric-a-deep-dive-comparison-part-1-2o7k</link>
      <guid>https://dev.to/arnabkaycee/ethereum-vs-hyperledger-fabric-a-deep-dive-comparison-part-1-2o7k</guid>
      <description>&lt;blockquote&gt;
&lt;p&gt;&lt;strong&gt;Caveat Emptor&lt;/strong&gt; - If you are concerned about the technical complexity of the article. Do not worry. I have tried to keep it jargon-free. So go ahead, enjoy and share your feedback.  &lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;&lt;em&gt;Credits: Thanks to Prateek Reddy Yammanuru for insights and reviews.&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;In this article, we deconstruct some of the similarities and differences between two of the most popular Blockchain Platforms - Hyperledger Fabric v2 and Ethereum v1 (as of 10th Oct 2020). The motive is simple. We have much material explaining the workings of each of these ledger platforms. However, there still does not exist a deep-dive comparison of these ledger platforms. 🧐&lt;/p&gt;

&lt;p&gt;Most ledger platform comparisons that I have stumbled discuss core features of the platforms like Consensus, Permissioning, smart contract language, and the likes. Personally, as a technology geek and a person who likes to dive deep and ask a lot of questions, these articles do not quench my thirst. 😅🍺&lt;/p&gt;

&lt;p&gt;So, as an aspiring Software Architect, I decided to make an attempt to understand these platforms deep and explore the fundamentals that make these Platforms tick and what claims the fame of these ledger platforms. &lt;/p&gt;

&lt;p&gt;I attempt to explore the architecture in four distinct areas. The overall functions that these ledger platforms provide, the architectural characteristics (also known as the non-functional requirements (NFRs)/ Quality Attributes / "ilities") that these functions are expected to exhibit, the architectural topology or simplified view, and finally some of the critical architectural decisions that were considered. &lt;/p&gt;

&lt;p&gt;This will be a six-part series of articles where I will attempt to take each of the fundamental concepts of a Blockchain Platform and attempt to expound them as it is architected in each of the platforms with the rationale behind it. I will also try to provide an essence of the key architectural considerations made while designing the platforms. &lt;/p&gt;

&lt;p&gt;I will try to explore the following areas, and in each, I try to cover three fundamental aspects. First is the need, second is key architectural considerations and finally the comparison. My goal is to be objective and non-partisan. For this, I will share the references to the sources from where I have obtained and compiled the information. &lt;/p&gt;

&lt;h2&gt;
  
  
  Comparison Areas
&lt;/h2&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;Area&lt;/th&gt;
&lt;th&gt;Covered In&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;Distributed Systems 101&lt;/td&gt;
&lt;td&gt;Part 1&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Overall Architecture&lt;/td&gt;
&lt;td&gt;Part 1&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Block Architecture&lt;/td&gt;
&lt;td&gt;Part 2&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Ledger &amp;amp; Storage&lt;/td&gt;
&lt;td&gt;Part 2&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Identity Management&lt;/td&gt;
&lt;td&gt;Part 3&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Transaction Lifecycle&lt;/td&gt;
&lt;td&gt;Part 4&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Smart Contracts &amp;amp; Ledger State&lt;/td&gt;
&lt;td&gt;Part 4&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Consensus Process&lt;/td&gt;
&lt;td&gt;Part 5&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Security&lt;/td&gt;
&lt;td&gt;Part 6&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Confidentiality&lt;/td&gt;
&lt;td&gt;Part 6&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;




&lt;h2&gt;
  
  
  Distributed Systems 101
&lt;/h2&gt;




&lt;p&gt;In this section, I attempt to break down the fundamental cogs that drive the Fabric Blockchain Operating system from the Ethereum Blockchain Operating system. Although mouthful it may sound, both of these platforms are irrefutably distributed in nature first - then decentralized. Hence all principles of distributed systems apply here. I believe it is fundamental to reason from the first principles of these. &lt;/p&gt;

&lt;p&gt;If you are not too familiar with distributed system principles, I cannot recommend &lt;a href="http://book.mixu.net/distsys/single-page.html"&gt;this&lt;/a&gt; article enough for a quick reckoner on Distributed systems. &lt;/p&gt;

&lt;p&gt;But let me take a quick plunge into the &lt;strong&gt;fundamentals of distributed systems&lt;/strong&gt;:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Distributed systems are composed of nodes or computers that are capable of computing (calculating), storing, and transmitting data.&lt;/li&gt;
&lt;li&gt;These computers are &lt;em&gt;Unreliable&lt;/em&gt; and so are the &lt;em&gt;communication channel(s)&lt;/em&gt; that connect them. Any or both can crash or malfunction at any point in time. &lt;/li&gt;
&lt;li&gt;Distributed systems do not have a global clock. Ever tried setting two electronic clocks precisely to the second (do it with two computers to the millisecond).&lt;/li&gt;
&lt;li&gt;Distributed systems are complicated. One does not design a distributed system if there was a monolith computer with infinite compute and storage.&lt;/li&gt;
&lt;li&gt;All systems are eventually intended to cater to Functional and Non-Functional needs. Non-Functional needs a.k.a. Quality Needs. Basic quality needs of any distributed system include Scalability, Performance, Availability, and Fault Tolerance.&lt;/li&gt;
&lt;li&gt;For reliability and availability, one needs to replicate data. Where there is replication involved in distributed systems, the famous CAP theorem applies. It says that you cannot have all three properties in a distributed system (which replicates data) at the same time, i.e. Consistency, Availability and Partition Tolerance. Try achieving any two, and you have to trade-off the other.
&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Let us start with the needs of a Blockchain Platform, discuss the rationale behind the architectural characteristics. &lt;/p&gt;




&lt;h2&gt;
  
  
  Contrast of Overall Architecture
&lt;/h2&gt;




&lt;h4&gt;
  
  
  Need: &lt;strong&gt;State Machine Replication&lt;/strong&gt;
&lt;/h4&gt;

&lt;p&gt;Any blockchain system is fundamentally a distributed database in the most simple terms. It needs to be consistent, that means all data in all the computer nodes has to be the same exactly. Note here; I am not emphasizing on time here. Consistency can be immediate or eventual. To replicate the state of the database, State Machine Replication is used. There are two ways to do replication. Active Replication and Passive Replication. Active replication is where every database server processes the request in a deterministic way (i.e. everyone produces the same output on a single input). To guarantee that all servers produce the same output, it has to be ensured that all servers receive all the inputs in the same order. This is ensured by &lt;em&gt;Atomic Broadcast&lt;/em&gt;. Atomic Broadcast says that the input should be received either by all servers or none. &lt;br&gt;
Passive replication is more of a &lt;em&gt;dictatorial&lt;/em&gt; in nature, which means that there is one master server executing the request and updates other servers with the execution result without blocking the client request. &lt;/p&gt;

&lt;h4&gt;
  
  
  Need: &lt;strong&gt;Smart Contract Execution or Agreement on the outcome of a business logic&lt;/strong&gt;
&lt;/h4&gt;

&lt;p&gt;Second-generation blockchain platforms work on the outcome of Smart Contracts, which is the custom business logic for determining the outcome of the transaction. However, there are subtleties involved here, and they are:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;em&gt;Who needs to execute the smart contracts and why is there a need to agree on the outcome?&lt;/em&gt; &lt;/li&gt;
&lt;li&gt;&lt;em&gt;What goes inside the ledger?&lt;/em&gt;&lt;/li&gt;
&lt;li&gt;&lt;em&gt;Is the agreement on the smart contract outcome different from the State Replication itself?&lt;/em&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Let us try to answer these fundamental questions subjective to each ledger platform.&lt;/p&gt;

&lt;h4&gt;
  
  
  &lt;strong&gt;&lt;em&gt;Who needs to execute the smart contracts and why is there a need to agree on the outcome?&lt;/em&gt;&lt;/strong&gt;
&lt;/h4&gt;

&lt;p&gt;Users who do not usually trust each other on the outcome of a transaction executes the smart contract. This helps one to verify the outcome is genuinely computed and has not been tampered. This dates back to the fundamental underpinnings of Bitcoin and cryptocurrency. Bank serves as the trusted arbiter to hold account balances for everyone. All banks universally operate on the same set of rules to maintain account balances. But if a nation or government or bank goes rogue, then what? This where secure computation comes into the picture. Smart contract execution ensures that every bank (hypothetically) executes the same logic and matches the outcome. &lt;/p&gt;

&lt;p&gt;Note the subtlety in the last line? Every bank needs to execute the contract to agree on the outcome. So, does this mean that a civilian like you or me should compute the outcome for every other transaction? Probably no. Why should you be concerned about a transaction happening between other parties? But Bitcoin and Ethereum enforce this. It mandates that all participating nodes must agree on the outcome of the transaction, even if one is not involved in the transaction. &lt;/p&gt;

&lt;p&gt;Moreover, there is not any need to bring store the transaction outcomes as well. This is the inception of the concept of Permissioned and private Blockchain platforms. So, if we delve into this a bit deeper, we would realize that:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Not everyone needs to store all transactions, and others would not be comfortable with sharing the data.&lt;/li&gt;
&lt;li&gt;Even a lesser proportion of the population would require actually to execute a transaction and agree on the outcome. &lt;/li&gt;
&lt;li&gt;Comparing 1 &amp;amp; 2, we can realize that there would be people who would be observers who are interested in storing the agreed outcome but not executing the transaction itself.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;So we can deduce that the state machine replication should be separated from the agreement on the outcome of the transaction by Smart Contract execution. &lt;/p&gt;

&lt;h4&gt;
  
  
  &lt;strong&gt;What goes inside the ledger?&lt;/strong&gt;
&lt;/h4&gt;

&lt;p&gt;The ledger should be composed of all the outcomes of transactions checkpointed using a specific mechanism called blocks, unlike databases, where checkpoints are granular to the level of transactions itself. Checkpoints in Blockchain are Blocks which comprises the transactions. &lt;/p&gt;

&lt;p&gt;The ledger then should contain all the delta updates (as transactions) that happened to the database checkpointed as blocks. Nodes in the network can either choose to store an irrefutable record of data and consent on the outcome of transactions (by executing smart contracts on the ledger data) or choose to store data as an observer, like a bank computer vs a bank vault. The ledger is merely the bank vault.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--zHxA_GnL--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/i/1br16ts8tmtaeac42ywn.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--zHxA_GnL--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/i/1br16ts8tmtaeac42ywn.png" alt="What goes in the ledger?"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h4&gt;
  
  
  &lt;strong&gt;Is the agreement on the smart contract outcome different from the State Replication itself?&lt;/strong&gt;
&lt;/h4&gt;

&lt;p&gt;This is a question related to the previous one. And the answer is yes. Everyone interested to agree on the outcome of the transaction needs to have an irrefutable copy but so do people who are just interested in a copy of the ledger. So, the State Machine Replication is what guarantees that all interested parties would get the replica of the ledger. &lt;/p&gt;

&lt;p&gt;Now, that we have established some fundamentals, we must realize that when we perform a transaction, we want both the steps to happen atomically (all or none). That means that relevant parties should agree on the outcome of the smart contract execution, and the appropriate parties should get a replica of the outcome of the transaction. &lt;/p&gt;

&lt;h4&gt;
  
  
  &lt;strong&gt;Different perspectives of Design Philosophy&lt;/strong&gt;
&lt;/h4&gt;

&lt;p&gt;As we know, Ethereum is famous for both dApps (i.e. it's the capability to host decentralized apps, leveraged by smart contracts) as well as it's acclaimed cryptocurrency. The backbone of trust in Ethereum is its backed cryptocurrency that allows to codify game-theoretic security and innoculate trust in the dApps. Likewise, the backbone of trust in Hyperledger platform is the consortial identity binding. &lt;br&gt;
In other words, the idea of trust is backed by some stake (like money, reputation, something that is dear to someone). In a public blockchain network which aims to be secure and conserve the privacy of the individual, money is at stake. In contrast, in a permissioned (i.e. known environment), the identity or the reputation is at stake. &lt;/p&gt;

&lt;p&gt;So, in a public network, to maintain the cryptocurrency or to enable cryptocurrency backed trust, all participants must host the ledger and run the base cryptocurrency codebase. And since the cryptocurrency is not bounded, its scope mandates every participant to run all the smart contracts ever hosted on the ledger. This essentially means that if you want to do transactions on the ledger, backed by the crypto trust; you have to vet not only who owns how much cryptocurrency but the transactions that alter the balances of the cryptocurrency as well - in this case, smart contract transactions. &lt;/p&gt;

&lt;p&gt;But in a permissioned network, participants are known to each other (i.e. the identity and reputation are at stake). So a rogue actor would think twice before ruining its own reputation. &lt;br&gt;
This gives a differentiating (edge) factor to permissioned chains. In the early days, communities used to serve the function of law and order. This is because the individuals of a community were tightly knit within that community, and the transactions were strictly within the community. As Globalization became more prevalent and transactional boundaries widened, central law and order became the need of the hour. A similar concept applies to consortial and public blockchain platforms. &lt;/p&gt;

&lt;p&gt;Let us explore how these distinct requirements shaped the architecture of both the ledger platforms.&lt;/p&gt;

&lt;h2&gt;
  
  
  &lt;strong&gt;Order-Execute vs Execute-Order-Validate&lt;/strong&gt;
&lt;/h2&gt;

&lt;p&gt;This title "Order-execute vs Execute-Order-Validate" is borrowed from the official &lt;a href="https://dl.acm.org/doi/10.1145/3190508.3190538"&gt;Hyperledger Fabric paper&lt;/a&gt;. Although I do not fully agree with the semantics, I still choose to borrow it for better relatability.&lt;/p&gt;

&lt;p&gt;Let us break down each of these steps &lt;em&gt;agnostic&lt;/em&gt; to any platform, and understand what these mean (not necessarily in that order). &lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Order&lt;/strong&gt;&lt;br&gt;
This is the fundamental step that tells which transactions should come first and what comes later. As a matter of fact, this is a really difficult (maybe even impossible) problem to solve. Remember distributed system fundamentals? If we have to find an order, we have to find a way to measure order. Time is out of the equation first because there is no global clock. In Distributed systems (especially Decentralised systems) it is not possible to decide on the order of N transactions taking consent of all the stakeholders (or at least the majority). It would be extremely inefficient to get everyone to agree on the order of transactions. So who decides the order? Well, someone dictates, and everyone agrees. But who dictates and the legitimacy of the ordering comes at a cost (at least, and incentive in some instances) which we would discuss more in our &lt;em&gt;Consensus&lt;/em&gt; discussion. &lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Execute&lt;/strong&gt;&lt;br&gt;
To decide on the next state of the ledger, one has to execute the transactions and derive on the next state unanimously. So, we saw that the order step has to order the transactions in a block. After executing the set of transactions in the next proposed block, everyone arrives at the next state (or the next block). Note that this transaction is sequential, which impacts the overall throughput. However, this can hardly be cited as a disadvantage because of the universality of the transactions and the ledger state. &lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Validate&lt;/strong&gt;&lt;br&gt;
This step encompasses the order and the execution step. When the transaction first is constructed, it has to be verified of the semantics, account balance, transaction fee paid (if applicable). Likewise, when the transaction is executed on the current state after the block is propagated, it has to be checked for proper state validations like dirty or phantom reads, race conditions, and header validations.&lt;/p&gt;

&lt;p&gt;Now let us contextualize each of these steps for Ethereum and Fabric by examining the transaction flow of each of the platforms and earmarking each of the above steps in the overall flow.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Ethereum - Transaction Flow&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;The forward transaction flow involves the flow of the transaction starting from the client (here a mobile dApp). The immediate full node &lt;strong&gt;&lt;em&gt;validates&lt;/em&gt;&lt;/strong&gt; the transactions for necessary checks like checking the transaction nonce, checking sufficiency of the gas price (transaction fees), transaction semantics, etc. The transactions continue to move through the network in the transaction pool (with its brothers) from full node to full node until it stumbles across a miner. Keep a note that the transaction has not been &lt;strong&gt;&lt;em&gt;executed&lt;/em&gt;&lt;/strong&gt;.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--Pz6DZClG--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/i/sx1jpmt0quvmb0fapaw3.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--Pz6DZClG--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/i/sx1jpmt0quvmb0fapaw3.png" alt="Eth Transaction Flow 1"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Like this, the transaction reaches other competing miners too who also want to compete to mine the block. So one lucky miner who solves that PoW puzzle first gets to propose the block. I will discuss this in detail in the Consensus architecture post. However, three things happen at the miner and in order:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;&lt;em&gt;Order&lt;/em&gt;&lt;/strong&gt; - The miner orders the block based on a predefined strategy. Mostly this strategy is one that yields him the maximum revenue per block. &lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;&lt;em&gt;Execute&lt;/em&gt;&lt;/strong&gt; - The miner executes the transactions to ensure the transactions correctly apply against the current state (as perceived by the miner) of the ledger, and it generates logically correct the next state for each account (this includes Externally Owned Accounts and Contract Accounts). If some transactions do not generate logically correct next state, the transaction is dropped. &lt;/li&gt;
&lt;li&gt;PoW and Broadcasting - The final set of transactions obtained in the previous step is put in a block, the PoW nonce is computed, and the block is constructed with all relevant details and broadcasted to the nodes.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;&lt;em&gt;Validate&lt;/em&gt;&lt;/strong&gt; - Each transaction is again vetted against the current perceived state in each full node before it accepts the block. Conceptually, the full node has the liberty to reject the block, but this does not happen in practice, because the miner spends stake (compute) to mine a block, it is not rational for him to mine a block which won't be accepted by other nodes. &lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;em&gt;Why do I say perceived state? Because each full node can run independently on a different blockchain. But ultimately the chain merges using a protocol called GHOST (Greedy Heaviest Observed Subtree).&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--Sml8HQGo--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/i/s31fefuybh811ui24g70.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--Sml8HQGo--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/i/s31fefuybh811ui24g70.png" alt="Eth Transaction Flow 2"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;So if you observe the overall flow is not just "&lt;strong&gt;Order&lt;/strong&gt; &amp;gt; &lt;strong&gt;Execute&lt;/strong&gt;" but is "&lt;strong&gt;Validate&lt;/strong&gt; &amp;gt; &lt;strong&gt;Order&lt;/strong&gt; &amp;gt; &lt;strong&gt;Execute&lt;/strong&gt; &amp;gt; &lt;strong&gt;Validate&lt;/strong&gt;" considering all the nuances.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Hyperledger Fabric - Transaction Flow&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--yD4CPznu--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/i/fi7maycguo6m620lpd5t.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--yD4CPznu--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/i/fi7maycguo6m620lpd5t.png" alt="Hyperledger Fabric Transaction Flow"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Execute&lt;/strong&gt;&lt;br&gt;
Like we did for Ethereum's transaction flow, the transaction flow for Fabric can be decomposed into two parts. Before ordering (mining) and after ordering. In the first half, the client selectively broadcasts the transaction to organizations for endorsement (endorsing peers). &lt;/p&gt;

&lt;p&gt;Few things to take note here. First, unlike the ocean of full nodes in Ethereum, the nodes who &lt;strong&gt;execute&lt;/strong&gt; the transaction is known upfront. This means the rule to determine a transaction as valid, i.e. who is needed to endorse or approve a transaction is decided upfront. Parties not interested in the endorsement but just the transaction can only receive the block. So postponing the &lt;em&gt;execute&lt;/em&gt; till the last is not an option. But the &lt;em&gt;validation&lt;/em&gt; can be delayed because it is the ultimate step. &lt;/p&gt;

&lt;p&gt;Each of the endorsing peer &lt;em&gt;validates&lt;/em&gt; the Transaction Execution Proposal with authenticity and authorization checks. Then the transaction is executed on &lt;em&gt;the current state&lt;/em&gt; of the ledger. Each endorsing peer generates &lt;em&gt;signed "Read-Write Sets"&lt;/em&gt; as a response. The endorsing peers have the liberty not to respond too. The "Read-Write set" is that &lt;em&gt;delta&lt;/em&gt; that adds on the current state of the ledger to determine the next state of the block. The onus of executing the actual transaction is only to the &lt;em&gt;endorsing peers&lt;/em&gt; who want to execute and compute the next state of the ledger is actually on who is interested. So this sort-of-voluntary mechanism eliminates the need for any gas or transaction fees which was otherwise introduced in Ethereum to cater to the Halting Problem. However, the halting problem is still not fully solved. We will discuss more how the halting problem is further catered in the Consensus article. (sneak-peek: Fabric encourages each organization to host its own source code for the smart contract, thereby eliminating the need to trust smart contracts written by others. So, the more complex or bad code your organization develops, the more compute you spend).&lt;/p&gt;

&lt;p&gt;In the end, the client collects these endorsement responses and sends them to the orderer along with the original transaction proposal to the orderer.  &lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Order&lt;/strong&gt; &lt;br&gt;
The client sends the transaction to a predetermined orderer or miner. Why is this the case? This is because the ordering is a crucial task. There is more accountability than reward here. Because of such high responsibility, Fabric introduces a separate concept (and status) of Orderer Organization who is identified as &lt;em&gt;the&lt;/em&gt; organization authorized to order transactions of a consortium. Although we may argue about the incentive and stake in such a private blockchain network, we park that discussion for a different thread. When the transaction and other transactions reach the orderer, the transactions are &lt;strong&gt;ordered&lt;/strong&gt; (based on the orderer consensus algorithm, like Raft) block can be formed based on some set parameters like Block size, block time and the number of transactions in a block. &lt;br&gt;
Once again, the temporality relation of these transactions is entirely subjective to the orderer. &lt;br&gt;
Next, these transactions are broadcasted to all peers, including ones who did not &lt;em&gt;execute&lt;/em&gt; the transaction (committing peers). An endorsing peer is a committing peer too. &lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Validate&lt;/strong&gt; &lt;br&gt;
The transaction is then &lt;strong&gt;validated&lt;/strong&gt; to check for sufficient endorsements (if the required stakeholder organizations have responded with the "Read-Write Set"), version checks against &lt;em&gt;the current state&lt;/em&gt; (done through Multiversion Concurrency check) and most importantly, if all the signed &lt;em&gt;endorsement responses (Read-Write Sets) are the same&lt;/em&gt;. This is the consensus on the next state of the ledger. There is no scope for inconsistent of ledger states here. &lt;br&gt;
This is because, in a private environment, where you have already &lt;em&gt;predetermined&lt;/em&gt; who would endorse the transaction and &lt;em&gt;prevalidated&lt;/em&gt; the transactions, there is no second scope of perceiving different states of the ledger. &lt;br&gt;
Once validated, the block is either appended if correct or rejected in full if the validation fails.&lt;/p&gt;

&lt;p&gt;Moreover, since this entire process happens in a microcosm of the ledger called the channels, the peers, orderers and data can be scoped out based on the privacy needs of the consortium. Channels being the microcosm greatly facilitate the confidentiality and the performance of the ledger. This means every channel hosts its own smart contract, requires a subset of the endorsing peers which means unrelated parallel operations is possible.&lt;/p&gt;

&lt;p&gt;Summarising, the overall flow is "&lt;strong&gt;Validate&lt;/strong&gt; &amp;gt; &lt;strong&gt;Execute&lt;/strong&gt; &amp;gt; &lt;strong&gt;Order&lt;/strong&gt; &amp;gt; &lt;strong&gt;Validate&lt;/strong&gt;" considering all the nuances.&lt;/p&gt;

&lt;p&gt;Well, if you made it this far, I thank you and congratulate you for reading this article. &lt;/p&gt;

&lt;p&gt;Thanks. Stay tuned for Part 2 where we dive deep into Block Architecture and Ledger Storage.&lt;/p&gt;

</description>
      <category>blockchain</category>
      <category>architecture</category>
      <category>ethereum</category>
      <category>hyperledger</category>
    </item>
  </channel>
</rss>
