1
Aprile 8th 2019 – Blockchain Devs, Milan
A l e s s a n d r o C o n f e t t i
2
Image from Julia Donaldson's books – in pictures
Alessandro Confetti - Aprile 8th 2019 – Blockchain Devs, Milan
IS THERE
SUCH A THING AS
A FAST BITCOIN
CHAIN?
QUESTIONS TO ASK YOURSELF…
3
Alessandro Confetti - April 26th 2018 – Politecnico, Milan
1.Who can set or change 

the rules of the protocol?
2.Who runs the nodes 

and pay for them?
3.Who can read 

and/or write 

the blocks?
4.Who validates the block 

and at which cost?
Source howmuch.net
4
Ok, I need a blockchain, but which one?
By Pavel Kravchenko Sep 26, 2016
Alessandro Confetti - Aprile 8th 2019 – Blockchain Devs, Milan
SLOW
FAST
5
Alessandro Confetti - Aprile 8th 2019 – Blockchain Devs, Milan
Source blockchainhub.net
STATE CHANNELS
Parties agree upon:
1.How to set initial state
2.How to handle state
changes
3.When and how to set
final state
6
Source The Basics of State Channels
Alessandro Confetti - Aprile 8th 2019 – Blockchain Devs, Milan
PAYMENT CHANNELS
1. Alice & Bob: agree upon the amount of money they
want to exchange, and how and/or up to when to
move the entire amount or fractions of it 

(aka smart-contract)
2. Alice & Bob: prove to own the amount of money in
their wallets and set it aside for each other on the
blockchain (aka funding transaction)
3. Alice or Bob: sends money to the each other on a
side-chain (aka commitment transactions)
4. Alice & Bob: close the transactions flow based on
the contract rules, and save the new balance
between Bob and Alice to their respective wallets or
refund them back if something goes wrong (aka
settlement transaction)
7
Alice Bob
bitcoin blockchain
side-chain transactions
mono-directional
Alice Bob
bitcoin blockchain
side-chain transactions
bi-directional
Alessandro Confetti - Aprile 8th 2019 – Blockchain Devs, Milan
PAYMENT CHANNELS
1. smart-contract:
• transaction-level timelocks (nLocktime)
• ARC (asymmetric revocable commitments) using script-
level timelocks (CHECKLOCKTIMEVERIFY)
• HTLC (Hash Time Lock Contracts) with script-level
timelocks (CHECKSEQUENCEVERIFY)
2. funding transaction:
• multisignature 2-of-2 address founded by both parties
and stored on the bitcoin blockchain
3. commitment transactions:
• bitcoin-like transactions starting from the founding
transaction using the same multisignature 2-of-2 as
input and parties’ wallets as output
4. settlement transaction:
• last bitcoin-like transaction saved back to the bitcoin
blockchain
8
• Problems:
• transaction-level timelocks: limited
channel life-time, transaction
number limited by blocks ahead
• Requires a channel for each
recipient
• Costs:
• transaction fees for initial and final
state persistence
• money is frozen until settlement
transaction
• Risks: contract safeguards levels
Alessandro Confetti - Aprile 8th 2019 – Blockchain Devs, Milan
Routed Payment Channels

(aka Lightning Network)
..allow any participant to route a payment 

from channel to channel without trusting 

any of the intermediaries.
Andreas M. Antonopoulos - Mastering Bitcoin, 2nd Edition [O’Reilly Media 2017]
9
The Bitcoin Lightning Network: Scalable Off-Chain Instant Payments (white paper)
Alessandro Confetti - Aprile 8th 2019 – Blockchain Devs, Milan
LIGHTNING NETWORK
10
Alessandro Confetti - Aprile 8th 2019 – Blockchain Devs, Milan
Source TheBlockPro.com
Alessandro Confetti - Aprile 8th 2019 – Blockchain Devs, Milan
LIGHTNING NETWORK
1. Alice: search for Eric’s LN node and ask for an hash of a secret
2. Alice: find out a route to Eric’s LN node
3. Alice: creates a HTLC with Eric’s hash with a +10 blocks refund,
payable to Bob if he knows the Eric’s secret
4. Bob: creates a HTLC with a +9 blocks refund payable to Carol
if she knows the Eric’s secret
5. Carol: creates a HTLC with a +8 blocks refund payable to
Diana if she knows the Eric’s secret
6. Diana: creates a HTLC with a +7 blocks refund payable to Eric
(that obviously he knows his own secret…)
7. Eric: claims the HTLC from Diana and gives her the secret
8. Diana: claims the HTLC from Carol and gives her the secret
9. Carol: claims the HTLC from Bob and gives him the secret
10. Bob: claims the HTLC from Alice
11. Diana: claims the or Bob: sends money to the each other
11
Alessandro Confetti - Aprile 8th 2019 – Blockchain Devs, Milan
Andreas M. Antonopoulos - Mastering Bitcoin, 2nd Edition [O’Reilly Media 2017]
LIGHTNING NETWORK
1. smart-contract:
• HTLC (Hash Time Lock Contracts) with script-level
timelocks (CHECKSEQUENCEVERIFY)
2. funding transaction:
• multisignature 2-of-2 address founded by both parties
and stored on the bitcoin blockchain
3. commitment transactions:
• bitcoin-like transactions starting from the founding
transaction using the same multisignature 2-of-2 as
input and parties’ wallets as output
4. settlement transaction:
• last bitcoin-like transaction saved back to the bitcoin
blockchain
5. Routing protocol:
• onion-routed protocol based on a scheme called Sphinx
• path is fixed at 20 hops padded with random data
12
• Benefits:
• privacy of transactions
• fungibility of the currency (limits
censorship and surveillance on
transactions)
• speed of transactions in millisecond
• micropayments
• increment of capacity of standard
bitcoin blockchain
• Costs:
• transaction fees for initial and final
state persistence
• transaction fees for each hop
• money is frozen until settlement
transaction for each channel
Alessandro Confetti - Aprile 8th 2019 – Blockchain Devs, Milan
LIGHTNING NETWORK
13
Alessandro Confetti - Aprile 8th 2019 – Blockchain Devs, Milan
Source eclair
LIGHTNING NETWORK
14
Alessandro Confetti - Aprile 8th 2019 – Blockchain Devs, Milan
Source bitcoinvisuals.com
WE ARE HIRING IN ITALY!
i n f o - i t @ t h o u g h t w o r k s . c o m
TECNOLOGY RADAR VOL19
https://info.thoughtworks.com/technology-radar-subscription.html
$ tail -f questions
16
Alessandro Confetti
aconfet@thoughtworks.com
twitter @zigolab 

blog http://blog.zigolab.it

What is lightning network and how it works.

  • 1.
    1 Aprile 8th 2019– Blockchain Devs, Milan A l e s s a n d r o C o n f e t t i
  • 2.
    2 Image from JuliaDonaldson's books – in pictures Alessandro Confetti - Aprile 8th 2019 – Blockchain Devs, Milan IS THERE SUCH A THING AS A FAST BITCOIN CHAIN?
  • 3.
    QUESTIONS TO ASKYOURSELF… 3 Alessandro Confetti - April 26th 2018 – Politecnico, Milan 1.Who can set or change 
 the rules of the protocol? 2.Who runs the nodes 
 and pay for them? 3.Who can read 
 and/or write 
 the blocks? 4.Who validates the block 
 and at which cost? Source howmuch.net
  • 4.
    4 Ok, I needa blockchain, but which one? By Pavel Kravchenko Sep 26, 2016 Alessandro Confetti - Aprile 8th 2019 – Blockchain Devs, Milan SLOW FAST
  • 5.
    5 Alessandro Confetti -Aprile 8th 2019 – Blockchain Devs, Milan Source blockchainhub.net
  • 6.
    STATE CHANNELS Parties agreeupon: 1.How to set initial state 2.How to handle state changes 3.When and how to set final state 6 Source The Basics of State Channels Alessandro Confetti - Aprile 8th 2019 – Blockchain Devs, Milan
  • 7.
    PAYMENT CHANNELS 1. Alice& Bob: agree upon the amount of money they want to exchange, and how and/or up to when to move the entire amount or fractions of it 
 (aka smart-contract) 2. Alice & Bob: prove to own the amount of money in their wallets and set it aside for each other on the blockchain (aka funding transaction) 3. Alice or Bob: sends money to the each other on a side-chain (aka commitment transactions) 4. Alice & Bob: close the transactions flow based on the contract rules, and save the new balance between Bob and Alice to their respective wallets or refund them back if something goes wrong (aka settlement transaction) 7 Alice Bob bitcoin blockchain side-chain transactions mono-directional Alice Bob bitcoin blockchain side-chain transactions bi-directional Alessandro Confetti - Aprile 8th 2019 – Blockchain Devs, Milan
  • 8.
    PAYMENT CHANNELS 1. smart-contract: •transaction-level timelocks (nLocktime) • ARC (asymmetric revocable commitments) using script- level timelocks (CHECKLOCKTIMEVERIFY) • HTLC (Hash Time Lock Contracts) with script-level timelocks (CHECKSEQUENCEVERIFY) 2. funding transaction: • multisignature 2-of-2 address founded by both parties and stored on the bitcoin blockchain 3. commitment transactions: • bitcoin-like transactions starting from the founding transaction using the same multisignature 2-of-2 as input and parties’ wallets as output 4. settlement transaction: • last bitcoin-like transaction saved back to the bitcoin blockchain 8 • Problems: • transaction-level timelocks: limited channel life-time, transaction number limited by blocks ahead • Requires a channel for each recipient • Costs: • transaction fees for initial and final state persistence • money is frozen until settlement transaction • Risks: contract safeguards levels Alessandro Confetti - Aprile 8th 2019 – Blockchain Devs, Milan
  • 9.
    Routed Payment Channels
 (akaLightning Network) ..allow any participant to route a payment 
 from channel to channel without trusting 
 any of the intermediaries. Andreas M. Antonopoulos - Mastering Bitcoin, 2nd Edition [O’Reilly Media 2017] 9 The Bitcoin Lightning Network: Scalable Off-Chain Instant Payments (white paper) Alessandro Confetti - Aprile 8th 2019 – Blockchain Devs, Milan
  • 10.
    LIGHTNING NETWORK 10 Alessandro Confetti- Aprile 8th 2019 – Blockchain Devs, Milan Source TheBlockPro.com Alessandro Confetti - Aprile 8th 2019 – Blockchain Devs, Milan
  • 11.
    LIGHTNING NETWORK 1. Alice:search for Eric’s LN node and ask for an hash of a secret 2. Alice: find out a route to Eric’s LN node 3. Alice: creates a HTLC with Eric’s hash with a +10 blocks refund, payable to Bob if he knows the Eric’s secret 4. Bob: creates a HTLC with a +9 blocks refund payable to Carol if she knows the Eric’s secret 5. Carol: creates a HTLC with a +8 blocks refund payable to Diana if she knows the Eric’s secret 6. Diana: creates a HTLC with a +7 blocks refund payable to Eric (that obviously he knows his own secret…) 7. Eric: claims the HTLC from Diana and gives her the secret 8. Diana: claims the HTLC from Carol and gives her the secret 9. Carol: claims the HTLC from Bob and gives him the secret 10. Bob: claims the HTLC from Alice 11. Diana: claims the or Bob: sends money to the each other 11 Alessandro Confetti - Aprile 8th 2019 – Blockchain Devs, Milan Andreas M. Antonopoulos - Mastering Bitcoin, 2nd Edition [O’Reilly Media 2017]
  • 12.
    LIGHTNING NETWORK 1. smart-contract: •HTLC (Hash Time Lock Contracts) with script-level timelocks (CHECKSEQUENCEVERIFY) 2. funding transaction: • multisignature 2-of-2 address founded by both parties and stored on the bitcoin blockchain 3. commitment transactions: • bitcoin-like transactions starting from the founding transaction using the same multisignature 2-of-2 as input and parties’ wallets as output 4. settlement transaction: • last bitcoin-like transaction saved back to the bitcoin blockchain 5. Routing protocol: • onion-routed protocol based on a scheme called Sphinx • path is fixed at 20 hops padded with random data 12 • Benefits: • privacy of transactions • fungibility of the currency (limits censorship and surveillance on transactions) • speed of transactions in millisecond • micropayments • increment of capacity of standard bitcoin blockchain • Costs: • transaction fees for initial and final state persistence • transaction fees for each hop • money is frozen until settlement transaction for each channel Alessandro Confetti - Aprile 8th 2019 – Blockchain Devs, Milan
  • 13.
    LIGHTNING NETWORK 13 Alessandro Confetti- Aprile 8th 2019 – Blockchain Devs, Milan Source eclair
  • 14.
    LIGHTNING NETWORK 14 Alessandro Confetti- Aprile 8th 2019 – Blockchain Devs, Milan Source bitcoinvisuals.com
  • 15.
    WE ARE HIRINGIN ITALY! i n f o - i t @ t h o u g h t w o r k s . c o m TECNOLOGY RADAR VOL19 https://info.thoughtworks.com/technology-radar-subscription.html
  • 16.
    $ tail -fquestions 16 Alessandro Confetti aconfet@thoughtworks.com twitter @zigolab 
 blog http://blog.zigolab.it