Skip to content

Commit 94064be

Browse files
authored
Merge pull request #9815 from mohamedawnallah/preventCurrentNodeAnnMutation
server.go: prevent partial mutation of `currentNodeAnn` in `server.genNodeAnnouncement` on `netann.SignNodeAnnouncement` failures
2 parents fe40542 + e7d30e0 commit 94064be

File tree

2 files changed

+17
-2
lines changed

2 files changed

+17
-2
lines changed

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

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,12 @@
2020

2121
# Bug Fixes
2222

23+
- Fixed potential update inconsistencies in node announcements [by creating
24+
a shallow copy before modifications](
25+
https://github.com/lightningnetwork/lnd/pull/9815). This ensures the original
26+
announcement remains unchanged until the new one is fully signed and
27+
validated.
28+
2329
# New Features
2430

2531
## Functional Enhancements
@@ -119,4 +125,5 @@ circuit. The indices are only available for forwarding events saved after v0.20.
119125
* Abdulkbk
120126
* Elle Mouton
121127
* Funyug
128+
* Mohamed Awnallah
122129
* Pins

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)