I'm deeply reluctant to do this, as I'd thought this was fixed with recent lnd versions. Logs below show that it continues, with channel loss on almost every restart. At this rate, we risk bifurcating the network. In fact, only four errors my node have ever been NOT "sync error". 2018-09-12T01:21:40.671Z lightningd(1263): 03e50492eab4107a773141bb419e107bda3de3d55652e6e1a41225f06a0bbf2d56 chan #3: Peer permanent failure in CHANNELD_NORMAL: lightning_channeld: received ERROR channel b7008735ad2425ab92bcffa2f255ba93f63e0b5c685368f308e76ca0d2a30a41: sync error 2018-12-07T06:41:26.209Z lightningd(1215): 03da1c27ca77872ac5b3e568af30673e599a47a5e4497f85c7b5da42048807b3ed chan #1038: Peer permanent failure in CHANNELD_NORMAL: lightning_channeld: received ERROR channel 48858b0d55ae982596932ceb72584d4bb31363b9ecbaa56721b158ca4d18f5f8: sync error 2018-12-07T06:41:43.707Z lightningd(1215): 0219c2f8818bd2124dcc41827b726fd486c13cdfb6edf4e1458194663fb07891c7 chan #2508: Peer permanent failure in CHANNELD_AWAITING_LOCKIN: lightning_channeld: received ERROR channel 388b653e433773d20d74a151c552df647b74e240ef983d21a6d6c5816523b858: sync error 2018-12-07T06:41:45.553Z lightningd(1215): 03e50492eab4107a773141bb419e107bda3de3d55652e6e1a41225f06a0bbf2d56 chan #1044: Peer permanent failure in CHANNELD_NORMAL: lightning_channeld: received ERROR channel b58e9391383bfbe848da881ab9ddd9a8987c76318d421dac6f552b0d451ff957: sync error 2018-12-07T06:41:46.501Z lightningd(1215): 0390b5d4492dc2f5318e5233ab2cebf6d48914881a33ef6a9c6bcdbb433ad986d0 chan #871: Peer permanent failure in CHANNELD_NORMAL: lightning_channeld: received ERROR channel 91f43cb6a8c37d0be237a7c491f11d9dfad48534699fb4f076b2c0cbde964424: sync error 2018-12-07T06:41:46.985Z lightningd(1215): 03e5ea100e6b1ef3959f79627cb575606b19071235c48b3e7f9808ebcd6d12e87d chan #1026: Peer permanent failure in CHANNELD_NORMAL: lightning_channeld: received ERROR channel 6cc360db0627b19df146ccd971570c14597b22662bbc0907a233042480e50be7: sync error 2018-12-07T06:41:47.340Z lightningd(1215): 03c2abfa93eacec04721c019644584424aab2ba4dff3ac9bdab4e9c97007491dda chan #1420: Peer permanent failure in CHANNELD_NORMAL: lightning_channeld: received ERROR channel f363d174390bf819b47e568cb5890c8e432d61c03ba0d38d7c53996679080a74: sync error 2018-12-07T06:41:47.641Z lightningd(1215): 032679fec1213e5b0a23e066c019d7b991b95c6e4d28806b9ebd1362f9e32775cf chan #1058: Peer permanent failure in CHANNELD_NORMAL: lightning_channeld: received ERROR channel 602dc88c7f333ed88f24c6f2c760cb53fa359a4299dfab677f6a81ca33613231: sync error 2019-01-06T10:56:47.332Z lightningd(1202): 02cdf83ef8e45908b1092125d25c68dcec7751ca8d39f557775cd842e5bc127469 chan #2608: Peer permanent failure in CHANNELD_NORMAL: lightning_channeld: received ERROR channel 17b7c895c3feb6ae5b8209ef05044b0aa125629ef1ebc2ce6b2efb27e231533b: sync error 2019-01-06T10:57:08.896Z lightningd(1202): 0219c2f8818bd2124dcc41827b726fd486c13cdfb6edf4e1458194663fb07891c7 chan #2610: Peer permanent failure in CHANNELD_NORMAL: lightning_channeld: received ERROR channel 52d5e3717c7b4f6b06f2b7d55aa8d904a0558706e18be981c82d2c11d4bdf82c: sync error 2019-01-06T10:57:08.950Z lightningd(1202): 02ad6fb8d693dc1e4569bcedefadf5f72a931ae027dc0f0c544b34c1c6f3b9a02b chan #7185: Peer permanent failure in CHANNELD_NORMAL: lightning_channeld: received ERROR channel 245438c15a986b53da7694114c646b77ab663d236d7928732764f5b9251cd2d1: sync error 2019-01-15T09:15:26.882Z lightningd(1191): 03a76b80027d7c067e0da77da95880faaf89e9bf87b73a7d57bd4a3f2a124b764f chan #7430: Peer permanent failure in CHANNELD_AWAITING_LOCKIN: lightning_channeld: received ERROR channel 97c1e01612faf5653af2980abdf382c0f3b24d8a5961b6a3a1eb12444cf9db2e: sync error 2019-05-02T11:32:06.511Z lightningd(14815): 036e8a8efeb26f3cffce99f462839ef6ea3b1691d569d59c402be0d3d6cef9b79c chan #7573: Peer permanent failure in CHANNELD_NORMAL: lightning_channeld: received ERROR channel 6766b0b14013de753f9b354ce7a4b6e4756165ef970aae2650aeda990cfe5687: sync error 2019-06-12T10:38:57.503Z lightningd(1264): 024d2387409269f3b79e2708bb39b895c9f4b6a8322153af54eba487d4993bf60f chan #9607: Peer permanent failure in CHANNELD_NORMAL: lightning_channeld: received ERROR channel 1f3111399c670dab87b4e3d7bac22865c29d4c9992df71fdce9e8893666a08bc: sync error 2019-06-12T10:41:00.435Z lightningd(1264): 02809e936f0e82dfce13bcc47c77112db068f569e1db29e7bf98bcdd68b838ee84 chan #9332: Peer permanent failure in CHANNELD_NORMAL: lightning_channeld: received ERROR channel a31b5252be9b001f573e00310ea9098532c81322389aa8721946185b1b70ca4c: sync error 2019-06-12T10:46:23.097Z lightningd(1264): 02fcdb04f51d61dddc0481c10751173d523e3408ebe3a848a1d6cb34b1f5df6668 chan #7586: Peer permanent failure in CHANNELD_NORMAL: lightning_channeld: received ERROR channel bd18e98f5bd56ac73e7b2eb7fd70f6dbe3a4dda1e5bebe7bf6484c3a0f6b55e7: sync error 2019-06-12T10:46:24.627Z lightningd(1264): 03bb88ccc444534da7b5b64b4f7b15e1eccb18e102db0e400d4b9cfe93763aa26d chan #9626: Peer permanent failure in CHANNELD_NORMAL: lightning_channeld: received ERROR channel 345e89c2f0100257940aff7413c1e29786d08b0a1ea1e259d577650d18791872: sync error 2019-06-12T10:46:26.381Z lightningd(1264): 0331f80652fb840239df8dc99205792bba2e559a05469915804c08420230e23c7c chan #9677: Peer permanent failure in CHANNELD_NORMAL: lightning_channeld: received ERROR channel d38752727ed5dab33abb06c5671e9d7d467feb469f0d249aa488f45e304221c1: sync error 2019-06-12T12:12:51.261Z lightningd(1264): 02d3366059edde4179fc0d071828b4bd726effba7225c3851f3d86a6a827f934a2 chan #9804: Peer permanent failure in CHANNELD_NORMAL: lightning_channeld: received ERROR channel d00c9eb31bb0c1f5794804114117be3cc75a756a1e4c08099b7188a5fd9f7215: sync error 2019-06-13T03:19:28.212Z lightningd(1218): 03e5ea100e6b1ef3959f79627cb575606b19071235c48b3e7f9808ebcd6d12e87d chan #10792: Peer permanent failure in CHANNELD_NORMAL: lightning_channeld: received ERROR channel 873a526043bbc680ea4398c7a45b9742762d782dea285c661bb90ab8f165976d: sync error 2019-06-13T06:19:52.486Z lightningd(1230): 030995c0c0217d763c2274aa6ed69a0bb85fa2f7d118f93631550f3b6219a577f5 chan #10743: Peer permanent failure in CHANNELD_NORMAL: lightning_channeld: received ERROR channel 29157b32dd0c13bcf4f785c5527d067159e102d62516e3a00fbf2c0f33bf59ec: sync error 2019-06-14T01:25:37.598Z lightningd(1235): 02cf60741c586aa54ff24381beab1aebf45eda61a8c49b043cf1f6e203e611e581 chan #12786: Peer permanent failure in CHANNELD_NORMAL: lightning_channeld: received ERROR channel 827472a7167ab1fecd680e4f28e1ee74bcd25d04dcdea5d1295ba381b6543661: sync error 2019-07-17T03:37:12.703Z UNUSUAL lightningd(1262): 03021c5f5f57322740e4ee6936452add19dc7ea7ccf90635f95119ab82a62ae268 chan #14764: Peer permanent failure in CHANNELD_NORMAL: lightning_channeld: received ERROR channel 5ff0890d9f1fbb63439a7d793c28cb74c3baef8c9b610c51c64b8a6497237540: sync error 2019-07-17T03:37:14.964Z UNUSUAL lightningd(1262): 030c3f19d742ca294a55c00376b3b355c3c90d61c6b6b39554dbc7ac19b141c14f chan #14839: Peer permanent failure in CHANNELD_NORMAL: lightning_channeld: received ERROR channel 79525ec2c4eaffb5fd6893957f330db81b7383c50d57113d5bf8ffee3c121bdc: sync error 2019-07-17T03:37:16.048Z UNUSUAL lightningd(1262): 028c1da32603fce64118e469ffe2cfeec04d1c4bd88205efb4e8b4208f77a8064e chan #14996: Peer permanent failure in CHANNELD_NORMAL: lightning_channeld: received ERROR channel 6913067c9c89404d9451df25fed1a6cc98b9d9ef801b623d5e8e90aa43ca3077: sync error Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
c-lightning: A specification compliant Lightning Network implementation in C
c-lightning is a standard compliant implementation of the Lightning Network protocol. The Lightning Network is a scalability solution for Bitcoin, enabling secure and instant transfer of funds between any two parties for any amount.
For more information about the Lightning Network please refer to http://lightning.network.
Project Status
This implementation is still very much a work in progress. It can be used for testing, but it should not be used for real funds. We do our best to identify and fix problems, and implement missing features.
Any help testing the implementation, reporting bugs, or helping with outstanding issues is very welcome. Don't hesitate to reach out to us on IRC at #lightning-dev @ freenode.net, #c-lightning @ freenode.net, or on the implementation-specific mailing list c-lightning@lists.ozlabs.org, or on the Lightning Network-wide mailing list lightning-dev@lists.linuxfoundation.org.
Getting Started
c-lightning currently only works on Linux (and possibly Mac OS with some
tweaking), and requires a locally (or remotely) running bitcoind (version 0.15 or
above) that is fully caught up with the network you're testing on.
Pruning (prune=n option in bitcoin.conf) is not currently supported.
Installation
Please refer to the installation documentation for detailed instructions. For the impatient here's the gist of it for Ubuntu and Debian:
sudo apt-get update
sudo apt-get install -y \
autoconf automake build-essential git libtool libgmp-dev \
libsqlite3-dev python python3 net-tools zlib1g-dev libsodium-dev \
python3-mako
git clone https://github.com/ElementsProject/lightning.git
cd lightning
./configure
make
Or if you like to throw docker into the mix, you can use the official docker image either directly or as a base layer for more complex images.
The docker image is elementsproject/lightningd (from this Dockerfile).
Image tags with -dev at the end are images built with DEVELOPER=1.
If you build the image yourself, you can use the build arg DEVELOPER=1 to build c-lightning in developer mode.
It has the following environment variable:
EXPOSE_TCPdefault to false, if true, use expose c-lightning RPC on port 9835. (Use this only for testing)
Here is an example of a docker-compose file with bitcoind and c-lightning on testnet which expose bitcoind's RPC interface on default ports 18332 and c-lightning API on port 9735:
version: "3"
services:
bitcoind:
image: nicolasdorier/docker-bitcoin:0.16.3
container_name: bitcoind
environment:
BITCOIN_EXTRA_ARGS: |
testnet=1
whitelist=0.0.0.0/0
server=1
rpcuser=rpcuser
rpcpassword=rpcpass
expose:
- "18332"
ports:
- "0.0.0.0:18333:18333"
volumes:
- "bitcoin_datadir:/data"
clightning_bitcoin:
image: elementsproject/lightningd
container_name: lightningd
command:
- --bitcoin-rpcconnect=bitcoind
- --bitcoin-rpcuser=rpcuser
- --bitcoin-rpcpassword=rpcpass
- --network=testnet
- --alias=myawesomenode
- --log-level=debug
environment:
EXPOSE_TCP: "true"
expose:
- "9735"
ports:
- "0.0.0.0:9735:9735"
volumes:
- "clightning_bitcoin_datadir:/root/.lightning"
- "bitcoin_datadir:/etc/bitcoin"
links:
- bitcoind
volumes:
bitcoin_datadir:
clightning_bitcoin_datadir:
Starting lightningd
In order to start lightningd you will need to have a local bitcoind
node running in either testnet or regtest mode:
bitcoind -daemon -testnet
Wait until bitcoind has synchronized with the testnet network.
Make sure that you do not have walletbroadcast=0 in your
~/.bitcoin/bitcoin.conf, or you may run into trouble.
Notice that currently pruned nodes are not supported and may result in
lightningd being unable to synchronize with the blockchain.
You can start lightningd with the following command:
lightningd/lightningd --network=testnet --log-level=debug
Listing all commands:
cli/lightning-cli help will print a table of the API and lists the
following commands
Opening a channel on the Bitcoin testnet
First you need to transfer some funds to lightningd so that it can
open a channel:
# Returns an address <address>
cli/lightning-cli newaddr
# Returns a transaction id <txid>
bitcoin-cli -testnet sendtoaddress <address> <amount_in_bitcoins>
lightningd will register the funds once the transaction is confirmed.
You can obtain testcoins from a faucet such as coinfaucet.eu.
You can send them directly to the lightningd address.
You may need to generate a p2sh-segwit address if the faucet does not support bech32:
# Return a p2sh-segwit address
cli/lightning-cli newaddr p2sh-segwit
Confirm lightningd got funds by:
# Returns an array of on-chain funds.
cli/lightning-cli listfunds
Once lightningd has funds, we can connect to a node and open a channel.
Let's assume the remote node is accepting connections at <ip>
(and optional <port>, if not 9735) and has the node ID <node_id>:
cli/lightning-cli connect <node_id> <ip> [<port>]
cli/lightning-cli fundchannel <node_id> <amount_in_satoshis>
This opens a connection and, on top of that connection, then opens
a channel.
The funding transaction needs 1 confirmation in order for the channel
to be usable, and 6 to be broadcast for others to use.
You can check the status of the channel using cli/lightning-cli listpeers, which after 3 confirmations (1 on testnet) should say
that state is CHANNELD_NORMAL; after 6 confirmations you can use
cli/lightning-cli listchannels to verify that the public field is now
true.
Different states
OPENINGDmeans thatlightning_openingdis negotiating channel opening.CHANNELD_AWAITING_LOCKINmeans thatlightning_channeldis waiting until the minimum number of confirmation on the channel funding transaction.CHANNELD_NORMALmeans your channel is operating normally.CHANNELD_SHUTTING_DOWNmeans one or both sides have asked to shut down the channel, and we're waiting for existing HTLCs to clear.CLOSINGD_SIGEXCHANGEmeans we're trying to negotiate the fee for the mutual close transaction.CLOSINGD_COMPLETEmeans we've broadcast our mutual close transaction (which spends the funding transaction) , but haven't seen it in a block yet.FUNDING_SPEND_SEENmeans we've seen the funding transaction spent.ONCHAINmeans that thelightning_onchaindis tracking the onchain closing of the channel.AWAITING_UNILATERALmeans that we're waiting for a unilateral close to hit the blockchain.
All these states have more information about what's going on in the
status field in listpeers.
Sending and receiving payments
Payments in Lightning are invoice based.
The recipient creates an invoice with the expected <amount> in
millisatoshi (or "any" for a donation), a unique <label> and a
<description> the payer will see:
cli/lightning-cli invoice <amount> <label> <description>
This returns some internal details, and a standard invoice
string called bolt11 (named after the BOLT #11 lightning
spec).
The sender can feed this bolt11 string to the decodepay command to
see what it is, and pay it simply using the pay command:
cli/lightning-cli pay <bolt11>
Note that there are lower-level interfaces (and more options to these interfaces) for more sophisticated use.
Configuration File
lightningd can be configured either by passing options via the command line, or via a configuration file. Command line options will always override the values in the configuration file.
To use a configuration file, create a file named "config" within your ".lightning" directory. Usually, this will be ~/.lightning/config
Configuration options are set using a key=value pair on each line of the file, for example:
alias=SLEEPYDRAGON
rgb=008000
network=testnet
For a full list of possible lightningd configuration options, run:
lightningd/lightningd --help
Further information
Developers
Developers wishing to contribute should start with the developer guide here.
JSON RPC
JSON-RPC interface is documented in the following manual pages:
For simple access to the JSON-RPC interface you can use the
cli/lightning-cli tool, or the python API client.