mirror of
https://github.com/lightningnetwork/lnd.git
synced 2026-08-20 13:27:27 +02:00
server.go: prevent partial mutation of currNodeAnn
In this commit, we prevent partial mutation of current node announcement during announcement signing. If node announcement signing failed the current node announcement becomes inconsistent.
This commit is contained in:
parent
fe405426ca
commit
d26a84e18b
1 changed files with 10 additions and 2 deletions
12
server.go
12
server.go
|
|
@ -3432,6 +3432,11 @@ func (s *server) genNodeAnnouncement(features *lnwire.RawFeatureVector,
|
|||
s.mu.Lock()
|
||||
defer s.mu.Unlock()
|
||||
|
||||
// Create a shallow copy of the current node announcement to work on.
|
||||
// This ensures the original announcement remains unchanged
|
||||
// until the new announcement is fully signed and valid.
|
||||
newNodeAnn := *s.currentNodeAnn
|
||||
|
||||
// First, try to update our feature manager with the updated set of
|
||||
// features.
|
||||
if features != nil {
|
||||
|
|
@ -3457,17 +3462,20 @@ func (s *server) genNodeAnnouncement(features *lnwire.RawFeatureVector,
|
|||
|
||||
// Apply the requested changes to the node announcement.
|
||||
for _, modifier := range modifiers {
|
||||
modifier(s.currentNodeAnn)
|
||||
modifier(&newNodeAnn)
|
||||
}
|
||||
|
||||
// Sign a new update after applying all of the passed modifiers.
|
||||
err := netann.SignNodeAnnouncement(
|
||||
s.nodeSigner, s.identityKeyLoc, s.currentNodeAnn,
|
||||
s.nodeSigner, s.identityKeyLoc, &newNodeAnn,
|
||||
)
|
||||
if err != nil {
|
||||
return lnwire.NodeAnnouncement{}, err
|
||||
}
|
||||
|
||||
// If signing succeeds, update the current announcement.
|
||||
*s.currentNodeAnn = newNodeAnn
|
||||
|
||||
return *s.currentNodeAnn, nil
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue