Add Testnet Toggle

This commit is contained in:
Taylor Helsper 2021-03-08 21:55:39 -06:00
parent 52aafe5777
commit 2528f52751
37 changed files with 338 additions and 92 deletions

View File

@ -9,6 +9,16 @@ behavior. If this happens, try disabling some applications. Some examples of thi
- The Bitcoin log may show numerous "RPC Work Queue" errors
- Electrum may stop syncing at a specific block until the device is rebooted.
## Testnet Toggle
- Testnet can be enabled via the settings page. This is a great way to test various Bitcoin and Lightning applications. However, not all apps support testnet yet or have not been integrated within myNode to work on testnet. The following apps
have support or patial support.
- Bitcoin
- Lightning
- Electrum Server
- Ride the Lightning
- THunderhub
- Specter
- Bitcoin RPC Explorer
## Thunderhub

View File

@ -12,7 +12,7 @@ KillMode=process
EnvironmentFile=/mnt/hdd/mynode/settings/.btcrpc_environment
ExecStartPre=/usr/bin/is_not_shutting_down.sh
ExecStartPre=/usr/bin/wait_on_bitcoin.sh
ExecStart=/usr/bin/electrs --timestamp --db-dir /mnt/hdd/mynode/electrs --electrum-rpc-addr 0.0.0.0:50001 --jsonrpc-import --bulk-index-threads 3 --index-batch-size 12 --daemon-rpc-addr 127.0.0.1:8332 --txid-limit 100 --tx-cache-size-mb 10.0 --wait-duration-secs 15 -vvvv
ExecStart=/usr/bin/electrs --conf=/mnt/hdd/mynode/electrs/electrs.toml -vvvv
User=bitcoin
Group=bitcoin
TimeoutSec=300

View File

@ -9,7 +9,8 @@ After=lnd.service
[Service]
ExecStartPre=/usr/bin/is_not_shutting_down.sh
ExecStartPre=/usr/bin/wait_on_lnd.sh
ExecStart=/usr/local/bin/loopd --loopdir=/mnt/hdd/mynode/loop
EnvironmentFile=/mnt/hdd/mynode/loop/env
ExecStart=/usr/local/bin/loopd --network=${NETWORK} --loopdir=/mnt/hdd/mynode/loop --lnd.macaroonpath=${LND_ADMIN_MACAROON_PATH}
User=bitcoin
Group=bitcoin

View File

@ -9,7 +9,8 @@ After=lnd.service
[Service]
ExecStartPre=/usr/bin/is_not_shutting_down.sh
ExecStartPre=/usr/bin/wait_on_lnd.sh
ExecStart=/usr/local/bin/poold --basedir=/mnt/hdd/mynode/pool
EnvironmentFile=/mnt/hdd/mynode/pool/env
ExecStart=/usr/local/bin/poold --network=${NETWORK} --basedir=/mnt/hdd/mynode/pool
User=bitcoin
Group=bitcoin

View File

@ -14,8 +14,13 @@ if { [file exists "/tmp/lnd_channel_backup"] == 1} {
set tls_cert "/home/bitcoin/.lnd/tls.cert"
set macaroon "/home/bitcoin/.lnd/data/chain/mainnet/admin.macaroon"
set network "--network=mainnet"
if { [file exists "/mnt/hdd/mynode/settings/.testnet_enabled"] == 1} {
set macaroon "/home/bitcoin/.lnd/data/chain/testnet/admin.macaroon"
set network "--network=testnet"
}
spawn lncli --tlscertpath $tls_cert --macaroonpath $macaroon create $backup_args
spawn lncli $network --tlscertpath $tls_cert --macaroonpath $macaroon create $backup_args
expect {
"recover funds from a static channel backup? (Enter y/n):" {
send -- "y\n"

View File

@ -1,5 +1,6 @@
#!/usr/local/bin/python3
from lnd_grpc import lnd_grpc
import os
def format_seed_numbered(seed):
formatted_seed = ""
@ -19,9 +20,13 @@ def format_seed_raw(seed):
# This is the main entry point for the program
if __name__ == "__main__":
network="mainnet"
if os.path.isfile("/mnt/hdd/mynode/settings/.testnet_enabled"):
network="testnet"
# Generate the seed
rpc = lnd_grpc.Client(lnd_dir="/home/bitcoin/.lnd/",
macaroon_path="/home/bitcoin/.lnd/data/chain/bitcoin/mainnet/admin.macaroon")
macaroon_path="/home/bitcoin/.lnd/data/chain/bitcoin/{}/admin.macaroon".format(network))
# Get seed and print
data = rpc.gen_seed()

View File

@ -5,7 +5,14 @@
# It is intended to attempt a manual unlock of the lnd wallet
set -e
source /usr/share/mynode/mynode_config.sh
NETWORK=mainnet
if [ -f $IS_TESTNET_ENABLED_FILE ]; then
NETWORK=testnet
fi
LND_PASS=$(cat /mnt/hdd/mynode/settings/.lndpw)
LND_TLS_CERT="/home/bitcoin/.lnd/tls.cert"
LND_MACAROON="/home/bitcoin/.lnd/data/chain/mainnet/admin.macaroon"
echo $LND_PASS | lncli --tlscertpath $LND_TLS_CERT --macaroonpath $LND_MACAROON unlock --stdin
LND_MACAROON="/home/bitcoin/.lnd/data/chain/$NETWORK/admin.macaroon"
echo $LND_PASS | lncli --network=$NETWORK --tlscertpath $LND_TLS_CERT --macaroonpath $LND_MACAROON unlock --stdin

View File

@ -49,12 +49,17 @@ else
sed -i "s/maxmempool=.*/maxmempool=50/g" /mnt/hdd/mynode/bitcoin/bitcoin.conf
fi
# Append other sections
# Append Tor/IP section
if [ -f /mnt/hdd/mynode/settings/.btc_lnd_tor_enabled ]; then
cat /usr/share/mynode/bitcoin_tor.conf >> /mnt/hdd/mynode/bitcoin/bitcoin.conf
else
cat /usr/share/mynode/bitcoin_ipv4.conf >> /mnt/hdd/mynode/bitcoin/bitcoin.conf
fi
# Append Mainnet/Testnet section
if [ -f /mnt/hdd/mynode/settings/.testnet_enabled ]; then
cat /usr/share/mynode/bitcoin_testnet.conf >> /mnt/hdd/mynode/bitcoin/bitcoin.conf
fi
fi
PW=$(cat /mnt/hdd/mynode/settings/.btcrpcpw)

View File

@ -13,12 +13,19 @@ else
# Generate a default config
cp -f /usr/share/mynode/lnd.conf /mnt/hdd/mynode/lnd/lnd.conf
# Append other sections
# Append Tor/IP section
if [ -f /mnt/hdd/mynode/settings/.btc_lnd_tor_enabled ]; then
cat /usr/share/mynode/lnd_tor.conf >> /mnt/hdd/mynode/lnd/lnd.conf
else
cat /usr/share/mynode/lnd_ipv4.conf >> /mnt/hdd/mynode/lnd/lnd.conf
fi
# Append Mainnet/Testnet section
if [ -f /mnt/hdd/mynode/settings/.testnet_enabled ]; then
sed -i "s/bitcoin.mainnet=.*/bitcoin.mainnet=0/g" /mnt/hdd/mynode/lnd/lnd.conf
sed -i "s/bitcoin.testnet=.*/bitcoin.testnet=1/g" /mnt/hdd/mynode/lnd/lnd.conf
cat /usr/share/mynode/lnd_testnet.conf >> /mnt/hdd/mynode/lnd/lnd.conf
fi
fi
# Append tor domain

View File

@ -0,0 +1,12 @@
#!/bin/bash
# Gen environment file to swap mainnet/testnet
echo "" > /mnt/hdd/mynode/loop/env
if [ -f /mnt/hdd/mynode/settings/.testnet_enabled ]; then
echo "NETWORK=testnet" >> /mnt/hdd/mynode/loop/env
echo "LND_ADMIN_MACAROON_PATH=/mnt/hdd/mynode/lnd/data/chain/bitcoin/testnet/admin.macaroon" >> /mnt/hdd/mynode/loop/env
else
echo "NETWORK=mainnet" >> /mnt/hdd/mynode/loop/env
echo "LND_ADMIN_MACAROON_PATH=/mnt/hdd/mynode/lnd/data/chain/bitcoin/mainnet/admin.macaroon" >> /mnt/hdd/mynode/loop/env
fi
chown bitcoin:bitcoin /mnt/hdd/mynode/loop/env

View File

@ -0,0 +1,10 @@
#!/bin/bash
# Gen environment file to swap mainnet/testnet
echo "" > /mnt/hdd/mynode/pool/env
if [ -f /mnt/hdd/mynode/settings/.testnet_enabled ]; then
echo "NETWORK=testnet" >> /mnt/hdd/mynode/pool/env
else
echo "NETWORK=mainnet" >> /mnt/hdd/mynode/pool/env
fi
chown bitcoin:bitcoin /mnt/hdd/mynode/pool/env

View File

@ -2,8 +2,13 @@
source /usr/share/mynode/mynode_config.sh
NETWORK=mainnet
if [ -f $IS_TESTNET_ENABLED_FILE ]; then
NETWORK=testnet
fi
mkdir -p /home/admin/.lnd/
mkdir -p /home/admin/.lnd/data/chain/bitcoin/mainnet/
mkdir -p /home/admin/.lnd/data/chain/bitcoin/$NETWORK/
chown -R admin:admin /home/admin/.lnd/
echo "Waiting on lnd files..."
@ -21,17 +26,17 @@ echo "LND files found!"
while true; do
# Make sure lnd path exists for admin user
mkdir -p /home/admin/.lnd/
mkdir -p /home/admin/.lnd/data/chain/bitcoin/mainnet/
mkdir -p /home/admin/.lnd/data/chain/bitcoin/$NETWORK/
chown -R admin:admin /home/admin/.lnd/
# Copy LND files to admin folder
cp -f $LND_TLS_CERT_FILE /home/admin/.lnd/
cp -f /mnt/hdd/mynode/lnd/data/chain/bitcoin/mainnet/*.macaroon /home/admin/.lnd/data/chain/bitcoin/mainnet/
cp -f /mnt/hdd/mynode/lnd/data/chain/bitcoin/$NETWORK/*.macaroon /home/admin/.lnd/data/chain/bitcoin/$NETWORK/
chown -R admin:admin /home/admin/.lnd/
echo "Updated admin copy of LND files!"
# Wait for changes
inotifywait -e modify -e create -e delete $LND_TLS_CERT_FILE /mnt/hdd/mynode/lnd/data/chain/bitcoin/mainnet/*.macaroon
inotifywait -e modify -e create -e delete $LND_TLS_CERT_FILE /mnt/hdd/mynode/lnd/data/chain/bitcoin/$NETWORK/*.macaroon
done
# Should never exit

View File

@ -31,21 +31,26 @@ while true; do
LND_TOR_ADDR=$(cat /var/lib/tor/mynode_lnd/hostname)
LOCAL_IP_ADDR=$(hostname -I | head -n 1 | cut -d' ' -f1)
net="--bitcoin.mainnet"
if [ -f /mnt/hdd/mynode/settings/.testnet_enabled ]; then
net="--bitcoin.testnet"
fi
# Generate QR Codes
lndconnect --lnddir=/mnt/hdd/mynode/lnd -o --bitcoin.mainnet --host=$LOCAL_IP_ADDR
lndconnect --lnddir=/mnt/hdd/mynode/lnd -o $net --host=$LOCAL_IP_ADDR
cp -f lndconnect-qr.png lndconnect_local_grpc.png
lndconnect --lnddir=/mnt/hdd/mynode/lnd -o --bitcoin.mainnet --host=$LOCAL_IP_ADDR -p 10080
lndconnect --lnddir=/mnt/hdd/mynode/lnd -o $net --host=$LOCAL_IP_ADDR -p 10080
cp -f lndconnect-qr.png lndconnect_local_rest.png
lndconnect --lnddir=/mnt/hdd/mynode/lnd -o --bitcoin.mainnet --host=$LND_TOR_ADDR
lndconnect --lnddir=/mnt/hdd/mynode/lnd -o $net --host=$LND_TOR_ADDR
cp -f lndconnect-qr.png lndconnect_tor_grpc.png
lndconnect --lnddir=/mnt/hdd/mynode/lnd -o --bitcoin.mainnet --host=$LND_TOR_ADDR -p 10080
lndconnect --lnddir=/mnt/hdd/mynode/lnd -o $net --host=$LND_TOR_ADDR -p 10080
cp -f lndconnect-qr.png lndconnect_tor_rest.png
# Generate Text Files
lndconnect --lnddir=/mnt/hdd/mynode/lnd -j --bitcoin.mainnet --host=$LOCAL_IP_ADDR > lndconnect_local_grpc.txt
lndconnect --lnddir=/mnt/hdd/mynode/lnd -j --bitcoin.mainnet --host=$LOCAL_IP_ADDR -p 10080 > lndconnect_local_rest.txt
lndconnect --lnddir=/mnt/hdd/mynode/lnd -j --bitcoin.mainnet --host=$LND_TOR_ADDR > lndconnect_tor_grpc.txt
lndconnect --lnddir=/mnt/hdd/mynode/lnd -j --bitcoin.mainnet --host=$LND_TOR_ADDR -p 10080 > lndconnect_tor_rest.txt
lndconnect --lnddir=/mnt/hdd/mynode/lnd -j $net --host=$LOCAL_IP_ADDR > lndconnect_local_grpc.txt
lndconnect --lnddir=/mnt/hdd/mynode/lnd -j $net --host=$LOCAL_IP_ADDR -p 10080 > lndconnect_local_rest.txt
lndconnect --lnddir=/mnt/hdd/mynode/lnd -j $net --host=$LND_TOR_ADDR > lndconnect_tor_grpc.txt
lndconnect --lnddir=/mnt/hdd/mynode/lnd -j $net --host=$LND_TOR_ADDR -p 10080 > lndconnect_tor_rest.txt
echo "Done! Waiting until LND changes, then regen lndconnect codes! (or 24 hours)"
inotifywait -t 86400 -e modify -e create -e delete $LND_TLS_CERT_FILE $LND_ADMIN_MACAROON_FILE

View File

@ -287,6 +287,12 @@ source /usr/bin/mynode_gen_bitcoin_config.sh
# LND Config
source /usr/bin/mynode_gen_lnd_config.sh
# Loop Config
source /usr/bin/mynode_gen_loop_config.sh
# Pool Config
source /usr/bin/mynode_gen_pool_config.sh
# Setup symlinks for bitcoin user so they have access to commands
users="bitcoin"
@ -318,6 +324,15 @@ if [ -d /opt/mynode/dojo ] && [ ! -d /mnt/hdd/mynode/dojo ] ; then
fi
# Setup electrs
cp -f /usr/share/mynode/electrs.toml /mnt/hdd/mynode/electrs/electrs.toml
# Update for testnet
if [ -f /mnt/hdd/mynode/settings/.testnet_enabled ]; then
sed -i "s/bitcoin/testnet/g" /mnt/hdd/mynode/electrs/electrs.toml || true
else
sed -i "s/testnet/bitcoin/g" /mnt/hdd/mynode/electrs/electrs.toml || true
fi
# RTL config
sudo -u bitcoin mkdir -p /opt/mynode/RTL
sudo -u bitcoin mkdir -p /mnt/hdd/mynode/rtl
@ -343,6 +358,12 @@ if [ -f /home/bitcoin/.mynode/.hashedpw ]; then
HASH=$(cat /home/bitcoin/.mynode/.hashedpw)
sed -i "s/\"multiPassHashed\":.*/\"multiPassHashed\": \"$HASH\",/g" /mnt/hdd/mynode/rtl/RTL-Config.json
fi
# Update for testnet
if [ -f /mnt/hdd/mynode/settings/.testnet_enabled ]; then
sed -i "s/mainnet/testnet/g" /mnt/hdd/mynode/rtl/RTL-Config.json || true
else
sed -i "s/testnet/mainnet/g" /mnt/hdd/mynode/rtl/RTL-Config.json || true
fi
# BTC RPC Explorer Config
cp /usr/share/mynode/btc_rpc_explorer_env /opt/mynode/btc-rpc-explorer/.env
@ -390,7 +411,13 @@ if [ -f /mnt/hdd/mynode/thunderhub/thub_config.yaml ]; then
HASH_BCRYPT=$(cat /home/bitcoin/.mynode/.hashedpw_bcrypt)
sed -i "s#masterPassword:.*#masterPassword: \"thunderhub-$HASH_BCRYPT\"#g" /mnt/hdd/mynode/thunderhub/thub_config.yaml
fi
if [ -f /mnt/hdd/mynode/settings/.testnet_enabled ]; then
sed -i "s/mainnet/testnet/g" /mnt/hdd/mynode/thunderhub/thub_config.yaml || true
else
sed -i "s/testnet/mainnet/g" /mnt/hdd/mynode/thunderhub/thub_config.yaml || true
fi
fi
chown -R bitcoin:bitcoin /mnt/hdd/mynode/thunderhub
# Setup CKBunker

View File

@ -30,7 +30,7 @@ while true; do
/usr/bin/expect /usr/bin/unlock_lnd.tcl
if [ $? -eq 0 ]; then
# Unlocked! Verify unlocked every time LND files change
inotifywait -t 600 -r -e modify -e create -e delete /mnt/hdd/mynode/lnd/data/chain/bitcoin/mainnet/ /mnt/hdd/mynode/lnd/tls.cert
inotifywait -t 600 -r -e modify -e create -e delete /mnt/hdd/mynode/lnd/data/chain/bitcoin/ /mnt/hdd/mynode/lnd/tls.cert
# Slow down check rate for next time around
CHECK_RATE="60s"

View File

@ -4,11 +4,16 @@ set timeout 20
set tls_cert "/home/bitcoin/.lnd/tls.cert"
set macaroon "/home/bitcoin/.lnd/data/chain/bitcoin/mainnet/admin.macaroon"
set network "--network=mainnet"
if { [file exists "/mnt/hdd/mynode/settings/.testnet_enabled"] == 1} {
set macaroon "/home/bitcoin/.lnd/data/chain/testnet/admin.macaroon"
set network "--network=testnet"
}
set f [open "/mnt/hdd/mynode/settings/.lndpw"]
set pw [read $f]
spawn lncli --tlscertpath $tls_cert --macaroonpath $macaroon unlock
spawn lncli $network --tlscertpath $tls_cert --macaroonpath $macaroon unlock
expect {
"wallet password:" {
send -- "$pw\n"

View File

@ -1,11 +1,18 @@
#!/bin/bash
source /usr/share/mynode/mynode_config.sh
NETWORK=mainnet
if [ -f $IS_TESTNET_ENABLED_FILE ]; then
NETWORK=testnet
fi
# Wait until lnd is synced
echo "Checking if LND is synced..."
lncli --lnddir /mnt/hdd/mynode/lnd getinfo | grep 'synced_to_chain": true'
lncli --network=$NETWORK --lnddir /mnt/hdd/mynode/lnd getinfo | grep 'synced_to_chain": true'
while [ ! $? ]; do
echo "LND not synced, sleeping for 60 seconds..."
/bin/sleep 60s
lncli --lnddir /mnt/hdd/mynode/lnd getinfo | grep 'synced_to_chain": true'
lncli --network=$NETWORK --lnddir /mnt/hdd/mynode/lnd getinfo | grep 'synced_to_chain": true'
done
exit 0

View File

@ -20,7 +20,7 @@ rpcallowip=192.168.0.0/16
# Set default wallet so some wallet APIs work
main.wallet=wallet.dat
wallet=joinmarket_wallet.dat
main.wallet=joinmarket_wallet.dat
# Enable Bloom filters
whitelist=bloomfilter@127.0.0.1

View File

@ -0,0 +1,7 @@
# Enable testnet
testnet=1
test.bind=127.0.0.1
test.rpcbind=0.0.0.0
test.rpcport=8332

View File

@ -7,3 +7,4 @@ bind=127.0.0.1
onlynet=onion
dnsseed=0
dns=0

View File

@ -0,0 +1,14 @@
# --timestamp --db-dir /mnt/hdd/mynode/electrs --electrum-rpc-addr 0.0.0.0:50001 --jsonrpc-import --bulk-index-threads 3 --index-batch-size 12 --daemon-rpc-addr 127.0.0.1:8332 --txid-limit 100 --tx-cache-size-mb 10.0 --wait-duration-secs 15 -vvvv
timestamp = true
jsonrpc_import = true
daemon_rpc_addr = "127.0.0.1:8332"
db_dir = "/mnt/hdd/mynode/electrs"
electrum_rpc_addr = "0.0.0.0:50001"
monitoring_addr = "127.0.0.1:4224"
bulk_index_threads = 3
index_batch_size = 12
txid_limit = 100
tx_cache_size_mb = 10.0
wait_duration_secs = 15
network = "bitcoin"

View File

@ -27,6 +27,7 @@ bitcoin.active=1
# enable either testnet or mainnet
bitcoin.mainnet=1
bitcoin.testnet=0
bitcoin.node=bitcoind

View File

@ -0,0 +1,3 @@
# ADD TESTNET CONFIG

View File

@ -62,6 +62,14 @@ LND_CHANNEL_FILE="/mnt/hdd/mynode/lnd/data/chain/bitcoin/mainnet/channel.backup"
LND_CHANNEL_FILE_BACKUP="/home/bitcoin/lnd_backup/channel.backup"
LND_ADMIN_MACAROON_FILE="/mnt/hdd/mynode/lnd/data/chain/bitcoin/mainnet/admin.macaroon"
PRODUCT_KEY_FILE="/home/bitcoin/.mynode/.product_key"
IS_TESTNET_ENABLED_FILE="/mnt/hdd/mynode/settings/.testnet_enabled"
if [ -f $IS_TESTNET_ENABLED_FILE ]; then
LND_WALLET_FILE="/mnt/hdd/mynode/lnd/data/chain/bitcoin/testnet/wallet.db"
LND_CHANNEL_FILE="/mnt/hdd/mynode/lnd/data/chain/bitcoin/testnet/channel.backup"
LND_CHANNEL_FILE_BACKUP="/home/bitcoin/lnd_backup/channel_testnet.backup"
LND_ADMIN_MACAROON_FILE="/mnt/hdd/mynode/lnd/data/chain/bitcoin/testnet/admin.macaroon"
fi
ELECTRS_ENABLED_FILE="/mnt/hdd/mynode/.mynode_electrs_enabled"
LNDHUB_ENABLED_FILE="/mnt/hdd/mynode/.mynode_lndhub_enabled"

View File

@ -120,6 +120,7 @@ def bitcoind_status_page():
"disk_size": (int(info["size_on_disk"]) / 1000 / 1000 / 1000),
"mempool_tx": mempool["size"],
"mempool_size": "{:.3} MB".format(float(mempool["bytes"]) / 1000 / 1000),
"is_testnet_enabled": is_testnet_enabled(),
"confirmed_balance": walletinfo["balance"],
"unconfirmed_balance": walletinfo["unconfirmed_balance"],
"bitcoin_whitepaper_exists": bitcoin_whitepaper_exists,

View File

@ -15,7 +15,6 @@ BITCOIN_ENV_FILE = "/mnt/hdd/mynode/bitcoin/env"
BITCOIN_SYNCED_FILE = "/mnt/hdd/mynode/.mynode_bitcoind_synced"
# LND Variables
LND_WALLET_FILE = "/mnt/hdd/mynode/lnd/data/chain/bitcoin/mainnet/wallet.db"
LND_DATA_FOLDER = "/mnt/hdd/mynode/lnd/data/"
# Variables marking if app should be installed

View File

@ -960,6 +960,11 @@ def get_bitcoin_rpc_password():
def stop_bitcoind():
os.system("systemctl stop bitcoind")
def get_bitcoin_log_file():
if is_testnet_enabled():
return "/mnt/hdd/mynode/bitcoin/testnet3/debug.log"
return "/mnt/hdd/mynode/bitcoin/debug.log"
def reset_bitcoin_env_file():
os.system("echo 'BTCARGS=' > "+BITCOIN_ENV_FILE)
@ -985,7 +990,6 @@ def restart_lnd():
os.system("systemctl restart lnd")
def delete_lnd_data():
#os.system("rm -f "+LND_WALLET_FILE)
os.system("rm -rf "+LND_DATA_FOLDER)
os.system("rm -rf /home/bitcoin/.lnd-admin/credentials.json")
os.system("rm -rf /mnt/hdd/mynode/settings/.lndpw")
@ -993,6 +997,23 @@ def delete_lnd_data():
return True
#==================================
# Mainnet / Testnet Functions
#==================================
def is_testnet_enabled():
return os.path.isfile("/mnt/hdd/mynode/settings/.testnet_enabled")
def enable_testnet():
os.system("touch /mnt/hdd/mynode/settings/.testnet_enabled")
os.system("sync")
def disable_testnet():
os.system("rm -f /mnt/hdd/mynode/settings/.testnet_enabled")
os.system("sync")
def toggle_testnet():
if is_testnet_enabled():
disable_testnet()
else:
enable_testnet()
#==================================
# Electrum Server Functions
#==================================

View File

@ -63,7 +63,7 @@ def get_electrs_status():
return "Starting..."
elif "opening DB at" in line or "enabling auto-compactions" in line:
return "Starting..."
elif "downloading 100000 block headers" in line:
elif "downloading 100000 block headers" in line or "downloading new block headers" in line:
return "Getting headers..."
elif "starting full compaction" in line:
return "Compressing..."

View File

@ -16,16 +16,14 @@ lnd_version = None
loop_version = None
pool_version = None
lightning_peers = None
lightning_peer_aliases = {}
lightning_channels = None
lightning_channel_balance = None
lightning_wallet_balance = None
lightning_desync_count = 0
LND_FOLDER = "/mnt/hdd/mynode/lnd/"
MACAROON_FILE = "/mnt/hdd/mynode/lnd/data/chain/bitcoin/mainnet/admin.macaroon"
WALLET_FILE = "/mnt/hdd/mynode/lnd/data/chain/bitcoin/mainnet/wallet.db"
TLS_CERT_FILE = "/mnt/hdd/mynode/lnd/tls.cert"
CHANNEL_BACKUP_FILE = "/home/bitcoin/lnd_backup/channel.backup"
LND_REST_PORT = "10080"
# Functions
@ -88,6 +86,22 @@ def get_lightning_peers():
global lightning_peers
return copy.deepcopy(lightning_peers)
def get_lightning_node_info(pubkey):
nodeinfo = lnd_get("/graph/node/{}".format(pubkey), timeout=2)
return nodeinfo
def get_lightning_peer_alias(pubkey):
global lightning_peer_aliases
if pubkey in lightning_peer_aliases:
return lightning_peer_aliases[pubkey]
nodeinfo = get_lightning_node_info(pubkey)
if nodeinfo != None and "node" in nodeinfo:
if "alias" in nodeinfo["node"]:
lightning_peer_aliases[pubkey] = nodeinfo["node"]["alias"]
return nodeinfo["node"]["alias"]
return "UNKNOWN"
def get_lightning_peer_count():
info = get_lightning_info()
num_peers = 0
@ -141,11 +155,11 @@ def is_lnd_ready():
global lnd_ready
return lnd_ready
def lnd_get(path):
def lnd_get(path, timeout=10):
try:
macaroon = get_macaroon()
headers = {"Grpc-Metadata-macaroon":macaroon}
r = requests.get("https://localhost:"+LND_REST_PORT+"/v1"+path, verify=TLS_CERT_FILE,headers=headers)
r = requests.get("https://localhost:"+LND_REST_PORT+"/v1"+path, verify=TLS_CERT_FILE,headers=headers, timeout=timeout)
except Exception as e:
app.logger.info("ERROR in lnd_get: "+str(e))
return {"error": str(e)}
@ -166,12 +180,25 @@ def restart_lnd():
t = Timer(1.0, restart_lnd_actual)
t.start()
def is_testnet_enabled():
return os.path.isfile("/mnt/hdd/mynode/settings/.testnet_enabled")
def get_lightning_wallet_file():
if is_testnet_enabled():
return "/mnt/hdd/mynode/lnd/data/chain/bitcoin/testnet/wallet.db"
return "/mnt/hdd/mynode/lnd/data/chain/bitcoin/mainnet/wallet.db"
def get_lightning_macaroon_file():
if is_testnet_enabled():
return "/mnt/hdd/mynode/lnd/data/chain/bitcoin/testnet/admin.macaroon"
return "/mnt/hdd/mynode/lnd/data/chain/bitcoin/mainnet/admin.macaroon"
def get_macaroon():
m = subprocess.check_output("xxd -ps -u -c 1000 "+MACAROON_FILE, shell=True)
m = subprocess.check_output("xxd -ps -u -c 1000 " + get_lightning_macaroon_file(), shell=True)
return m.strip()
def lnd_wallet_exists():
return os.path.isfile(WALLET_FILE)
return os.path.isfile( get_lightning_wallet_file() )
def create_wallet(seed):
try:
@ -196,8 +223,13 @@ def is_lnd_logged_in():
except:
return False
def get_lnd_channel_backup_file():
if is_testnet_enabled():
return "/home/bitcoin/lnd_backup/channel_testnet.backup"
return "/home/bitcoin/lnd_backup/channel.backup"
def lnd_channel_backup_exists():
return os.path.isfile(CHANNEL_BACKUP_FILE)
return os.path.isfile( get_lnd_channel_backup_file() )
def get_lnd_status():
if not lnd_wallet_exists():

View File

@ -69,7 +69,7 @@ def page_lnd():
"version": get_lnd_version(),
"loop_version": get_loop_version(),
"pool_version": get_pool_version(),
"status": status,
"status": "Please Create Wallet",
"ui_settings": read_ui_settings()
}
return render_template('lnd.html', **templateData)
@ -123,6 +123,10 @@ def page_lnd():
peer["bytes_sent"] = "N/A"
if "ping_time" not in p:
peer["ping_time"] = "N/A"
if "pub_key" in p:
peer["alias"] = get_lightning_peer_alias( p["pub_key"] )
else:
peer["alias"] = "Unknown"
peers.append(peer)
channeldata = get_lightning_channels()
@ -134,6 +138,10 @@ def page_lnd():
channel["local_balance"] = "0"
if "remote_balance" not in channel:
channel["remote_balance"] = "0"
if "remote_pubkey" in channel:
channel["remote_alias"] = get_lightning_peer_alias( channel["remote_pubkey"] )
else:
channel["remote_alias"] = "Unknown"
channels.append(channel)
balance_info = get_lightning_balance_info()
@ -166,6 +174,7 @@ def page_lnd():
"version": get_lnd_version(),
"loop_version": get_loop_version(),
"pool_version": get_pool_version(),
"is_testnet_enabled": is_testnet_enabled(),
"channel_backup_exists": channel_backup_exists,
"status": status,
"height": height,
@ -209,25 +218,32 @@ def lnd_tls_cert():
def lnd_admin_macaroon():
check_logged_in()
folder = "mainnet"
if is_testnet_enabled():
folder = "testnet"
# Download macaroon
return send_from_directory(directory="/mnt/hdd/mynode/lnd/data/chain/bitcoin/mainnet/", filename="admin.macaroon")
return send_from_directory(directory="/mnt/hdd/mynode/lnd/data/chain/bitcoin/{}/".format(folder), filename="admin.macaroon")
@mynode_lnd.route("/lnd/readonly.macaroon")
def lnd_readonly_macaroon():
check_logged_in()
folder = "mainnet"
if is_testnet_enabled():
folder = "testnet"
# Download macaroon
return send_from_directory(directory="/mnt/hdd/mynode/lnd/data/chain/bitcoin/mainnet/", filename="readonly.macaroon")
return send_from_directory(directory="/mnt/hdd/mynode/lnd/data/chain/bitcoin/{}/".format(folder), filename="readonly.macaroon")
@mynode_lnd.route("/lnd/channel.backup")
def lnd_channel_backup():
check_logged_in()
# First, check for lnd file
if os.path.isfile('/mnt/hdd/mynode/lnd/data/chain/bitcoin/mainnet/channel.backup'):
return send_from_directory(directory="/mnt/hdd/mynode/lnd/data/chain/bitcoin/mainnet/", filename="channel.backup")
else:
return send_from_directory(directory="/home/bitcoin/lnd_backup/", filename="channel.backup")
scb_location = get_lnd_channel_backup_file()
parts = os.path.split(scb_location)
return send_from_directory(directory=parts[0]+"/", filename=parts[1])
@mynode_lnd.route("/lnd/create_wallet")
def page_lnd_create_wallet():

View File

@ -554,6 +554,7 @@ def index():
"lnd_peer_count": get_lightning_peer_count(),
"lnd_channel_count": get_lightning_channel_count(),
"lnd_balance_info": get_lightning_balance_info(),
"lnd_wallet_exists": lnd_wallet_exists(),
"lnd_version": get_lnd_version(),
"is_testnet_enabled": is_testnet_enabled(),
"tor_status_color": tor_status_color,

View File

@ -38,34 +38,6 @@ def page_settings():
date = get_system_date()
local_ip = get_local_ip()
# Get Startup Status
startup_status_log = get_journalctl_log("mynode")
# Get QuickSync Status
quicksync_enabled = is_quicksync_enabled()
quicksync_status = "Disabled"
quicksync_status_color = "gray"
quicksync_status_log = "DISABLED"
if quicksync_enabled:
quicksync_status = get_service_status_basic_text("quicksync")
quicksync_status_color = get_service_status_color("quicksync")
try:
quicksync_status_log = subprocess.check_output(["mynode-get-quicksync-status"]).decode("utf8")
except:
quicksync_status_log = "ERROR"
# Get Bitcoin Status
bitcoin_status_log = ""
try:
bitcoin_status_log = subprocess.check_output(["tail","-n","200","/mnt/hdd/mynode/bitcoin/debug.log"]).decode("utf8")
lines = bitcoin_status_log.split('\n')
lines.reverse()
bitcoin_status_log = '\n'.join(lines)
except:
bitcoin_status_log = "ERROR"
# Get QuickSync Rates
upload_rate = 100
download_rate = 100
@ -101,7 +73,8 @@ def page_settings():
"is_bitcoin_synced": is_bitcoind_synced(),
"is_installing_docker_images": is_installing_docker_images(),
"firewall_rules": get_firewall_rules(),
"is_quicksync_disabled": not quicksync_enabled,
"is_testnet_enabled": is_testnet_enabled(),
"is_quicksync_disabled": not is_quicksync_enabled(),
"is_netdata_enabled": is_netdata_enabled(),
"is_uploader_device": is_uploader(),
"download_rate": download_rate,
@ -158,7 +131,7 @@ def page_status():
quicksync_status_log = "ERROR"
# Get Bitcoin Status
bitcoin_status_log = get_file_log("/mnt/hdd/mynode/bitcoin/debug.log")
bitcoin_status_log = get_file_log( get_bitcoin_log_file() )
# GET lnd, loopd, poold logs from file???
#lnd_status_log = get_file_log("/mnt/hdd/mynode/lnd/logs/bitcoin/mainnet/lnd.log")
#loopd_status_log = get_file_log("/mnt/hdd/mynode/loop/logs/mainnet/loopd.log")
@ -845,6 +818,28 @@ def toggle_quicksync_page():
}
return render_template('reboot.html', **templateData)
@mynode_settings.route("/settings/toggle-testnet")
def toggle_testnet_page():
check_logged_in()
check_and_mark_reboot_action("toggle_testnet")
# Toggle testnet
toggle_testnet()
# Trigger reboot
t = Timer(1.0, reboot_device)
t.start()
# Wait until device is restarted
templateData = {
"title": "myNode Reboot",
"header_text": "Restarting",
"subheader_text": "This will take several minutes...",
"ui_settings": read_ui_settings()
}
return render_template('reboot.html', **templateData)
@mynode_settings.route("/settings/ping")
def ping_page():
return "alive"

View File

@ -30,7 +30,7 @@
}
.bitcoind_table {
width: 800px;
width: 1000px;
margin: auto;
text-align: center;
vertical-align: middle;
@ -54,7 +54,7 @@ table.bitcoind_table tbody tr:nth-child(even) td{
}
table.bitcoind_table td {
padding: 20px 0;
padding: 10px 0;
margin: 0px;
}
.bitcoind_dump_contents {

View File

@ -38,6 +38,12 @@
<div class="info_tile_header">Difficulty</div>
<div class="info_tile_contents">{{difficulty}}</div>
</div>
{% if is_testnet_enabled %}
<div class="info_tile">
<div class="info_tile_header">Network</div>
<div class="info_tile_contents">Testnet</div>
</div>
{% endif %}
<div class="info_tile">
<div class="info_tile_header">Version</div>
<div class="info_tile_contents">{{version}}</div>

View File

@ -6,6 +6,9 @@
<div class="app_logo"><img class="app_logo_icon" src="{{ url_for('static', filename="images/bitcoin.png")}}"/></div>
<div class="app_title">Bitcoin</div>
<div class="app_status" id="bitcoin_status">{{ bitcoind_status }}</div>
{% if is_testnet_enabled %}
<div class="app_status" style="color: green; margin-top: 3px;">Testnet</div>
{% endif %}
<div class="app_contents">
<a class="ui-button ui-widget ui-corner-all mynode_button" href="/bitcoind">Manage</a>
</div>
@ -43,11 +46,18 @@
<div class="app_logo"><img class="app_logo_icon" src="{{ url_for('static', filename="images/lightning.png")}}"/></div>
<div class="app_title">Lightning</div>
<div class="app_status" id="lnd_status">{{ lnd_status }}</div>
{% if is_testnet_enabled %}
<div class="app_status" style="color: green; margin-top: 3px;">Testnet</div>
{% endif %}
<div class="app_contents">
{% if lnd_ready %}
<a class="ui-button ui-widget ui-corner-all mynode_button" href="#" id="lndconnect">Pair Wallet</a>
{% endif %}
<a class="ui-button ui-widget ui-corner-all mynode_button" href="/lnd">Manage</a>
{% if lnd_wallet_exists %}
<a class="ui-button ui-widget ui-corner-all mynode_button" href="/lnd">Wallet</a>
{% else %}
<a class="ui-button ui-widget ui-corner-all mynode_button" href="/lnd">Create Wallet</a>
{% endif %}
</div>
</div>
<div style="width: 230px; padding-left: 10px; float: right;">

View File

@ -131,6 +131,12 @@
<div class="info_tile_header">Num Peers</div>
<div class="info_tile_contents">{{num_peers}}</div>
</div>
{% if is_testnet_enabled %}
<div class="info_tile">
<div class="info_tile_header">Network</div>
<div class="info_tile_contents">Testnet</div>
</div>
{% endif %}
<div class="info_tile">
<div class="info_tile_header">LND Version</div>
<div class="info_tile_contents">{{version}}</div>
@ -278,7 +284,7 @@
<div class="app_tile_row">
<table class="bitcoind_table">
<thead class="bitcoind_table_header">
<td>Chan ID</td>
<td>Peer Alias</td>
<td>Capacity</td>
<td>Local Capacity</td>
<td>Remote Capacity</td>
@ -286,7 +292,7 @@
<tbody>
{% for channel in channels %}
<tr>
<td>{{ channel.chan_id }}</td>
<td>{{ channel.remote_alias }}</td>
<td>{{ channel.capacity }}</td>
<td>{{ channel.local_balance }}</td>
<td>{{ channel.remote_balance }}</td>
@ -301,22 +307,22 @@
<div class="app_tile_row">
<table class="bitcoind_table">
<thead class="bitcoind_table_header">
<td>Alias</td>
<td>Pub Key</td>
<td>Address</td>
<td>TX (MB)</td>
<td>RX (MB)</td>
<td>Ping Time</td>
<td>Sync Type</td>
<!--<td>Address</td>-->
<td>Sats TX</td>
<td>Sats RX</td>
<!--<td>Sync Type</td>-->
</thead>
<tbody>
{% for peer in peers %}
<tr>
<td>{{ peer.pub_key }}</td>
<td>{{ peer.address }}</td>
<td>{{ peer.bytes_sent }}</td>
<td>{{ peer.bytes_recv }}</td>
<td>{{ peer.ping_time }}</td>
<td>{{ peer.sync_type }}</td>
<td>{{ peer.alias }}</td>
<td style="font-size: 10px;">{{ peer.pub_key }}</td>
<!--<td>{{ peer.address }}</td>-->
<td>{{ peer.sat_sent }}</td>
<td>{{ peer.sat_recv }}</td>
<!--<td>{{ peer.sync_type }}</td>-->
</tr>
{% endfor %}
</tbody>

View File

@ -676,7 +676,7 @@
<div class="divider"></div>
<div class="settings_block_subheader">Rescan Blockchain</div>
Advanced: If you are having issues parsing the Bitcoin blockchain or blocks cannot be found, please try rescanning.
Advanced: If you are having issues seeing transactions in your wallets, try re-scanning the blockchain.
<br/>
<button id="rescan-blockchain" class="ui-button ui-widget ui-corner-all settings_button">Rescan Blockchain</button>
@ -821,6 +821,19 @@
<a id="advanced"></a>
<div class="settings_block_header">Advanced</div>
<div class="settings_block_subheader">Toggle Testnet</div>
Testnet can be enabled for Bitcoin and Lightning, which can be used to test various features, but may cause other applications to
fail or become unstable if enabled. This testnet toggle does not work if you have customized your bitcoin or lnd configs. This will
reboot your device.
<br/>
{% if not is_testnet_enabled %}
<a href="/settings/toggle-testnet" class="ui-button ui-widget ui-corner-all settings_button">Enable Testnet</a>
{% else %}
<a href="/settings/toggle-testnet" class="ui-button ui-widget ui-corner-all settings_button">Disable Testnet</a>
{% endif %}
<div class="divider"></div>
<div class="settings_block_subheader">Reset HTTPS Certificates</div>
This will regenerate your HTTPS certificates.
<br/>