Tutorial for Qtum Eclair — A Lightning Network Client

Qtum
Qtum
Published in
8 min readJul 2, 2019

--

The scalability of the blockchain is the key to processing massive transactions. Currently, Bitcoin network can achieve up to 7 TPS, and Qtum network can currently achieve ten times that of Bitcoin, but it is still not enough for massive transactions. (eg: in e-commerce application scenarios, in Alibaba Double Eleven Shopping Festival recently, peak transactions of Alipay network exceeded 100,000 TPS; Visa achieved 47,000 TPS during the 2013 holiday). In order to solve the performance and storage problems caused by such massive transactions, Joseph Poon proposed the Lightning Network solution, which is a decentralized system that can realize a real-time and massive transaction network without trusting the other party and third parties. The basic idea is that the two parties in the transaction create a payment channel through the transaction script on the chain. After that, the real-time and massive payment transactions of the two parties are completed off the chain. By linking multiple channels, any two peers in the network can perform fund transaction and complete the value transfer without the need to trust third parties for fund custody and settlement. These transfers can be made along the delivery path through smart contracts between untrusted parties.

Eclair is a lightning network implementation on the Bitcoin blockchain, which currently supports functions including the creation of payment channels and receipt of payments for Lightning Networks. Qtum has implemented Qtum Eclair based on Eclair, which enables functions such as channel creation, real-time transaction, and small transactions on Qtum. The following are some tests of the lightning network’s features on the Qtum Testnet.

Step 1 — Install and run the Qtum Core wallet

Qtum Eclair requires a synchronized, non-pruned Qtum Core wallet that supports segwit, zeromq, transfer, and transaction indexing. Qtum Eclair will use any Qtum it finds in the Qtum Core wallet to pay for any lightning network channels that you choose to open. When the channel is closed, the remaining Qtum in the channel will be refunded to the Qtum Core wallet. You can configure the Qtum Core wallet to use the p2sh-segwit address or bech32 address, and Qtum Eclair is compatible with both modes.

Here is the download address of the core wallet : https://github.com/qtumproject/qtum/releases, select the download package according to your operating system and architecture.

Create and edit the configuration file ~./qtum.conf as follows:

server=1
rpcuser=foo
rpcpassword=bar
txindex=1
addresstype=bech32
zmqpubrawblock=tcp://127.0.0.1:29000
zmqpubrawtx=tcp://127.0.0.1:29000

It’s recommended to modify rpcuser and rpcpassword in the configuration file for sake of security.

For Linux, the path of qtum.conf is ~/.qtum/qtum.conf

For Mac OSX, the path of qtum.conf is ~/Library/Application\ Support/Qtum/qtum.conf

For Windows, the path of qtum.conf is %APPDATA%\Qtum\qtum.conf

Run the Qtum Core wallet, and send a certain amount of testnet coins to the wallet after the block is synchronized.

Qtum testnet coins can be claimed at http://testnet-faucet.qtum.info/.

Step 2 — Install Qtum Eclair

2.1 Install JDK and Maven

Qtum Eclair is developed using the Scala language. To run Qtum Eclair, you must first install the JDK, and OpenJDK 11 or above is recommended.

For Linux, apt-get install default-jdk

For Mac OSX, brew cask install adoptopenjdk

For Windows, download the installer at https://jdk.java.net/archive/.

You also need to install Maven, which you can download at http://maven.apache.org/download.cgi.

Run command mvn -v, and a return as follows indicates that the installation is successful.

2.2 Compile Qtum Eclair

2.3 Run Qtum Eclair

Create and edit the configuration file ~/.qtum-eclair/eclair.conf as follows:

eclair {
chain = "testnet" // "mainnet" for mainnet, "testnet" for testnet, "regtest" for regtest
server {
public-ips = []
binding-ip = "0.0.0.0"
port = 9735
}
api {
enabled = false
binding-ip = "127.0.0.1"
port = 8080
password = "qtum-eclair"
use-old-api = false
}

watcher-type = "bitcoind"
bitcoind {
host = "localhost"
rpcport = 13889
bitdir = ""
rpcuser = "foo"
rpcpassword = "bar"
zmqblock = "tcp://127.0.0.1:29000"
zmqtx = "tcp://127.0.0.1:29000"
}

default-feerates {
delay-blocks {
1 = 1200000
2 = 1000000
6 = 800000
12 = 600000
36 = 500000
72 = 410000
}
}
min-feerate = 400
smooth-feerate-window = 6 // 1 = no smoothing
node-alias = "qtum-eclair"
node-color = "49daaa"
global-features = ""
local-features = "8a"
override-features = []
channel-flags = 1
dust-limit-satoshis = 72800
max-htlc-value-in-flight-msat = 500000000000 // 5 QTUM
htlc-minimum-msat = 1
max-accepted-htlcs = 30
reserve-to-funding-ratio = 0.01
max-reserve-to-funding-ratio = 0.05
to-remote-delay-blocks = 3600
max-to-local-delay-blocks = 10080
mindepth-blocks = 3
expiry-delta-blocks = 720
fee-base-msat = 400000
fee-proportional-millionths = 100
max-feerate-mismatch = 1.56
update-fee_min-diff-ratio = 0.1
revocation-timeout = 20 seconds
ping-interval = 30 seconds
ping-timeout = 10 seconds
ping-disconnect = true
auto-reconnect = true
payment-handler = "local"
payment-request-expiry = 1 hour
min-funding-satoshis = 1000000 // 0.01 Qtum
max-payment-attempts = 5
autoprobe-count = 0

router {
randomize-route-selection = true
channel-exclude-duration = 60 seconds
broadcast-interval = 60 seconds
init-timeout = 5 minutes

path-finding {
max-route-length = 6
max-cltv = 5040
fee-threshold-sat = 8400
max-fee-pct = 0.03
heuristics-enable = true
ratio-cltv = 0.15
ratio-channel-age = 0.35
ratio-channel-capacity = 0.5
}
}
}

// do not edit or move this section
eclair {
backup-mailbox {
mailbox-type = "akka.dispatch.BoundedMailbox"
mailbox-capacity = 1
mailbox-push-timeout-time = 0
}
backup-dispatcher {
executor = "thread-pool-executor"
type = PinnedDispatcher
}
}

The public-ips in the above configuration file is an array of the public IP of the local machine, and rpcuser and rpcpassword should be modified accordingly.

Start the client with the command java -jar ./eclair-node-gui/target/lightning-capsule.jar

Create a lightning network channel

Right-click the lower left corner of the local Qtum Eclair client and select “Copy URI” to get its node address.

Click the “Channel” button in the upper left corner and select “Open Channel”.

In the pop-up page, fill in the URI of the channel partner, and the capacity of the channel, which is set to 10 QTUM as an example. Click “Connect” to create the channel. At this point, you need to wait for 6 blocks to confirm the transaction and the channel will be created successfully.

Lightning Network Payment

Once the channel is set up, you can use the Lightning Network for micropayments.

Click the “Channel” button in the upper left corner, select “Receive Payment”, fill in the receipt amount in the pop-up page, click the “Generate” button to get your own receipt address. Here we choose a very small amount of 1 Satoshi, which is equivalent to 0.00000001 QTUM. Such a small transferred amount is unimaginable without using a lightning network.

Click the “Channel” button in the upper left corner, select “Send Payment”, fill in the other party’s lightning network receipt address and amount in the pop-up page, and click the “Send” button, then you can transfer tokens to the other party.

After the transfer is completed, the amount of the two parties’ changes instantaneously. Because this is a pure transaction off the chain, there is no need to wait for the block confirmation, and it is free of fees.

Close the channel for settlement

The channel can be closed when the channel is no longer needed.

Click the “Close” button to close the channel.

Once closed, the remaining QTUM in the channel will be refunded to the respective Qtum Core wallet.

Rapid deployment of Qtum Eclair services on the server using Docker

The above is a graphical interface tutorial for ordinary users. If you want to deploy Qtum lightning network nodes on the server, you can refer to this section for quick deployment.

  • sudo docker pull qtum/qtum:latest
  • mkdir /opt/qtum
  • vim /opt/qtum/qtum.conf
server=1
rpcallowip=172.17.0.0/24
rpcbind=0.0.0.0
rpcuser=foo
rpcpassword=bar
txindex=1
addresstype=bech32
zmqpubrawblock=tcp://0.0.0.0:29000
zmqpubrawtx=tcp://0.0.0.0:29000
  • sudo docker run -tid --rm -v "/opt/qtum:/root/.qtum" --name qtum qtum/qtum:latest qtumd --testnet
  • check the block sync progress with sudo docker exec -ti qtum qtum-cli --testnet getblockchaininfo, and wait for the block to be fully synchronized
  • git clone https://github.com/qtumproject/lightning-demo.git
  • cd lightning-demo
  • mkdir /opt/qtum-eclair
  • vim /opt/qtum-eclair/eclair.conf, enter the configuration information in the third section, and replace localhost and 127.0.0.1 with your qtum rpc parameters
  • sudo docker build -t qtum-eclair-img .
  • sudo docker run -ti --rm --name qtum-eclair -v "/opt/qtum-eclair:/data" -p 9735:9735 --link qtum:qtumhost -e "JAVA_OPTS=-Declair.printToConsole" qtum-eclair-img

Lightning Network Nodes on Qtum Testnet for testing

Here are two public Qtum lightning network nodes on Qtum testnet,

  • URI:030fa5900d9ddb1fb0641220b50e695c7e4a791dda682c9d70e1c20278d2f84a98@39.104.93.51:13415
  • URI:02b88d5a2b3f3e5aba35a5fb4497294cf1cf15bb60532e788eeff756dc53633e7c@39.104.100.220:13435

You can establish lightning network channels with these nodes for micropayment testing.

Conclusion

Through the above tests, we can learn that the Qtum-based lightning network can realize real-time transactions and settlement off the chain. For transactions involved only two parties, they are free of charge, making it possible to make small payment, for example. In theory, by establishing a large number of lightning network channels and placing transactions off the Qtum chain, it is possible to process massive transactions in real time.

We will publish more documentation and tests report recently, please stay tuned.

--

--