Upgrade to Pro — share decks privately, control downloads, hide ads and more …

Lightning Network Ptarmigan Hands-on

Lightning Network Ptarmigan Hands-on

Introduction for hands-on about Ptarmigan which is Lightning Network Software.
Please download this file and try it in your environment.

Nayuta

May 20, 2019
Tweet

More Decks by Nayuta

Other Decks in Technology

Transcript

  1. About Docker ϗετOS Ծ૝Խιϑτ΢ΣΞ ΞϓϦέʔγϣϯ … Hyper-V ΍ VirtualBox ͱಉ͡Α͏ͳԾ૝؀ڥͷ࡞੒ΛՄೳͱ͢Διϑτ΢ΣΞɹ

    ্هιϑτ΢ΣΞ܈ͱൺͯ͠ɺήετOSΛ౎౓্ཱͪ͛Δඞཁ͕ͳ͍ ΞϓϦέʔγϣϯ ήετOS ήετOS … ⾢ ඞཁͳ͠ ϗετϚγϯͷΧʔωϧΛར༻͠ɺϓϩηεΛִ཭͢Δ͜ͱͰܰྔɺߴ଎ʹಈ͘
  2. Mac OS Command + Shift + U → λʔϛφϧىಈ Windows

    Docker Quickstart Terminal $ docker -v
  3. $ docker pull char1yxok/ptarmigan:2.0 $ docker images $ docker run

    --name ptarmigan -p 3333:3000 -d -it cd75364f4ffe $ docker ps $ docker exec -it ptarmigan /bin/bash Docker্ͷίϯςφ(ubuntu)΁ɺϩάΠϯ׬ྃʂ
  4. Bitcoin Core Daemon version : 0.18.99.0 Ptarmigan version : 0.2.2

    ίϯςφ಺Ͱͷૢ࡞खॱ ⾢ Bitcoind ͷ࣮ߦ(ࠓճ͸regtestͰߦ͍·͢) $ cd ~/ $ bitcoind -daemon $ ./new_nodedir.sh first ⾢ Ptarmigan ͷϊʔυ࡞੒ $ cd first $ ptarmd --network=regtest ⾢ Ptarmigan ͷ࣮ߦ $ cd ptarmigan/install όʔδϣϯ৘ใ ⾢ ࡞੒ͨ͠ϊʔυ໊ͷσΟϨΫτϦ΁Ҡಈ
  5. ৽͘͠ίϯιʔϧΛ্ཱͪ͛Δ $ docker-machine ls $ docker exec -it ptarmigan /bin/bash

    $ cd ~/ptarmigan/ptarmapi (WindowsͷΈ) ⾢ URLΛ߇͓͑ͯ͘ $ npm run start ϒϥ΢βΛ্ཱͪ͛ɺΞυϨεόʔʹҎԼͷ஋Λೖྗ͢Δ Mac Windows localhost:3333/api ্෦Ͱ߇͑ͨURL:3333/api ⾢ (ྫ)192.168.99.100:3333/api
  6. (ex.2) createinvoice ػೳ … Lightning Network಺Ͱ࢖༻͢ΔinvoiceΛൃߦ͢Δ ૢ࡞ॱ … 'Try it

    out' → 'Parameters' → Example Valueͷ"amountMsat"ʹ਺஋Λೖྗ ɹɹɹɹ 'Execute' → Response body಺ͷ"bolt11"ͷ஋Λpayerʹ౉͢ɻ https://starblocks.acinq.co/ https://shop.nayuta.co/
  7. (ex.3) 2ϊʔυؒͷconnectʙpayment·Ͱɹ ৽͘͠ίϯιʔϧΛ্ཱͪ͛ɺdocker exec -it ptarmigan /bin/bash ͰίϯςφʹೖΔ $ cd

    ~/ptarmigan/install $ ./new_nodedir.sh second $ cd second/ $ ptarmd --network=regtest --port=1111 $ cd ~/ptarmigan/install/second ৽͘͠ίϯιʔϧΛ্ཱͪ͛ɺdocker exec -it ptarmigan /bin/bash ͰίϯςφʹೖΔ $ ptarmcli -l ⾢ node_id ͷ஋(“”͸ෆཁ)Λ߇͓͑ͯ͘: ᶃ $ hostname -I ⾢ ग़ྗ஋Λ߇͓͑ͯ͘: ᶄ $ bitcoin-cli getnewaddress $ bitcoin-cli generatetoaddress 500 ᶅ ⾢ ग़ྗ஋Λ߇͓͑ͯ͘: ᶅ ⾢ 500ͷޙʹᶅͷ஋Λೖྗ ※͜͜·ͰͰɺLightningͷ2ͭͷϊʔυ͕׬੒ͨ͠ͷͰɺ࣍͸connectͱfundingΛߦ͏ ⾢ secondͱ͍͏ϊʔυΛ৽ͨʹ࡞੒
  8. ϒϥ΢βͷconnectػೳ͔ΒExample Value΁ҎԼͷ஋Λೖྗ͠ɺ'Execute'ΛԡԼ ࠶ͼgetinfo͢Δͱ"peers"͕૿͑ɺϊʔυ͕઀ଓ͞Εͨ͜ͱ͕Θ͔Δɻ openchannelػೳ͔ΒExample Value΁ҎԼͷ஋Λೖྗ͠ɺ'Execute'ΛԡԼ "peerNodeId": "ᶃ", "fundingSat": 100000 Response

    bodyͷ"status"͕"Progressing"ʹͳ͍ͬͯΕ͹੒ޭʂ "peerNodeId": "ᶃ", "peerAddr": "ᶄ", "peerPort": 1111 $ bitcoin-cli generatetoaddress 1 ᶅ ⾢ NodeIdʹᶃɺAddrʹᶄͷ஋Λೖྗ $ ptarmcli -i 1000 ⾢ ग़ྗ஋Λ߇͓͑ͯ͘: ᶆ (=secondͷinvoice) ⾢ ϒϩοΫΛ1ͭ࡞ΓɺfundingΛ׬ྃͤ͞Δ getinfoػೳΛ࣮ߦ͠ɺlocal ͱremote ͷmsatoshiͷ஋Λ֬ೝ͢Δ sendpaymentػೳ͔ΒExample Value΁ҎԼͷ஋Λೖྗ͠ɺ'Execute'ΛԡԼ "bolt11": ᶆ ⾢ first→second΁ͷfundingΛߦ͏ ⾢ invoiceΛड͚ͯfirst→second΁ͷpayment
  9. ※͜Ε͕Lightningͷಛ௃ͷҰͭͰ͋Δଈ࣌ੑͰɺBitcoinͩͱࢧ෷͍ʹ࠷௿10෼͔͔Δ closeػೳ͔ΒExample Value΁ҎԼͷ஋Λೖྗ͠ɺ'Execute'ΛԡԼ "peerNodeId": ᶃ Response bodyͷresult͕"Start Mutual Close"ͱͳ͍ͬͯΕ͹੒ޭ $

    bitcoin-cli generatetoaddress 1 ᶅ ⾢ ϒϩοΫΛ1ͭ࡞ΓɺclosingΛ׬ྃͤ͞Δ 10ඵఔ଴ͪgetinfoػೳΛ࣮ߦ͠ɺܨ͕͍ͬͯͨϊʔυ͕੾அ͞Ε͍ͯΔ͜ͱΛ֬ೝ͢Δ ※ࠓճ͸regtestͷͨΊ࣮ࡍʹBitcoinͷ࢒ߴ͕ߦ͖དྷͨ͠ͷ͔֬ೝ͕Ͱ͖·ͤΜɻ ɹtestnet౳Ͱ࣮ߦͨ͠ࡍʹ͸LightningͷϊʔυؒͰνϟωϧΛ։͘લޙʹ ɹbitcoin-cli getbalanceΛ࣮ߦ͠ɺ࢒ߴ͕Ҡ͍ͬͯΔ(ࢧ෷͍͕ग़དྷ͍ͯΔ)͜ͱΛ֬ೝ͍ͯͩ͘͠͞ɻ getinfoػೳΛ࣮ߦ͠ɺlocal ͱremote ͷ஋͕±1000ͣͭมԽ͍ͯ͠Ε͹ࢧ෷͍੒ޭ
  10. ⾢ ίϯςφͷݩͱͳΔΠϝʔδΛ࡟আ $ exit Dockerͷఀࢭͱ࡟আͷํ๏ $ docker stop ptarmigan $

    docker rm ptarmigan $ docker rmi cd75364f4ffe ⾢ ίϯςφ͔Βൈ͚Δ ⾢ ίϯςφΛఀࢭ ⾢ ίϯςφΛ࡟আ
  11. Appendix mainnetͱtestnetͰಈ͔͢ํ๏(bitcoin core v0.18.99 ͷྫ) ࠓճ͸regtestͰૢ࡞Λߦ͍·͕ͨ͠ɺ͜ͷ؀ڥͰଞͷnet΋ಈ͔͢͜ͱ͕Ͱ͖·͢ɻ ͦΕͧΕɺ~/.bitcoin/bitcoin.conf ΛҎԼͷΑ͏ʹฤू͠ɺBitcoindΛىಈ͠·͢ɻ Main net

    testnet rpcuser=bitcoinuser rpcpassword=bitcoinpassword testnet=3 txindex=1 server=1 rpcuser=bitcoinuser rpcpassword=bitcoinpassword txindex=1 server=1 ※BitcoindͷىಈޙʹϒϩοΫ৘ใͷμ΢ϯϩʔυ͕ ɹ࢝·Γ·͕͢ɺtestnetͰ͋Ε͹20GBऑɺ ɹmainnetͰ͋Ε͹200GB௒ͷσΟεΫ༰ྔΛ ɹඞཁͱ͢ΔͨΊ͝஫ҙ͍ͩ͘͞ɻ ɹ·ͨɺμ΢ϯϩʔυʹ΋૬Ԡͷ͕͔͔࣌ؒΓ·͢ɻɹ ɹ ɹptarmd͸ϒϩοΫ৘ใͷμ΢ϯϩʔυ׬ྃޙʹ ɹߦ͍ͬͯͩ͘͞ɻ ~/ptarmigan/install/new_node.shͰ৽ͨʹϊʔυΛ࡞੒͠ɺσΟϨΫτϦΛҠಈ͢Δ $ ptarmd --network=testnet/mainnet ҎԼͷίϚϯυΛ࣮ߦ͢Δ(testnetͱmainnetͰಡΈସ͑Δ)