• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

lightningnetwork / lnd / 13236757158

10 Feb 2025 08:39AM UTC coverage: 57.649% (-1.2%) from 58.815%
13236757158

Pull #9493

github

ziggie1984
lncli: for some cmds we don't replace the data of the response.

For some cmds it is not very practical to replace the json output
because we might pipe it into other commands. For example when
creating the route we want to pipe it into sendtoRoute.
Pull Request #9493: For some lncli cmds we should not replace the content with other data

0 of 9 new or added lines in 2 files covered. (0.0%)

19535 existing lines in 252 files now uncovered.

103517 of 179563 relevant lines covered (57.65%)

24878.49 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

23.73
/netann/node_announcement.go
1
package netann
2

3
import (
4
        "bytes"
5
        "image/color"
6
        "net"
7
        "time"
8

9
        "github.com/btcsuite/btcd/btcec/v2"
10
        "github.com/btcsuite/btcd/chaincfg/chainhash"
11
        "github.com/go-errors/errors"
12
        "github.com/lightningnetwork/lnd/keychain"
13
        "github.com/lightningnetwork/lnd/lnwallet"
14
        "github.com/lightningnetwork/lnd/lnwire"
15
)
16

17
// NodeAnnModifier is a closure that makes in-place modifications to an
18
// lnwire.NodeAnnouncement.
19
type NodeAnnModifier func(*lnwire.NodeAnnouncement)
20

21
// NodeAnnSetAlias is a functional option that sets the alias of the
22
// given node announcement.
UNCOV
23
func NodeAnnSetAlias(alias lnwire.NodeAlias) func(*lnwire.NodeAnnouncement) {
×
UNCOV
24
        return func(nodeAnn *lnwire.NodeAnnouncement) {
×
UNCOV
25
                nodeAnn.Alias = alias
×
UNCOV
26
        }
×
27
}
28

29
// NodeAnnSetAddrs is a functional option that allows updating the addresses of
30
// the given node announcement.
UNCOV
31
func NodeAnnSetAddrs(addrs []net.Addr) func(*lnwire.NodeAnnouncement) {
×
UNCOV
32
        return func(nodeAnn *lnwire.NodeAnnouncement) {
×
UNCOV
33
                nodeAnn.Addresses = addrs
×
UNCOV
34
        }
×
35
}
36

37
// NodeAnnSetColor is a functional option that sets the color of the
38
// given node announcement.
UNCOV
39
func NodeAnnSetColor(newColor color.RGBA) func(*lnwire.NodeAnnouncement) {
×
UNCOV
40
        return func(nodeAnn *lnwire.NodeAnnouncement) {
×
UNCOV
41
                nodeAnn.RGBColor = newColor
×
UNCOV
42
        }
×
43
}
44

45
// NodeAnnSetFeatures is a functional option that allows updating the features of
46
// the given node announcement.
UNCOV
47
func NodeAnnSetFeatures(features *lnwire.RawFeatureVector) func(*lnwire.NodeAnnouncement) {
×
UNCOV
48
        return func(nodeAnn *lnwire.NodeAnnouncement) {
×
UNCOV
49
                nodeAnn.Features = features
×
UNCOV
50
        }
×
51
}
52

53
// NodeAnnSetTimestamp is a functional option that sets the timestamp of the
54
// announcement to the current time, or increments it if the timestamp is
55
// already in the future.
UNCOV
56
func NodeAnnSetTimestamp(nodeAnn *lnwire.NodeAnnouncement) {
×
UNCOV
57
        newTimestamp := uint32(time.Now().Unix())
×
UNCOV
58
        if newTimestamp <= nodeAnn.Timestamp {
×
UNCOV
59
                // Increment the prior value to  ensure the timestamp
×
UNCOV
60
                // monotonically increases, otherwise the announcement won't
×
UNCOV
61
                // propagate.
×
UNCOV
62
                newTimestamp = nodeAnn.Timestamp + 1
×
UNCOV
63
        }
×
UNCOV
64
        nodeAnn.Timestamp = newTimestamp
×
65
}
66

67
// SignNodeAnnouncement signs the lnwire.NodeAnnouncement provided, which
68
// should be the most recent, valid update, otherwise the timestamp may not
69
// monotonically increase from the prior.
70
func SignNodeAnnouncement(signer lnwallet.MessageSigner,
UNCOV
71
        keyLoc keychain.KeyLocator, nodeAnn *lnwire.NodeAnnouncement) error {
×
UNCOV
72

×
UNCOV
73
        // Create the DER-encoded ECDSA signature over the message digest.
×
UNCOV
74
        sig, err := SignAnnouncement(signer, keyLoc, nodeAnn)
×
UNCOV
75
        if err != nil {
×
76
                return err
×
77
        }
×
78

79
        // Parse the DER-encoded signature into a fixed-size 64-byte array.
UNCOV
80
        nodeAnn.Signature, err = lnwire.NewSigFromSignature(sig)
×
UNCOV
81
        return err
×
82
}
83

84
// ValidateNodeAnn validates the node announcement by ensuring that the
85
// attached signature is needed a signature of the node announcement under the
86
// specified node public key.
87
func ValidateNodeAnn(a *lnwire.NodeAnnouncement) error {
17✔
88
        // Reconstruct the data of announcement which should be covered by the
17✔
89
        // signature so we can verify the signature shortly below
17✔
90
        data, err := a.DataToSign()
17✔
91
        if err != nil {
18✔
92
                return err
1✔
93
        }
1✔
94

95
        nodeSig, err := a.Signature.ToSignature()
16✔
96
        if err != nil {
16✔
97
                return err
×
98
        }
×
99
        nodeKey, err := btcec.ParsePubKey(a.NodeID[:])
16✔
100
        if err != nil {
16✔
101
                return err
×
102
        }
×
103

104
        // Finally ensure that the passed signature is valid, if not we'll
105
        // return an error so this node announcement can be rejected.
106
        dataHash := chainhash.DoubleHashB(data)
16✔
107
        if !nodeSig.Verify(dataHash, nodeKey) {
16✔
108
                var msgBuf bytes.Buffer
×
109
                if _, err := lnwire.WriteMessage(&msgBuf, a, 0); err != nil {
×
110
                        return err
×
111
                }
×
112

113
                return errors.Errorf("signature on NodeAnnouncement(%x) is "+
×
114
                        "invalid: %x", nodeKey.SerializeCompressed(),
×
115
                        msgBuf.Bytes())
×
116
        }
117

118
        return nil
16✔
119
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2025 Coveralls, Inc