Pages:
Author

Topic: bitcoind, c-lightning and RTL on centos 7 (walktrough) - page 2. (Read 512 times)

legendary
Activity: 2898
Merit: 1823
But, that reinforces the belief that the nodes in the Lightning Network will evolve to become more specialized, and routing fees becoming higher than they are now. It also takes a valuable commodity, Bitcoins, staked in channels.

why?

it's a supply and demand equation, but with privacy incentives distorting the supply-side. It seems more likely to me that the market will always tend toward liquidity over-supply (which is obviously better than under-supply), and so fees will frequently or always be at or lower than any "specialized" node could tolerate


In theory, I could be wrong. Because I don't believe that the people running LN nodes will continue doing so altruistically forever, not especially when it requires staking a valued commodity, and some level of specialization.
legendary
Activity: 3430
Merit: 3071
But, that reinforces the belief that the nodes in the Lightning Network will evolve to become more specialized, and routing fees becoming higher than they are now. It also takes a valuable commodity, Bitcoins, staked in channels.

why?

it's a supply and demand equation, but with privacy incentives distorting the supply-side. It seems more likely to me that the market will always tend toward liquidity over-supply (which is obviously better than under-supply), and so fees will frequently or always be at or lower than any "specialized" node could tolerate
legendary
Activity: 3388
Merit: 4919
https://merel.mobi => buy facemasks with BTC/LTC
That was going to be in my next question.

But, that reinforces the belief that the nodes in the Lightning Network will evolve to become more specialized, and routing fees becoming higher than they are now. It also takes a valuable commodity, Bitcoins, staked in channels.

My main idear wasn't to make a profit, but rather learn the "new" (at that time) lightning protocol... I do hope that sooner or later, the fees might increase a little bit, but as for now: nobody knows Smiley

I'm a bit curious,
1. What is average RAM usage after install all of these tools?
2. Does Bitcoin Core use most of the RAM in your case (since you use value 2048 for you dbcahce) ?


Yup, dbcache was set to 2048 to speed up the intial sync, afterwards it's perfectly fine to remove this parameter.
Here you go (i've snipped all processes that had nothing to do with this particular stack) Smiley
Code:
 ps -o pid,user,%mem,command ax | sort -b -k3 -r
  PID USER     %MEM COMMAND
13827 bitcoin  18.3 /usr/local/bin/bitcoind -daemon -conf=/home/bitcoin/.bitcoin/bitcoin.conf
22686 bitcoin   0.7 /usr/bin/node /home/bitcoin/RTL/rtl.js
20476 bitcoin   0.6 /usr/local/bin/lightningd --daemon --conf /home/bitcoin/.lightning/bitcoin/lightningd.conf
21778 bitcoin   0.6 /usr/bin/node /home/bitcoin/c-lightning-REST/cl-rest.js
20487 bitcoin   0.0 /usr/local/libexec/c-lightning/lightning_hsmd
20489 bitcoin   0.0 /usr/local/libexec/c-lightning/lightning_gossipd
20488 bitcoin   0.0 /usr/local/libexec/c-lightning/lightning_connectd
20478 bitcoin   0.0 /usr/local/bin/../libexec/c-lightning/plugins/pay
20477 bitcoin   0.0 /usr/local/bin/../libexec/c-lightning/plugins/fundchannel
20479 bitcoin   0.0 /usr/local/bin/../libexec/c-lightning/plugins/autoclean
29533 nginx     0.0 nginx: worker process
29532 nginx     0.0 nginx: worker process
29531 nginx     0.0 nginx: worker process

Code:
cat /proc/meminfo
MemTotal:        2913960 kB
MemFree:           79220 kB
MemAvailable:    1919348 kB
Buffers:            3020 kB
Cached:          2067608 kB
SwapCached:        11496 kB
Active:          1341376 kB
Inactive:        1354236 kB
Active(anon):     362948 kB
Inactive(anon):   375720 kB
Active(file):     978428 kB
Inactive(file):   978516 kB
Unevictable:           4 kB
Mlocked:               4 kB
SwapTotal:       1048568 kB
SwapFree:         741632 kB
Dirty:                64 kB
Writeback:             0 kB
AnonPages:        615284 kB
Mapped:           105608 kB
Shmem:            113628 kB
Slab:              59592 kB
SReclaimable:      36760 kB
SUnreclaim:        22832 kB
KernelStack:        5104 kB
PageTables:        21064 kB
NFS_Unstable:          0 kB
Bounce:                0 kB
WritebackTmp:          0 kB
CommitLimit:     2505548 kB
Committed_AS:    2735808 kB
VmallocTotal:   34359738367 kB
VmallocUsed:       13956 kB
VmallocChunk:   34359720444 kB
HardwareCorrupted:     0 kB
AnonHugePages:     20480 kB
CmaTotal:              0 kB
CmaFree:               0 kB
HugePages_Total:       0
HugePages_Free:        0
HugePages_Rsvd:        0
HugePages_Surp:        0
Hugepagesize:       2048 kB
DirectMap4k:      182144 kB
DirectMap2M:     1914880 kB
DirectMap1G:     1048576 kB

Code:
top - 07:27:07 up 4 days,  4:39,  1 user,  load average: 0.00, 0.03, 0.05
Tasks: 140 total,   1 running, 139 sleeping,   0 stopped,   0 zombie
%Cpu(s):  0.0 us,  2.1 sy,  0.0 ni, 97.9 id,  0.0 wa,  0.0 hi,  0.0 si,  0.0 st
KiB Mem :  2913960 total,    85292 free,   727596 used,  2101072 buff/cache
KiB Swap:  1048568 total,   741632 free,   306936 used.  1919012 avail Mem
legendary
Activity: 2870
Merit: 7490
Crypto Swap Exchange
I'm a bit curious,
1. What is average RAM usage after install all of these tools?
2. Does Bitcoin Core use most of the RAM in your case (since you use value 2048 for you dbcahce) ?
legendary
Activity: 2898
Merit: 1823
How much would your average monthly cost be for electricity, internet connection, maintenance, if you keep your Lightning node running for 24/7 that specializes in providing liquidity?

To be honest, i hire a dedicated server which i've partitioned into smaller VPS's. A dedicated box costs me €40/month, but i would be able to install 5 or 6 full stacks on such a dedicated server, so if you pool your resources with 3 other forum members, you'd have a nice VPS with plenty of resources for €10/month if you'd want to.

If you want to do a home setup, much depends on the power draw of your machine... An avarage laptop draws 60 Watts (according to google), beause there's a lot of IO and system load, i'd guess a laptop running such a stack would draw a little bit more.
80 Watt * 24 hours * 31 days =~ 60 Kwh.
In my country i pay about 30 cents per Kwh, so the cost of running a node on a home laptop would be ~€18/month, not including the wear and tear of the hardware.

As you can see in the screenshot, i'll never break even (my node has been online for about 1 year and 3 months, and i've earned 1.2 satoshi's in routing fees)

That was going to be in my next question.

But, that reinforces the belief that the nodes in the Lightning Network will evolve to become more specialized, and routing fees becoming higher than they are now. It also takes a valuable commodity, Bitcoins, staked in channels.
legendary
Activity: 3388
Merit: 4919
https://merel.mobi => buy facemasks with BTC/LTC
How much would your average monthly cost be for electricity, internet connection, maintenance, if you keep your Lightning node running for 24/7 that specializes in providing liquidity?

To be honest, i hire a dedicated server which i've partitioned into smaller VPS's. A dedicated box costs me €40/month, but i would be able to install 5 or 6 full stacks on such a dedicated server, so if you pool your resources with 3 other forum members, you'd have a nice VPS with plenty of resources for €10/month if you'd want to.

If you want to do a home setup, much depends on the power draw of your machine... An avarage laptop draws 60 Watts (according to google), beause there's a lot of IO and system load, i'd guess a laptop running such a stack would draw a little bit more.
80 Watt * 24 hours * 31 days =~ 60 Kwh.
In my country i pay about 30 cents per Kwh, so the cost of running a node on a home laptop would be ~€18/month, not including the wear and tear of the hardware.

As you can see in the screenshot, i'll never break even (my node has been online for about 1 year and 3 months, and i've earned 1.2 satoshi's in routing fees)
legendary
Activity: 2898
Merit: 1823
How much would your average monthly cost be for electricity, internet connection, maintenance, if you keep your Lightning node running for 24/7 that specializes in providing liquidity?
legendary
Activity: 3388
Merit: 4919
https://merel.mobi => buy facemasks with BTC/LTC
I'm thinking about adding a walktrough on how to install btcpayserver on top of the above stack... But i haven't written any documentation about this process (yet)... So i'll either update this post in the future, or i'll remove it (if i decide adding btcpayserver is to much work)
legendary
Activity: 3388
Merit: 4919
https://merel.mobi => buy facemasks with BTC/LTC
RTL
prereqs: running and synced bitcoin core, running lightningd (c-lightning)

step 1: make sure you're user bitcoin, make sure you're in the home folder, install the prereqs
Code:
whoami
pwd
cd ~
sudo yum install -y gcc-c++ make
sudo curl -sL https://rpm.nodesource.com/setup_12.x | sudo -E bash -
sudo yum install nodejs

step 2: clone and build c-lightning-REST (this is a prereq for RTL)
Code:
git clone https://github.com/saubyk/c-lightning-REST
cd c-lightning-REST
npm install
cp sample-cl-rest-config.json cl-rest-config.json
sudo lsof -i :3001
sudo lsof -i :4001
if the lsof command return nothing, the cl-rest-config.json should not be edited, if an other service is listening to port 3001 or 4001, you'll need to edit cl-rest-config.json

step 3: create a service file for c-lightning-REST
Code:
sudo nano /etc/systemd/system/c-lightning-REST.service

step 4: fill c-lightning-REST.service
Code:
[Unit]
Description=c-lightning-REST daemon
Wants=lightningd.service
After=lightningd.service

[Service]
ExecStart=/usr/bin/node /home/bitcoin/c-lightning-REST/cl-rest.js
User=bitcoin
Group=bitcoin
Restart=always
TimeoutSec=120
RestartSec=30

[Install]
WantedBy=multi-user.target

step 5: enable and start the service
Code:
sudo systemctl enable c-lightning-REST.service
sudo service c-lightning-REST start

step 6: make sure you're back into your home folder
Code:
cd ~

step 7: clone and build RTL
Code:
git clone https://github.com/Ride-The-Lightning/RTL.git
cd RTL
npm install
cp sample-RTL-Multi-Node-Conf.json RTL-Multi-Node-Conf.json

step 8: edit RTL-Multi-Node-Conf.json
Code:
{
  "multiPass": "very_strong_password",
  "port": "3000",
  "defaultNodeIndex": 1,
  "SSO": {
    "rtlSSO": 0,
    "rtlCookiePath": "",
    "logoutRedirectLink": ""
  },
  "nodes": [
    {
      "index": 1,
      "lnNode": "C Lighting",
      "lnImplementation": "CLT",
      "Authentication": {
        "macaroonPath": "/home/bitcoin/c-lightning-REST/certs/"
      },
      "Settings": {
        "userPersona": "MERCHANT",
        "themeMode": "NIGHT",
        "themeColor": "TEAL",
        "channelBackupPath": "/home/bitcoin/RTL/",
        "bitcoindConfigPath": "/home/bitcoin/.bitcoin/",
        "enableLogging": true,
        "fiatConversion": false,
        "lnServerUrl": "https://127.0.0.1:3001/v1"
      }
    }
  ]

step 9: create service file
Code:
sudo nano /etc/systemd/system/RTL.service

step 10: fill RTL.service
Code:
[Unit]
Description=RTL daemon
Wants=c-lightning-REST.service
After=c-lightning-REST.service

[Service]
ExecStart=/usr/bin/node /home/bitcoin/RTL/rtl.js
User=bitcoin
Group=bitcoin
Restart=always
TimeoutSec=120
RestartSec=30

[Install]
WantedBy=multi-user.target

step 11: enable and start RTL service
Code:
sudo systemctl enable RTL.service
sudo service RTL start

At this point, you have RTL up and running... If you surf to https://127.0.0.1:3000 you'll be able to login and manage your lightning node.
HOWEVER, if you've installed RTL on a server without a desktop environment and/or without proper x server forewarding, you'll need to execute the following steps in order to be able to surf to RTL (the RTL daemon only listens on localhost port 3000, so i't not accessible on an external port


step 1: register a tld. If you don't want to spend any money, a .tk domain is free. Make sure there's an a-record for this domain that points to your server. If you really don't have a domain, contact me and i'll give you a free [yourname].mocacinno.com subdomain

step 2: request a certificate for this domain using certbot
Code:
sudo yum install nginx certbot
sudo certbot certonly

step 3: open nginx.conf
Code:
nano /etc/nginx/nginx.conf

step 4: edit nginx.conf
Code:
user nginx;
worker_processes auto;
error_log /var/log/nginx/error.log;
pid /run/nginx.pid;

# Load dynamic modules. See /usr/share/doc/nginx/README.dynamic.
include /usr/share/nginx/modules/*.conf;

events {
    worker_connections 1024;
}



stream {
        upstream RTL {
                server 127.0.0.1:3000;
        }

        server {
                listen 3002 ssl;
                proxy_pass RTL;

                ssl_certificate /etc/letsencrypt/live/yourdomain.tld/fullchain.pem;
                ssl_certificate_key /etc/letsencrypt/live/yourdomain.tld/privkey.pem;
                ssl_session_cache shared:SSL:1m;
                ssl_session_timeout 4h;
                ssl_protocols TLSv1 TLSv1.1 TLSv1.2;
                ssl_prefer_server_ciphers on;
        }
}


step 5: restart nginx
Code:
sudo service nginx restart

step 6: you now have RTL up and running: https://yourdomain.tld:3002







legendary
Activity: 3388
Merit: 4919
https://merel.mobi => buy facemasks with BTC/LTC
c-lightning
prereqs: running and synced bitcoin core

step 1: make sure you're user bitcoin, make sure you're in the home folder, install the prereqs
Code:
whoami
pwd
cd ~
sudo  yum install -y autoconf automake boost-devel gcc-c++ git libdb4-cxx libdb4-cxx-devel libevent-devel libtool openssl-devel wget libsodium-devel gmp-devel sqlite-devel python34 asciidoc clang python2-devel pythong34-devel python34-pip
sudo pip3 install Mako

step 2: clone and build c-lightning
Code:
git clone https://github.com/ElementsProject/lightning.git
cd lightning
git checkout v0.8.0
./configure
make -j $(nproc)
sudo make install
make sure you checkout the latest release (at the time of writing, this is v0.8.0, but later on this number will increase)

step 3: create the service
Code:
sudo nano /usr/lib/systemd/system/lightningd.service

step 4: fill lightningd.service
Code:
[Unit]
Description=C-Lightning daemon
Requires=bitcoind.service
After=bitcoind.service
Wants=network-online.target
After=network-online.target

[Service]
ExecStart=/usr/local/bin/lightningd --daemon --conf /home/bitcoin/.lightning/bitcoin/lightningd.conf

User=bitcoin
Group=bitcoin
Type=forking
Restart=on-failure

# Hardening measures
####################

# Provide a private /tmp and /var/tmp.
PrivateTmp=true

# Mount /usr, /boot/ and /etc read-only for the process.
ProtectSystem=full

# Disallow the process and all of its children to gain
# new privileges through execve().
NoNewPrivileges=true

# Use a new /dev namespace only populated with API pseudo devices
# such as /dev/null, /dev/zero and /dev/random.
PrivateDevices=true

# Deny the creation of writable and executable memory mappings.
MemoryDenyWriteExecute=true

[Install]
WantedBy=multi-user.target

step 5: create conf file
Code:
nano /home/bitcoin/.lightning/bitcoin/lightningd.conf

step 6: fill conf file
Code:
network=bitcoin
log-level=debug
log-file=/home/bitcoin/.lightning/debug.log
daemon
alias=alias_for_your_node

step 7: enable and start the service
Code:
sudo systemctl enable lightningd.service
sudo service lightningd start

step 8: monitor the startup progress
Code:
tail -f /home/bitcoin/.lightning/debug.log
press "Ctrl-c" to stop the tail, after a while you might decide to decrease the log level (step 6)

Finished...

legendary
Activity: 3388
Merit: 4919
https://merel.mobi => buy facemasks with BTC/LTC
Bitcoin core
prereqs: running (base) system

step 1: create service user, install prereqs
Code:
adduser bitcoin
passwd bitcoin
usermod -aG wheel bitcoin
yum -y install epel-release
yum install -y autoconf automake boost-devel gcc-c++ git libdb4-cxx libdb4-cxx-devel libevent-devel libtool openssl-devel wget nano python3
su - bitcoin

step 2: verify
Code:
whoami
pwd
you should see you're "bitcoin" and your current working directory is "/home/bitcoin"

step 3: build Smiley
Code:
git clone https://github.com/bitcoin/bitcoin.git
cd bitcoin
git checkout v0.19.0.1
./autogen.sh
./configure
make -j $(nproc)
sudo make install
make sure you checkout the latest release (at the time of writing, this is v0.19.0.1, but later on this number will increase)

step 4: create password hash
Code:
cd share/rpcauth/
 python3 rpcauth.py the_username_of_the_user_you_want cleartext_password_unique_long
Caveat: the plaintext password will be saved in your history!! pick a unique one and/or clean up your history afterwards!!!

step 5: make dir, create conf
Code:
mkdir ~/.bitcoin
nano ~/.bitcoin/bitcoin.conf

step 6: fill bitcoin.conf
Code:
daemon=1
server=1
maxmempool=50
mempoolexpiry=2
rpcauth=user_chose_in_step_4:hash_created_in_step_4
dbcache=2048
banscore=10
datadir=/home/bitcoin/.bitcoin/

step 7: create service file
Code:
sudo nano /usr/lib/systemd/system/bitcoind.service

step 8: file bitcoind.service
Code:
[Unit]
Description=Bitcoin daemon
After=network.target

[Service]
ExecStart=/usr/local/bin/bitcoind -daemon -conf=/home/bitcoin/.bitcoin/bitcoin.conf

# Make sure the config directory is readable by the service user
PermissionsStartOnly=true

# Process management
####################

Type=forking
Restart=on-failure

# Directory creation and permissions
####################################

# Run as bitcoin:bitcoin
User=bitcoin
Group=bitcoin

# Hardening measures
####################

# Provide a private /tmp and /var/tmp.
PrivateTmp=true

# Mount /usr, /boot/ and /etc read-only for the process.
ProtectSystem=full

# Disallow the process and all of its children to gain
# new privileges through execve().
NoNewPrivileges=true

# Use a new /dev namespace only populated with API pseudo devices
# such as /dev/null, /dev/zero and /dev/random.
PrivateDevices=true

# Deny the creation of writable and executable memory mappings.
MemoryDenyWriteExecute=true

[Install]
WantedBy=multi-user.target

step 9: enable and start bitcoind service
Code:
sudo systemctl enable bitcoind.service
sudo service bitcoind start

step 10: final step: check if your node is syncing
Code:
tail -f ~/.bitcoin/debug.log
once everything seems to be working, press "Ctrl-C"

step 11: (optional), re-visit step 6 and remove the banscore variable and decrease dbcache

Finished... Now you'll have to wait several hours for your node to sync... You can only proceed to the next step once this process is finished

legendary
Activity: 3388
Merit: 4919
https://merel.mobi => buy facemasks with BTC/LTC
bitcoind, c-lightning and RTL on centos 7 (walktrough)

I decided to write down some documentation on how to rebuild some of my services in case i ever faced a system crash, and because i more or less had all documentation on my system, i decided to update everything and publish it on this forum AND my blog... This way everybody could use my documentation to setup their own services of they ever wanted to.

some remaks:
  • I'm not taking any political stance here... The lightning network has pro's and con's, it's not completely mature (yet). This thread is NOT for discussing LN merits or shortcomings, but merely a technical walk-trough on how to get things up and running
  • my system specs: Centos 7, KVM VPS, 3 Gb RAM, 3vCPU's... The most important spec, however, is the disksize... A full node requires 278G at this moment, and there is a (theoritical) growth potential of ~17 Gb/month. Add some space for binaries, updates, builds, logs,... So you'll need at very least 350 Gb of free space on your filesystem
  • not all VPS providers will deliver a VPS that has the same configuration... It's possible some prereqs were already met in my basic image, while you have to install them yourself (or vice-versa)
  • i didn't document the firewall rules, because there are several possible firewall-implementations, and basically, if i'd have to go into the details of setting up firewallrules, i'd need a completely seperate firewall tutorial alltogether. If you have a clean (unused) VPS or you're installing a server in your HOME network (behind your own firewall), you *might* want to disable the firewall for testing puposes (re-enable it afterwards tough!!!)
  • i didn't document the backup procedures. Always make sure you backup wallets, seeds,...
  • no guarantee... If you follow these steps and lose money: don't blame me
  • no help... Sure, i might try to help you out if you run into problems, but i'm under no obligation to do so. Best effort only, and only when i have time to help you
  • no docker. Sure, docker is great, but if you run docker containers, you'll never know what's under the hood Smiley. It's easy to download and spin up a docker container, but you'll learn little (or nothing). Don't get me wrong, if you're building your own containers or if you don't want to learn how to setup your service, docker is great... Just not if you want to get your hands dirty Smiley
  • bitcoin core, c-lightning and RTL are built from source in this walktrough... It's up to you to periodically perform updates (not only for these binaries, but for all packages on your system)
  • this tutorial is a work in progress... There are many other steps (hardening, cleanup,...) that could happen. I'll probably edit these steps when i get input, or when i think about something myself. This is also why i split up this thread, this way every step has the chance/space to grow in the future...

Overview Of what we'll be installing
Bitcoin Core: a full node implementation and wallet, sometimes called the reference client. This node fetches all blocks and unconfirmed transactions from the peers it's connected to, parses and verifies everything and has a full wallet functionality
C-lightning: a Lightning Network implementation in C. Create lightning channels, create or pay lightning invoices.
RTL: Ride the lightning: one of the best GUI's that can be used on top of an existing c-lightning daemon. No extra functionality, but a lot easyer to use than using lightning-cli
Pages:
Jump to: