From 783c887824ff789c3cad6b63767ed9964fc252a5 Mon Sep 17 00:00:00 2001 From: Abdullahi Yunus Date: Mon, 22 Sep 2025 18:21:04 +0100 Subject: [PATCH 1/4] lnd: stop using prev persisted addresses In this commit we stop using persisted address in LND's prev run. This means addresses set using `externalip` will be used without merging them with the ones from prev run. We will introduce the condition to use persisted addresses in the next commit. --- server.go | 18 ------------------ 1 file changed, 18 deletions(-) diff --git a/server.go b/server.go index 44be180ea..9c29adf72 100644 --- a/server.go +++ b/server.go @@ -5559,15 +5559,6 @@ func (s *server) setSelfNode(ctx context.Context, nodePub route.Vertex, return fmt.Errorf("unable to normalize addresses: %w", err) } - // To avoid having duplicate addresses, we'll only add addresses from - // the source node that are not already in our address list yet. We - // create this map for quick lookup. - addressMap := make(map[string]struct{}, len(addrs)) - // Populate the map with the existing addresses. - for _, existingAddr := range addrs { - addressMap[existingAddr.String()] = struct{}{} - } - // Parse the color from config. We will update this later if the config // color is not changed from default (#3399FF) and we have a value in // the source node. @@ -5604,15 +5595,6 @@ func (s *server) setSelfNode(ctx context.Context, nodePub route.Vertex, alias = srcNode.Alias } - // Append unique addresses from the source node to the address - // list. - for _, addr := range srcNode.Addresses { - if _, found := addressMap[addr.String()]; !found { - addrs = append(addrs, addr) - addressMap[addr.String()] = struct{}{} - } - } - case errors.Is(err, graphdb.ErrSourceNodeNotSet): // If an alias is not specified in the config, we'll use the // default, which is the first 10 bytes of the serialized From cf287e9693ef83970fbf0e4b9c8f6ecfe357b23e Mon Sep 17 00:00:00 2001 From: Abdullahi Yunus Date: Mon, 22 Sep 2025 18:55:41 +0100 Subject: [PATCH 2/4] lnd: use persisted addrs if not set in config --- server.go | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/server.go b/server.go index 9c29adf72..b7e498a79 100644 --- a/server.go +++ b/server.go @@ -5595,6 +5595,12 @@ func (s *server) setSelfNode(ctx context.Context, nodePub route.Vertex, alias = srcNode.Alias } + // If the `externalip` is not specified in the config, it means + // `addrs` will be empty, we'll use the source node's addresses. + if len(s.cfg.ExternalIPs) == 0 { + addrs = srcNode.Addresses + } + case errors.Is(err, graphdb.ErrSourceNodeNotSet): // If an alias is not specified in the config, we'll use the // default, which is the first 10 bytes of the serialized From 141cc571ab3d1ff3884a807ca39fa76807bb9e87 Mon Sep 17 00:00:00 2001 From: Abdullahi Yunus Date: Mon, 22 Sep 2025 21:39:58 +0100 Subject: [PATCH 3/4] itest: check for config addrs precedence In this commit, we update the itest to check for precedence of the config addresses over the persisted addresses. We did not check for address persistence after restart (without the extraArgs `--externalip`) because in `lntest/node/config.goL300`, `GenArg` by default sets the `--externalip` flag, which makes the config addrs to always take precedence over the persisted addrs, for the tests. --- itest/lnd_channel_graph_test.go | 43 +++++++++++++-------------------- 1 file changed, 17 insertions(+), 26 deletions(-) diff --git a/itest/lnd_channel_graph_test.go b/itest/lnd_channel_graph_test.go index 6d30fe211..f8d63c1d5 100644 --- a/itest/lnd_channel_graph_test.go +++ b/itest/lnd_channel_graph_test.go @@ -728,25 +728,7 @@ func testSelfNodeAnnouncementPersistence(ht *lntest.HarnessTest) { } assertUpdateNodeAnnouncementResponse(ht, response, expectedOps) - resp = alice.RPC.GetInfo() - assertNodeInfo( - resp, "alice", "#eeeeee", "192.168.1.10:8333", - "192.168.1.11:8333", - ) - - // Restart Alice. - ht.RestartNode(alice) - - // After restarting, the node info should contain the values that were - // set in the update request since the updated values take precedence - // over the default values. - resp = alice.RPC.GetInfo() - assertNodeInfo( - resp, "alice", "#eeeeee", "192.168.1.10:8333", - "192.168.1.11:8333", - ) - - // Test that we can still remove an address. + // Test that we can remove an address. removeAddrReq := &peersrpc.NodeAnnouncementUpdateRequest{ AddressUpdates: []*peersrpc.UpdateAddressAction{ { @@ -761,6 +743,20 @@ func testSelfNodeAnnouncementPersistence(ht *lntest.HarnessTest) { } assertUpdateNodeAnnouncementResponse(ht, response, expectedOps) + resp = alice.RPC.GetInfo() + assertNodeInfo( + resp, "alice", "#eeeeee", "192.168.1.11:8333", + ) + + // Restart Alice. + ht.RestartNode(alice) + + // After restarting, the node info should contain the values that were + // set in the update request since the updated values take precedence + // over the default values. + resp = alice.RPC.GetInfo() + assertNodeInfo(resp, "alice", "#eeeeee") + // Now we restart the node with custom values in the config. lndArgs := []string{ "--externalip=192.168.1.12:8333", @@ -772,16 +768,11 @@ func testSelfNodeAnnouncementPersistence(ht *lntest.HarnessTest) { // Get the node info and verify that the values are the same as the // ones we set in the config (and not the updated values). - // The addresses should be the same as the ones we set in the config - // plus the ones we set in the update request earlier. resp = alice.RPC.GetInfo() assertNodeInfo( - resp, "alice-updated", "#ffffff", "192.168.1.11:8333", - "192.168.1.12:8333", "192.168.1.13:8333", + resp, "alice-updated", "#ffffff", "192.168.1.12:8333", + "192.168.1.13:8333", ) - - // The address we removed earlier should not be present. - require.Error(ht, assertAddrs(resp.Uris, "192.168.1.10:8333")) } // assertSyncType asserts that the peer has an expected syncType. From ed2880ef1766b20617c046489961eb565dbec08b Mon Sep 17 00:00:00 2001 From: Abdullahi Yunus Date: Wed, 24 Sep 2025 10:49:38 +0100 Subject: [PATCH 4/4] lnd: update docs on nodeann addresses retaining --- config.go | 2 +- sample-lnd.conf | 16 +++++++++++++++- 2 files changed, 16 insertions(+), 2 deletions(-) diff --git a/config.go b/config.go index 85cdc09d0..6d5bc546a 100644 --- a/config.go +++ b/config.go @@ -339,7 +339,7 @@ type Config struct { RawRPCListeners []string `long:"rpclisten" description:"Add an interface/port/socket to listen for RPC connections"` RawRESTListeners []string `long:"restlisten" description:"Add an interface/port/socket to listen for REST connections"` RawListeners []string `long:"listen" description:"Add an interface/port to listen for peer connections"` - RawExternalIPs []string `long:"externalip" description:"Add an ip:port to the list of local addresses we claim to listen on to peers. If a port is not specified, the default (9735) will be used regardless of other parameters"` + RawExternalIPs []string `long:"externalip" description:"Add an ip:port (local addresses we listen on) to advertise to the network (default port 9735 is used if port is not specified). Note: Removing this option does not clear previously advertised addresses; remove them with 'lncli peers updatenodeannouncement --address_remove=host:port'."` ExternalHosts []string `long:"externalhosts" description:"Add a hostname:port that should be periodically resolved to announce IPs for. If a port is not specified, the default (9735) will be used."` RPCListeners []net.Addr RESTListeners []net.Addr diff --git a/sample-lnd.conf b/sample-lnd.conf index 6b2ca8a1c..506b99914 100644 --- a/sample-lnd.conf +++ b/sample-lnd.conf @@ -212,6 +212,14 @@ ; advertise your node, this value doesn't need to be set. Unless specified ; (with host:port notation), the default port (9735) will be added to the ; address. +; +; NOTE: If you previously set one or more `externalip` entries and later +; remove `externalip` entirely from the config, lnd will continue to advertise +; the last known addresses from the previous run (they are stored with your node +; information). To stop advertising them, remove those addresses explicitly +; using the peers RPC/CLI, for example: +; `lncli peers updatenodeannouncement --address_remove=1.2.3.4:9735` +; A restart is not required, a new node announcement will be broadcasted. ; externalip= ; ; Instead of explicitly stating your external IP address, you can also enable @@ -553,13 +561,19 @@ ; The alias your node will use, which can be up to 32 UTF-8 characters in ; length. -; Default: +; Default is the first 10-bytes of the node's pubkey. +; +; NOTE: If this is not set lnd will use the last known alias from the previous +; run. ; alias= ; Example: ; alias=My Lightning ☇ ; The color of the node in hex format, used to customize node appearance in ; intelligence services. +; +; NOTE: If this is not set or is set to the default (#3399FF) lnd will use the +; last known color from the previous run. ; color=#3399FF ; The maximum duration that the server will wait before timing out reading