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

lightningnetwork / lnd / 19027031130

03 Nov 2025 07:27AM UTC coverage: 56.922% (-9.7%) from 66.639%
19027031130

Pull #9334

github

web-flow
Merge b9be11a16 into f938e40af
Pull Request #9334: Use all valid routes during blinded path construction

9 of 11 new or added lines in 3 files covered. (81.82%)

29175 existing lines in 461 files now uncovered.

99696 of 175144 relevant lines covered (56.92%)

1.77 hits per line

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

9.62
/lnwallet/aux_leaf_store.go
1
package lnwallet
2

3
import (
4
        "github.com/btcsuite/btcd/btcutil"
5
        "github.com/btcsuite/btcd/chaincfg/chainhash"
6
        "github.com/btcsuite/btcd/wire"
7
        "github.com/lightningnetwork/lnd/channeldb"
8
        "github.com/lightningnetwork/lnd/fn/v2"
9
        "github.com/lightningnetwork/lnd/input"
10
        "github.com/lightningnetwork/lnd/lntypes"
11
        "github.com/lightningnetwork/lnd/lnwire"
12
        "github.com/lightningnetwork/lnd/routing/route"
13
        "github.com/lightningnetwork/lnd/tlv"
14
)
15

16
// CommitSortFunc is a function type alias for a function that sorts the
17
// commitment transaction outputs. The second parameter is a list of CLTV
18
// timeouts that must correspond to the number of transaction outputs, with the
19
// value of 0 for non-HTLC outputs. The HTLC indexes are needed to have a
20
// deterministic sort value for HTLCs that have the identical amount, CLTV
21
// timeout and payment hash (e.g. multiple MPP shards of the same payment, where
22
// the on-chain script would be identical).
23
type CommitSortFunc func(tx *wire.MsgTx, cltvs []uint32,
24
        indexes []input.HtlcIndex) error
25

26
// DefaultCommitSort is the default commitment sort function that sorts the
27
// commitment transaction inputs and outputs according to BIP69. The second
28
// parameter is a list of CLTV timeouts that must correspond to the number of
29
// transaction outputs, with the value of 0 for non-HTLC outputs. The third
30
// parameter is unused for the default sort function.
31
func DefaultCommitSort(tx *wire.MsgTx, cltvs []uint32,
32
        _ []input.HtlcIndex) error {
3✔
33

3✔
34
        InPlaceCommitSort(tx, cltvs)
3✔
35
        return nil
3✔
36
}
3✔
37

38
// CommitAuxLeaves stores two potential auxiliary leaves for the remote and
39
// local output that may be used to augment the final tapscript trees of the
40
// commitment transaction.
41
type CommitAuxLeaves struct {
42
        // LocalAuxLeaf is the local party's auxiliary leaf.
43
        LocalAuxLeaf input.AuxTapLeaf
44

45
        // RemoteAuxLeaf is the remote party's auxiliary leaf.
46
        RemoteAuxLeaf input.AuxTapLeaf
47

48
        // OutgoingHTLCLeaves is the set of aux leaves for the outgoing HTLCs
49
        // on this commitment transaction.
50
        OutgoingHtlcLeaves input.HtlcAuxLeaves
51

52
        // IncomingHTLCLeaves is the set of aux leaves for the incoming HTLCs
53
        // on this commitment transaction.
54
        IncomingHtlcLeaves input.HtlcAuxLeaves
55
}
56

57
// AuxChanState is a struct that holds certain fields of the
58
// channeldb.OpenChannel struct that are used by the aux components. The data
59
// is copied over to prevent accidental mutation of the original channel state.
60
type AuxChanState struct {
61
        // ChanType denotes which type of channel this is.
62
        ChanType channeldb.ChannelType
63

64
        // FundingOutpoint is the outpoint of the final funding transaction.
65
        // This value uniquely and globally identifies the channel within the
66
        // target blockchain as specified by the chain hash parameter.
67
        FundingOutpoint wire.OutPoint
68

69
        // ShortChannelID encodes the exact location in the chain in which the
70
        // channel was initially confirmed. This includes: the block height,
71
        // transaction index, and the output within the target transaction.
72
        //
73
        // If IsZeroConf(), then this will the "base" (very first) ALIAS scid
74
        // and the confirmed SCID will be stored in ConfirmedScid.
75
        ShortChannelID lnwire.ShortChannelID
76

77
        // IsInitiator is a bool which indicates if we were the original
78
        // initiator for the channel. This value may affect how higher levels
79
        // negotiate fees, or close the channel.
80
        IsInitiator bool
81

82
        // Capacity is the total capacity of this channel.
83
        Capacity btcutil.Amount
84

85
        // LocalChanCfg is the channel configuration for the local node.
86
        LocalChanCfg channeldb.ChannelConfig
87

88
        // RemoteChanCfg is the channel configuration for the remote node.
89
        RemoteChanCfg channeldb.ChannelConfig
90

91
        // ThawHeight is the height when a frozen channel once again becomes a
92
        // normal channel. If this is zero, then there're no restrictions on
93
        // this channel. If the value is lower than 500,000, then it's
94
        // interpreted as a relative height, or an absolute height otherwise.
95
        ThawHeight uint32
96

97
        // TapscriptRoot is an optional tapscript root used to derive the MuSig2
98
        // funding output.
99
        TapscriptRoot fn.Option[chainhash.Hash]
100

101
        // PeerPubKey is the peer pub key of the peer we've established this
102
        // channel with.
103
        PeerPubKey route.Vertex
104

105
        // CustomBlob is an optional blob that can be used to store information
106
        // specific to a custom channel type. This information is only created
107
        // at channel funding time, and after wards is to be considered
108
        // immutable.
109
        CustomBlob fn.Option[tlv.Blob]
110
}
111

112
// NewAuxChanState creates a new AuxChanState from the given channel state.
UNCOV
113
func NewAuxChanState(chanState *channeldb.OpenChannel) AuxChanState {
×
UNCOV
114
        peerPub := chanState.IdentityPub.SerializeCompressed()
×
UNCOV
115

×
UNCOV
116
        return AuxChanState{
×
UNCOV
117
                ChanType:        chanState.ChanType,
×
UNCOV
118
                FundingOutpoint: chanState.FundingOutpoint,
×
UNCOV
119
                ShortChannelID:  chanState.ShortChannelID,
×
UNCOV
120
                IsInitiator:     chanState.IsInitiator,
×
UNCOV
121
                Capacity:        chanState.Capacity,
×
UNCOV
122
                LocalChanCfg:    chanState.LocalChanCfg,
×
UNCOV
123
                RemoteChanCfg:   chanState.RemoteChanCfg,
×
UNCOV
124
                ThawHeight:      chanState.ThawHeight,
×
UNCOV
125
                TapscriptRoot:   chanState.TapscriptRoot,
×
UNCOV
126
                PeerPubKey:      route.Vertex(peerPub),
×
UNCOV
127
                CustomBlob:      chanState.CustomBlob,
×
UNCOV
128
        }
×
UNCOV
129
}
×
130

131
// CommitDiffAuxInput is the input required to compute the diff of the auxiliary
132
// leaves for a commitment transaction.
133
type CommitDiffAuxInput struct {
134
        // ChannelState is the static channel information of the channel this
135
        // commitment transaction relates to.
136
        ChannelState AuxChanState
137

138
        // PrevBlob is the blob of the previous commitment transaction.
139
        PrevBlob tlv.Blob
140

141
        // UnfilteredView is the unfiltered, original HTLC view of the channel.
142
        // Unfiltered in this context means that the view contains all HTLCs,
143
        // including the canceled ones.
144
        UnfilteredView AuxHtlcView
145

146
        // WhoseCommit denotes whose commitment transaction we are computing the
147
        // diff for.
148
        WhoseCommit lntypes.ChannelParty
149

150
        // OurBalance is the balance of the local party.
151
        OurBalance lnwire.MilliSatoshi
152

153
        // TheirBalance is the balance of the remote party.
154
        TheirBalance lnwire.MilliSatoshi
155

156
        // KeyRing is the key ring that can be used to derive keys for the
157
        // commitment transaction.
158
        KeyRing CommitmentKeyRing
159
}
160

161
// CommitDiffAuxResult is the result of computing the diff of the auxiliary
162
// leaves for a commitment transaction.
163
type CommitDiffAuxResult struct {
164
        // AuxLeaves are the auxiliary leaves for the new commitment
165
        // transaction.
166
        AuxLeaves fn.Option[CommitAuxLeaves]
167

168
        // CommitSortFunc is an optional function that sorts the commitment
169
        // transaction inputs and outputs.
170
        CommitSortFunc fn.Option[CommitSortFunc]
171
}
172

173
// AuxLeafStore is used to optionally fetch auxiliary tapscript leaves for the
174
// commitment transaction given an opaque blob. This is also used to implement
175
// a state transition function for the blobs to allow them to be refreshed with
176
// each state.
177
type AuxLeafStore interface {
178
        // FetchLeavesFromView attempts to fetch the auxiliary leaves that
179
        // correspond to the passed aux blob, and pending original (unfiltered)
180
        // HTLC view.
181
        FetchLeavesFromView(
182
                in CommitDiffAuxInput) fn.Result[CommitDiffAuxResult]
183

184
        // FetchLeavesFromCommit attempts to fetch the auxiliary leaves that
185
        // correspond to the passed aux blob, and an existing channel
186
        // commitment.
187
        FetchLeavesFromCommit(chanState AuxChanState,
188
                commit channeldb.ChannelCommitment, keyRing CommitmentKeyRing,
189
                whoseCommit lntypes.ChannelParty) fn.Result[CommitDiffAuxResult]
190

191
        // FetchLeavesFromRevocation attempts to fetch the auxiliary leaves
192
        // from a channel revocation that stores balance + blob information.
193
        FetchLeavesFromRevocation(
194
                r *channeldb.RevocationLog) fn.Result[CommitDiffAuxResult]
195

196
        // ApplyHtlcView serves as the state transition function for the custom
197
        // channel's blob. Given the old blob, and an HTLC view, then a new
198
        // blob should be returned that reflects the pending updates.
199
        ApplyHtlcView(in CommitDiffAuxInput) fn.Result[fn.Option[tlv.Blob]]
200
}
201

202
// auxLeavesFromView is used to derive the set of commit aux leaves (if any),
203
// that are needed to create a new commitment transaction using the original
204
// (unfiltered) htlc view.
205
func auxLeavesFromView(leafStore AuxLeafStore, chanState *channeldb.OpenChannel,
206
        prevBlob fn.Option[tlv.Blob], originalView *HtlcView,
207
        whoseCommit lntypes.ChannelParty, ourBalance,
208
        theirBalance lnwire.MilliSatoshi,
UNCOV
209
        keyRing CommitmentKeyRing) fn.Result[CommitDiffAuxResult] {
×
UNCOV
210

×
UNCOV
211
        return fn.MapOptionZ(
×
UNCOV
212
                prevBlob, func(blob tlv.Blob) fn.Result[CommitDiffAuxResult] {
×
213
                        return leafStore.FetchLeavesFromView(CommitDiffAuxInput{
×
214
                                ChannelState:   NewAuxChanState(chanState),
×
215
                                PrevBlob:       blob,
×
216
                                UnfilteredView: newAuxHtlcView(originalView),
×
217
                                WhoseCommit:    whoseCommit,
×
218
                                OurBalance:     ourBalance,
×
219
                                TheirBalance:   theirBalance,
×
220
                                KeyRing:        keyRing,
×
221
                        })
×
222
                },
×
223
        )
224
}
225

226
// updateAuxBlob is a helper function that attempts to update the aux blob
227
// given the prior and current state information.
228
func updateAuxBlob(leafStore AuxLeafStore, chanState *channeldb.OpenChannel,
229
        prevBlob fn.Option[tlv.Blob], nextViewUnfiltered *HtlcView,
230
        whoseCommit lntypes.ChannelParty, ourBalance,
231
        theirBalance lnwire.MilliSatoshi,
UNCOV
232
        keyRing CommitmentKeyRing) fn.Result[fn.Option[tlv.Blob]] {
×
UNCOV
233

×
UNCOV
234
        return fn.MapOptionZ(
×
UNCOV
235
                prevBlob, func(blob tlv.Blob) fn.Result[fn.Option[tlv.Blob]] {
×
236
                        return leafStore.ApplyHtlcView(CommitDiffAuxInput{
×
237
                                ChannelState: NewAuxChanState(chanState),
×
238
                                PrevBlob:     blob,
×
239
                                UnfilteredView: newAuxHtlcView(
×
240
                                        nextViewUnfiltered,
×
241
                                ),
×
242
                                WhoseCommit:  whoseCommit,
×
243
                                OurBalance:   ourBalance,
×
244
                                TheirBalance: theirBalance,
×
245
                                KeyRing:      keyRing,
×
246
                        })
×
247
                },
×
248
        )
249
}
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