Run Lnd

academy lnd

Running LND

In this section we will finally run LND and achieve our course objective! We are going to learn how to run LND as a background process, unlock the wallet, check its status and retrieve important information. We are also going to go through how to deposit Bitcoin into your node, and how to open a channel from the command line.

Useful resources:

Make sure Bitcoin is running and synced

Before we can run litd, we will have to make sure Bitcoin Core is running and synced on our machine. We can do that by running:

bitcoin-cli --getinfo

We’ll want to see a line such as Verification progress: 99.9995% in the output. If the verification progress is stalled or the command returns an error, we will need to go back to Run Bitcoin or we will simply have to wait.

Run litd

As we want litd to keep running in the background even when we close the Terminal window, we will append nohup to the command.

nohup litd > /dev/null 2> ~/.lnd/err.log &

Press Enter and observe the logs. It might be very helpful at this stage to open a second Terminal window, ssh into your server and simply keep the logs running in one window, while we interact with the program in another. The LND logs can be very noisy, so we may have to occasionally restart the logs if they appear stuck.

tail -f ~/.lnd/logs/bitcoin/mainnet/lnd.log

Create a wallet

Most likely, our LND logs will eventually stop at the following line:

2023-06-06 15:10:05.825 [INF] LTND: Version: 0.16.2-beta commit=v0.16.2-beta, build=production, logging=default, debuglevel=info
2023-06-06 15:10:05.825 [INF] LTND: Active chain: Bitcoin (network=mainnet)
2023-06-06 15:10:05.825 [INF] RPCS: Generating TLS certificates...
2023-06-06 15:10:05.828 [INF] RPCS: Done generating TLS certificates
2023-06-06 15:10:05.831 [INF] RPCS: RPC server listening on
2023-06-06 15:10:05.834 [INF] RPCS: gRPC proxy started at
2023-06-06 15:10:05.834 [INF] LTND: Opening the main database, this might take a few minutes...
2023-06-06 15:10:05.834 [INF] LTND: Opening bbolt database, sync_freelist=false, auto_compact=false
2023-06-06 15:10:06.889 [INF] LTND: Creating local graph and channel state DB instances
2023-06-06 15:10:09.757 [INF] CHDB: Checking for schema update: latest_version=29, db_version=29
2023-06-06 15:10:09.757 [INF] CHDB: Checking for optional update: prune_revocation_log=false, db_version=empty
2023-06-06 15:10:09.757 [INF] LTND: Database(s) now open (time_to_open=3.923391736s)!
2023-06-06 15:10:09.758 [INF] LTND: We're not running within systemd or the service type is not 'notify'
2023-06-06 15:10:09.758 [INF] LTND: Waiting for wallet encryption password. Use `lncli create` to create a wallet, `lncli unlock` to unlock an existing wallet, or `lncli changepassword` to change the password of an existing wallet and unlock it.

As this is our first time opening LND, we will generate a new wallet. Ideally, use the second Terminal window and run

lncli create

At first, we will be asked for a wallet password. Choose a good password, ideally from your password manager. You will have to enter it everytime you start up LND.

Do you have an existing cipher seed mnemonic or extended master root key you want to use?
Enter 'y' to use an existing cipher seed mnemonic, 'x' to use an extended master root key 
or 'n' to create a new seed (Enter y/x/n):

Next, we are asked if we already have a seed. Unless we are restoring an old, inactive node, we will generate a new seed by pressing n.

Optionally, you are asked if you want to encrypt your seed phrase. If you opt to do so, don’t forget to back up this encryption phrase, too! Otherwise, just leave the field empty and press Enter.

Write down the seed phrase, in your password manager or ideally on a piece of paper and store it well. You are not able to retrieve the seed phrase later from your node.

Your node will now begin to sync to the B

2023-06-06 15:13:18.964 [INF] LNWL: Started rescan from block 00000000000000000002e56ebe6959efb73a3c09fd177c1f5a9041a103b6657f (height 792856) for 0 addresses
2023-06-06 15:15:03.275 [INF] LNWL: Catching up block hashes to height 793172, this might take a while
2023-06-06 15:15:03.277 [INF] LNWL: Done catching up block hashes
2023-06-06 15:15:03.278 [INF] LNWL: Finished rescan for 0 addresses (synced to block 000000000000000000055507311aafceeb734d5ab028c9ca24750c32ddf7af91, height 793172)
2023-06-06 15:15:03.918 [INF] LTND: Chain backend is fully synced (end_height=793172)!
2023-06-06 15:15:03.919 [WRN] HLCK: check: disk space configured with 0 attempts, skipping it
2023-06-06 15:15:03.919 [WRN] HLCK: check: tls configured with 0 attempts, skipping it
2023-06-06 15:15:03.919 [INF] LNWL: SigPool starting
2023-06-06 15:15:03.961 [INF] CHNF: ChannelNotifier starting
2023-06-06 15:15:03.961 [INF] PRNF: PeerNotifier starting
2023-06-06 15:15:03.961 [INF] HSWC: HtlcNotifier starting
2023-06-06 15:15:03.961 [INF] SWPR: Sweeper starting
2023-06-06 15:15:03.961 [INF] BTCN: Broadcaster now active
2023-06-06 15:15:03.961 [INF] NTFN: New block epoch subscription
2023-06-06 15:15:03.961 [INF] NTFN: New block epoch subscription
2023-06-06 15:15:03.961 [INF] UTXN: UTXO nursery starting
2023-06-06 15:15:03.968 [INF] BRAR: Breach arbiter starting
2023-06-06 15:15:03.969 [INF] FNDG: Funding manager starting
2023-06-06 15:15:03.969 [INF] HSWC: HTLC Switch starting
2023-06-06 15:15:03.969 [INF] BRAR: Starting contract observer, watching for breaches.
2023-06-06 15:15:03.968 [INF] NTFN: New block epoch subscription
2023-06-06 15:15:03.996 [INF] NTFN: New block epoch subscription
2023-06-06 15:15:03.996 [INF] NTFN: New block epoch subscription
2023-06-06 15:15:03.996 [INF] CNCT: ChainArbitrator starting
2023-06-06 15:15:03.996 [INF] DISC: Authenticated Gossiper starting
2023-06-06 15:15:03.996 [INF] NTFN: New block epoch subscription
2023-06-06 15:15:03.996 [INF] NTFN: New block epoch subscription
2023-06-06 15:15:04.005 [INF] CRTR: Channel Router starting
2023-06-06 15:15:04.031 [INF] CRTR: FilteredChainView starting
2023-06-06 15:15:04.066 [INF] CRTR: Filtering chain using 0 channels active
2023-06-06 15:15:04.081 [INF] CRTR: Prune tip for Channel Graph: height=793172, hash=000000000000000000055507311aafceeb734d5ab028c9ca24750c32ddf7af91
2023-06-06 15:15:04.093 [INF] INVC: InvoiceRegistry starting
2023-06-06 15:15:04.094 [INF] HSWC: Onion processor starting
2023-06-06 15:15:04.094 [INF] NTFN: New block epoch subscription
2023-06-06 15:15:04.119 [INF] NANN: Channel Status Manager starting
2023-06-06 15:15:04.119 [INF] CHFT: ChannelEventStore starting
2023-06-06 15:15:04.119 [INF] CHFT: Adding 0 channels to event store
2023-06-06 15:15:04.119 [INF] CHBU: chanbackup.SubSwapper starting
2023-06-06 15:15:04.119 [INF] NTFN: New block epoch subscription

This shouldn’t take very long as we only just generated our wallet, and LND will only need to scan through the most recent blocks to see if we already made an on-chain transaction to our node.

Next our node is going to sync to the network graph, meaning it is going to download a list of all Lightning Network channels in existence.

2023-06-06 15:16:08.868 [INF] SRVR: Initializing peer network bootstrappers!
2023-06-06 15:16:08.868 [INF] SRVR: Creating DNS peer bootstrapper with seeds: [[nodes.lightning.directory soa.nodes.lightning.directory] [lseed.bitcoinstats.com ]]
2023-06-06 15:16:08.868 [INF] DISC: Attempting to bootstrap with: Authenticated Channel Graph
2023-06-06 15:16:08.873 [INF] DISC: Attempting to bootstrap with: BOLT-0010 DNS Seed: [[nodes.lightning.directory soa.nodes.lightning.directory] [lseed.bitcoinstats.com ]]

We can always follow the progress.

lncli getinfo

We’ll be looking for the following lines in the output to tell us when we are fully synced to the network graph:

    "synced_to_chain": true,
    "synced_to_graph": true

You can also run this command to see progress:

lncli getnetworkinfo

For a fully synced node, it will look something like this. Note that no two Lightning Nodes are exactly the same, they will always have a slightly different view of the network based on how old they are, how they are configured and where in the graph they are located.

    "graph_diameter": 12,
    "avg_out_degree": 5.154589371980676,
    "max_out_degree": 126,
    "num_nodes": 16146,
    "num_channels": 41613,
    "total_network_capacity": "165101051411",
    "avg_channel_size": 3967535.419484296,
    "min_channel_size": "1050",
    "max_channel_size": "550000000",
    "median_channel_size_sat": "1000000",
    "num_zombie_chans": "240377"

Course Objective

Once our node is synced to chain and graph, we will grab it’s URI. A URI is a bit like a URL, it contains your node’s public key before the @ symbol, and how to reach it.

Get the node URI

We’re looking for the uri output of lncli getinfo. Your node may have more than one URI, but it should have at least one to be reachable from the outside. It is also possible to run a node without it being reachable from the outside, but this makes having incoming channels more complicated. Below is an example of a node with an IPv6, IPv4 and Tor URI.

    "uris": [

Generate your first invoice

We are going to generate an invoice with the following command. You can see below how we define the amount, a memo and an expiration time in seconds, which in this case is set to one month.

lncli addinvoice --memo "nodeacademy course objective" --amt 210000 --expiry 2592000

The relevant output will be the “payment request”, and looks like this:



Exciting! You’re now running your own Lightning Network node from source!

Useful commands in LND

Get basic information about your active daemon, such as if it’s running, synced to the main chain, your node URI, etc.

lncli getinfo

Generates a new onchain Taproot address for your node. You can use it to deposit funds to your node.

lncli newaddress p2tr

Shows your on-chain balance:

lncli walletbalance

Opens a channel. Don’t forget to substitute nodekey and the node’s URI! You can find ranked nodes to open channels to on LightningTerminal.

lncli openchannel --node_key <nodekey> --connect <ip address or onion>:<port> --local_amt 2200000 --sat_per_vbyte 21

You can see whether a channel is currently opening or closing with:

lncli pendingchannels

You can see all your channels with:

lncli listchannels

You can pay an invoice with:

lncli payinvoice <invoice>

You can make an onchain payment with:

lncli sendcoins

You can see if your node forwarded any payments with:

lncli fwdinghistory

You can sign a message with:

lncli signmessage

You can see all available commands with:

lncli help

You can turn off LND with:

lncli stop
© 2024 Vancouver Bitcoiners   •  Powered by Bitdevs Vancouver   •   Theme  Moonwalk