Skip to content

Commit 9a49686

Browse files
authored
Merge pull request #8825 from Abdulkbk/restore-node-announcement
lnd: use persisted node announcement settings across restarts
2 parents fb1adfc + fbac730 commit 9a49686

File tree

4 files changed

+315
-135
lines changed

4 files changed

+315
-135
lines changed

docs/release-notes/release-notes-0.20.0.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,10 @@
3939

4040

4141
# New Features
42+
43+
* Use persisted [nodeannouncement](https://github.com/lightningnetwork/lnd/pull/8825)
44+
settings across restart. Before this change we always go back to the default
45+
settings when the node restarts.
4246

4347
- Added [NoOp HTLCs](https://github.com/lightningnetwork/lnd/pull/9871). This
4448
allows sending HTLCs to the remote party without shifting the balances of the

itest/list_on_test.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -170,6 +170,10 @@ var allTestCases = []*lntest.TestCase{
170170
Name: "update node announcement rpc",
171171
TestFunc: testUpdateNodeAnnouncement,
172172
},
173+
{
174+
Name: "self node announcement persistence",
175+
TestFunc: testSelfNodeAnnouncementPersistence,
176+
},
173177
{
174178
Name: "list payments",
175179
TestFunc: testListPayments,

itest/lnd_channel_graph_test.go

Lines changed: 130 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package itest
22

33
import (
4+
"encoding/hex"
45
"fmt"
56
"strings"
67
"testing"
@@ -654,6 +655,135 @@ func testUpdateNodeAnnouncement(ht *lntest.HarnessTest) {
654655
dave.RPC.UpdateNodeAnnouncementErr(nodeAnnReq)
655656
}
656657

658+
// testSelfNodeAnnouncementPersistence tests that the node announcement configs
659+
// are persisted correctly and reused when the node is restarted using the
660+
// correct hierarchy (config > source node > defaults).
661+
func testSelfNodeAnnouncementPersistence(ht *lntest.HarnessTest) {
662+
// Start Alice with default node announcement options.
663+
alice := ht.NewNode("Alice", nil)
664+
665+
// assertAddrs is a helper function to assert that the node info
666+
// contains the correct addresses.
667+
assertAddrs := func(addrsFound []string, targetAddrs ...string) error {
668+
addrs := make(map[string]struct{}, len(addrsFound))
669+
for _, addr := range addrsFound {
670+
addr = strings.Split(addr, "@")[1]
671+
addrs[addr] = struct{}{}
672+
}
673+
674+
for _, addr := range targetAddrs {
675+
_, ok := addrs[addr]
676+
if !ok {
677+
return fmt.Errorf("address %v not found in "+
678+
"node announcement", addr)
679+
}
680+
}
681+
682+
return nil
683+
}
684+
685+
// assertNodeInfo is a helper function to assert that the node info
686+
// contains the correct values.
687+
assertNodeInfo := func(resp *lnrpc.GetInfoResponse, expectedAlias,
688+
expectedColor string, expectedAddrs ...string) {
689+
690+
require.Equal(ht, expectedAlias, resp.Alias)
691+
require.Equal(ht, expectedColor, resp.Color)
692+
err := assertAddrs(resp.Uris, expectedAddrs...)
693+
require.NoError(ht, err)
694+
}
695+
696+
// Get the node info and verify that the default values are used for
697+
// alias and color.
698+
resp := alice.RPC.GetInfo()
699+
700+
// The alias should be the first 10 bytes of the serialized public key.
701+
defaultAlias := hex.EncodeToString(alice.PubKey[:10])
702+
703+
// Assert that the default values are used for alias and color.
704+
assertNodeInfo(resp, defaultAlias, "#3399ff")
705+
706+
// Update the node announcement and set an alias, color, and addresses.
707+
nodeAnnReq := &peersrpc.NodeAnnouncementUpdateRequest{
708+
Alias: "alice",
709+
Color: "#eeeeee",
710+
AddressUpdates: []*peersrpc.UpdateAddressAction{
711+
{
712+
Action: peersrpc.UpdateAction_ADD,
713+
Address: "192.168.1.10:8333",
714+
},
715+
{
716+
Action: peersrpc.UpdateAction_ADD,
717+
Address: "192.168.1.11:8333",
718+
},
719+
},
720+
}
721+
722+
response := alice.RPC.UpdateNodeAnnouncement(nodeAnnReq)
723+
724+
expectedOps := map[string]int{
725+
"alias": 1,
726+
"color": 1,
727+
"addresses": 2,
728+
}
729+
assertUpdateNodeAnnouncementResponse(ht, response, expectedOps)
730+
731+
resp = alice.RPC.GetInfo()
732+
assertNodeInfo(
733+
resp, "alice", "#eeeeee", "192.168.1.10:8333",
734+
"192.168.1.11:8333",
735+
)
736+
737+
// Restart Alice.
738+
ht.RestartNode(alice)
739+
740+
// After restarting, the node info should contain the values that were
741+
// set in the update request since the updated values take precedence
742+
// over the default values.
743+
resp = alice.RPC.GetInfo()
744+
assertNodeInfo(
745+
resp, "alice", "#eeeeee", "192.168.1.10:8333",
746+
"192.168.1.11:8333",
747+
)
748+
749+
// Test that we can still remove an address.
750+
removeAddrReq := &peersrpc.NodeAnnouncementUpdateRequest{
751+
AddressUpdates: []*peersrpc.UpdateAddressAction{
752+
{
753+
Action: peersrpc.UpdateAction_REMOVE,
754+
Address: "192.168.1.10:8333",
755+
},
756+
},
757+
}
758+
response = alice.RPC.UpdateNodeAnnouncement(removeAddrReq)
759+
expectedOps = map[string]int{
760+
"addresses": 1,
761+
}
762+
assertUpdateNodeAnnouncementResponse(ht, response, expectedOps)
763+
764+
// Now we restart the node with custom values in the config.
765+
lndArgs := []string{
766+
"--externalip=192.168.1.12:8333",
767+
"--externalip=192.168.1.13:8333",
768+
"--alias=alice-updated",
769+
"--color=#ffffff",
770+
}
771+
ht.RestartNodeWithExtraArgs(alice, lndArgs)
772+
773+
// Get the node info and verify that the values are the same as the
774+
// ones we set in the config (and not the updated values).
775+
// The addresses should be the same as the ones we set in the config
776+
// plus the ones we set in the update request earlier.
777+
resp = alice.RPC.GetInfo()
778+
assertNodeInfo(
779+
resp, "alice-updated", "#ffffff", "192.168.1.11:8333",
780+
"192.168.1.12:8333", "192.168.1.13:8333",
781+
)
782+
783+
// The address we removed earlier should not be present.
784+
require.Error(ht, assertAddrs(resp.Uris, "192.168.1.10:8333"))
785+
}
786+
657787
// assertSyncType asserts that the peer has an expected syncType.
658788
//
659789
// NOTE: only made for tests in this file.

0 commit comments

Comments
 (0)