|
6 | 6 | "crypto/rand" |
7 | 7 | "encoding/hex" |
8 | 8 | "fmt" |
| 9 | + "image/color" |
9 | 10 | "math/big" |
10 | 11 | prand "math/rand" |
11 | 12 | "net" |
@@ -803,33 +804,74 @@ func newServer(cfg *Config, listenAddrs []net.Addr, |
803 | 804 | // replicate it, and instead it'll only be stored locally. |
804 | 805 | chanGraph := dbs.GraphDB.ChannelGraph() |
805 | 806 |
|
| 807 | + // Fetch the source node from the channel graph. If a source node is |
| 808 | + // found, we'll use its values for our initial node announcement. |
| 809 | + persistedNode, err := chanGraph.SourceNode() |
| 810 | + if err != nil { |
| 811 | + srvrLog.Errorf("unable to fetch source node: %v", err) |
| 812 | + } |
| 813 | + |
806 | 814 | // We'll now reconstruct a node announcement based on our current |
807 | 815 | // configuration so we can send it out as a sort of heart beat within |
808 | 816 | // the network. |
809 | 817 | // |
810 | | - // We'll start by parsing the node color from configuration. |
811 | | - color, err := lncfg.ParseHexColor(cfg.Color) |
812 | | - if err != nil { |
813 | | - srvrLog.Errorf("unable to parse color: %v\n", err) |
814 | | - return nil, err |
815 | | - } |
816 | 818 |
|
817 | | - // If no alias is provided, default to first 10 characters of public |
818 | | - // key. |
819 | | - alias := cfg.Alias |
820 | | - if alias == "" { |
821 | | - alias = hex.EncodeToString(serializedPubKey[:10]) |
| 819 | + // If the node is restarted, we should use the previously persisted |
| 820 | + // values for the node's alias, color, addresses, and features. |
| 821 | + // Otherwise, we'll use the configured values. |
| 822 | + var ( |
| 823 | + color color.RGBA |
| 824 | + alias = cfg.Alias |
| 825 | + features *lnwire.FeatureVector |
| 826 | + ) |
| 827 | + |
| 828 | + // If the node was previously persisted, we'll use the saved values. |
| 829 | + if persistedNode != nil { |
| 830 | + // If the color is still set to the default, we'll use the |
| 831 | + // persisted color. |
| 832 | + if cfg.Color == defaultColor { |
| 833 | + color = persistedNode.Color |
| 834 | + } |
| 835 | + |
| 836 | + // If an alias was not specified in the configuration, |
| 837 | + // we'll use the saved alias. |
| 838 | + if alias == "" { |
| 839 | + alias = persistedNode.Alias |
| 840 | + } |
| 841 | + |
| 842 | + features = persistedNode.Features |
| 843 | + |
| 844 | + // Append the persisted addresses to the list of addresses our |
| 845 | + // node can be reached at. |
| 846 | + selfAddrs = append(selfAddrs, persistedNode.Addresses...) |
| 847 | + } else { |
| 848 | + color, err = lncfg.ParseHexColor(cfg.Color) |
| 849 | + if err != nil { |
| 850 | + srvrLog.Errorf("unable to parse color: %v\n", err) |
| 851 | + |
| 852 | + return nil, err |
| 853 | + } |
| 854 | + |
| 855 | + // If an alias was not specified, we'll generate one based on |
| 856 | + // the serialized public key. |
| 857 | + if alias == "" { |
| 858 | + alias = hex.EncodeToString(serializedPubKey[:10]) |
| 859 | + } |
| 860 | + |
| 861 | + features = s.featureMgr.Get(feature.SetNodeAnn) |
822 | 862 | } |
| 863 | + |
823 | 864 | nodeAlias, err := lnwire.NewNodeAlias(alias) |
824 | 865 | if err != nil { |
825 | 866 | return nil, err |
826 | 867 | } |
| 868 | + |
827 | 869 | selfNode := &channeldb.LightningNode{ |
828 | 870 | HaveNodeAnnouncement: true, |
829 | 871 | LastUpdate: time.Now(), |
830 | 872 | Addresses: selfAddrs, |
831 | 873 | Alias: nodeAlias.String(), |
832 | | - Features: s.featureMgr.Get(feature.SetNodeAnn), |
| 874 | + Features: features, |
833 | 875 | Color: color, |
834 | 876 | } |
835 | 877 | copy(selfNode.PubKeyBytes[:], nodeKeyDesc.PubKey.SerializeCompressed()) |
|
0 commit comments