• 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

65.45
/lnwire/revoke_and_ack.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
// RevokeAndAck is sent by either side once a CommitSig message has been
12
// received, and validated. This message serves to revoke the prior commitment
13
// transaction, which was the most up to date version until a CommitSig message
14
// referencing the specified ChannelPoint was received.  Additionally, this
15
// message also piggyback's the next revocation hash that Alice should use when
16
// constructing the Bob's version of the next commitment transaction (which
17
// would be done before sending a CommitSig message).  This piggybacking allows
18
// Alice to send the next CommitSig message modifying Bob's commitment
19
// transaction without first asking for a revocation hash initially.
20
type RevokeAndAck struct {
21
        // ChanID uniquely identifies to which currently active channel this
22
        // RevokeAndAck applies to.
23
        ChanID ChannelID
24

25
        // Revocation is the preimage to the revocation hash of the now prior
26
        // commitment transaction.
27
        Revocation [32]byte
28

29
        // NextRevocationKey is the next commitment point which should be used
30
        // for the next commitment transaction the remote peer creates for us.
31
        // This, in conjunction with revocation base point will be used to
32
        // create the proper revocation key used within the commitment
33
        // transaction.
34
        NextRevocationKey *btcec.PublicKey
35

36
        // LocalNonce is the next _local_ nonce for the sending party. This
37
        // allows the receiving party to propose a new commitment using their
38
        // remote nonce and the sender's local nonce.
39
        LocalNonce OptMusig2NonceTLV
40

41
        // ExtraData is the set of data that was appended to this message to
42
        // fill out the full maximum transport message size. These fields can
43
        // be used to specify optional data such as custom TLV fields.
44
        ExtraData ExtraOpaqueData
45
}
46

47
// NewRevokeAndAck creates a new RevokeAndAck message.
UNCOV
48
func NewRevokeAndAck() *RevokeAndAck {
×
UNCOV
49
        return &RevokeAndAck{
×
UNCOV
50
                ExtraData: make([]byte, 0),
×
UNCOV
51
        }
×
UNCOV
52
}
×
53

54
// A compile time check to ensure RevokeAndAck implements the lnwire.Message
55
// interface.
56
var _ Message = (*RevokeAndAck)(nil)
57

58
// Decode deserializes a serialized RevokeAndAck message stored in the
59
// passed io.Reader observing the specified protocol version.
60
//
61
// This is part of the lnwire.Message interface.
62
func (c *RevokeAndAck) Decode(r io.Reader, pver uint32) error {
3✔
63
        err := ReadElements(r,
3✔
64
                &c.ChanID,
3✔
65
                c.Revocation[:],
3✔
66
                &c.NextRevocationKey,
3✔
67
        )
3✔
68
        if err != nil {
3✔
UNCOV
69
                return err
×
UNCOV
70
        }
×
71

72
        var tlvRecords ExtraOpaqueData
3✔
73
        if err := ReadElements(r, &tlvRecords); err != nil {
3✔
74
                return err
×
75
        }
×
76

77
        localNonce := c.LocalNonce.Zero()
3✔
78
        typeMap, err := tlvRecords.ExtractRecords(&localNonce)
3✔
79
        if err != nil {
3✔
UNCOV
80
                return err
×
UNCOV
81
        }
×
82

83
        // Set the corresponding TLV types if they were included in the stream.
84
        if val, ok := typeMap[c.LocalNonce.TlvType()]; ok && val == nil {
6✔
85
                c.LocalNonce = tlv.SomeRecordT(localNonce)
3✔
86
        }
3✔
87

88
        if len(tlvRecords) != 0 {
6✔
89
                c.ExtraData = tlvRecords
3✔
90
        }
3✔
91

92
        return nil
3✔
93
}
94

95
// Encode serializes the target RevokeAndAck into the passed io.Writer
96
// observing the protocol version specified.
97
//
98
// This is part of the lnwire.Message interface.
99
func (c *RevokeAndAck) Encode(w *bytes.Buffer, pver uint32) error {
3✔
100
        recordProducers := make([]tlv.RecordProducer, 0, 1)
3✔
101
        c.LocalNonce.WhenSome(func(localNonce Musig2NonceTLV) {
6✔
102
                recordProducers = append(recordProducers, &localNonce)
3✔
103
        })
3✔
104
        err := EncodeMessageExtraData(&c.ExtraData, recordProducers...)
3✔
105
        if err != nil {
3✔
106
                return err
×
107
        }
×
108

109
        if err := WriteChannelID(w, c.ChanID); err != nil {
3✔
110
                return err
×
111
        }
×
112

113
        if err := WriteBytes(w, c.Revocation[:]); err != nil {
3✔
114
                return err
×
115
        }
×
116

117
        if err := WritePublicKey(w, c.NextRevocationKey); err != nil {
3✔
118
                return err
×
119
        }
×
120

121
        return WriteBytes(w, c.ExtraData)
3✔
122
}
123

124
// MsgType returns the integer uniquely identifying this message type on the
125
// wire.
126
//
127
// This is part of the lnwire.Message interface.
128
func (c *RevokeAndAck) MsgType() MessageType {
3✔
129
        return MsgRevokeAndAck
3✔
130
}
3✔
131

132
// TargetChanID returns the channel id of the link for which this message is
133
// intended.
134
//
135
// NOTE: Part of peer.LinkUpdater interface.
136
func (c *RevokeAndAck) TargetChanID() ChannelID {
3✔
137
        return c.ChanID
3✔
138
}
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