Progress pill
Introduction and Preparatory Courses

Running Bitcoin

Alekos Filini
Alekos Filini
  • Installation of Bitcoin Core
  • Running a Bitcoin node
  • What you can do with Bitcoin Core and its benefits
  • Fundamental commands
  • Installation of C-lightning
  • C-Lightning installation
  • Security and hardware devices
  • Specter and Ledger device
  • Setup and configuration
  • Advanced configurations

Installation of Bitcoin Core

In the first lecture of the 4th module, we explored Bitcoin's architecture and the installation of a Bitcoin Core node.

Running a Bitcoin node

1. Introduction recap Welcome back! In the previous session, we covered the fundamental concepts behind Bitcoin’s architecture, including its cryptographic foundations and the peer-to-peer network structure. Today, we'll move from theory to practice by demonstrating how to install and configure a Bitcoin node.
2. Practical session overview In this session, Alekos will walk us through the process of setting up a Bitcoin node using a virtual machine. This hands-on tutorial is designed to familiarize you with the steps involved in configuring your node to participate in the Bitcoin network.
Running a Bitcoin node involves validating transactions and blocks, enforcing consensus rules, and supporting the network’s decentralization. Setting up a node ensures you have a direct connection to the Bitcoin network, allowing you to contribute to its security and integrity.
In this lecture, you will find a guide to install and run your own Bitcoin Core, learn how to prune the blockchain to save space, and begin experimenting with the software. Alekos will guide you step by step through this exciting process.

What you can do with Bitcoin Core and its benefits

By running Bitcoin Core, you gain the ability to:
  • Validate your own transactions and blocks: Ensuring that the Bitcoin network's rules are followed without relying on third parties.
  • Strengthen the network: By participating in the network, you help keep it decentralized, making Bitcoin more resilient to attacks.
  • Prune the blockchain: Reduce the storage requirements by keeping only the most recent transactions, which is ideal if you have limited disk space.
  • Use advanced wallet features: Manage your Bitcoin with privacy and security, generate private keys offline, and sign transactions securely.
  • Interact with the Bitcoin network directly: By using Bitcoin Core, you can connect directly to the network without intermediaries, ensuring you get the most accurate data.
  • Benefit from increased privacy: As a full node operator, you don’t have to trust external services, protecting your transaction privacy from external surveillance.
The benefits of running a Bitcoin node are substantial for any dedicated Bitcoiner. Not only do you help secure the network and reinforce its decentralization, but you also enhance your privacy, ensure the integrity of your own transactions, and take a proactive role in the Bitcoin ecosystem. Running a node is a key step in achieving financial sovereignty and fully embracing the decentralized nature of Bitcoin.

Fundamental commands

These are some of the basic commands when configuring your node:
  • Check the status of the Bitcoin daemon:
    sudo systemctl status bitcoind
  • Start the Bitcoin daemon::
    systemctl start bitcoind
  • Stop the Bitcoin daemon::
    sudo systemctl stop bitcoind
    • Get detailed information:
    bitcoin-cli getblockchaininfo
  • Prune the blockchain to save disk space by keeping only the most recent blocks::
    prune=550
  • Enable the Bitcoin Core server and configure RPC settings::
    server=1 rpcuser=yourusername rpcpassword=yourpassword
  • Check the status of the Bitcoin daemon:
    sudo systemctl status bitcoind
  • Check the balance of your Bitcoin wallet::
    sudo systemctl status bitcoind

Installation of C-lightning

1. Bitcoin Core recap

Let's start with a brief recap of the steps involved in installing Bitcoin Core on a cloud VM, as this will be crucial for our subsequent setup of C-Lightning.
Reinstalling Bitcoin Core on a cloud VM To begin, you'll want to reinstall Bitcoin Core on your virtual machine. For this session, we'll skip the verification of binaries to save time, but remember that in a production environment, verifying binaries is a critical step to ensure security.
Download and verify file hashes First, download the latest Bitcoin Core release and verify the file hashes to ensure no tampering has occurred.
wget https://bitcoin.org/bin/bitcoin-core-22.0/bitcoin-22.0-x86_64-linux-gnu.tar.gz sha256sum bitcoin-22.0-x86_64-linux-gnu.tar.gz # Compare the output hash with the official hash
Install the binary and configure auto-start with systemd Next, install the binary and set it up to auto-start using systemd.
tar -xzf bitcoin-22.0-x86_64-linux-gnu.tar.gz sudo install -m 0755 -o root -g root -t /usr/local/bin bitcoin-22.0/bin/*
Create a systemd service file:
sudo nano /etc/systemd/system/bitcoind.service
Add the following configuration:
[Unit] Description=Bitcoin daemon After=network.target [Service] ExecStart=/usr/local/bin/bitcoind -daemon User=bitcoin Group=bitcoin Type=forking PIDFile=/var/lib/bitcoind/bitcoind.pid Restart=on-failure [Install] WantedBy=multi-user.target
Create and configure Bitcoin user and directories Create a dedicated user and set up directories for Bitcoin Core.
sudo adduser --disabled-login --gecos "" bitcoin sudo mkdir -p /var/lib/bitcoind sudo chown bitcoin:bitcoin /var/lib/bitcoind
Use minimal disk space by pruning the blockchain To save disk space, enable pruning in the configuration file.
sudo nano /var/lib/bitcoind/bitcoin.conf
Add the following lines:
prune=550
With these steps, you should have Bitcoin Core up and running with minimal disk usage, ready to interact with C-Lightning.

2. C-Lightning overview and installation

C-Lightning overview
C-Lightning, also known as Core-Lightning, is a Layer 2 protocol that facilitates faster and cheaper transactions using off-chain channels. It stands out due to its modular and developer-friendly architecture, which allows for extensive customization through plugins.
Importance of modularity and extensibility with plugins The modular design of C-Lightning means you can add or remove features as needed, enabling you to tailor the system to specific use-cases. Example use-cases include:
  • Payment processing: Custom plugins can handle specific payment conditions.
  • Routing fees: Adjust routing fees dynamically based on network conditions.
  • Automation: Automate tasks like channel management and liquidity provisioning.

C-Lightning installation

Let's move on to installing C-Lightning.
Use the latest stable release For this lecture, we'll use the latest stable release, e.g., 22.11.1.
wget https://github.com/ElementsProject/lightning/releases/download/v22.11.1/clightning-v22.11.1.tar.gz sha256sum clightning-v22.11.1.tar.gz # Verify the hash against the provided hash
Verify integrity with GPG Keys Always verify the integrity of the downloaded file with GPG keys.
gpg --recv-keys <developer-key-id> gpg --verify clightning-v22.11.1.tar.gz.asc clightning-v22.11.1.tar.gz
Install dependencies and compile from source code Install the necessary dependencies and compile C-Lightning from the source.
sudo apt-get update sudo apt-get install -y autoconf automake build-essential git libtool libgmp-dev \ libsqlite3-dev python3 python3-mako net-tools zlib1g-dev tar -xzf clightning-v22.11.1.tar.gz cd clightning-v22.11.1 ./configure make sudo make install
Configure the systemd service for auto-start Create a systemd service file for C-Lightning:
sudo nano /etc/systemd/system/lightningd.service
Add the following configuration:
[Unit] Description=C-Lightning daemon After=network.target bitcoind.service [Service] ExecStart=/usr/local/bin/lightningd User=bitcoin Group=bitcoin Type=simple Restart=on-failure [Install] WantedBy=multi-user.target

3. Configuration and setup

Create necessary directories and configuration files Create directories and configuration files required for C-Lightning.
sudo mkdir -p /var/lib/lightning sudo chown bitcoin:bitcoin /var/lib/lightning sudo -u bitcoin nano /var/lib/lightning/config
Add the following lines to the config file:
network=testnet log-level=debug plugin=/usr/local/libexec/c-lightning/plugins
Configure C-Lightning to connect with Bitcoin Core on testnet Ensure that C-Lightning can connect with Bitcoin Core by adding the following lines:
bitcoin-datadir=/var/lib/bitcoind bitcoin-rpcuser=<rpcusername> bitcoin-rpcpassword=<rpcpassword>
Ensure compatibility and synchronization Start the services and ensure they are compatible and synchronized.
sudo systemctl start bitcoind sudo systemctl start lightningd sudo systemctl enable bitcoind sudo systemctl enable lightningd
Address file paths and permissions, especially for Tor integration Configure file paths and permissions to ensure smooth operation, especially if using Tor for privacy.
sudo apt-get install tor sudo -u bitcoin nano /var/lib/lightning/config
Add the following for Tor integration:
proxy=127.0.0.1:9050
Backup HSM secret for fund recovery Backup the HSM secret for fund recovery.
sudo cp /var/lib/lightning/hsm_secret /path/to/secure/location
Test connections and validate node's operational status Finally, validate the operational status of your node by testing connections and ensuring everything works as expected.
lightning-cli getinfo
By following these steps, you will have a fully functional C-Lightning setup connected to your Bitcoin Core node, ready for testnet transactions.

Conclusion & questions

In conclusion, today we covered the essential steps for reinstalling Bitcoin Core, followed by a detailed walkthrough of installing and configuring C-Lightning. If you have any questions, please feel free to ask now or prepare them for further clarification in our next session. Remember, practical hands-on experience is crucial, so use the Testnet setup we discussed to gain more insights.

Security and hardware devices

Specter and Ledger device

Introduction

Welcome to our lecture on security and device setup for Bitcoin. Today's focus is on understanding the utilization of security tools, particularly the Specter desktop wallet and Ledger hardware wallet, and how to configure them effectively for enhanced Bitcoin security.
Tools: Specter desktop wallet and Ledger emulator
Specter is a desktop wallet designed to facilitate the creation and management of Bitcoin wallets, particularly those using hardware devices. For our demonstration, we'll employ a Ledger emulator, which mimics a Ledger hardware wallet's functionality.
Difference between Ledger device and company controversy
The Ledger device, a popular hardware wallet, is celebrated for its robust security. However, the company behind Ledger has faced scrutiny due to various controversies concerning user data privacy. Understanding the distinction between the physical device's security and the company's practices is crucial for informed usage.
Security models: importance of multi-sig wallets and diverse hardware
A key aspect of Bitcoin security is leveraging multi-signature (multi-sig) wallets. Multi-sig wallets require multiple private keys to authorize a transaction, significantly enhancing security. Additionally, using different types of hardware wallets diversifies risk and strengthens the security model.

Setup and configuration

Downloading and setting up Specter
The first step in our setup process involves downloading Specter from its official repository. It's crucial to verify the integrity of the download to avoid compromised software. Once downloaded, install Specter on your desktop and launch the application.
Configuring Specter to connect with Bitcoin Core or Electrum servers
To configure Specter, you need to connect it to a Bitcoin Core or Electrum server. These servers provide the necessary blockchain data for wallet operations. Configuration involves setting the server address in Specter's settings and ensuring a stable connection.
Explaining derivation paths and public key retrieval
Understanding derivation paths is essential for wallet management. Derivation paths define how keys are generated from a master key. In Specter, you can retrieve public keys by connecting your hardware wallet (or emulator) and navigating through the wallet interface. Ensure you document these paths for future reference.
Practical demonstration: Using Ledger Emulator
We'll now use a Ledger emulator to fetch keys. This involves connecting the emulator to Specter, navigating to the key management section, and selecting the appropriate keys for wallet creation.
Creating and managing wallets in Specter
Creating a wallet in Specter is straightforward. Access the wallet creation interface, input the necessary details, and include your retrieved public keys. Once created, you can manage the wallet, monitor transactions, and ensure robust security practices.
Receiving and monitoring transactions
After the wallet setup, receiving transactions is as simple as sharing your wallet address. Specter provides real-time monitoring of incoming transactions, ensuring you're always up-to-date on your wallet's status.

Advanced configurations

Setting up remote Specter daemon
For advanced users, setting up a remote Specter daemon can enhance accessibility and security. This involves configuring a remote server to run Specter's backend, allowing secure access from different devices.
Enabling Tor for privacy
To bolster privacy, configuring Specter to use Tor is highly recommended. Tor anonymizes your network traffic, protecting your IP address from potential surveillance. This is particularly important for users concerned about privacy and security.
Connecting to remote nodes securely
When connecting to remote nodes, ensure the connection is secure. This involves using SSL/TLS certificates and verifying the node's authenticity. Secure connections prevent man-in-the-middle attacks and ensure data integrity.
Debugging issues: practical techniques
Encountering issues is inevitable. Practical debugging involves checking user permissions, verifying data directory access, and consulting logs for errors. For example, ensure Specter has the necessary permissions to access the Bitcoin Core data directory to avoid operational disruptions.
Example issue: data directory access
A common issue is incorrect data directory access. Verify that the path to your Bitcoin Core data directory is correctly set in Specter's configuration. This ensures Specter has access to the necessary blockchain data for wallet operations.
Next steps and integration
As we conclude, the next steps involve integrating Specter with the Lightning network. This enables sending funds from Specter to a Lightning node, facilitating faster and cheaper transactions. Future lessons will cover this integration in detail, enhancing your Bitcoin transaction capabilities.
Block timing variability
Understanding block timing variability is crucial. Bitcoin blocks can be mined at varying intervals, affecting transaction confirmation times. This variability must be accounted for in all configurations and wallet operations.
Learning resources
For additional learning, consider resources like "Mastering the Lightning Network" and Rusty Russell's tutorials. These materials provide in-depth knowledge on Lightning nodes and advanced Bitcoin configurations.
Node installation and Tor security
Installing nodes, whether locally or remotely, benefits from using Tor for enhanced security. Running your own node ensures personal transaction validation, improving security and privacy.
Philosophy: self-sufficiency in learning
Embrace a philosophy of self-sufficiency. Practical skills and self-learning are paramount, often surpassing formal education's benefits. Engage in hands-on practices to deepen your understanding of Bitcoin security.
Privacy considerations
Maintain privacy by avoiding services that track or log transactions. Anonymity is crucial for secure Bitcoin operations, and careful service selection helps protect your identity and transaction history.
This concludes our lecture on security and device setup for Bitcoin using Specter and Ledger. Feel free to ask any questions or seek clarification on any points discussed.