ElementsProject / lightning

Core Lightning — Lightning Network implementation focusing on spec compliance and performance
Other
2.84k stars 901 forks source link

Finetuning lightning #2264

Open Elmit2015 opened 5 years ago

Elmit2015 commented 5 years ago

lightning-cli getinfo

{
  "id": "035aef5661e1a6e370db60dc0455796800afd5b51fbc12a0a8b34836b15f5d7ef6", 
  "alias": "TWronald✅", 
  "color": "15c315", 
  "num_peers": 9, 
  "num_pending_channels": 2, 
  "num_active_channels": 6, 
  "num_inactive_channels": 1, 
  "address": [
    {
      "type": "ipv4", 
      "address": "220.133.223.206", 
      "port": 9735
    }
  ], 
  "binding": [
    {
      "type": "ipv4", 
      "address": "0.0.0.0", 
      "port": 9735
    }
  ], 
  "version": "", 
  "blockheight": 558434, 
  "network": "bitcoin", 
  "msatoshi_fees_collected": 0
}

$ lightning-cli listconfigs (partly)

{
  "# version": "", 
  "rgb": "15c315", 
  "alias": "TWronald✅", 
  "log-level": "DEBUG", 
  "log-prefix": "lightningd(6):", 
  "lightning-dir": "/root/.lightning", 
  "rpc-file": "lightning-rpc", 
  "daemon": "false", 
  "ignore-fee-limits": false, 
  "watchtime-blocks": 144, 
  "max-locktime-blocks": 2016, 
  "funding-confirms": 3, 
  "commit-fee-min": 200, 
  "commit-fee-max": 2000, 
  "commit-fee": 500, 
  "cltv-delta": 14, 
  "cltv-final": 10, 
  "commit-time": 10, 
  "fee-base": 1000, 
  "rescan": 15, 
  "fee-per-satoshi": 10, 
  "bind-addr": "0.0.0.0:9735", 
  "announce-addr": "220.133.223.206:9735", 
  "offline": "false", 
  "autolisten": true, 
  "network": "bitcoin", 
  "allow-deprecated-apis": true, 
  "autocleaninvoice-cycle": 0, 
  "autocleaninvoice-expired-by": 86400, 
  "always-use-proxy": false, 
  "disable-dns": "false"
}

I am using docker-compose.

Questions:

  1. Which version do I use? listconfigs removed it, so getinfo can't show it.
  2. Where is the settings done for the fee? To attract more connection to me, I would be willing to change the fee even negative (pay for using my channel) - TEMPORARY Somebody said, he doesn't want to connect to me, because my fees are too high. Really?
  3. If I change something in docker-compose of the settings for lightning, I used to: docker-compose stop docker-compose ps docker-compose rm clightning_bitcoind nano docker-compose.yml docker-compose up (I don't use -d, so that this window always show me something) Do I need to do all that for changing a parameter?

Questions to the channels: Initially I had the impression, that both sides of the channel had to invest a certain amount. I started to invest in 5 channels each 20 US$.

  1. How should I choose peers to make a channel to? by local distance? by fee structure? by ?????
  2. If I lower my fee, then I would attract other nodes to connect to me. How low can I go (negative)?
  3. My understanding about lightning isn't mature yet. If I invested 20 US$ into a channel, and somebody wants to send 40 US$, would my channel be used for 20 and another channel(s) for the rest, or not at all? What happens, if somebody send through my channel 20 US$, then my funds are gone. Can I top up? Or need a new channel?
  4. How is the routing done at all? If somebody wants to pay 1 BTC to person B, I know Alice send 1 BTC to Bob, ... but why was Alice and not Martin sending that 1 BTC? How was Alice chosen? How does the system know that Alice would have somehow a connection to person B?
conscott commented 5 years ago

I'll try to answer some of these...

Which version do I use? listconfigs removed it, so getinfo can't show it.

The latest release is typically desired, you can find it here

Where is the settings done for the fee?

If you run

lightningd --help

You can see all possible config settings, the ones you may be interested in related to fees are --fee-base and --fee-per-satoshi. You can start lightningd with these on the command line or add the following lines to to the lightningd config in ~/.lightning/config

fee-base=XXXX
fee-per-satoshi=XX

There appear to be different philosophies on channel fee-rates. Indeed it's possible to set a negative fee-per-satoshi to encourage incoming connections, but it's up to you if you really want to pay to help route. May people set higher fees than default, believing good routing nodes should earn money for performing the service.

Note that not every node has to be setup like a routing node. If you don't plan on receiving payments and just want to use your channels to pay for things (like Bitrefill), you don't necessarily have to take all the time and effort to get incoming connections and play with routing fees.

If I change something in docker-compose of the settings for lightning, I used to...

I don't run using docker, but yes, if you change the docker-compose.yml you need to restart the instances afaik

How should I choose peers to make a channel to?

The most general answer is: You want a peer that is reliably online with sufficient capacity to handle the amounts you plan to send, and connected-ness to reach most parts of the network graph. Sites like 1ML can help you find the nodes. Eventually features like autopilot will help automate this process so users don't have to manage channels themselves.

I highly recommend watching Alex Bosworth's video explaining channel management here

If I lower my fee, then I would attract other nodes to connect to me. How low can I go (negative)?

Presumably, yes, but I have not actually tested this theory. There are currently thousands of nodes to choose from, so whether or not a random person chooses to connect to you is somewhat up to chance. When you first come online it is unclear if your node will be reliable (which you can only improve by staying online). The best option now may be to just to find other people via ric / reddit / twitter / etc. to connect to your node. As said before, if you don't actually need to receive payments on your node and just want to pay for stuff, it may be less important to have incoming capacity. You also naturally increase your incoming capacity when you pay for things (because it drops your outgoing capacity and the channel total remains fixed). There also may also be services / sites automatically doing a 'connect to me and ill connect to you' type thing that I am not aware of.

My understanding about lightning isn't mature yet. If I invested 20 US$ into a channel, and somebody wants to send 40 US$, would my channel be used for 20 and another channel(s) for the rest, or not at all? What happens, if somebody send through my channel 20 US$, then my funds are gone.

If you open a channel funding yourself with $20, you have $20 of outgoing capacity on $0 of incoming capacity. If you send $10 over that channel to pay for something, you now have $10 outgoing capacity and $10 incoming capacity. Assuming this is your only channel, you could only receive up to $10 over this channel. If someone wanted to send you $40, they would have to open up another channel to you for at least $40.

Right now a single payment cannot be split between multiple channels, but this is planned as a future feature (Atomic Multi-Path Payments)

Can I top up? Or need a new channel?

"Toppping up" is also a future improvement planned called 'splicing'. For now you would need to open a new channel if you want to increase your capacity.

How is the routing done at all?

This is a complex topic that I cannot sufficiently summarize here. I recommend reading the Lightning Network section of this chapter in Mastering Bitcoin.

Hope this helps. If any else reading this had a correction to what I have written, please update, I am no expert :)

Elmit2015 commented 5 years ago

Thank you so much. I appreciate your lengthy reply. It helps me a lot, however, it brings also up more questions. Just guide me to the right places to find the answers.

Watching the movie of Alex Bosworth. He mentioned that you can route easier or more difficulty for nodes unreliable, by use a different fee structure. However, I can only see a fee structure for MY node, not the node I am connecting / routing to (channel).

Watching 1ML (to which I am connected to) I see mostly different values on my connection peers and my node. Should I adjust, and what does it actually mean anyway:

Example:

Alias | Capacity | Time Lock Delta | Min HTLC | Base Fee | Fee Rate TWronald✅ | 0.05892979 BTC $217.46 | 14 | 1,000 | 1.000 sat $0.000036901 | 0.000010 sat $0.000000000369

NewMoney | 1.59655778 BTC $5,891.43 | 144 | 0 | 1.000 sat $0.000036901 | 0.000001 sat $0.000000000037

Time Lock Delta is on the other side 144, mine 14 Min HTLC is on the other side 0, mine 1,000 Fee Rate is on the other side 0.000001 sat, mine 0.000010 sat

Should I adjust that? What would the result be of a change?

What is a good channel funding? I used to the 5 channels I (randomly) opened each about 20 US$. Alex says double of expected amount people spend over your channel. I don't know that. I don't know where they want to buy something, what it cost, ... I understand that if I put into each channel 10 BTC it's just dormant and waste, if I use only 1 US$, my channel would be hardly used. What is the best value? 50 US$?

If I watch all my channels I am connected to and made a list like:

Node name: Capacity Channel Count Color IP Addresses
Livingfree 0.50716083 BTC (0.106% of total) $1,870.34 21 (0.108% of total) #3399ff 27.33.191.163:9735
NewMoney 1.59655778 BTC (0.335% of total) $5,887.88 171 (0.882% of total) #39ff14 188.84.254.97:9735
1ML.com node ALPHA 4.42108072 BTC (0.927% of total) $16,299.91 513 (2.645% of total) #3399ff 23.237.77.11:9735
KRYPTO.KOELN 1.51674434 BTC (0.318% of total) $5,592.07 372 (1.918% of total) #3399ff 5.189.141.242:9735
LightningTo.Me 7.04017160 BTC (1.477% of total) $25,958.45 416 (2.145% of total) #3dffbe 138.68.14.104:9735
blindedbythelight 0.15936654 BTC (0.033% of total) $587.61 17 (0.088% of total) #3399ff 50.66.209.54:9735 50.66.209.54:9736
         
Twronald 0.05892979 BTC (0.012% of total) $217.46 6 (0.031% of total) #15c315 220.133.223.206:9735
         
mylightningworld.com 0.12000010 BTC (0.025% of total) $442.45 5 (0.026% of total) #02986d 159.65.202.160:9735

Is there a way to make that list automatically from my collected data?

Is loglevel DEBUG useful? Would be INFO, UNUSUAL or IO sufficient for me?

Regarding the version. With docker-compose I pull the latest version. Is there a file I can see what version it is? or do I need to remember and change the docker-compose.yml file?

conscott commented 5 years ago

Sorry for taking a while to get back to you. Tried to give another round of answers.

What is a good channel funding?

It really depends on how much/often you want to use the network. For a regular user, the answer might be: "The amount I intend to spend with bitcoin in the next few months"

You really only need to worry about having balanced channels and inbound capacity if you intend on making your node attractive for payment routing or receiving payments. If you just want to spend money using lightning on services like Bitrefill, it's less of a concern, you just want a channel with outbound capacity equivalent to what you want to spend. Keep in mind that opening and closing a channel each requires 1 on-chain transaction, which incurs tx fees, so opening small channels (< $5) isn't very cost effective depending on the current fee market. For instance, paying $0.30 in tx fees to open a $2 channel doesn't make much sense.

Also note that if you opened 5 channels with $20 each, it doesn't mean you could purchase something worth $100, you could only purchase 5 things worth $20. You can only send up the max amount for a single channel. In the future this may change with AMP but for now it's not the case.

If you want to make your make your channel attractive for routing, it takes some effort and requires larger channels. In the future this will all be much more automated but for now requires a bit of manual management (which you saw in Alex's video).

Is there a way to make that list automatically from my collected data?

lightning-cli listpeers gives you information on the peers you are currently connected to, however it does not give you aggregated info like their channel count and total capacity (which 1ML does). You can manually build this information with the output of lightning-cli listchannels, but it would require some code. I am building some plugins to make these stats easier from the command line.

Is loglevel DEBUG useful? Would be INFO, UNUSUAL or IO sufficient for me?

Debug level is useful if you encounter an error, so you can paste logs here and developers can help assess any issues. Just be aware that debug logs are much larger than the default log level (info), and can grow considerably (300 MB+) and take IO from your other processes. Most people don't run in debug level unless they are a developer, or specifically trying to recreate a bug so they can capture the logs prior to a crash/unexpected behavior. The default level of "INFO" should be fine for you.

As for the other questions about time lock delta and max HTLC, you can read more about those setting in the config docs here. For most users, the default settings should be fine, they are mostly "tweakables" for those interested in optimizing their routing.

ZmnSCPxj commented 4 years ago

Has this been satisfactorily answered?