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

lightningnetwork / lnd / 13211764208

08 Feb 2025 03:08AM UTC coverage: 49.288% (-9.5%) from 58.815%
13211764208

Pull #9489

github

calvinrzachman
itest: verify switchrpc server enforces send then track

We prevent the rpc server from allowing onion dispatches for
attempt IDs which have already been tracked by rpc clients.

This helps protect the client from leaking a duplicate onion
attempt. NOTE: This is not the only method for solving this
issue! The issue could be addressed via careful client side
programming which accounts for the uncertainty and async
nature of dispatching onions to a remote process via RPC.
This would require some lnd ChannelRouter changes for how
we intend to use these RPCs though.
Pull Request #9489: multi: add BuildOnion, SendOnion, and TrackOnion RPCs

474 of 990 new or added lines in 11 files covered. (47.88%)

27321 existing lines in 435 files now uncovered.

101192 of 205306 relevant lines covered (49.29%)

1.54 hits per line

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

74.58
/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.
23
func NodeAnnSetAlias(alias lnwire.NodeAlias) func(*lnwire.NodeAnnouncement) {
3✔
24
        return func(nodeAnn *lnwire.NodeAnnouncement) {
6✔
25
                nodeAnn.Alias = alias
3✔
26
        }
3✔
27
}
28

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

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

45
// NodeAnnSetFeatures is a functional option that allows updating the features of
46
// the given node announcement.
47
func NodeAnnSetFeatures(features *lnwire.RawFeatureVector) func(*lnwire.NodeAnnouncement) {
3✔
48
        return func(nodeAnn *lnwire.NodeAnnouncement) {
6✔
49
                nodeAnn.Features = features
3✔
50
        }
3✔
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.
56
func NodeAnnSetTimestamp(nodeAnn *lnwire.NodeAnnouncement) {
3✔
57
        newTimestamp := uint32(time.Now().Unix())
3✔
58
        if newTimestamp <= nodeAnn.Timestamp {
6✔
59
                // Increment the prior value to  ensure the timestamp
3✔
60
                // monotonically increases, otherwise the announcement won't
3✔
61
                // propagate.
3✔
62
                newTimestamp = nodeAnn.Timestamp + 1
3✔
63
        }
3✔
64
        nodeAnn.Timestamp = newTimestamp
3✔
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,
71
        keyLoc keychain.KeyLocator, nodeAnn *lnwire.NodeAnnouncement) error {
3✔
72

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

79
        // Parse the DER-encoded signature into a fixed-size 64-byte array.
80
        nodeAnn.Signature, err = lnwire.NewSigFromSignature(sig)
3✔
81
        return err
3✔
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 {
3✔
88
        // Reconstruct the data of announcement which should be covered by the
3✔
89
        // signature so we can verify the signature shortly below
3✔
90
        data, err := a.DataToSign()
3✔
91
        if err != nil {
3✔
UNCOV
92
                return err
×
UNCOV
93
        }
×
94

95
        nodeSig, err := a.Signature.ToSignature()
3✔
96
        if err != nil {
3✔
97
                return err
×
98
        }
×
99
        nodeKey, err := btcec.ParsePubKey(a.NodeID[:])
3✔
100
        if err != nil {
3✔
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)
3✔
107
        if !nodeSig.Verify(dataHash, nodeKey) {
3✔
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
3✔
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