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

lightningnetwork / lnd / 17830307614

18 Sep 2025 01:29PM UTC coverage: 54.617% (-12.0%) from 66.637%
17830307614

Pull #10200

github

web-flow
Merge 181a0a7bc into b34fc964b
Pull Request #10200: github: change to form-based issue template

109249 of 200028 relevant lines covered (54.62%)

21896.43 hits per line

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

72.0
/htlcswitch/packet.go
1
package htlcswitch
2

3
import (
4
        "fmt"
5

6
        "github.com/lightningnetwork/lnd/channeldb"
7
        "github.com/lightningnetwork/lnd/graph/db/models"
8
        "github.com/lightningnetwork/lnd/htlcswitch/hop"
9
        "github.com/lightningnetwork/lnd/lnwire"
10
        "github.com/lightningnetwork/lnd/record"
11
)
12

13
// htlcPacket is a wrapper around htlc lnwire update, which adds additional
14
// information which is needed by this package.
15
type htlcPacket struct {
16
        // incomingChanID is the ID of the channel that we have received an incoming
17
        // HTLC on.
18
        incomingChanID lnwire.ShortChannelID
19

20
        // outgoingChanID is the ID of the channel that we have offered or will
21
        // offer an outgoing HTLC on.
22
        outgoingChanID lnwire.ShortChannelID
23

24
        // incomingHTLCID is the ID of the HTLC that we have received from the peer
25
        // on the incoming channel.
26
        incomingHTLCID uint64
27

28
        // outgoingHTLCID is the ID of the HTLC that we offered to the peer on the
29
        // outgoing channel.
30
        outgoingHTLCID uint64
31

32
        // sourceRef is used by forwarded htlcPackets to locate incoming Add
33
        // entry in a fwdpkg owned by the incoming link. This value can be nil
34
        // if there is no such entry, e.g. switch initiated payments.
35
        sourceRef *channeldb.AddRef
36

37
        // destRef is used to locate a settle/fail entry in the outgoing link's
38
        // fwdpkg. If sourceRef is non-nil, this reference should be to a
39
        // settle/fail in response to the sourceRef.
40
        destRef *channeldb.SettleFailRef
41

42
        // incomingAmount is the value in milli-satoshis that arrived on an
43
        // incoming link.
44
        incomingAmount lnwire.MilliSatoshi
45

46
        // amount is the value of the HTLC that is being created or modified.
47
        amount lnwire.MilliSatoshi
48

49
        // htlc lnwire message type of which depends on switch request type.
50
        htlc lnwire.Message
51

52
        // obfuscator contains the necessary state to allow the switch to wrap
53
        // any forwarded errors in an additional layer of encryption.
54
        obfuscator hop.ErrorEncrypter
55

56
        // localFailure is set to true if an HTLC fails for a local payment before
57
        // the first hop. In this case, the failure reason is simply encoded, not
58
        // encrypted with any shared secret.
59
        localFailure bool
60

61
        // linkFailure is non-nil for htlcs that fail at our node. This may
62
        // occur for our own payments which fail on the outgoing link,
63
        // or for forwards which fail in the switch or on the outgoing link.
64
        linkFailure *LinkError
65

66
        // convertedError is set to true if this is an HTLC fail that was
67
        // created using an UpdateFailMalformedHTLC from the remote party. If
68
        // this is true, then when forwarding this failure packet, we'll need
69
        // to wrap it as if we were the first hop if it's a multi-hop HTLC. If
70
        // it's a direct HTLC, then we'll decode the error as no encryption has
71
        // taken place.
72
        convertedError bool
73

74
        // hasSource is set to true if the incomingChanID and incomingHTLCID
75
        // fields of a forwarded fail packet are already set and do not need to
76
        // be looked up in the circuit map.
77
        hasSource bool
78

79
        // isResolution is set to true if this packet was actually an incoming
80
        // resolution message from an outside sub-system. We'll treat these as
81
        // if they emanated directly from the switch. As a result, we'll
82
        // encrypt all errors related to this packet as if we were the first
83
        // hop.
84
        isResolution bool
85

86
        // circuit holds a reference to an Add's circuit which is persisted in
87
        // the switch during successful forwarding.
88
        circuit *PaymentCircuit
89

90
        // incomingTimeout is the timeout that the incoming HTLC carried. This
91
        // is the timeout of the HTLC applied to the incoming link.
92
        incomingTimeout uint32
93

94
        // outgoingTimeout is the timeout of the proposed outgoing HTLC. This
95
        // will be extracted from the hop payload received by the incoming
96
        // link.
97
        outgoingTimeout uint32
98

99
        // inOnionCustomRecords are user-defined records in the custom type
100
        // range that were included in the onion payload.
101
        inOnionCustomRecords record.CustomSet
102

103
        // inWireCustomRecords are custom type range TLVs that are included
104
        // in the incoming update_add_htlc wire message.
105
        inWireCustomRecords lnwire.CustomRecords
106

107
        // originalOutgoingChanID is used when sending back failure messages.
108
        // It is only used for forwarded Adds on option_scid_alias channels.
109
        // This is to avoid possible confusion if a payer uses the public SCID
110
        // but receives a channel_update with the alias SCID. Instead, the
111
        // payer should receive a channel_update with the public SCID.
112
        originalOutgoingChanID lnwire.ShortChannelID
113

114
        // inboundFee is the fee schedule of the incoming channel.
115
        inboundFee models.InboundFee
116
}
117

118
// inKey returns the circuit key used to identify the incoming htlc.
119
func (p *htlcPacket) inKey() CircuitKey {
8,121✔
120
        return CircuitKey{
8,121✔
121
                ChanID: p.incomingChanID,
8,121✔
122
                HtlcID: p.incomingHTLCID,
8,121✔
123
        }
8,121✔
124
}
8,121✔
125

126
// outKey returns the circuit key used to identify the outgoing, forwarded htlc.
127
func (p *htlcPacket) outKey() CircuitKey {
2,360✔
128
        return CircuitKey{
2,360✔
129
                ChanID: p.outgoingChanID,
2,360✔
130
                HtlcID: p.outgoingHTLCID,
2,360✔
131
        }
2,360✔
132
}
2,360✔
133

134
// keystone returns a tuple containing the incoming and outgoing circuit keys.
135
func (p *htlcPacket) keystone() Keystone {
513✔
136
        return Keystone{
513✔
137
                InKey:  p.inKey(),
513✔
138
                OutKey: p.outKey(),
513✔
139
        }
513✔
140
}
513✔
141

142
// String returns a human-readable description of the packet.
143
func (p *htlcPacket) String() string {
×
144
        return fmt.Sprintf("keystone=%v, sourceRef=%v, destRef=%v, "+
×
145
                "incomingAmount=%v, amount=%v, localFailure=%v, hasSource=%v "+
×
146
                "isResolution=%v", p.keystone(), p.sourceRef, p.destRef,
×
147
                p.incomingAmount, p.amount, p.localFailure, p.hasSource,
×
148
                p.isResolution)
×
149
}
×
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