multi/refactor: separate methods for get and set node announcement
In preparation for a more complex function signature for set node announcement, separate get and set so that readonly callers don't need to handle the extra arguments.
This commit is contained in:
10 files changed
+94
-91
No files matched your search
+10
-12
@@ -203,11 +203,14 @@ type Config struct {
|
|||||||
// notification for when it reconnects.
|
// notification for when it reconnects.
|
||||||
NotifyWhenOffline func(peerPubKey [33]byte) <-chan struct{}
|
NotifyWhenOffline func(peerPubKey [33]byte) <-chan struct{}
|
||||||
|
|
||||||
// SelfNodeAnnouncement is a function that fetches our own current node
|
// FetchSelfAnnouncement retrieves our current node announcement, for
|
||||||
// announcement, for use when determining whether we should update our
|
// use when determining whether we should update our peers about our
|
||||||
// peers about our presence on the network. If the refresh is true, a
|
// presence in the network.
|
||||||
// new and updated announcement will be returned.
|
FetchSelfAnnouncement func() lnwire.NodeAnnouncement
|
||||||
SelfNodeAnnouncement func(refresh bool) (lnwire.NodeAnnouncement, error)
|
|
||||||
|
// UpdateSelfAnnouncement produces a new announcement for our node with
|
||||||
|
// an updated timestamp which can be broadcast to our peers.
|
||||||
|
UpdateSelfAnnouncement func() (lnwire.NodeAnnouncement, error)
|
||||||
|
|
||||||
// ProofMatureDelta the number of confirmations which is needed before
|
// ProofMatureDelta the number of confirmations which is needed before
|
||||||
// exchange the channel announcement proofs.
|
// exchange the channel announcement proofs.
|
||||||
@@ -1660,12 +1663,7 @@ func (d *AuthenticatedGossiper) retransmitStaleAnns(now time.Time) error {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// We'll also check that our NodeAnnouncement is not too old.
|
// We'll also check that our NodeAnnouncement is not too old.
|
||||||
currentNodeAnn, err := d.cfg.SelfNodeAnnouncement(false)
|
currentNodeAnn := d.cfg.FetchSelfAnnouncement()
|
||||||
if err != nil {
|
|
||||||
return fmt.Errorf("unable to get current node announment: %v",
|
|
||||||
err)
|
|
||||||
}
|
|
||||||
|
|
||||||
timestamp := time.Unix(int64(currentNodeAnn.Timestamp), 0)
|
timestamp := time.Unix(int64(currentNodeAnn.Timestamp), 0)
|
||||||
timeElapsed := now.Sub(timestamp)
|
timeElapsed := now.Sub(timestamp)
|
||||||
|
|
||||||
@@ -1673,7 +1671,7 @@ func (d *AuthenticatedGossiper) retransmitStaleAnns(now time.Time) error {
|
|||||||
// node announcement, refresh it and resend it.
|
// node announcement, refresh it and resend it.
|
||||||
nodeAnnStr := ""
|
nodeAnnStr := ""
|
||||||
if timeElapsed >= d.cfg.RebroadcastInterval {
|
if timeElapsed >= d.cfg.RebroadcastInterval {
|
||||||
newNodeAnn, err := d.cfg.SelfNodeAnnouncement(true)
|
newNodeAnn, err := d.cfg.UpdateSelfAnnouncement()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return fmt.Errorf("unable to get refreshed node "+
|
return fmt.Errorf("unable to get refreshed node "+
|
||||||
"announcement: %v", err)
|
"announcement: %v", err)
|
||||||
|
|||||||
+31
-22
@@ -775,7 +775,14 @@ func createTestCtx(t *testing.T, startHeight uint32) (*testCtx, error) {
|
|||||||
c := make(chan struct{})
|
c := make(chan struct{})
|
||||||
return c
|
return c
|
||||||
},
|
},
|
||||||
SelfNodeAnnouncement: func(bool) (lnwire.NodeAnnouncement, error) {
|
FetchSelfAnnouncement: func() lnwire.NodeAnnouncement {
|
||||||
|
return lnwire.NodeAnnouncement{
|
||||||
|
Timestamp: testTimestamp,
|
||||||
|
}
|
||||||
|
},
|
||||||
|
UpdateSelfAnnouncement: func() (lnwire.NodeAnnouncement,
|
||||||
|
error) {
|
||||||
|
|
||||||
return lnwire.NodeAnnouncement{
|
return lnwire.NodeAnnouncement{
|
||||||
Timestamp: testTimestamp,
|
Timestamp: testTimestamp,
|
||||||
}, nil
|
}, nil
|
||||||
@@ -1446,28 +1453,30 @@ func TestSignatureAnnouncementRetryAtStartup(t *testing.T) {
|
|||||||
return lnwire.ShortChannelID{}, fmt.Errorf("no peer alias")
|
return lnwire.ShortChannelID{}, fmt.Errorf("no peer alias")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//nolint:lll
|
||||||
gossiper := New(Config{
|
gossiper := New(Config{
|
||||||
Notifier: ctx.gossiper.cfg.Notifier,
|
Notifier: ctx.gossiper.cfg.Notifier,
|
||||||
Broadcast: ctx.gossiper.cfg.Broadcast,
|
Broadcast: ctx.gossiper.cfg.Broadcast,
|
||||||
NotifyWhenOnline: ctx.gossiper.reliableSender.cfg.NotifyWhenOnline,
|
NotifyWhenOnline: ctx.gossiper.reliableSender.cfg.NotifyWhenOnline,
|
||||||
NotifyWhenOffline: ctx.gossiper.reliableSender.cfg.NotifyWhenOffline,
|
NotifyWhenOffline: ctx.gossiper.reliableSender.cfg.NotifyWhenOffline,
|
||||||
SelfNodeAnnouncement: ctx.gossiper.cfg.SelfNodeAnnouncement,
|
FetchSelfAnnouncement: ctx.gossiper.cfg.FetchSelfAnnouncement,
|
||||||
Router: ctx.gossiper.cfg.Router,
|
UpdateSelfAnnouncement: ctx.gossiper.cfg.UpdateSelfAnnouncement,
|
||||||
TrickleDelay: trickleDelay,
|
Router: ctx.gossiper.cfg.Router,
|
||||||
RetransmitTicker: ticker.NewForce(retransmitDelay),
|
TrickleDelay: trickleDelay,
|
||||||
RebroadcastInterval: rebroadcastInterval,
|
RetransmitTicker: ticker.NewForce(retransmitDelay),
|
||||||
ProofMatureDelta: proofMatureDelta,
|
RebroadcastInterval: rebroadcastInterval,
|
||||||
WaitingProofStore: ctx.gossiper.cfg.WaitingProofStore,
|
ProofMatureDelta: proofMatureDelta,
|
||||||
MessageStore: ctx.gossiper.cfg.MessageStore,
|
WaitingProofStore: ctx.gossiper.cfg.WaitingProofStore,
|
||||||
RotateTicker: ticker.NewForce(DefaultSyncerRotationInterval),
|
MessageStore: ctx.gossiper.cfg.MessageStore,
|
||||||
HistoricalSyncTicker: ticker.NewForce(DefaultHistoricalSyncInterval),
|
RotateTicker: ticker.NewForce(DefaultSyncerRotationInterval),
|
||||||
NumActiveSyncers: 3,
|
HistoricalSyncTicker: ticker.NewForce(DefaultHistoricalSyncInterval),
|
||||||
MinimumBatchSize: 10,
|
NumActiveSyncers: 3,
|
||||||
SubBatchDelay: time.Second * 5,
|
MinimumBatchSize: 10,
|
||||||
IsAlias: isAlias,
|
SubBatchDelay: time.Second * 5,
|
||||||
SignAliasUpdate: signAliasUpdate,
|
IsAlias: isAlias,
|
||||||
FindBaseByAlias: findBaseByAlias,
|
SignAliasUpdate: signAliasUpdate,
|
||||||
GetAlias: getAlias,
|
FindBaseByAlias: findBaseByAlias,
|
||||||
|
GetAlias: getAlias,
|
||||||
}, &keychain.KeyDescriptor{
|
}, &keychain.KeyDescriptor{
|
||||||
PubKey: ctx.gossiper.selfKey,
|
PubKey: ctx.gossiper.selfKey,
|
||||||
KeyLocator: ctx.gossiper.selfKeyLoc,
|
KeyLocator: ctx.gossiper.selfKeyLoc,
|
||||||
|
|||||||
+2
-1
@@ -373,7 +373,8 @@ type Config struct {
|
|||||||
msg []byte, doubleHash bool) (*ecdsa.Signature, error)
|
msg []byte, doubleHash bool) (*ecdsa.Signature, error)
|
||||||
|
|
||||||
// CurrentNodeAnnouncement should return the latest, fully signed node
|
// CurrentNodeAnnouncement should return the latest, fully signed node
|
||||||
// announcement from the backing Lightning Network node.
|
// announcement from the backing Lightning Network node with a fresh
|
||||||
|
// timestamp.
|
||||||
CurrentNodeAnnouncement func() (lnwire.NodeAnnouncement, error)
|
CurrentNodeAnnouncement func() (lnwire.NodeAnnouncement, error)
|
||||||
|
|
||||||
// SendAnnouncement is used by the FundingManager to send announcement
|
// SendAnnouncement is used by the FundingManager to send announcement
|
||||||
|
|||||||
@@ -18,7 +18,7 @@ import (
|
|||||||
type Config struct {
|
type Config struct {
|
||||||
// GetNodeAnnouncement is used to send our retrieve the current
|
// GetNodeAnnouncement is used to send our retrieve the current
|
||||||
// node announcement information.
|
// node announcement information.
|
||||||
GetNodeAnnouncement func() (lnwire.NodeAnnouncement, error)
|
GetNodeAnnouncement func() lnwire.NodeAnnouncement
|
||||||
|
|
||||||
// ParseAddr parses an address from its string format to a net.Addr.
|
// ParseAddr parses an address from its string format to a net.Addr.
|
||||||
ParseAddr func(addr string) (net.Addr, error)
|
ParseAddr func(addr string) (net.Addr, error)
|
||||||
|
|||||||
@@ -313,11 +313,7 @@ func (s *Server) UpdateNodeAnnouncement(_ context.Context,
|
|||||||
resp := &NodeAnnouncementUpdateResponse{}
|
resp := &NodeAnnouncementUpdateResponse{}
|
||||||
nodeModifiers := make([]netann.NodeAnnModifier, 0)
|
nodeModifiers := make([]netann.NodeAnnModifier, 0)
|
||||||
|
|
||||||
currentNodeAnn, err := s.cfg.GetNodeAnnouncement()
|
currentNodeAnn := s.cfg.GetNodeAnnouncement()
|
||||||
if err != nil {
|
|
||||||
return nil, fmt.Errorf("unable to get current node "+
|
|
||||||
"announcement: %v", err)
|
|
||||||
}
|
|
||||||
|
|
||||||
if len(req.FeatureUpdates) > 0 {
|
if len(req.FeatureUpdates) > 0 {
|
||||||
features, ops, err := s.updateFeatures(
|
features, ops, err := s.updateFeatures(
|
||||||
|
|||||||
+6
-3
@@ -168,15 +168,18 @@ func (h *HostAnnouncer) hostWatcher() {
|
|||||||
// NodeAnnUpdater describes a function that's able to update our current node
|
// NodeAnnUpdater describes a function that's able to update our current node
|
||||||
// announcement on disk. It returns the updated node announcement given a set
|
// announcement on disk. It returns the updated node announcement given a set
|
||||||
// of updates to be applied to the current node announcement.
|
// of updates to be applied to the current node announcement.
|
||||||
type NodeAnnUpdater func(refresh bool, modifier ...NodeAnnModifier,
|
type NodeAnnUpdater func(modifier ...NodeAnnModifier,
|
||||||
) (lnwire.NodeAnnouncement, error)
|
) (lnwire.NodeAnnouncement, error)
|
||||||
|
|
||||||
// IPAnnouncer is a factory function that generates a new function that uses
|
// IPAnnouncer is a factory function that generates a new function that uses
|
||||||
// the passed annUpdater function to to announce new IP changes for a given
|
// the passed annUpdater function to to announce new IP changes for a given
|
||||||
// host.
|
// host.
|
||||||
func IPAnnouncer(annUpdater NodeAnnUpdater) func([]net.Addr, map[string]struct{}) error {
|
func IPAnnouncer(annUpdater NodeAnnUpdater) func([]net.Addr,
|
||||||
|
map[string]struct{}) error {
|
||||||
|
|
||||||
return func(newAddrs []net.Addr, oldAddrs map[string]struct{}) error {
|
return func(newAddrs []net.Addr, oldAddrs map[string]struct{}) error {
|
||||||
_, err := annUpdater(true, func(currentNodeAnn *lnwire.NodeAnnouncement) {
|
_, err := annUpdater(func(
|
||||||
|
currentNodeAnn *lnwire.NodeAnnouncement) {
|
||||||
// To ensure we don't duplicate any addresses, we'll
|
// To ensure we don't duplicate any addresses, we'll
|
||||||
// filter out the same of addresses we should no longer
|
// filter out the same of addresses we should no longer
|
||||||
// advertise.
|
// advertise.
|
||||||
|
|||||||
+3
-3
@@ -263,8 +263,8 @@ type Config struct {
|
|||||||
|
|
||||||
// GenNodeAnnouncement is used to send our node announcement to the remote
|
// GenNodeAnnouncement is used to send our node announcement to the remote
|
||||||
// on startup.
|
// on startup.
|
||||||
GenNodeAnnouncement func(bool,
|
GenNodeAnnouncement func(...netann.NodeAnnModifier) (
|
||||||
...netann.NodeAnnModifier) (lnwire.NodeAnnouncement, error)
|
lnwire.NodeAnnouncement, error)
|
||||||
|
|
||||||
// PrunePersistentPeerConnection is used to remove all internal state
|
// PrunePersistentPeerConnection is used to remove all internal state
|
||||||
// related to this peer in the server.
|
// related to this peer in the server.
|
||||||
@@ -1036,7 +1036,7 @@ func (p *Brontide) maybeSendNodeAnn(channels []*channeldb.OpenChannel) {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
ourNodeAnn, err := p.cfg.GenNodeAnnouncement(false)
|
ourNodeAnn, err := p.cfg.GenNodeAnnouncement()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
p.log.Debugf("Unable to retrieve node announcement: %v", err)
|
p.log.Debugf("Unable to retrieve node announcement: %v", err)
|
||||||
return
|
return
|
||||||
|
|||||||
+3
-10
@@ -762,10 +762,6 @@ func (r *rpcServer) addDeps(s *server, macService *macaroons.Service,
|
|||||||
return s.featureMgr.Get(feature.SetInvoiceAmp)
|
return s.featureMgr.Get(feature.SetInvoiceAmp)
|
||||||
}
|
}
|
||||||
|
|
||||||
getNodeAnnouncement := func() (lnwire.NodeAnnouncement, error) {
|
|
||||||
return s.genNodeAnnouncement(false)
|
|
||||||
}
|
|
||||||
|
|
||||||
parseAddr := func(addr string) (net.Addr, error) {
|
parseAddr := func(addr string) (net.Addr, error) {
|
||||||
return parseAddr(addr, r.cfg.net)
|
return parseAddr(addr, r.cfg.net)
|
||||||
}
|
}
|
||||||
@@ -786,7 +782,7 @@ func (r *rpcServer) addDeps(s *server, macService *macaroons.Service,
|
|||||||
routerBackend, s.nodeSigner, s.graphDB, s.chanStateDB,
|
routerBackend, s.nodeSigner, s.graphDB, s.chanStateDB,
|
||||||
s.sweeper, tower, s.towerClient, s.anchorTowerClient,
|
s.sweeper, tower, s.towerClient, s.anchorTowerClient,
|
||||||
r.cfg.net.ResolveTCPAddr, genInvoiceFeatures,
|
r.cfg.net.ResolveTCPAddr, genInvoiceFeatures,
|
||||||
genAmpInvoiceFeatures, getNodeAnnouncement,
|
genAmpInvoiceFeatures, s.getNodeAnnouncement,
|
||||||
s.updateAndBrodcastSelfNode, parseAddr, rpcsLog,
|
s.updateAndBrodcastSelfNode, parseAddr, rpcsLog,
|
||||||
s.aliasMgr.GetPeerAlias,
|
s.aliasMgr.GetPeerAlias,
|
||||||
)
|
)
|
||||||
@@ -2910,11 +2906,8 @@ func (r *rpcServer) GetInfo(_ context.Context,
|
|||||||
|
|
||||||
// Check if external IP addresses were provided to lnd and use them
|
// Check if external IP addresses were provided to lnd and use them
|
||||||
// to set the URIs.
|
// to set the URIs.
|
||||||
nodeAnn, err := r.server.genNodeAnnouncement(false)
|
nodeAnn := r.server.getNodeAnnouncement()
|
||||||
if err != nil {
|
|
||||||
return nil, fmt.Errorf("unable to retrieve current fully signed "+
|
|
||||||
"node announcement: %v", err)
|
|
||||||
}
|
|
||||||
addrs := nodeAnn.Addresses
|
addrs := nodeAnn.Addresses
|
||||||
uris := make([]string, len(addrs))
|
uris := make([]string, len(addrs))
|
||||||
for i, addr := range addrs {
|
for i, addr := range addrs {
|
||||||
|
|||||||
@@ -993,15 +993,18 @@ func newServer(cfg *Config, listenAddrs []net.Addr,
|
|||||||
}
|
}
|
||||||
|
|
||||||
s.authGossiper = discovery.New(discovery.Config{
|
s.authGossiper = discovery.New(discovery.Config{
|
||||||
Router: s.chanRouter,
|
Router: s.chanRouter,
|
||||||
Notifier: s.cc.ChainNotifier,
|
Notifier: s.cc.ChainNotifier,
|
||||||
ChainHash: *s.cfg.ActiveNetParams.GenesisHash,
|
ChainHash: *s.cfg.ActiveNetParams.GenesisHash,
|
||||||
Broadcast: s.BroadcastMessage,
|
Broadcast: s.BroadcastMessage,
|
||||||
ChanSeries: chanSeries,
|
ChanSeries: chanSeries,
|
||||||
NotifyWhenOnline: s.NotifyWhenOnline,
|
NotifyWhenOnline: s.NotifyWhenOnline,
|
||||||
NotifyWhenOffline: s.NotifyWhenOffline,
|
NotifyWhenOffline: s.NotifyWhenOffline,
|
||||||
SelfNodeAnnouncement: func(refresh bool) (lnwire.NodeAnnouncement, error) {
|
FetchSelfAnnouncement: s.getNodeAnnouncement,
|
||||||
return s.genNodeAnnouncement(refresh)
|
UpdateSelfAnnouncement: func() (lnwire.NodeAnnouncement,
|
||||||
|
error) {
|
||||||
|
|
||||||
|
return s.genNodeAnnouncement()
|
||||||
},
|
},
|
||||||
ProofMatureDelta: 0,
|
ProofMatureDelta: 0,
|
||||||
TrickleDelay: time.Millisecond * time.Duration(cfg.TrickleDelay),
|
TrickleDelay: time.Millisecond * time.Duration(cfg.TrickleDelay),
|
||||||
@@ -1271,6 +1274,7 @@ func newServer(cfg *Config, listenAddrs []net.Addr,
|
|||||||
return ourPolicy, err
|
return ourPolicy, err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//nolint:lll
|
||||||
s.fundingMgr, err = funding.NewFundingManager(funding.Config{
|
s.fundingMgr, err = funding.NewFundingManager(funding.Config{
|
||||||
NoWumboChans: !cfg.ProtocolOptions.Wumbo(),
|
NoWumboChans: !cfg.ProtocolOptions.Wumbo(),
|
||||||
IDKey: nodeKeyDesc.PubKey,
|
IDKey: nodeKeyDesc.PubKey,
|
||||||
@@ -1283,8 +1287,10 @@ func newServer(cfg *Config, listenAddrs []net.Addr,
|
|||||||
Notifier: cc.ChainNotifier,
|
Notifier: cc.ChainNotifier,
|
||||||
FeeEstimator: cc.FeeEstimator,
|
FeeEstimator: cc.FeeEstimator,
|
||||||
SignMessage: cc.MsgSigner.SignMessage,
|
SignMessage: cc.MsgSigner.SignMessage,
|
||||||
CurrentNodeAnnouncement: func() (lnwire.NodeAnnouncement, error) {
|
CurrentNodeAnnouncement: func() (lnwire.NodeAnnouncement,
|
||||||
return s.genNodeAnnouncement(true)
|
error) {
|
||||||
|
|
||||||
|
return s.genNodeAnnouncement()
|
||||||
},
|
},
|
||||||
SendAnnouncement: s.authGossiper.ProcessLocalAnnouncement,
|
SendAnnouncement: s.authGossiper.ProcessLocalAnnouncement,
|
||||||
NotifyWhenOnline: s.NotifyWhenOnline,
|
NotifyWhenOnline: s.NotifyWhenOnline,
|
||||||
@@ -2476,12 +2482,8 @@ out:
|
|||||||
// throughout the network. We'll only include addresses
|
// throughout the network. We'll only include addresses
|
||||||
// that have a different IP from the previous one, as
|
// that have a different IP from the previous one, as
|
||||||
// the previous IP is no longer valid.
|
// the previous IP is no longer valid.
|
||||||
currentNodeAnn, err := s.genNodeAnnouncement(false)
|
currentNodeAnn := s.getNodeAnnouncement()
|
||||||
if err != nil {
|
|
||||||
srvrLog.Debugf("Unable to retrieve current "+
|
|
||||||
"node announcement: %v", err)
|
|
||||||
continue
|
|
||||||
}
|
|
||||||
for _, addr := range currentNodeAnn.Addresses {
|
for _, addr := range currentNodeAnn.Addresses {
|
||||||
host, _, err := net.SplitHostPort(addr.String())
|
host, _, err := net.SplitHostPort(addr.String())
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@@ -2503,7 +2505,7 @@ out:
|
|||||||
// announcement with the updated addresses and broadcast
|
// announcement with the updated addresses and broadcast
|
||||||
// it to our peers.
|
// it to our peers.
|
||||||
newNodeAnn, err := s.genNodeAnnouncement(
|
newNodeAnn, err := s.genNodeAnnouncement(
|
||||||
true, netann.NodeAnnSetAddrs(newAddrs),
|
netann.NodeAnnSetAddrs(newAddrs),
|
||||||
)
|
)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
srvrLog.Debugf("Unable to generate new node "+
|
srvrLog.Debugf("Unable to generate new node "+
|
||||||
@@ -2892,7 +2894,7 @@ func (s *server) createNewHiddenService() error {
|
|||||||
// Now that the onion service has been created, we'll add the onion
|
// Now that the onion service has been created, we'll add the onion
|
||||||
// address it can be reached at to our list of advertised addresses.
|
// address it can be reached at to our list of advertised addresses.
|
||||||
newNodeAnn, err := s.genNodeAnnouncement(
|
newNodeAnn, err := s.genNodeAnnouncement(
|
||||||
true, func(currentAnn *lnwire.NodeAnnouncement) {
|
func(currentAnn *lnwire.NodeAnnouncement) {
|
||||||
currentAnn.Addresses = append(currentAnn.Addresses, addr)
|
currentAnn.Addresses = append(currentAnn.Addresses, addr)
|
||||||
},
|
},
|
||||||
)
|
)
|
||||||
@@ -2942,20 +2944,22 @@ func (s *server) findChannel(node *btcec.PublicKey, chanID lnwire.ChannelID) (
|
|||||||
return nil, fmt.Errorf("unable to find channel")
|
return nil, fmt.Errorf("unable to find channel")
|
||||||
}
|
}
|
||||||
|
|
||||||
// genNodeAnnouncement generates and returns the current fully signed node
|
// getNodeAnnouncement fetches the current, fully signed node announcement.
|
||||||
// announcement. If refresh is true, then the time stamp of the announcement
|
func (s *server) getNodeAnnouncement() lnwire.NodeAnnouncement {
|
||||||
// will be updated in order to ensure it propagates through the network.
|
|
||||||
func (s *server) genNodeAnnouncement(refresh bool,
|
|
||||||
modifiers ...netann.NodeAnnModifier) (lnwire.NodeAnnouncement, error) {
|
|
||||||
|
|
||||||
s.mu.Lock()
|
s.mu.Lock()
|
||||||
defer s.mu.Unlock()
|
defer s.mu.Unlock()
|
||||||
|
|
||||||
// If we don't need to refresh the announcement, then we can return a
|
return *s.currentNodeAnn
|
||||||
// copy of our cached version.
|
}
|
||||||
if !refresh {
|
|
||||||
return *s.currentNodeAnn, nil
|
// genNodeAnnouncement generates and returns the current fully signed node
|
||||||
}
|
// announcement. The time stamp of the announcement will be updated in order
|
||||||
|
// to ensure it propagates through the network.
|
||||||
|
func (s *server) genNodeAnnouncement(modifiers ...netann.NodeAnnModifier) (
|
||||||
|
lnwire.NodeAnnouncement, error) {
|
||||||
|
|
||||||
|
s.mu.Lock()
|
||||||
|
defer s.mu.Unlock()
|
||||||
|
|
||||||
// Always update the timestamp when refreshing to ensure the update
|
// Always update the timestamp when refreshing to ensure the update
|
||||||
// propagates.
|
// propagates.
|
||||||
@@ -2966,8 +2970,7 @@ func (s *server) genNodeAnnouncement(refresh bool,
|
|||||||
modifier(s.currentNodeAnn)
|
modifier(s.currentNodeAnn)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Otherwise, we'll sign a new update after applying all of the passed
|
// Sign a new update after applying all of the passed modifiers.
|
||||||
// modifiers.
|
|
||||||
err := netann.SignNodeAnnouncement(
|
err := netann.SignNodeAnnouncement(
|
||||||
s.nodeSigner, s.identityKeyLoc, s.currentNodeAnn,
|
s.nodeSigner, s.identityKeyLoc, s.currentNodeAnn,
|
||||||
)
|
)
|
||||||
@@ -2985,7 +2988,7 @@ func (s *server) genNodeAnnouncement(refresh bool,
|
|||||||
func (s *server) updateAndBrodcastSelfNode(
|
func (s *server) updateAndBrodcastSelfNode(
|
||||||
modifiers ...netann.NodeAnnModifier) error {
|
modifiers ...netann.NodeAnnModifier) error {
|
||||||
|
|
||||||
newNodeAnn, err := s.genNodeAnnouncement(true, modifiers...)
|
newNodeAnn, err := s.genNodeAnnouncement(modifiers...)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return fmt.Errorf("unable to generate new node "+
|
return fmt.Errorf("unable to generate new node "+
|
||||||
"announcement: %v", err)
|
"announcement: %v", err)
|
||||||
|
|||||||
@@ -118,7 +118,7 @@ func (s *subRPCServerConfigs) PopulateDependencies(cfg *Config,
|
|||||||
tcpResolver lncfg.TCPResolver,
|
tcpResolver lncfg.TCPResolver,
|
||||||
genInvoiceFeatures func() *lnwire.FeatureVector,
|
genInvoiceFeatures func() *lnwire.FeatureVector,
|
||||||
genAmpInvoiceFeatures func() *lnwire.FeatureVector,
|
genAmpInvoiceFeatures func() *lnwire.FeatureVector,
|
||||||
getNodeAnnouncement func() (lnwire.NodeAnnouncement, error),
|
getNodeAnnouncement func() lnwire.NodeAnnouncement,
|
||||||
updateNodeAnnouncement func(modifiers ...netann.NodeAnnModifier) error,
|
updateNodeAnnouncement func(modifiers ...netann.NodeAnnModifier) error,
|
||||||
parseAddr func(addr string) (net.Addr, error),
|
parseAddr func(addr string) (net.Addr, error),
|
||||||
rpcLogger btclog.Logger,
|
rpcLogger btclog.Logger,
|
||||||
|
|||||||
Reference in new issue
Block a user