• 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

75.0
/lnwire/channel_ready.go
1
package lnwire
2

3
import (
4
        "bytes"
5
        "io"
6

7
        "github.com/btcsuite/btcd/btcec/v2"
8
        "github.com/lightningnetwork/lnd/tlv"
9
)
10

11
// ChannelReady is the message that both parties to a new channel creation
12
// send once they have observed the funding transaction being confirmed on the
13
// blockchain. ChannelReady contains the signatures necessary for the channel
14
// participants to advertise the existence of the channel to the rest of the
15
// network.
16
type ChannelReady struct {
17
        // ChanID is the outpoint of the channel's funding transaction. This
18
        // can be used to query for the channel in the database.
19
        ChanID ChannelID
20

21
        // NextPerCommitmentPoint is the secret that can be used to revoke the
22
        // next commitment transaction for the channel.
23
        NextPerCommitmentPoint *btcec.PublicKey
24

25
        // AliasScid is an alias ShortChannelID used to refer to the underlying
26
        // channel. It can be used instead of the confirmed on-chain
27
        // ShortChannelID for forwarding.
28
        AliasScid *ShortChannelID
29

30
        // NextLocalNonce is an optional field that stores a local musig2 nonce.
31
        // This will only be populated if the simple taproot channels type was
32
        // negotiated. This is the local nonce that will be used by the sender
33
        // to accept a new commitment state transition.
34
        NextLocalNonce OptMusig2NonceTLV
35

36
        // AnnouncementNodeNonce is an optional field that stores a public
37
        // nonce that will be used along with the node's ID key during signing
38
        // of the ChannelAnnouncement2 message.
39
        AnnouncementNodeNonce tlv.OptionalRecordT[tlv.TlvType0, Musig2Nonce]
40

41
        // AnnouncementBitcoinNonce is an optional field that stores a public
42
        // nonce that will be used along with the node's bitcoin key during
43
        // signing of the ChannelAnnouncement2 message.
44
        AnnouncementBitcoinNonce tlv.OptionalRecordT[tlv.TlvType2, Musig2Nonce]
45

46
        // ExtraData is the set of data that was appended to this message to
47
        // fill out the full maximum transport message size. These fields can
48
        // be used to specify optional data such as custom TLV fields.
49
        ExtraData ExtraOpaqueData
50
}
51

52
// NewChannelReady creates a new ChannelReady message, populating it with the
53
// necessary IDs and revocation secret.
54
func NewChannelReady(cid ChannelID, npcp *btcec.PublicKey) *ChannelReady {
3✔
55
        return &ChannelReady{
3✔
56
                ChanID:                 cid,
3✔
57
                NextPerCommitmentPoint: npcp,
3✔
58
                ExtraData:              nil,
3✔
59
        }
3✔
60
}
3✔
61

62
// A compile time check to ensure ChannelReady implements the lnwire.Message
63
// interface.
64
var _ Message = (*ChannelReady)(nil)
65

66
// Decode deserializes the serialized ChannelReady message stored in the
67
// passed io.Reader into the target ChannelReady using the deserialization
68
// rules defined by the passed protocol version.
69
//
70
// This is part of the lnwire.Message interface.
71
func (c *ChannelReady) Decode(r io.Reader, _ uint32) error {
3✔
72
        // Read all the mandatory fields in the message.
3✔
73
        err := ReadElements(r,
3✔
74
                &c.ChanID,
3✔
75
                &c.NextPerCommitmentPoint,
3✔
76
        )
3✔
77
        if err != nil {
3✔
UNCOV
78
                return err
×
UNCOV
79
        }
×
80

81
        var tlvRecords ExtraOpaqueData
3✔
82
        if err := ReadElements(r, &tlvRecords); err != nil {
3✔
83
                return err
×
84
        }
×
85

86
        // Next we'll parse out the set of known records. For now, this is just
87
        // the AliasScidRecordType.
88
        var (
3✔
89
                aliasScid  ShortChannelID
3✔
90
                localNonce = c.NextLocalNonce.Zero()
3✔
91
                nodeNonce  = tlv.ZeroRecordT[tlv.TlvType0, Musig2Nonce]()
3✔
92
                btcNonce   = tlv.ZeroRecordT[tlv.TlvType2, Musig2Nonce]()
3✔
93
        )
3✔
94
        typeMap, err := tlvRecords.ExtractRecords(
3✔
95
                &btcNonce, &aliasScid, &nodeNonce, &localNonce,
3✔
96
        )
3✔
97
        if err != nil {
3✔
UNCOV
98
                return err
×
UNCOV
99
        }
×
100

101
        // We'll only set AliasScid if the corresponding TLV type was included
102
        // in the stream.
103
        if val, ok := typeMap[AliasScidRecordType]; ok && val == nil {
6✔
104
                c.AliasScid = &aliasScid
3✔
105
        }
3✔
106
        if val, ok := typeMap[c.NextLocalNonce.TlvType()]; ok && val == nil {
6✔
107
                c.NextLocalNonce = tlv.SomeRecordT(localNonce)
3✔
108
        }
3✔
109
        val, ok := typeMap[c.AnnouncementBitcoinNonce.TlvType()]
3✔
110
        if ok && val == nil {
3✔
UNCOV
111
                c.AnnouncementBitcoinNonce = tlv.SomeRecordT(btcNonce)
×
UNCOV
112
        }
×
113
        val, ok = typeMap[c.AnnouncementNodeNonce.TlvType()]
3✔
114
        if ok && val == nil {
3✔
UNCOV
115
                c.AnnouncementNodeNonce = tlv.SomeRecordT(nodeNonce)
×
UNCOV
116
        }
×
117

118
        if len(tlvRecords) != 0 {
6✔
119
                c.ExtraData = tlvRecords
3✔
120
        }
3✔
121

122
        return nil
3✔
123
}
124

125
// Encode serializes the target ChannelReady message into the passed io.Writer
126
// implementation. Serialization will observe the rules defined by the passed
127
// protocol version.
128
//
129
// This is part of the lnwire.Message interface.
130
func (c *ChannelReady) Encode(w *bytes.Buffer, _ uint32) error {
3✔
131
        if err := WriteChannelID(w, c.ChanID); err != nil {
3✔
132
                return err
×
133
        }
×
134

135
        if err := WritePublicKey(w, c.NextPerCommitmentPoint); err != nil {
3✔
136
                return err
×
137
        }
×
138

139
        // We'll only encode the AliasScid in a TLV segment if it exists.
140
        recordProducers := make([]tlv.RecordProducer, 0, 4)
3✔
141
        if c.AliasScid != nil {
6✔
142
                recordProducers = append(recordProducers, c.AliasScid)
3✔
143
        }
3✔
144
        c.NextLocalNonce.WhenSome(func(localNonce Musig2NonceTLV) {
6✔
145
                recordProducers = append(recordProducers, &localNonce)
3✔
146
        })
3✔
147
        c.AnnouncementBitcoinNonce.WhenSome(
3✔
148
                func(nonce tlv.RecordT[tlv.TlvType2, Musig2Nonce]) {
3✔
UNCOV
149
                        recordProducers = append(recordProducers, &nonce)
×
UNCOV
150
                },
×
151
        )
152
        c.AnnouncementNodeNonce.WhenSome(
3✔
153
                func(nonce tlv.RecordT[tlv.TlvType0, Musig2Nonce]) {
3✔
UNCOV
154
                        recordProducers = append(recordProducers, &nonce)
×
UNCOV
155
                },
×
156
        )
157

158
        err := EncodeMessageExtraData(&c.ExtraData, recordProducers...)
3✔
159
        if err != nil {
3✔
160
                return err
×
161
        }
×
162

163
        return WriteBytes(w, c.ExtraData)
3✔
164
}
165

166
// MsgType returns the uint32 code which uniquely identifies this message as a
167
// ChannelReady message on the wire.
168
//
169
// This is part of the lnwire.Message interface.
170
func (c *ChannelReady) MsgType() MessageType {
3✔
171
        return MsgChannelReady
3✔
172
}
3✔
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