From 2d1327ee2be82a6c34d549c23b80e32f47531635 Mon Sep 17 00:00:00 2001 From: Roland <33993199+rolznz@users.noreply.github.com> Date: Tue, 17 Dec 2024 11:48:03 +0700 Subject: [PATCH] feat: make it easier to run multiple hubs locally (#861) --- README.md | 20 ++++++++++++++++++-- config/models.go | 1 + frontend/vite.config.ts | 5 +++-- lnclient/ldk/ldk.go | 11 +++++------ 4 files changed, 27 insertions(+), 10 deletions(-) diff --git a/README.md b/README.md index 14f190f7..5df5a50b 100644 --- a/README.md +++ b/README.md @@ -163,6 +163,7 @@ _To configure via env, the following parameters must be provided:_ - `LDK_ESPLORA_SERVER`: By default the optimized Alby esplora is used. You can configure your own esplora server (note: the public blockstream one is slow and can cause onchain syncing and issues with opening channels) - `LDK_VSS_URL`: Use VSS (encrypted remote storage) rather than local sqlite store for lightning and bitcoin data. Currently this feature only works for brand new Alby Hub instances that are connected to Alby Accounts with an active subscription plan. +- `LDK_LISTENING_ADDRESSES`: configure listening addresses, required for public channels, and ideally reachable if you would like others to be able to initiate peering with your node. #### LDK Network Configuration @@ -188,7 +189,7 @@ See [Phoenixd](scripts/linux-x86_64/phoenixd/README.md) Create an OAuth client at the [Alby Developer Portal](https://getalby.com/developer) and set your `ALBY_OAUTH_CLIENT_ID` and `ALBY_OAUTH_CLIENT_SECRET` in your .env. If not running locally, you'll also need to change your `BASE_URL`. -> If running the React app locally, OAuth redirects will not work locally if running the react app you will need to manually change the port to 5173. **Login in Wails mode is not yet supported** +> If running the React app locally, make sure to set `FRONTEND_URL=http://localhost:5173` so that the OAuth redirect works. ## Getting Started with Mutinynet @@ -214,7 +215,7 @@ Follow the steps to integrate Mutinynet with your NWC Next setup: 3. After the transaction confirms, the new channel will appear in the Channels section -### Opening a Channel in NWC Next +### Opening a Channel from Alby Hub 1. From the Channels interface (`/channels`), select "Open a Channel" and opt for "Custom Channel." @@ -222,6 +223,21 @@ Follow the steps to integrate Mutinynet with your NWC Next setup: 3. Specify a channel capacity greater than 25,000 sats, confirm the action, and return to the Channels page to view your newly established channel. +### Running Multiple Hubs Locally + +You can run multiple hubs locally to e.g. open channels between the two nodes or test sending payments between them. Currently this will only work with LDK. + +You will need two copies of the alby hub repository. + +For the second hub, you will need to update your .env with the following changes: + + FRONTEND_URL=http://localhost:5174 + BASE_URL=http://localhost:8081 + PORT=8081 + LDK_LISTENING_ADDRESSES=0.0.0.0:9736,[::]:9736 + +Then launch the frontend with `VITE_PORT=5174 VITE_API_URL=http://localhost:8081 yarn dev:http` + ## Application deeplink options ### `/apps/new` deeplink options diff --git a/config/models.go b/config/models.go index eb54ba0a..71174b76 100644 --- a/config/models.go +++ b/config/models.go @@ -29,6 +29,7 @@ type AppConfig struct { LDKGossipSource string `envconfig:"LDK_GOSSIP_SOURCE"` LDKLogLevel string `envconfig:"LDK_LOG_LEVEL" default:"3"` LDKVssUrl string `envconfig:"LDK_VSS_URL"` + LDKListeningAddresses string `envconfig:"LDK_LISTENING_ADDRESSES" default:"0.0.0.0:9735,[::]:9735"` MempoolApi string `envconfig:"MEMPOOL_API" default:"https://mempool.space/api"` AlbyClientId string `envconfig:"ALBY_OAUTH_CLIENT_ID" default:"J2PbXS1yOf"` AlbyClientSecret string `envconfig:"ALBY_OAUTH_CLIENT_SECRET" default:"rABK2n16IWjLTZ9M1uKU"` diff --git a/frontend/vite.config.ts b/frontend/vite.config.ts index 2e3648f1..ce32a788 100644 --- a/frontend/vite.config.ts +++ b/frontend/vite.config.ts @@ -48,13 +48,14 @@ export default defineConfig(({ command }) => ({ ...(command === "serve" ? [insertDevCSPPlugin] : []), ], server: { + port: process.env.VITE_PORT ? parseInt(process.env.VITE_PORT) : undefined, proxy: { "/api": { - target: "http://localhost:8080", + target: process.env.VITE_API_URL || "http://localhost:8080", secure: false, }, "/logout": { - target: "http://localhost:8080", + target: process.env.VITE_API_URL || "http://localhost:8080", secure: false, }, }, diff --git a/lnclient/ldk/ldk.go b/lnclient/ldk/ldk.go index 565df49b..e94e4686 100644 --- a/lnclient/ldk/ldk.go +++ b/lnclient/ldk/ldk.go @@ -68,10 +68,8 @@ func NewLDKService(ctx context.Context, cfg config.Config, eventPublisher events logDirPath := filepath.Join(newpath, "./logs") ldkConfig := ldk_node.DefaultConfig() - listeningAddresses := []string{ - "0.0.0.0:9735", - "[::]:9735", - } + listeningAddresses := strings.Split(cfg.GetEnv().LDKListeningAddresses, ",") + ldkConfig.TrustedPeers0conf = []string{ lsp.OlympusLSP().Pubkey, lsp.AlbyPlebsLSP().Pubkey, @@ -136,8 +134,9 @@ func NewLDKService(ctx context.Context, cfg config.Config, eventPublisher events } logger.Logger.WithFields(logrus.Fields{ - "migrate_storage": migrateStorage, - "vss_enabled": vssToken != "", + "migrate_storage": migrateStorage, + "vss_enabled": vssToken != "", + "listening_addresses": listeningAddresses, }).Info("Creating node") var node *ldk_node.Node if vssToken != "" {