Skip to content

Commit d26a84e

Browse files
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.
1 parent fe40542 commit d26a84e

File tree

1 file changed

+10
-2
lines changed

1 file changed

+10
-2
lines changed

server.go

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3432,6 +3432,11 @@ func (s *server) genNodeAnnouncement(features *lnwire.RawFeatureVector,
34323432
s.mu.Lock()
34333433
defer s.mu.Unlock()
34343434

3435+
// Create a shallow copy of the current node announcement to work on.
3436+
// This ensures the original announcement remains unchanged
3437+
// until the new announcement is fully signed and valid.
3438+
newNodeAnn := *s.currentNodeAnn
3439+
34353440
// First, try to update our feature manager with the updated set of
34363441
// features.
34373442
if features != nil {
@@ -3457,17 +3462,20 @@ func (s *server) genNodeAnnouncement(features *lnwire.RawFeatureVector,
34573462

34583463
// Apply the requested changes to the node announcement.
34593464
for _, modifier := range modifiers {
3460-
modifier(s.currentNodeAnn)
3465+
modifier(&newNodeAnn)
34613466
}
34623467

34633468
// Sign a new update after applying all of the passed modifiers.
34643469
err := netann.SignNodeAnnouncement(
3465-
s.nodeSigner, s.identityKeyLoc, s.currentNodeAnn,
3470+
s.nodeSigner, s.identityKeyLoc, &newNodeAnn,
34663471
)
34673472
if err != nil {
34683473
return lnwire.NodeAnnouncement{}, err
34693474
}
34703475

3476+
// If signing succeeds, update the current announcement.
3477+
*s.currentNodeAnn = newNodeAnn
3478+
34713479
return *s.currentNodeAnn, nil
34723480
}
34733481

0 commit comments

Comments
 (0)