Liquid Network Lightning Payment Guide

Posted by patrickmvi on Thu, 29 Aug 2019 12:06:39 +0200

This tutorial describes how to use c-lightning of Liquid side chains to create lightning payment channels. Using these payment channels, users can trade Liquid-BTC in real time and privately.

Liquid networks include support for private transactions and asset issuance, so users can use lightning payment channels to trade any assets issued on Liquid networks, such as currency issuance, encrypted assets, etc. In addition, support for the conversion of on-line BTC and payment channel L-BTC is also under way.

Using c-lightning on the Liquid network is the same as the process on the main Bitcoin network, so if you are familiar with the steps, this tutorial will be easy -- albeit easy.

1. Software Installation

First of all, we need a synchronized bitcoin node and a synchronized Elements node to open the lightning payment channel on the Liquid side chain. You can refer to the following links to install bitcoin node software and elements node software:

Once both nodes are synchronized, the necessary dependencies are installed:

~$ sudo apt-get install -y \
  autoconf automake build-essential git libtool libgmp-dev \
  libsqlite3-dev python python3 net-tools zlib1g-dev libsodium-dev

Then the lightening-elements branch is pulled from Christian Decker's github warehouse:

~$ git clone https://github.com/cdecker/lightning
~$ cd lightning 
~/lightning$ git fetch --all
~/lightning$ git checkout lightning-elements

Now build with source code:

~/lightning$ ./configure
~/lightning$ make

After the build is complete, you can get lightingd / lightning GD and cli/lightning-cli.

If you want to quickly grasp the development of block chain applications, we recommend Hui Zhi's. A series of tutorials on block chain application and development It covers many block chains, such as Bitcoin, ETF, eos, Super Account fabric and tendermint, as well as java, go, nodejs, python, php, dart and other development languages.

2. Start the Lightning Service Process

lightningd provides a -- network parameter to choose which chain to run on, such as the main chain of bitcoin, the test chain, the private development chain, etc. The lightning-elements branch also supports liquid side chains, so we use this option:

~/lightning$ ./lightningd/lightningd --network liquid ... <other arguments>

It will start synchronizing with Liquid side chains:

~/lighting$ ./lightningd/lightningd --network liquid                                                                           
2019-06-29T23:14:40.599Z lightning_gossipd(29574): We seem to be missing gossip messages                                                              
2019-06-29T23:14:40.689Z lightningd(29562): --------------------------------------------------
2019-06-29T23:14:40.689Z lightningd(29562): Server started with public key 02954a618a5684fbb7454d0c1bc87579d5164c35829fccc54d9f4df1a369356b48, alias $
OUDFIRE (color #02954a) and lightningd v0.6rc1-1998-g6d4c40f
2019-06-29T23:22:46.297Z lightningd(29562): JSON-RPC shutdown
grubles@thinky:~/builds/lightning$ ./lightningd/lightningd --network liquid --log-level debug
2019-06-29T23:22:55.640Z lightningd(29963): testing /home/grubles/builds/lightning/lightningd/lightning_channeld
2019-06-29T23:22:55.641Z lightningd(29963): testing /home/grubles/builds/lightning/lightningd/lightning_closingd
2019-06-29T23:22:55.642Z lightningd(29963): testing /home/grubles/builds/lightning/lightningd/lightning_connectd
2019-06-29T23:22:55.643Z lightningd(29963): testing /home/grubles/builds/lightning/lightningd/lightning_gossipd
2019-06-29T23:22:55.645Z lightningd(29963): testing /home/grubles/builds/lightning/lightningd/lightning_hsmd
2019-06-29T23:22:55.646Z lightningd(29963): testing /home/grubles/builds/lightning/lightningd/lightning_onchaind
2019-06-29T23:22:55.647Z lightningd(29963): testing /home/grubles/builds/lightning/lightningd/lightning_openingd
2019-06-29T23:22:55.677Z lightning_hsmd(29973): pid 29973, msgfd 17
2019-06-29T23:22:55.687Z lightning_connectd(29974): pid 29974, msgfd 20
2019-06-29T23:22:55.688Z lightning_hsmd(29973): Client: Received message 11 from client
2019-06-29T23:22:55.688Z lightning_hsmd(29973): Client: Received message 9 from client
2019-06-29T23:22:55.688Z lightning_hsmd(29973): new_client: 0
2019-06-29T23:22:55.806Z lightning_connectd(29974): Broken DNS resolver detected, will check for dummy replies
2019-06-29T23:22:55.806Z lightning_connectd(29974): Created IPv6 listener on port 9735
2019-06-29T23:22:55.806Z lightning_connectd(29974): Failed to connect 10 socket: Network is unreachable
2019-06-29T23:22:55.806Z lightning_connectd(29974): Created IPv4 listener on port 9735
2019-06-29T23:22:55.806Z lightning_connectd(29974): REPLY WIRE_CONNECTCTL_INIT_REPLY with 0 fds
2019-06-29T23:22:55.807Z lightning_gossipd(29975): pid 29975, msgfd 19
2019-06-29T23:22:55.822Z lightning_hsmd(29973): Client: Received message 9 from client
2019-06-29T23:22:55.822Z lightning_hsmd(29973): new_client: 0
2019-06-29T23:22:55.822Z lightning_gossipd(29975): gossip_store_compact_offline: 0 deleted, 0 copied
2019-06-29T23:22:55.822Z lightning_gossipd(29975): total store load time: 0 msec
2019-06-29T23:22:55.822Z lightning_gossipd(29975): gossip_store: Read 0/0/0/0 cannounce/cupdate/nannounce/cdelete from store (0 deleted) in 1 bytes
2019-06-29T23:22:55.823Z lightning_gossipd(29975): We seem to be missing gossip messages
2019-06-29T23:22:55.859Z lightningd(29963): Adding block 367714: 8173bffd993028ee63fd46adc808d9820f752c550140028f2fd7ca67b654cdcc
2019-06-29T23:22:55.893Z lightningd(29963): Smoothed feerate estimate for urgent initialized to polled estimate 250
2019-06-29T23:22:55.893Z lightningd(29963): ... feerate estimate for urgent hit floor 253
2019-06-29T23:22:55.893Z lightningd(29963): Feerate estimate for urgent set to 253 (was 0)
2019-06-29T23:22:55.893Z lightningd(29963): Smoothed feerate estimate for normal initialized to polled estimate 250
2019-06-29T23:22:55.893Z lightningd(29963): ... feerate estimate for normal hit floor 253
2019-06-29T23:22:55.893Z lightningd(29963): Feerate estimate for normal set to 253 (was 0)
2019-06-29T23:22:55.893Z lightningd(29963): Smoothed feerate estimate for slow initialized to polled estimate 250
2019-06-29T23:22:55.893Z lightningd(29963): ... feerate estimate for slow hit floor 253
2019-06-29T23:22:55.893Z lightningd(29963): Feerate estimate for slow set to 253 (was 0)
2019-06-29T23:22:55.894Z lightningd(29963): Loaded 0 channels from DB
2019-06-29T23:22:55.894Z jsonrpc Listening on 'lightning-rpc'
2019-06-29T23:22:55.894Z lightning_connectd(29974): REPLY WIRE_CONNECTCTL_ACTIVATE_REPLY with 0 fds
2019-06-29T23:22:55.894Z lightningd(29963): --------------------------------------------------
2019-06-29T23:22:55.894Z lightningd(29963): Server started with public key 02954a618a5684fbb7454d0c1bc87579d5164c35829fccc54d9f4df1a369356b48, alias LOUDFIRE (color #02954a) and lightningd v0.6rc1-1998-g6d4c40f
2019-06-29T23:22:55.895Z plugin-autoclean autocleaning not active
2019-06-29T23:22:55.907Z lightningd(29963): Adding block 367715: 9efb9d3cc313bd403225a8a461603157c74b7c8878169c5140cafa808f3dd71f
2019-06-29T23:22:55.937Z lightningd(29963): Adding block 367716: 6b2df8e54a58a933d7d5e19e76428e06a6447db8254d875a966536b6e7eadbda
2019-06-29T23:22:55.980Z lightningd(29963): Adding block 367717: 2fed71e138f77b8ab6e3f286f308be829fb436154d83aa83a58275ac3745735f
2019-06-29T23:22:56.003Z lightningd(29963): Adding block 367718: aaf417b0e696d737b3e49ab24c0d1562f930be5a44e84136ef9b60a49ce70f65
2019-06-29T23:22:56.040Z lightningd(29963): Adding block 367719: 2563e72d0e7cade03e4005bba463baf80f06a310c373453bb1b22a1395ef46a3
2019-06-29T23:22:56.066Z lightningd(29963): Adding block 367720: dd33dd008c96fdb8f44018fe1d361fa84d7a444f41b1b522c69a9a21e0ce5353
2019-06-29T23:22:56.102Z lightningd(29963): Adding block 367721: 96b0fb6c2ffce86fad91fd001130c37674778312a9f13cccbbffecfd75d21d3a
2019-06-29T23:22:56.132Z lightningd(29963): Adding block 367722: 4fcf8c4b922eeaa604a6c86d3fbfcfd2f6380fad02b0c3150af524d7008fcbcd
2019-06-29T23:22:56.163Z lightningd(29963): Adding block 367723: ac7f818271dd1c7e4dd6bc0e7a4a578edb3ec18cf686cfe7390ab432f4d7cdc5
2019-06-29T23:22:56.199Z lightningd(29963): Adding block 367724: d1b6790da7dca153dd247efeaf11f0592df469cc588b92f07f954521a66cefb6
2019-06-29T23:22:56.235Z lightningd(29963): Adding block 367725: f0a4824ee24e0f327571bdc0acb238162a001be00f12d203e9f15fffba9de20b
2019-06-29T23:22:56.263Z lightningd(29963): Adding block 367726: c6e9b5088c32313272a2235b6865e416f8130a51b5c8fcae5329f80dc6ed1b88
2019-06-29T23:22:56.305Z lightningd(29963): Adding block 367727: 3564d2781de473b6c5cb83cfb819f77523cc4e3a53b3dd19244eeb9d5498aa1a
2019-06-29T23:22:56.336Z lightningd(29963): Adding block 367728: a3b0362a5b6dfc9060f36baa1eb801281eb29438fa0c5287bcba043c6c6a9e02
2019-06-29T23:22:56.398Z lightningd(29963): Adding block 367729: 7b741e9d21e6da7c10807734b8380ea133fafefe10d8e4ba5933ad3c15331317

3. Open Lightning Payment Channel

Now we can start recharging an address to open the lightning channel. Just use lightning-cli to generate a p2sh-segwit address and send it some L-BTC.

To obtain Liquid-BTC (L-BTC), either buy it from a Liquid member exchange, such as Bitfinex, The Rock Trading or Shape shift.ai, or anchor it manually according to the following guidelines.

First, a p2sh-segwit address is generated:

~/lightning$ ./cli/lightning-cli newaddr p2sh-segwit                                                                                                                                                                                                                                    
{                                                                                                                                                     
   "address" : "Gqkico7M9JGyQmk2TjFgqXwYMrrT2ExwXL",                                                                                                  
   "p2sh-segwit" : "Gqkico7M9JGyQmk2TjFgqXwYMrrT2ExwXL"                        
}

Then transfer some L-BTC to this address and connect to the Liquid LIghting peer. The connection command format is as follows:

connect public_key@ip_address:port

In this tutorial, we use a peer on a LAN:

~/lightning$ ./cli/lightning-cli connect 0322d8d3fb7e77a88f373fa369a3e91cb63a24f1313c480ae09c5ffc56dbef7ead@192.168.1.230
{
   "id" : "0322d8d3fb7e77a88f373fa369a3e91cb63a24f1313c480ae09c5ffc56dbef7ead"
}

You can use the listpeers command to view connected peers:

~/lightning$ ./cli/lightning-cli listpeers
{
   "peers" : [
      {
         "id" : "0322d8d3fb7e77a88f373fa369a3e91cb63a24f1313c480ae09c5ffc56dbef7ead",
         "connected" : true,
         "netaddr" : [
            "192.168.1.230:9735"
         ],
         "globalfeatures" : "",
         "localfeatures" : "aa",
         "channels" : []
      }
   ]
}

The L-BTC transaction should have been confirmed, because the settlement time on the Liquid side face is very fast (1-2 minutes):

~/lightnint$ ./cli/lightning-cli listfunds
{
   "outputs" : [
      {
         "txid" : "1ca26aa0c5938997b82abd9de25e5207bedb08bf46635ff40b067e2e91d735e4",
         "output" : 0,
         "value" : 100000,
         "amount_msat" : "100000000msat",
         "address" : "Gqkico7M9JGyQmk2TjFgqXwYMrrT2ExwXL",
         "status" : "confirmed"
      },   ],
   "channels" : []
}

As you can see, the value is 100000, corresponding to 0.00100000 L-BTC.

Now let's open the channel. The command format is as follows:

fundchannel <peer id> <amount in satoshis>

The amount parameter can be all to use all available L-BTC in the wallet:

~/lighting$ ./cli/lightning-cli fundchannel 0322d8d3fb7e77a88f373fa369a3e91cb63a24f1313c480ae09c5ffc56dbef7ead 100000

After the command is executed, the transaction string, transaction ID and channel ID represented in hexadecimal system are output:

{
   "tx" : "020000000102167ff7b6501b78069db92d0dc1abc56bd12e3e12a049a7e668ea0023ed68db9f00000000171600144c36e234a654d79b3c052a98c087ca51a69077a9ffffffffe435d7912e7e060bf45f6346bf08dbbe07525ee29dbd2ab8978993c5a06aa21c00000000171600144c36e234a654d79b3c052a98c087ca51a69077a9ffffffff03016d521c38ec1ea15734ae22b7c46064412829c0d0579f0a713d1c04ede979026f0100000000000186a000220020f6c2e31f79596b12c103fa6b6d42dbe422e42bf3ca208247301ebb6a34f16f2e016d521c38ec1ea15734ae22b7c46064412829c0d0579f0a713d1c04ede979026f010000000000957e5d00160014aefd2d126fc8f9bbbeea3aad39dab5564c7b92ae016d521c38ec1ea15734ae22b7c46064412829c0d0579f0a713d1c04ede979026f010000000000000192000000000000000002483045022100fe77d62b82afb07cf77a4a332cec1e5bce9f9419ca17c7c7385515790c9c4e1102202ac8d4f74f9c4d40fb51515ea12603e3bea1d3fb5749beab475a3de9bc861b7e0121022b46e22dea88d566d894d98e406b1a24b8b985821457875dd4fc909dd2522bfc0000000247304402203f43266df0423aedc1a4c78999f470e34fd698ab993787644f76885c9c372ed802204665f7ff9644ff7f9b7c3a13ec16bf1ed96120a1d348aaa7a96fc1df49c9d6090121022b46e22dea88d566d894d98e406b1a24b8b985821457875dd4fc909dd2522bfc00000000000000",
   "txid" : "e6dda930c3fca7102bae1222928d022b3cf8664667a1b3b33680955ad2c0cf41",
   "channel_id" : "41cfc0d25a958036b3b3a1674666f83c2b028d922212ae2b10a7fcc330a9dde6"
}

If you look at it with the listpeers command, you can see that the state of the channel is as follows:

~/lightning$ ./cli/lightning-cli listpeers                                                                                      
{                                                                                                                                                     
   "peers" : [ 
      {                                                                                                                                      [35/1969]
         "id" : "0322d8d3fb7e77a88f373fa369a3e91cb63a24f1313c480ae09c5ffc56dbef7ead",                                                                 
         "connected" : true,                                                                                                                          
         "netaddr" : [                                                                                                                                
            "192.168.1.230:9735"                                                                                                                      
         ],                                                                                                                                           
         "globalfeatures" : "",                                                                                                                       
         "localfeatures" : "aa",                                                                                                                      
         "channels" : [                                                                                                                               
            {                                                                                                                                         
               "state" : "CHANNELD_AWAITING_LOCKIN",                                                                                                  
               "scratch_txid" : "1668cfe52945cef47f9310c07292b773f4a1c2c113d0a84fd905f01409931948",                                                   
               "owner" : "lightning_channeld",                                                                                                        
               "channel_id" : "41cfc0d25a958036b3b3a1674666f83c2b028d922212ae2b10a7fcc330a9dde6",                                                     
               "funding_txid" : "e6dda930c3fca7102bae1222928d022b3cf8664667a1b3b33680955ad2c0cf41",                                                   
               "private" : false,                                                                                                                     
               "funding_allocation_msat" : {                                                                                                          
                  "0322d8d3fb7e77a88f373fa369a3e91cb63a24f1313c480ae09c5ffc56dbef7ead" : 0,                                                           
                  "0298f02eaad77c7c8c3d64bd5f8604c80593dc454918b28353d1ea814e541111f0" : 100000000                                                    
               },                                                                                                                                     
               "funding_msat" : {                                                                                                                     
                  "0322d8d3fb7e77a88f373fa369a3e91cb63a24f1313c480ae09c5ffc56dbef7ead" : "0msat",                                                     
                  "0298f02eaad77c7c8c3d64bd5f8604c80593dc454918b28353d1ea814e541111f0" : "100000000msat"                                              
               },                                                                                                                                     
               "msatoshi_to_us" : 100000000,                                                                                                          
               "to_us_msat" : "100000000msat",                                                                                                        
               "msatoshi_to_us_min" : 100000000,                                                                                                      
               "min_to_us_msat" : "100000000msat",                                                                                                    
               "msatoshi_to_us_max" : 100000000,                                                                                                      
               "max_to_us_msat" : "100000000msat",
               "msatoshi_total" : 100000000,
               "total_msat" : "100000000msat",
               "dust_limit_satoshis" : 546,
               "dust_limit_msat" : "546000msat",

               "max_total_htlc_in_msat" : "18446744073709551615msat",
               "their_channel_reserve_satoshis" : 1000,
               "their_reserve_msat" : "1000000msat",
               "our_channel_reserve_satoshis" : 1000,
               "our_reserve_msat" : "1000000msat",
               "spendable_msatoshi" : 98774000,
               "spendable_msat" : "98774000msat",
               "htlc_minimum_msat" : 0,
               "minimum_htlc_in_msat" : "0msat",
               "their_to_self_delay" : 144,
               "our_to_self_delay" : 144,
               "max_accepted_htlcs" : 483,
               "status" : [
                  "CHANNELD_AWAITING_LOCKIN:Funding needs 2 more confirmations for lockin."
               ],
               "in_payments_offered" : 0,
               "in_msatoshi_offered" : 0,
               "in_offered_msat" : "0msat",
               "in_payments_fulfilled" : 0,
               "in_msatoshi_fulfilled" : 0,
               "in_fulfilled_msat" : "0msat",
               "out_payments_offered" : 0,
               "out_msatoshi_offered" : 0,
               "out_offered_msat" : "0msat",
               "out_payments_fulfilled" : 0,
               "out_msatoshi_fulfilled" : 0,
               "out_fulfilled_msat" : "0msat",
               "htlcs" : []
            }
         ]
      }
   ]
}

After three Liquid blocks (3 minutes), listpeers will display "CHANNELD_NORMAL:Funding transaction locked".

Now the Lightning Channel is open!

4. Payment of L-BTC by Lightning

Now that the local network has a channel connecting peers, we can generate a lightning invoice and send L-BTC micro-payment.

The command format for generating invoices is as follows:

invoice msatoshi label description

In the following example, a L-BTC invoice of 1 million satoshi will be created, using the label "test1" and describing "testing lightning on liquid". The invoice itself is a long string of seemingly random characters, beginning with ln:

~/lightning$ ./cli/lightning-cli invoice 1 test1 "testing lightning on liquid"
{
   "payment_hash" : "1c03f18a5e3f36a7100c6524794cef9ef8873f3fb22ed5ec6311936e794b71cb",
   "expires_at" : 1562629445,
   "bolt11" : "lnex10p1pw34xk9pp5rsplrzj78um2wyqvv5j8jn80nmugw0elkghdtmrrzxfku72tw89sdpvw3jhxarfdenjqmrfva58gmnfdenjqmmwypkxjut4d9jqxqyjw5qcqp2mvzgw7fk48sn0n3jwuycs9ahqtl4nc7qp8j69g6sfphjyktztcnyqtsynjjykqc30820p5avqaf9af2mcsjctwwxj8avkpjfv2vh0dqq2wyzpa",
  
}

On the sending node, we can use decodepay to decode the lightning invoice encoded by bech32:

~/lightning$ ./cli/lightning-cli decodepay lnex10p1pw34xk9pp5rsplrzj78um2wyqvv5j8jn80nmugw0elkghdtmrrzxfku72tw89sdpvw3jhxarfdenjqmrfva58gmnfdenjqmmwypkxjut4d9jqxqyjw5qcqp2mvzgw7fk48sn0n3jwuycs9ahqtl4nc7qp8j69g6sfphjyktztcnyqtsynjjykqc30820p5avqaf9af2mcsjctwwxj8avkpjfv2vh0dqq2wyzpa
{
   "currency" : "ex",
   "created_at" : 1562024645,
   "expiry" : 604800,
   "payee" : "0322d8d3fb7e77a88f373fa369a3e91cb63a24f1313c480ae09c5ffc56dbef7ead",
   "msatoshi" : 1,
   "amount_msat" : "1msat",
   "description" : "testing lightning on liquid",
   "min_final_cltv_expiry" : 10,
   "payment_hash" : "1c03f18a5e3f36a7100c6524794cef9ef8873f3fb22ed5ec6311936e794b71cb",
   "signature" : "3045022100db04877936a9e137ce3277098817b702ff59e3c009e5a2a350486f2259625e260220402e049ca44b031179d4f0d3ac07525ea55bc42585b9c691facb0649629977b4"
}

On the sending node, pay command is used to pay 0.00000001 L-BTC:

~/lightnint$ ./cli/lightning-cli pay lnex10p1pw34xk9pp5rsplrzj78um2wyqvv5j8jn80nmugw0elkghdtmrrzxfku72tw89sdpvw3jhxarfdenjqmrfva58gmnfdenjqmmwypkxjut4d9jqxqyjw5qcqp2mvzgw7fk48sn0n3jwuycs9ahqtl4nc7qp8j69g6sfphjyktztcnyqtsynjjykqc30820p5avqaf9af2mcsjctwwxj8avkpjfv2vh0dqq2wyzpa
{
   "id" : 1,
   "payment_hash" : "1c03f18a5e3f36a7100c6524794cef9ef8873f3fb22ed5ec6311936e794b71cb",
   "destination" : "0322d8d3fb7e77a88f373fa369a3e91cb63a24f1313c480ae09c5ffc56dbef7ead",
   "msatoshi" : 1,
   "amount_msat" : "1msat",
   "msatoshi_sent" : 1,
   "amount_sent_msat" : "1msat",
   "created_at" : 1562024759,
   "status" : "complete",   
   "payment_preimage" : "7c6357460a3782ed806c8661b0b20c65287ecdc9cf7c6a9c2e85399ffff88f15",
   "bolt11" : "lnex10p1pw34xk9pp5rsplrzj78um2wyqvv5j8jn80nmugw0elkghdtmrrzxfku72tw89sdpvw3jhxarfdenjqmrfva58gmnfdenjqmmwypkxjut4d9jqxqyjw5qcqp2mvzgw7fk48sn0n3jwuycs9ahqtl4nc7qp8j69g6sfphjyktztcnyqtsynjjykqc30820p5avqaf9af2mcsjctwwxj8avkpjfv2vh0dqq2wyzpa"
}

The value of "status" is "complete", indicating that the payment has been completed and the invoice has been paid!

Close Payment Channel

Some L-BTC s can be sent freely between two nodes. After last night's test, the following steps can be taken to close the channel.

On one of the nodes, a channel closure is initiated using the close command:

~/lightnint$ ./cli/lightning-cli close <channel id>

The above command will submit a closed transaction on the chain and the channel will be closed.

Links to the original text: Learning Bitcoin Lightning Payment with Liquid Network

Topics: Blockchain network git Python github