willcl-ark
    • Create new note
    • Create a note from template
      • Sharing URL Link copied
      • /edit
      • View mode
        • Edit mode
        • View mode
        • Book mode
        • Slide mode
        Edit mode View mode Book mode Slide mode
      • Customize slides
      • Note Permission
      • Read
        • Only me
        • Signed-in users
        • Everyone
        Only me Signed-in users Everyone
      • Write
        • Only me
        • Signed-in users
        • Everyone
        Only me Signed-in users Everyone
      • Engagement control Commenting, Suggest edit, Emoji Reply
    • Invite by email
      Invitee

      This note has no invitees

    • Publish Note

      Share your work with the world Congratulations! 🎉 Your note is out in the world Publish Note

      Your note will be visible on your profile and discoverable by anyone.
      Your note is now live.
      This note is visible on your profile and discoverable online.
      Everyone on the web can find and read all notes of this public team.
      See published notes
      Unpublish note
      Please check the box to agree to the Community Guidelines.
      View profile
    • Commenting
      Permission
      Disabled Forbidden Owners Signed-in users Everyone
    • Enable
    • Permission
      • Forbidden
      • Owners
      • Signed-in users
      • Everyone
    • Suggest edit
      Permission
      Disabled Forbidden Owners Signed-in users Everyone
    • Enable
    • Permission
      • Forbidden
      • Owners
      • Signed-in users
    • Emoji Reply
    • Enable
    • Versions and GitHub Sync
    • Note settings
    • Note Insights
    • Engagement control
    • Transfer ownership
    • Delete this note
    • Save as template
    • Insert from template
    • Import from
      • Dropbox
      • Google Drive
      • Gist
      • Clipboard
    • Export to
      • Dropbox
      • Google Drive
      • Gist
    • Download
      • Markdown
      • HTML
      • Raw HTML
Menu Note settings Versions and GitHub Sync Note Insights Sharing URL Create Help
Create Create new note Create a note from template
Menu
Options
Engagement control Transfer ownership Delete this note
Import from
Dropbox Google Drive Gist Clipboard
Export to
Dropbox Google Drive Gist
Download
Markdown HTML Raw HTML
Back
Sharing URL Link copied
/edit
View mode
  • Edit mode
  • View mode
  • Book mode
  • Slide mode
Edit mode View mode Book mode Slide mode
Customize slides
Note Permission
Read
Only me
  • Only me
  • Signed-in users
  • Everyone
Only me Signed-in users Everyone
Write
Only me
  • Only me
  • Signed-in users
  • Everyone
Only me Signed-in users Everyone
Engagement control Commenting, Suggest edit, Emoji Reply
  • Invite by email
    Invitee

    This note has no invitees

  • Publish Note

    Share your work with the world Congratulations! 🎉 Your note is out in the world Publish Note

    Your note will be visible on your profile and discoverable by anyone.
    Your note is now live.
    This note is visible on your profile and discoverable online.
    Everyone on the web can find and read all notes of this public team.
    See published notes
    Unpublish note
    Please check the box to agree to the Community Guidelines.
    View profile
    Engagement control
    Commenting
    Permission
    Disabled Forbidden Owners Signed-in users Everyone
    Enable
    Permission
    • Forbidden
    • Owners
    • Signed-in users
    • Everyone
    Suggest edit
    Permission
    Disabled Forbidden Owners Signed-in users Everyone
    Enable
    Permission
    • Forbidden
    • Owners
    • Signed-in users
    Emoji Reply
    Enable
    Import from Dropbox Google Drive Gist Clipboard
       owned this note    owned this note      
    Published Linked with GitHub
    Subscribed
    • Any changes
      Be notified of any changes
    • Mention me
      Be notified of mention me
    • Unsubscribe
    Subscribe
    --- title: the Lightning Network tags: Slides description: An introduction to the Lightning Network slideOptions: transition: 'fade' --- <style> .reveal { font-size: 36px; } </style> # The Lightning Network --- ## About me - Materials Engineer - Self-taught programmer ( Python, C++, Rust, Bitcoin) - Lightning Engineer at Gotenna / Global Mesh Labs - Teacher at Qala ([qala.dev](qala.dev)) --- ## Survey --- ## What is Lightning? ---- Lightning _is_ bitcoin ---- ## Lightning vs. Bitcoin - Better sender privacy - Lower transaction fees - Instant settlement - Enables micropayments ---- ## How to use Lightning 1. Get a Lightning wallet 1. Send bitcoin to Lightning wallet 1. Open a channel (often automatic) 1. Send / recv transactions ---- <iframe width="1024" height="600" style="background: #FFFFFF;" data-src="https://jochen-hoenicke.de/queue/#BTC,24h,weight" data-preload></iframe> ---- <iframe width="600" height="600" style="background: #FFFFFF;" data-src="https://mempool.jhoenicke.de/lightning/" data-preload></iframe> --- ## Why not scale bitcoin? ---- ### Bitcoin scalability - Poor - Every node validates every transaction - Requires global consensus - Block size ~ 1.7MB - Time between blocks ~ 10 min - ~ 3 tx/second ---- ### Response to Bitcoin Satoshi: > I've been working on a new p2p electronic cash system... James Donald: > We very, very much need such a system, but the way I understand your proposal it does not seem to scale to the required size. ---- ### Scaling approaches - Reduce transaction size :x: - SegWit - Increase block size / speed up block time :x: - Only a linear increase - Affects decentralisation; bandwidth, CPU, disk space etc. ---- ### Scaling approaches - Segment network :heavy_check_mark: - Don't make everyone validate every transaction - Can maintain security & trustlessness - Aggregate many payments into fewer payments :heavy_check_mark: ---- ## Aggregating payments - Like a bar tab :beer: 1. Set up 2. Make (many) payments 3. Settle them all with a single transaction at the end ```mermaid flowchart LR S[set up tab] F[settle tab] subgraph P[make many payments] direction TB bar tx1 tx2 tx3 ... tx1 --> bar tx2 --> bar tx3 --> bar tx4 --> bar ... --> bar end S ---> P P ---> F ``` --- ## Payment Channels - Many bitcoin transactions can be aggregated into two: 1. Open the channel (set up tab) <span style="color:#98c379">... many payments can take place here, just don't broadcast them! ...</span> 2. Close the channel (settle tab) ---- ### How a simple payment channel operates ```mermaid flowchart LR Alice Bob Alice2[Alice] Open[channel open] Tx1[channel close v1] Tx2[channel close v2] Tx3[channel close v3] Tx4[channel close n] Close[channel close n] classDef onchain fill:orange,stroke:#333,stroke-width:3px; classDef offchain fill:green,stroke:#333,stroke-width:3px,color:white; class Open,Close onchain; class Tx1,Tx2,Tx3,Tx4 offchain; subgraph updates[ ] direction TB Tx1 -- Alice pays Bob 1\nAlice:4 Bob:1 --> Tx2 Tx2 -- Alice pays Bob 1\nAlice:3 Bob:2 --> Tx3 Tx3 -- Alice pays Bob 1\nAlice:2 Bob:3 --> Tx4 end Alice -- 5 --> Open Open --> updates updates --> Close Close -- 2 --> Alice2 Close -- 3 --> Bob ``` ---- ### Problems with these payment channels - Mono-directional - Need a direct channel with everyone you want to pay Only really useful for recurring payments with a single counterparty --- ## Lightning payment channels 1. Use <span style="color:#98c379">multisignature</span> bitcoin transactions to setup and update the channel 2. Use <span style="color:#98c379">revocable</span> transactions so that old versions can be made invalid 3. Allow <span style="color:#98c379">multi-hop</span> payments over multiple connected channels ---- ### How a Lightning channel operates ```mermaid flowchart LR Alice Bob Alice2 Bob2 Open[channel open] Tx1[channel close v1] Tx2[channel close v2] Tx3[channel close v3] Tx4[channel close n] Close[channel close n] classDef onchain fill:orange,stroke:#333,stroke-width:3px; classDef offchain fill:green,stroke:#333,stroke-width:3px,color:white; class Open,Close onchain; class Tx1,Tx2,Tx3,Tx4 offchain; subgraph updates[ ] direction TB Tx1 -- Alice pays Bob 4\nAlice:1 Bob:4 --> Tx2 Tx2 -- Bob pays Alice 3\nAlice:4: Bob:1 --> Tx3 Tx3 -- Alice pays Bob 1\nAlice:3 Bob:2 --> Tx4 end Alice -- 5 --> Open Bob -- 0 --> Open Open --> updates --> Close Close -- 3 --> Alice2 Close -- 2 --> Bob2 ``` ---- ### Multisignature - Transaction must be signed by both participants before valid - Stops spending the coins unilaterally ```mermaid flowchart LR Alice Bob MS[2-of-2 Multisig] MS1[...] Alice-- signed by Alice -->MS Bob-- signed by Bob -->MS MS-- signed by Alice + Bob -->MS1 ``` ---- ### Revocable transactions ```mermaid sequenceDiagram %%{init: { "sequence": { "wrap": true, "width":300, "height":30} } }%% Alice->>Bob: <br/>Sign new transaction Bob->>Alice: <br/>Revoke previous transaction (send secret) Bob->>Alice: <br/>Sign new transaction Alice->>Bob: <br/>Revoke previous transaction (send secret) ``` ---- ### Multi-hop channels If we had channels between Alice + Bob, Bob + Carol and Carol + Dave: ```mermaid flowchart LR Alice Bob Carol Dave Alice<--->Bob Bob<--->Carol Carol<--->Dave ``` We want Alice to be able to safely pay Dave without trusting anyone: ```mermaid flowchart LR Alice Bob Carol Dave Alice-. 0.25 .->Bob Bob-. 0.25 .->Carol Carol-. 0.25 .->Dave ``` This would greatly increase the number of people we could make payments to --- ## Lightning payments :zap: Lightning payments are exactly these revocable, multi-hop off-chain Bitcoin transactions :tada: - No need to make channels to everyone - Can send to anybody else in the network you can make a path to --- ## Lightning problems - Onboarding - Liquidity - Routing - Privacy - Trust - Liveness --- ### Onboarding - Need an on-chain transaction to both open and close a channel - If you can't get space for your tx in a block, risk being cheated! --- ## Liquidity - Like beads on an abacus - Can only send if there is sufficient liquidity in the right direction - Can limit transaction value <img src="https://miro.medium.com/max/1400/1*h3R-vZLFYugnghEF405QOg.gif"> source: https://medium.com/@peter_r/visualizing-htlcs-and-the-lightning-networks-dirty-little-secret-cb9b5773a0 ---- ### Liquidity ```mermaid flowchart LR id1((A)) --- id2(( )) --- id3(( )) --- id4(( )) --- id5(( )) --- id6(( )) --- id7(( )) --- id8(( )) --- id9(( )) --------------- id10((B)) ``` Liquidity all at `A` `A` can only send and `B` can only recieve ```mermaid flowchart LR id1((A)) --- id2(( )) --- id3(( )) --- id4(( )) --- id5(( )) ===============> id6(( )) --- id7(( )) --- id8(( )) --- id9(( )) --- id10((B)) ``` Balanced liquidity `A` and `B` can both send and receive ```mermaid flowchart LR id1((A)) ===============> id2(( )) --- id3(( )) --- id4(( )) --- id5(( )) --- id6(( )) --- id7(( )) --- id8(( )) --- id9(( )) --- id10((B)) ``` Liquidity at `A` depleted `A` can only recieve and `B` can only send ---- ### Re-balancing liquidity <img src="https://i.imgur.com/4YX2Sln.png"> source: https://www.peerswap.dev --- ### Routing - Computationally expensive - Can be outsourced --- ### Privacy - Reciever must share fixed pubkey and ip address - Could use Tor - Blinded paths - "Private channels" are not private - Balance probing --- ### Trust - Trust channel counterparty not to close the channel - Wastes *your* on-chain transaction fees --- ### Liveness - Must be online to receive - LSPs - Must monitor blockchain semi-regularly to avoid being cheated - Penalty mechanism sufficient deterrent? --- ## How to use Lightning 1. Get a Lightning wallet 1. Send bitcoin to Lightning wallet 1. Open a channel (often automatic) 1. Send / recv transactions ---- ### Lightning wallets (mobile/lite) | Name | Model | | ----------------- | ------------- | | Wallet of Satoshi | Custodial | | Blue Wallet | Custodial | | Phoenix | Non-custodial | | Muun | Non-custodial | | Breez | Non-custodial | | ... | | ---- ### Full lightning nodes | Name | Language | | --------------------- | ---------------------- | | Core-LN (C-Lightning) | C, Rust, (plugins any) | | LND | Go | | Electrum | Python | | Rust Lightning | Rust | | Eclair | Scala | All include wallet functionality ---- ### Testing Lightning on mainnet pollofeed.com <img src="https://i.imgur.com/lNLtYrm.png" height="400px"> #reckless --- ## Lightning summary - Scales bitcoin payments <span style="color:#98c379">trustlessly</span> - Compresses many off-chain transactions into two on-chain transactions - <span style="color:#98c379">Better privacy, lower fees, faster speed and smaller payment amounts</span> --- ### Thank you! :sheep: You can find me on - Twitter: [@willcl_ark](https://twitter.com/willcl_ark) - GitHub: [@willcl-ark](https://github.com/willcl-ark) --- ### Questions

    Import from clipboard

    Paste your markdown or webpage here...

    Advanced permission required

    Your current role can only read. Ask the system administrator to acquire write and comment permission.

    This team is disabled

    Sorry, this team is disabled. You can't edit this note.

    This note is locked

    Sorry, only owner can edit this note.

    Reach the limit

    Sorry, you've reached the max length this note can be.
    Please reduce the content or divide it to more notes, thank you!

    Import from Gist

    Import from Snippet

    or

    Export to Snippet

    Are you sure?

    Do you really want to delete this note?
    All users will lose their connection.

    Create a note from template

    Create a note from template

    Oops...
    This template has been removed or transferred.
    Upgrade
    All
    • All
    • Team
    No template.

    Create a template

    Upgrade

    Delete template

    Do you really want to delete this template?
    Turn this template into a regular note and keep its content, versions, and comments.

    This page need refresh

    You have an incompatible client version.
    Refresh to update.
    New version available!
    See releases notes here
    Refresh to enjoy new features.
    Your user state has changed.
    Refresh to load new user state.

    Sign in

    Forgot password

    or

    By clicking below, you agree to our terms of service.

    Sign in via Facebook Sign in via Twitter Sign in via GitHub Sign in via Dropbox Sign in with Wallet
    Wallet ( )
    Connect another wallet

    New to HackMD? Sign up

    Help

    • English
    • 中文
    • Français
    • Deutsch
    • 日本語
    • Español
    • Català
    • Ελληνικά
    • Português
    • italiano
    • Türkçe
    • Русский
    • Nederlands
    • hrvatski jezik
    • język polski
    • Українська
    • हिन्दी
    • svenska
    • Esperanto
    • dansk

    Documents

    Help & Tutorial

    How to use Book mode

    Slide Example

    API Docs

    Edit in VSCode

    Install browser extension

    Contacts

    Feedback

    Discord

    Send us email

    Resources

    Releases

    Pricing

    Blog

    Policy

    Terms

    Privacy

    Cheatsheet

    Syntax Example Reference
    # Header Header 基本排版
    - Unordered List
    • Unordered List
    1. Ordered List
    1. Ordered List
    - [ ] Todo List
    • Todo List
    > Blockquote
    Blockquote
    **Bold font** Bold font
    *Italics font* Italics font
    ~~Strikethrough~~ Strikethrough
    19^th^ 19th
    H~2~O H2O
    ++Inserted text++ Inserted text
    ==Marked text== Marked text
    [link text](https:// "title") Link
    ![image alt](https:// "title") Image
    `Code` Code 在筆記中貼入程式碼
    ```javascript
    var i = 0;
    ```
    var i = 0;
    :smile: :smile: Emoji list
    {%youtube youtube_id %} Externals
    $L^aT_eX$ LaTeX
    :::info
    This is a alert area.
    :::

    This is a alert area.

    Versions and GitHub Sync
    Get Full History Access

    • Edit version name
    • Delete

    revision author avatar     named on  

    More Less

    Note content is identical to the latest version.
    Compare
      Choose a version
      No search result
      Version not found
    Sign in to link this note to GitHub
    Learn more
    This note is not linked with GitHub
     

    Feedback

    Submission failed, please try again

    Thanks for your support.

    On a scale of 0-10, how likely is it that you would recommend HackMD to your friends, family or business associates?

    Please give us some advice and help us improve HackMD.

     

    Thanks for your feedback

    Remove version name

    Do you want to remove this version name and description?

    Transfer ownership

    Transfer to
      Warning: is a public team. If you transfer note to this team, everyone on the web can find and read this note.

        Link with GitHub

        Please authorize HackMD on GitHub
        • Please sign in to GitHub and install the HackMD app on your GitHub repo.
        • HackMD links with GitHub through a GitHub App. You can choose which repo to install our App.
        Learn more  Sign in to GitHub

        Push the note to GitHub Push to GitHub Pull a file from GitHub

          Authorize again
         

        Choose which file to push to

        Select repo
        Refresh Authorize more repos
        Select branch
        Select file
        Select branch
        Choose version(s) to push
        • Save a new version and push
        • Choose from existing versions
        Include title and tags
        Available push count

        Pull from GitHub

         
        File from GitHub
        File from HackMD

        GitHub Link Settings

        File linked

        Linked by
        File path
        Last synced branch
        Available push count

        Danger Zone

        Unlink
        You will no longer receive notification when GitHub file changes after unlink.

        Syncing

        Push failed

        Push successfully