Note
If you are new to the blockchain technology, taking our Introduction to Blockchain Technology self-paced course is highly recommended. Also, for a comprehensive coverage of blockchain development in Ethereum or mastering Solidity programming, taking our below self paced courses is highly recommended:
Recap
In our previous article (How Plasma Chains Work in Ethereum), we covered how Plasma Chains work in Ethereum.
In this article, we learn how Sharding and Gasper work in Ethereum.
Ethereum sharding and Casper
As we mentioned earlier, sharding has been implemented in many distributed database systems. Essentially, sharding is a particular method for horizontally partitioning a large dataset within a database. More specifically, the database is broken into little pieces called shards. When aggregated together, they form the original database. In the following diagram, one large dataset can be sliced horizontally into two or more partitions, and each partition may be stored in separate database instances:
In a decentralized blockchain network, the network consists of a series of nodes connected in a peer-to-peer format, with no central authority. As is the case with current blockchain system, each node stores all states of the network and processes all of the transactions.
In order to match transaction scalability and throughput from Mastercard or Visa, Ethereum will have to process large volumes of transactions much faster. One logical way we discussed earlier is to increase the block size, but this may not be able to fundamentally address the scalability issues, since every node still needs to validate and verify a large block of more transactions. They will need more computing resources to handle the increased load. That is where sharding comes to help.
Not only the large volume of transactions can be sharded, but the entire peer-to-peer network of nodes can be grouped into smaller groups, also called shards. This greatly improves the parallel execution in the network, and scalability.
One-to-One Live Blockchain Classes
Coding Bootcamps school offers One-to-One Live Blockchain Classes for Beginners.
Imagine at any period, in order to process a large volume of transactions, you would need to have a really large block to be able to hold all the transactions submitted in this period. Instead of creating a larger physical block, what if you slice them into different smaller blocks, as in the following diagram, and have smaller blocks stored in the subset of network nodes? Similar to database sharding, in order to find all transactions and verify any particular transactions, you have to aggregate the transactions from all shards for that period. When you aggregate all transactions, you will have a virtual large block:
It looks like a simple concept, but complexity arises when dealing with maintaining the integrity and security of the Ethereum world state and transaction ledger across a subset of network partitions. Like any other blockchains, Ethereum maintains transactions and their ordering in the chain of blocks through a consensus mechanism. Furthermore, Ethereum also manages the account as a state object in the work state. A state object makes things much more complicated.
Let us take a look at how the transactions and data work in Ethereum sharding. As depicted in the following diagram, let us say the network is split into multiple groups and each group is an Ethereum shard. Transactions pertaining to each shard will be collected and added to the shard chain. A group of validators in the collator pool, stake their coins and become the validators in the PoS system. Let’s take a look at the following diagram:
Shard chain is similar to blockchain in concept. The miner’s role in Ethereum is split into three separate roles: collation proposer, collator, and executor. A collation is the same as a block in the blockchain. As the following diagram shows, at any time period, a collation proposer collects all transactions, and adds them to a proposed collation. Data blobs from transactions are packaged together into the collation body, a Merkle tree of the data blobs, and other shard identifier information is packaged as the collation header.
The collation proposer proposes the proposed collation to the collator, which is randomly selected from the validator pool. The collator’s role in this process is to validate the proposed collations and pass the collation header to smart contracts through the executor on the main chain. The collation headers from all shards will be added to blocks on the main blockchain:
The smart contract is also called a validator manager contract (VMC), as depicted in the preceding diagram. It is a shard-specific smart contract, deployed on the main chain. The VMC main role is to maintain the entire sharding systems and act as the connection between the main chain and the shard chain it links to. Its responsibilities include the following:
- Validate and maintain collation headers from each shard
- Manage a pool of collation proposers
- Manage a pool of collators and hold the collator’s stakes to enforce PoS and perform random sampling of collators for each shard
- Shuffle and pseudo-randomly select an eligible collator for each shard
- Process cross-shard transactions and record all cross-shard receipts
Cross-shard transactions, as discussed earlier, are one of the challenges that the sharding system faces. When a transaction happens across different shards, it is typically implemented through the cross-shard communications of transactions and receipts.
For example, suppose Alice from shard 1 needs to pay 100ETH to Bob on shard 2. The single transaction will be broken into two separate transactions: one is a debit transaction to draw 100ETH from Alice’s account on shard 1, and another one is the credit transaction of 100ETH made to Bob on shard 2. The following are the steps involved:
- One debit transaction of 100ETH deducted from Alice’s account on shard 1 is submitted to the main chain. A receipt is generated once the transaction is verified.
- Wait until the debit transaction is finalized.
- Submit the second credit transaction to deposit 100ETH to Bob’s account on shard 2, along with the original receipt from the debit transaction.
- A second receipt is generated once the debit transaction is processed. The receipt is sent back to Alice on shard 1, so that further account action can be taken.
Sharding, along with the PoS consensus mechanism, has the potential to drastically improve Ethereum’s scalability and increase the transaction throughput in Ethereum. There are too many moving parts in combining both layer 1 scalability solutions and creating a solid implementation. It has been handled in multiple phases, we will go over the current Ethereum 2.0 roadmap in later articles to discuss which different components should be implemented and when.
Next Article
In our next article (How Proof-of-Stack Consensus Works in Ethereum), we discuss how the Proof-of-Stack consensus is used in Ethereum.
This article is written in collaboration with Brian Wu who is a leading author of “Learn Ethereum: Build your own decentralized applications with Ethereum and smart contracts” book. He has written 7 books on blockchain development.
Resources
Free Webinars on Blockchain
Here is the list of our free webinars that are highly recommended:
- Hyperledger Fabric for system admin versus developers
- How to harness blockchain for environmental and corporate sustainability
- Review of Initial Coin Offering, Security Token Offering and asset tokenization use cases and best practices
- Hyperledger Fabric Deployment on Cloud
- Hyperledger Fabric for entrepreneurship- 21 blockchain business use cases
Free Courses
Here is the list of our 10 free self-paced courses that are highly recommended:
- IT Career Roadmap Explained
- Web Design with Bootstrap
- User Experience Best Practices
- Intro to Search Engine Optimization
- Web Design with WordPress
- Introduction to Drupal CMS
- Intro to Joomla CMS
- Intro to Cybersecurity
- Introduction to Cloud Technology
- Recorded Live Webinars and Classes
Self-Paced Blockchain Courses
If you like to learn more about Hyperledger Fabric, Hyperledger Sawtooth, Ethereum or Corda, taking the following self-paced classes is highly recommended:
- Intro to Blockchain Technology
- Blockchain Management in Hyperledger for System Admins
- Hyperledger Fabric for Developers
- Intro to Blockchain Cybersecurity
- Learn Solidity Programming by Examples
- Introduction to Ethereum Blockchain Development
- Learn Blockchain Dev with Corda R3
- Intro to Hyperledger Sawtooth for System Admins
Live Blockchain Courses
If you want to master Hyperledger Fabric, Ethereum or Corda, taking the following live classes is highly recommended:
- Live and self-paced blockchain development with Ethereum
- Live and self-paced blockchain development with Hyperledger Fabric
- Live and self-paced blockchain development with Corda
- Immersive Blockchain Bootcamp with live and self-paced courses
- Live crash course for learning Ethereum with Solidity
- Live crash course for building DApps with Hyperledger Fabric
- Live crash course for building DApps with Corda
- Live full-stack blockchain development in Hyperledger and Ethereum
Articles and Tutorials on Blockchain Technology
If you like to learn more about blockchain technology and how it works, reading the following articles is highly recommended:
- History and Evolution of Blockchain Technology from Bitcoin
- Overview of Blockchain evolution and phases from Ethereum to Hyperledger
- Comprehensive overview and analysis of blockchain use cases in many industries
- Blockchain Crowdfunding Security Token or Initial Coin Offerings
- A beginner Guide to Blockchain Technology
- How Decentralized Peer-To-Peer Network Works
- How blocks are added to the blockchain
- How Public and Private Keys of Cryptography Work
- What Is A Cryptographic Hash Function
- How Digital Signature Works In Blockchain
- The role and types of consensus mechanism in blockchain
- How Proof-of-Work Consensus Works in Blockchain
- How Proof of Stake Consensus works in Blockchain
Articles and Tutorials on Ethereum and Solidity
If you like to learn more about blockchain development in Ethereum with Solidity, reading the following articles and tutorials is highly recommended:
- Review of Architecture and Components of Ethereum
- Comprehensive Blockchain Ethereum Developer Guide from Beginner to Advance Level
- How to Write Ethereum Smart Contracts with Solidity in 1 hour
- Review of Architecture and Components of Ethereum
- How Ethereum Manages Accounts
- How Ethereum Manages Transactions
- How Smart Contracts Work in Ethereum
- How Ether and Gas Work in Ethereum
- How Ethereum Virtual Machine works
- How address and wallet work in Ethereum
- How mining works in Ethereum
- List of Tools and Technologies in Ethereum Ecosystem
- Review of challenges in distributed systems
- Review of Cap Theorem in Distributed Systems
- Horizontal Scaling versus Vertical Scaling in Distributed Systems
- How to Scale up Ethereum Blockchain Applications
- Review of scaling solutions for Ethereum
- How to Manage Ethereum State Channel with Raiden
- How Plasma Chains Work in Ethereum
- How Sharding and Gasper work in Ethereum
- How Proof-of-Stack Consensus Works in Ethereum
- A roadmap for Implementing Ethereum 2.0
- How to work with Decentralized Data and Content Storage in Ethereum
- How Decentralized Messaging with Whisper Works in Ethereum
- Review of Infura for Ethereum Development
- Review of Infura Ethereum API
- How to Use Remix with Infura for Ethereum Development
- How Ethereum Client API Works
- How Ethereum IPFS Storage Works
- How to Install and Start Ethereum IPFS Storage
- How to Run Ethereum IPFS Storage
- How to Work with Ethereum Swarm Storage
- How to Install Ethereum Swarm Storage
- How to Handle Ethereum Messages with Whisper
- Review of Popular Ethereum Smart Contract Libraries
- Review of Private and Permissioned blockchain
- How to Set up a Local Private Ethereum Blockchain
- How to Run Geth on a Local Private Ethereum Blockchain
- How to Build a Local Private Ethereum Blockchain with Mining
- How to Run Geth on a Local Private Ethereum Blockchain with Mining
- How to Create an Account on a Local Private Ethereum Blockchain
- How to Use Ethereum Optional Flags with New Chains
- Review of Ethereum Options for Development and Testing
- Review of Ethereum Developer Chain Options
- Review of Ethereum API and Console Options
- Review of Ethereum Networking Options
- Review of Ethereum Transaction Pool Options
Articles and Tutorials on Hyperledger Family
If you like to learn more about blockchain development with Hyperledger, reading the following articles and tutorials is highly recommended:
- Introduction to Hyperledger Architecture, Projects, Tools and Libraries
- Complete Review of Hyperledger Fabric Architecture and Components
- Hyperledger Fabric for System Administers versus Developers
- How to use Prometheus and Grafana to monitor Hyperledger Fabric
- Blockchain Developer Guide- How to Install Hyperledger Fabric on AWS
- Blockchain Developer Guide- How to Install and work with Hyperledger Sawtooth
- Blockchain Developer Guide- How to Install Hyperledger Burrow on AWS
- Blockchain Developer Guide- How to Install Hyperledger Iroha on AWS
- Blockchain Developer Guide- How to Install Hyperledger Indy and Indy CLI on AWS
- Blockchain Developer Guide- How to Install Hyperledger Seth and Docker on AWS
- Blockchain Developer Guide- How to Configure Hyperledger Sawtooth Validator and REST API on AWS
- Blockchain Developer Guide- How to Build Transaction Processor as a Service and Python Egg for Hyperledger Sawtooth
- Blockchain Developer Guide- How to Deploy Ethereum Smart Contracts with Hyperledger Burrow
- Blockchain Developer Guide- How to Create Cryptocurrency Using Hyperledger Iroha CLI
- Blockchain Developer Guide- How to Explore Hyperledger Indy Command Line Interface
- Blockchain Developer Guide- Comprehensive Blockchain Hyperledger Developer Guide from Beginner to Advance Level
- Introduction to Hyperledger Sawtooth Blockchain Development
Articles and Tutorials on R3 Corda
If you like to learn more about blockchain development on Corda , reading the following articles and tutorials is highly recommended:
Articles and Tutorials on Other Blockchain Platforms
If you like to learn more about blockchain development in other platforms, reading the following articles and tutorials is highly recommended: