Skip to content

Commit

Permalink
feat(config): Add Lightning implementation selection
Browse files Browse the repository at this point in the history
- Introduce 'lightning' configuration option
- Allow users to choose between LND and Alby embedded node (LDK)
- Implement handling of switching between LND and Alby/LDK setups with backup and restore system for different configurations.
- Update description with detailed explanations for each option
- Update instructions and change marketing-site to albyhub.com
  • Loading branch information
k0gen committed Sep 14, 2024
1 parent 353884a commit 6f0a62b
Show file tree
Hide file tree
Showing 5 changed files with 174 additions and 62 deletions.
118 changes: 106 additions & 12 deletions docker_entrypoint.sh
Original file line number Diff line number Diff line change
@@ -1,19 +1,113 @@
#!/bin/sh

export LN_BACKEND_TYPE="LND"
export LND_ADDRESS="lnd.embassy:10009" #the LND gRPC address, eg. localhost:10009 (used with the LND backend)
export LND_CERT_FILE="/mnt/lnd/tls.cert" #the location where LND's tls.cert file can be found (used with the LND backend)
export LND_MACAROON_FILE="/mnt/lnd/admin.macaroon" #the location where LND's admin.macaroon file can be found (used with the LND backend)
printf "\n\n [i] Starting Alby Hub ...\n\n"

# Read current LN setup from config
LN_VALUE=$(grep 'lightning:' /data/start9/config.yaml | cut -d ' ' -f 2)

# File to track initial setup (lnd or alby)
SETUP_FILE="/data/start9/initial_setup"
WORK_DIR="/data/albyhub"
BACKUP_DIR="/data/start9/backups"

# Ensure the backup directory exists
mkdir -p "$BACKUP_DIR"

# Determine the initial setup
if [ -f "$SETUP_FILE" ]; then
INITIAL_SETUP=$(cat "$SETUP_FILE")
else
INITIAL_SETUP="$LN_VALUE"
echo "$INITIAL_SETUP" >"$SETUP_FILE" # Store initial setup if it doesn't exist
fi
# Function to create a tar.gz backup of the albyhub directory
backup_dir() {
suffix="$INITIAL_SETUP"
tar_file="$BACKUP_DIR/${suffix}_backup.tar.gz"

# Create a tar.gz file containing the albyhub directory
tar -czf "$tar_file" -C "/data" albyhub 2>/dev/null
echo "[i] Created backup: $tar_file"
}
# Function to restore the albyhub directory from a tar.gz backup
restore_dir() {
suffix="$1" # Either 'lnd' or 'alby'
tar_file="$BACKUP_DIR/${suffix}_backup.tar.gz"

if [ -f "$tar_file" ]; then
rm -rf "$WORK_DIR"
tar -xzf "$tar_file" -C "/data"
echo "[i] Restored from backup: $tar_file"
else
echo "[i] No $suffix backup found."
fi
}

# Handling different setups
if [ "$INITIAL_SETUP" != "$LN_VALUE" ]; then
if [ "$INITIAL_SETUP" = "lnd" ] && [ "$LN_VALUE" = "alby" ]; then
echo "[i] Switching from LND to Alby/LDK..."

# Backup current LND directory
backup_dir

# Restore Alby backup if it exists, otherwise start fresh
if [ -f "$BACKUP_DIR/alby_backup.tar.gz" ]; then
restore_dir "alby"
else
echo "[i] No Alby/LDK backup found, starting fresh..."
rm -rf "$WORK_DIR"
mkdir -p "$WORK_DIR"
fi

# Update the initial setup to 'alby'
echo "alby" >"$SETUP_FILE"

elif [ "$INITIAL_SETUP" = "alby" ] && [ "$LN_VALUE" = "lnd" ]; then
echo "[i] Switching from Alby/LDK to LND..."

# Backup current Alby directory
backup_dir

# Restore LND backup if it exists, otherwise clean up the data directory for initial LND setup
if [ -f "$BACKUP_DIR/lnd_backup.tar.gz" ]; then
restore_dir "lnd"
else
echo "[i] No LND backup found, cleaning up the data directory for initial LND setup..."
rm -rf "$WORK_DIR"
mkdir -p "$WORK_DIR"
fi

# Update the initial setup to 'lnd'
echo "lnd" >"$SETUP_FILE"
fi
fi

# Set up environment variables based on LN_VALUE
if [ "$LN_VALUE" = "lnd" ]; then
export LN_BACKEND_TYPE="LND"
export LND_ADDRESS="lnd.embassy:10009" # the LND gRPC address
export LND_CERT_FILE="/mnt/lnd/tls.cert" # the location where LND's tls.cert file can be found
export LND_MACAROON_FILE="/mnt/lnd/admin.macaroon" # the location where LND's admin.macaroon file can be found
else
# Default to Alby/LDK if lightning value is not "lnd"
export LN_BACKEND_TYPE="LDK"
unset LND_ADDRESS
unset LND_CERT_FILE
unset LND_MACAROON_FILE
fi

export WORK_DIR="/data/albyhub"
export PORT=8080 #the port on which the app should listen on (default='blah' #8080)
export PORT=8080 #the port on which the app should listen on (default='blah' #8080)
export LOG_EVENTS=true # makes debugging easier

# export TOR_ADDRESS=$(yq e '.tor-address' /data/start9/config.yaml)
# export LAN_ADDRESS=$(yq e '.lan-address' /data/start9/config.yaml)
printf "\n\n [i] Starting Alby Hub ...\n\n"
echo "LN Backend Type: " $LN_BACKEND_TYPE
echo "LN Address: " $LND_ADDRESS
echo "LND Cert: " $LND_CERT_FILE
echo "LND Macaroon: " $LND_MACAROON_FILE
# Output some debug information
echo "LN Backend Type: $LN_BACKEND_TYPE"
if [ "$LN_VALUE" = "lnd" ]; then
echo "LN Address: $LND_ADDRESS"
echo "LND Cert: $LND_CERT_FILE"
echo "LND Macaroon: $LND_MACAROON_FILE"
fi

# Start the Alby Hub app
exec /bin/main
29 changes: 19 additions & 10 deletions instructions.md
Original file line number Diff line number Diff line change
@@ -1,22 +1,31 @@
# Quick Start Guide for Alby Hub

1. **Launch Alby Hub**
Click the `Launch UI` button to start Alby Hub.
1. **Configure Alby Hub**
In the Alby Hub configuration settings, select your preferred Lightning implementation:

2. **Get Started**
On the Alby Welcome screen, click **Get Started (LND)**.
- **LND on this node**: This is the default and preferred method, offering full control over your node. Use the LND (Lightning Network Daemon) implementation for increased sovereignty and security.
- **Alby embedded node (LDK)**: Use the built-in Alby's Lightning Development Kit (LDK) implementation for convenience. This option doesn't require running your own LND node and might be a good choice for low-powered devices.

3. **Create a Strong Password**
Set a strong password for your Alby Hub account. It’s recommended to store this password securely in your self-hosted Vaultwarden.
2. **Start the Service**
After configuring, start the Alby Hub service.

4. **Connect Your Alby Account**
3. **Launch Alby Hub**
Click the `Launch UI` button to open the Alby Hub interface.

4. **Get Started**
On the Alby Welcome screen, click the **Get Started** button. The button will display either (LND) or (LDK) based on your chosen configuration.

5. **Create a Strong Password**
Set a strong password for your Alby Hub account. It's recommended to store this password securely in your self-hosted Vaultwarden.

6. **Connect Your Alby Account**
Follow the on-screen instructions to connect your Alby account.

5. **All Set!**
Youre done! Your Alby Hub is now ready to use.
7. **All Set!**
You're done! Your Alby Hub is now ready to use.

## Getting Help

For more information and help about Alby visit [getalby.com](https://getalby.com)
For more information and help about Alby Hub visit [albyhub.com](https://albyhub.com/)

You can also ask for assistance in the [Start9 community chats](https://start9.com/contact).
18 changes: 9 additions & 9 deletions manifest.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ license: Apache-2.0
wrapper-repo: "https://github.com/horologger/albyhub-startos"
upstream-repo: "https://github.com/getAlby/hub"
support-site: "https://github.com/getAlby/hub/issues"
marketing-site: "https://getalby.com/"
marketing-site: "https://albyhub.com/"
build: ["make"]
description:
short: Self-custodial Lightning wallet with integrated node.
Expand All @@ -29,11 +29,11 @@ health-checks:
name: Web UI
success-message: Alby Hub is ready
type: script
config: ~
# get:
# type: script
# set:
# type: script
config:
get:
type: script
set:
type: script
properties: ~
environment: ~
volumes:
Expand Down Expand Up @@ -63,10 +63,10 @@ interfaces:
dependencies:
lnd:
version: ">=0.16.0 <0.20.0"
description: Nostr Wallet Connect works with your LND
description: Alby Hub works with your LND
requirement:
type: "required"
how: Use the LND instance by default
type: "opt-in"
how: "Can alternatively use Alby's LDK node"
config: ~
backup:
create:
Expand Down
41 changes: 23 additions & 18 deletions scripts/procedures/getConfig.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,22 +3,27 @@
import { compat, types as T } from "../deps.ts";

export const getConfig: T.ExpectedExports.getConfig = compat.getConfig({
"tor-address": {
"name": "Tor Address",
"description": "The Tor address of the network interface",
"type": "pointer",
"subtype": "package",
"package-id": "albyhub",
"target": "tor-address",
"interface": "main",
"tor-address": {
name: "Tor Address",
description: "The Tor address of the network interface",
type: "pointer",
subtype: "package",
"package-id": "albyhub",
target: "tor-address",
interface: "main",
},

lightning: {
name: "Lightning Implementation",
description:
"Choose the Lightning implementation to use with Alby Hub.<br><br><strong>LND on this node</strong>: Use the LND (Lightning Network Daemon) implementation. This is the more sovereign and secure option, allowing full control over your node.<br><br><strong>Alby embedded node (LDK)</strong>: Use the built-in Lightning Development Kit (LDK) implementation. This option is convenient but offers less control over your node.",
type: "enum",
values: ["lnd", "alby"],
"value-names": {
lnd: "LND on this node",
alby: "Alby embedded node (LDK)",
},
"lan-address": {
"name": "LAN Address",
"description": "The LAN address of the network interface",
"type": "pointer",
"subtype": "package",
"package-id": "albyhub",
"target": "lan-address",
"interface": "main",
}
});
default: "lnd",
// "warning": "The Alby embedded node (LDK) is a convenient starting option, but for increased sovereignty and security, it's recommended to switch to LND when possible."
},
});
30 changes: 17 additions & 13 deletions scripts/procedures/setConfig.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,21 @@

import { compat, types as T } from "../deps.ts";

// export const setConfig = compat.setConfig;
// deno-lint-ignore require-await
export const setConfig: T.ExpectedExports.setConfig = async (
effects: T.Effects,
newConfig: T.Config
) => {
// deno-lint-ignore no-explicit-any
const dependsOnLND: { [key: string]: string[] } =
(newConfig as any)?.lightning === "lnd" ? { lnd: [] } : {};

export const setConfig: T.ExpectedExports.setConfig = async (effects, input ) => {
// deno-lint-ignore no-explicit-any
const newConfig = input as any;

const depsLnd: T.DependsOn = newConfig?.implementation === "LndRestWallet" ? {lnd: []} : {}
const depsCln: T.DependsOn = newConfig?.implementation === "CLightningWallet" ? {"c-lightning": []} : {}

return await compat.setConfig(effects,input, {
...depsLnd,
...depsCln,
})
}
// deno-lint-ignore no-explicit-any
const dependsOnAlby: { [key: string]: string[] } =
(newConfig as any)?.lightning === "alby" ? { alby: [] } : {};

return compat.setConfig(effects, newConfig, {
...dependsOnLND,
...dependsOnAlby,
});
};

0 comments on commit 6f0a62b

Please sign in to comment.