Slide 1

Slide 1 text

Scaling Blockchain with state channels Koshik Raj

Slide 2

Slide 2 text

Agenda ● Blockchain scaling issues ● Layer 2 protocol basics ● State channels and side chains ● Lightning Network design ● Setting up LN nodes ● Interacting with LN nodes ● Basic LApp ● Raiden network ● Payment channel ● Payment network ● Benefits and limitations ● Getting started

Slide 3

Slide 3 text

Scaling issues in blockchain ● Remember CryptoKitties? 7 TPS 50,000 TPS ● Bitcoin cannot scale like centralized payment gateways such as VISA ○ In December, 2017, CryptoKitties clogged up Ethereum network due to increased transactions

Slide 4

Slide 4 text

Why doesn’t blockchain scale? ● CAP theorem states any distributed system cannot possess consistency, availability and partition tolerance properties ● Due to blockchain trilemma, any DLT can possess only 2 of the 3 properties Scalability Decentralization Security

Slide 5

Slide 5 text

How to scale? Layer 1 solution: ● Modifying the core blockchain consensus algorithms to support higher transaction rates: ● Increase the blocksize Layer 2 solutions: ● Take the transaction outside blockchain (offchain transactions) ○ State channels ○ Sidechains

Slide 6

Slide 6 text

Off-chain state channels Nodes create a channel and perform a series of transactions and commit only the final state to the blockchain Alice Bob

Slide 7

Slide 7 text

Lightning Network (LN) ● A layer-2 protocol built for Bitcoin based blockchain. ● It was created to reduce the transaction fee for micropayments. ● Lightning network essentially performs only 2 blockchain transactions for every channel ● Currently runs beta implementation on Bitcoin mainnet

Slide 8

Slide 8 text

A basic design ● Create a payment channel by committing initial funds ● Perform micro transactions using and update the funds in the channel ● Close and broadcast the final state at any time to include in the blockchain Alice Bob Multisig account

Slide 9

Slide 9 text

Channel commitments ● Alice and Bob can perform any number of operations. ● Every operation must create a commitment in the channel. ● Finally commit the last transaction to the blockchain Alice Bob 10 10 07 13 05 06 6.5 15 14 13.5 03 02 01 0.5

Slide 10

Slide 10 text

Trustless channel But there is a problem:“ What if either Alice or Bob commit any of the old commitment?” We need to create a trustless channel ● Solution 1: Time locked commitments ● Solution 2: Revocable commitments

Slide 11

Slide 11 text

Time locked commitments Alice Bob 10 10 07 13 05 06 6.5 15 14 13.5 03 02 01 0.5 +10 blocks +09 blocks +08 blocks +07 blocks

Slide 12

Slide 12 text

Routed payment channel in LN ● LN can perform transactions without creating a direct channel ● Routed payment system uses Hash time lock contracts (HTLC) ● HTLC makes sure that none of the actors in the routed channel can cheat Alice Carol Bob

Slide 13

Slide 13 text

Routed payment channel in LN ● Alice creates a routed channel with Carol via Bob ● Carol creates a Secret and shares only its hash value ● Alice constructs an HTLC worth 1.1 BTC and shares it with Bob ● Bob constructs an HTLC worth 1.0 BTC and shares it with Carol ● Funds are retrieved by Bob and Carol only after they disclose the secret 1.1 BTC 1.0 BTC 2.0 2.0 4.0 3.0 3.0 0.9 4.1 Alice Carol Bob

Slide 14

Slide 14 text

LN implementations ● There are several implementations of LN. Few of them are: ○ Lightning network daemon (Scala implementation by Lightning Labs) ○ C-lightning (C) ○ Eclair (Go) ● Huge number of apps (LApps) have been built using these LN implementations: ○ FileBazar - A marketplace for images, video. ○ Lightning Tip - Tipping service in LN ○ HamerCoin - RPG that uses LN for payment

Slide 15

Slide 15 text

Setting up Lightning nodes cluster 1. Install any LN node implementation 2. Configure the LN nodes with BTC node 3. Find other LN nodes and setup and connection 4. Create channels with the connected nodes

Slide 16

Slide 16 text

Other layer 1 scaling solutions ● Sharding ○ Provides solution to the Increasing size of blockchain ○ Ethereum is implementing sharding in the serenity release using PoS ● Improved consensus algorithms: ○ Variants of BFT (FBFT, DBFT) ○ PoS, DPoS, PoET, PoA

Slide 17

Slide 17 text

Raiden network ➔ Raiden Network is an off-chain scaling solution for performing ERC20-compliant token transfers on the Ethereum blockchain ➔ Ethereum’s version of Lightning Network ➔ Allows unlimited bidirectional transfers with the help of payment channels

Slide 18

Slide 18 text

Payment channel ➔ Initial balances are locked into the smart contract ➔ Micro payments are made through balance proof (Hash locks) ➔ Either of the participants will produce the final transaction to the blockchain

Slide 19

Slide 19 text

Payment channel network ➔ A network of channels to route a payment ➔ The network route should have enough token balance in the channels ➔ Optimised route will be selected for each transaction

Slide 20

Slide 20 text

Benefits of Raiden ➔ Instant settlement of the fund transfer ➔ Scales payment system in any of the ERC20 token services ➔ Provides greater privacy of the transactions through private channel

Slide 21

Slide 21 text

Limitations of Raiden ➔ Need to lock certain funds into the channel contract ➔ May not be suitable for payment needs of every use case ➔ May not find a suitable path for some of the transactions (higher value)

Slide 22

Slide 22 text

Getting started ➔ Connect to an Ethereum full node (Mainnet, Testnet or Private) ➔ Start the Raiden client ➔ Register/join Raiden network ➔ Create a channel and deposit token ➔ Create a transaction

Slide 23

Slide 23 text

Contact me: Koshik Raj linkedIn: koshikraj GitHub: koshikraj twitter: rajkoshik [email protected] www.koshikraj.com “keep calm and scale Bitcoin”