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

lightningnetwork / lnd / 11393106485

17 Oct 2024 09:10PM UTC coverage: 57.848% (-1.0%) from 58.81%
11393106485

Pull #9148

github

ProofOfKeags
lnwire: convert DynPropose and DynCommit to use typed tlv records
Pull Request #9148: DynComms [2/n]: lnwire: add authenticated wire messages for Dyn*

142 of 177 new or added lines in 4 files covered. (80.23%)

18983 existing lines in 242 files now uncovered.

99003 of 171143 relevant lines covered (57.85%)

36968.25 hits per line

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

68.99
/contractcourt/htlc_incoming_contest_resolver.go
1
package contractcourt
2

3
import (
4
        "bytes"
5
        "encoding/binary"
6
        "errors"
7
        "fmt"
8
        "io"
9

10
        "github.com/btcsuite/btcd/btcutil"
11
        "github.com/btcsuite/btcd/txscript"
12
        "github.com/lightningnetwork/lnd/channeldb"
13
        "github.com/lightningnetwork/lnd/channeldb/models"
14
        "github.com/lightningnetwork/lnd/fn"
15
        "github.com/lightningnetwork/lnd/htlcswitch/hop"
16
        "github.com/lightningnetwork/lnd/invoices"
17
        "github.com/lightningnetwork/lnd/lntypes"
18
        "github.com/lightningnetwork/lnd/lnwallet"
19
        "github.com/lightningnetwork/lnd/lnwire"
20
        "github.com/lightningnetwork/lnd/queue"
21
)
22

23
// htlcIncomingContestResolver is a ContractResolver that's able to resolve an
24
// incoming HTLC that is still contested. An HTLC is still contested, if at the
25
// time of commitment broadcast, we don't know of the preimage for it yet, and
26
// it hasn't expired. In this case, we can resolve the HTLC if we learn of the
27
// preimage, otherwise the remote party will sweep it after it expires.
28
//
29
// TODO(roasbeef): just embed the other resolver?
30
type htlcIncomingContestResolver struct {
31
        // htlcExpiry is the absolute expiry of this incoming HTLC. We use this
32
        // value to determine if we can exit early as if the HTLC times out,
33
        // before we learn of the preimage then we can't claim it on chain
34
        // successfully.
35
        htlcExpiry uint32
36

37
        // htlcSuccessResolver is the inner resolver that may be utilized if we
38
        // learn of the preimage.
39
        *htlcSuccessResolver
40
}
41

42
// newIncomingContestResolver instantiates a new incoming htlc contest resolver.
43
func newIncomingContestResolver(
44
        res lnwallet.IncomingHtlcResolution, broadcastHeight uint32,
UNCOV
45
        htlc channeldb.HTLC, resCfg ResolverConfig) *htlcIncomingContestResolver {
×
UNCOV
46

×
UNCOV
47
        success := newSuccessResolver(
×
UNCOV
48
                res, broadcastHeight, htlc, resCfg,
×
UNCOV
49
        )
×
UNCOV
50

×
UNCOV
51
        return &htlcIncomingContestResolver{
×
UNCOV
52
                htlcExpiry:          htlc.RefundTimeout,
×
UNCOV
53
                htlcSuccessResolver: success,
×
UNCOV
54
        }
×
UNCOV
55
}
×
56

57
func (h *htlcIncomingContestResolver) processFinalHtlcFail() error {
5✔
58
        // Mark the htlc as final failed.
5✔
59
        err := h.ChainArbitratorConfig.PutFinalHtlcOutcome(
5✔
60
                h.ChannelArbitratorConfig.ShortChanID, h.htlc.HtlcIndex, false,
5✔
61
        )
5✔
62
        if err != nil {
5✔
63
                return err
×
64
        }
×
65

66
        // Send notification.
67
        h.ChainArbitratorConfig.HtlcNotifier.NotifyFinalHtlcEvent(
5✔
68
                models.CircuitKey{
5✔
69
                        ChanID: h.ShortChanID,
5✔
70
                        HtlcID: h.htlc.HtlcIndex,
5✔
71
                },
5✔
72
                channeldb.FinalHtlcInfo{
5✔
73
                        Settled:  false,
5✔
74
                        Offchain: false,
5✔
75
                },
5✔
76
        )
5✔
77

5✔
78
        return nil
5✔
79
}
80

81
// Resolve attempts to resolve this contract. As we don't yet know of the
82
// preimage for the contract, we'll wait for one of two things to happen:
83
//
84
//  1. We learn of the preimage! In this case, we can sweep the HTLC incoming
85
//     and ensure that if this was a multi-hop HTLC we are made whole. In this
86
//     case, an additional ContractResolver will be returned to finish the
87
//     job.
88
//
89
//  2. The HTLC expires. If this happens, then the contract is fully resolved
90
//     as we have no remaining actions left at our disposal.
91
//
92
// NOTE: Part of the ContractResolver interface.
93
func (h *htlcIncomingContestResolver) Resolve(
94
        _ bool) (ContractResolver, error) {
9✔
95

9✔
96
        // If we're already full resolved, then we don't have anything further
9✔
97
        // to do.
9✔
98
        if h.resolved {
9✔
99
                return nil, nil
×
100
        }
×
101

102
        // If the HTLC has custom records, then for now we'll pause resolution.
103
        //
104
        // TODO(roasbeef): Implement resolving HTLCs with custom records
105
        // (follow-up PR).
106
        if len(h.htlc.CustomRecords) != 0 {
9✔
107
                select { //nolint:gosimple
×
108
                case <-h.quit:
×
109
                        return nil, errResolverShuttingDown
×
110
                }
111
        }
112

113
        // First try to parse the payload. If that fails, we can stop resolution
114
        // now.
115
        payload, nextHopOnionBlob, err := h.decodePayload()
9✔
116
        if err != nil {
9✔
117
                log.Debugf("ChannelArbitrator(%v): cannot decode payload of "+
×
118
                        "htlc %v", h.ChanPoint, h.HtlcPoint())
×
119

×
120
                // If we've locked in an htlc with an invalid payload on our
×
121
                // commitment tx, we don't need to resolve it. The other party
×
122
                // will time it out and get their funds back. This situation
×
123
                // can present itself when we crash before processRemoteAdds in
×
124
                // the link has ran.
×
125
                h.resolved = true
×
126

×
127
                if err := h.processFinalHtlcFail(); err != nil {
×
128
                        return nil, err
×
129
                }
×
130

131
                // We write a report to disk that indicates we could not decode
132
                // the htlc.
133
                resReport := h.report().resolverReport(
×
134
                        nil, channeldb.ResolverTypeIncomingHtlc,
×
135
                        channeldb.ResolverOutcomeAbandoned,
×
136
                )
×
137
                return nil, h.PutResolverReport(nil, resReport)
×
138
        }
139

140
        // Register for block epochs. After registration, the current height
141
        // will be sent on the channel immediately.
142
        blockEpochs, err := h.Notifier.RegisterBlockEpochNtfn(nil)
9✔
143
        if err != nil {
9✔
144
                return nil, err
×
145
        }
×
146
        defer blockEpochs.Cancel()
9✔
147

9✔
148
        var currentHeight int32
9✔
149
        select {
9✔
150
        case newBlock, ok := <-blockEpochs.Epochs:
9✔
151
                if !ok {
9✔
152
                        return nil, errResolverShuttingDown
×
153
                }
×
154
                currentHeight = newBlock.Height
9✔
155
        case <-h.quit:
×
156
                return nil, errResolverShuttingDown
×
157
        }
158

159
        log.Debugf("%T(%v): Resolving incoming HTLC(expiry=%v, height=%v)", h,
9✔
160
                h.htlcResolution.ClaimOutpoint, h.htlcExpiry, currentHeight)
9✔
161

9✔
162
        // We'll first check if this HTLC has been timed out, if so, we can
9✔
163
        // return now and mark ourselves as resolved. If we're past the point of
9✔
164
        // expiry of the HTLC, then at this point the sender can sweep it, so
9✔
165
        // we'll end our lifetime. Here we deliberately forego the chance that
9✔
166
        // the sender doesn't sweep and we already have or will learn the
9✔
167
        // preimage. Otherwise the resolver could potentially stay active
9✔
168
        // indefinitely and the channel will never close properly.
9✔
169
        if uint32(currentHeight) >= h.htlcExpiry {
10✔
170
                // TODO(roasbeef): should also somehow check if outgoing is
1✔
171
                // resolved or not
1✔
172
                //  * may need to hook into the circuit map
1✔
173
                //  * can't timeout before the outgoing has been
1✔
174

1✔
175
                log.Infof("%T(%v): HTLC has timed out (expiry=%v, height=%v), "+
1✔
176
                        "abandoning", h, h.htlcResolution.ClaimOutpoint,
1✔
177
                        h.htlcExpiry, currentHeight)
1✔
178
                h.resolved = true
1✔
179

1✔
180
                if err := h.processFinalHtlcFail(); err != nil {
1✔
181
                        return nil, err
×
182
                }
×
183

184
                // Finally, get our report and checkpoint our resolver with a
185
                // timeout outcome report.
186
                report := h.report().resolverReport(
1✔
187
                        nil, channeldb.ResolverTypeIncomingHtlc,
1✔
188
                        channeldb.ResolverOutcomeTimeout,
1✔
189
                )
1✔
190
                return nil, h.Checkpoint(h, report)
1✔
191
        }
192

193
        // applyPreimage is a helper function that will populate our internal
194
        // resolver with the preimage we learn of. This should be called once
195
        // the preimage is revealed so the inner resolver can properly complete
196
        // its duties. The error return value indicates whether the preimage
197
        // was properly applied.
198
        applyPreimage := func(preimage lntypes.Preimage) error {
12✔
199
                // Sanity check to see if this preimage matches our htlc. At
4✔
200
                // this point it should never happen that it does not match.
4✔
201
                if !preimage.Matches(h.htlc.RHash) {
4✔
202
                        return errors.New("preimage does not match hash")
×
203
                }
×
204

205
                // Update htlcResolution with the matching preimage.
206
                h.htlcResolution.Preimage = preimage
4✔
207

4✔
208
                log.Infof("%T(%v): applied preimage=%v", h,
4✔
209
                        h.htlcResolution.ClaimOutpoint, preimage)
4✔
210

4✔
211
                isSecondLevel := h.htlcResolution.SignedSuccessTx != nil
4✔
212

4✔
213
                // If we didn't have to go to the second level to claim (this
4✔
214
                // is the remote commitment transaction), then we don't need to
4✔
215
                // modify our canned witness.
4✔
216
                if !isSecondLevel {
8✔
217
                        return nil
4✔
218
                }
4✔
219

UNCOV
220
                isTaproot := txscript.IsPayToTaproot(
×
UNCOV
221
                        h.htlcResolution.SignedSuccessTx.TxOut[0].PkScript,
×
UNCOV
222
                )
×
UNCOV
223

×
UNCOV
224
                // If this is our commitment transaction, then we'll need to
×
UNCOV
225
                // populate the witness for the second-level HTLC transaction.
×
UNCOV
226
                switch {
×
227
                // For taproot channels, the witness for sweeping with success
228
                // looks like:
229
                //   - <sender sig> <receiver sig> <preimage> <success_script>
230
                //     <control_block>
231
                //
232
                // So we'll insert it at the 3rd index of the witness.
UNCOV
233
                case isTaproot:
×
UNCOV
234
                        //nolint:lll
×
UNCOV
235
                        h.htlcResolution.SignedSuccessTx.TxIn[0].Witness[2] = preimage[:]
×
236

237
                // Within the witness for the success transaction, the
238
                // preimage is the 4th element as it looks like:
239
                //
240
                //  * <0> <sender sig> <recvr sig> <preimage> <witness script>
241
                //
242
                // We'll populate it within the witness, as since this
243
                // was a "contest" resolver, we didn't yet know of the
244
                // preimage.
UNCOV
245
                case !isTaproot:
×
UNCOV
246
                        h.htlcResolution.SignedSuccessTx.TxIn[0].Witness[3] = preimage[:]
×
247
                }
248

UNCOV
249
                return nil
×
250
        }
251

252
        // Define a closure to process htlc resolutions either directly or
253
        // triggered by future notifications.
254
        processHtlcResolution := func(e invoices.HtlcResolution) (
8✔
255
                ContractResolver, error) {
12✔
256

4✔
257
                // Take action based on the type of resolution we have
4✔
258
                // received.
4✔
259
                switch resolution := e.(type) {
4✔
260
                // If the htlc resolution was a settle, apply the
261
                // preimage and return a success resolver.
262
                case *invoices.HtlcSettleResolution:
2✔
263
                        err := applyPreimage(resolution.Preimage)
2✔
264
                        if err != nil {
2✔
265
                                return nil, err
×
266
                        }
×
267

268
                        return h.htlcSuccessResolver, nil
2✔
269

270
                // If the htlc was failed, mark the htlc as
271
                // resolved.
272
                case *invoices.HtlcFailResolution:
2✔
273
                        log.Infof("%T(%v): Exit hop HTLC canceled "+
2✔
274
                                "(expiry=%v, height=%v), abandoning", h,
2✔
275
                                h.htlcResolution.ClaimOutpoint,
2✔
276
                                h.htlcExpiry, currentHeight)
2✔
277

2✔
278
                        h.resolved = true
2✔
279

2✔
280
                        if err := h.processFinalHtlcFail(); err != nil {
2✔
281
                                return nil, err
×
282
                        }
×
283

284
                        // Checkpoint our resolver with an abandoned outcome
285
                        // because we take no further action on this htlc.
286
                        report := h.report().resolverReport(
2✔
287
                                nil, channeldb.ResolverTypeIncomingHtlc,
2✔
288
                                channeldb.ResolverOutcomeAbandoned,
2✔
289
                        )
2✔
290
                        return nil, h.Checkpoint(h, report)
2✔
291

292
                // Error if the resolution type is unknown, we are only
293
                // expecting settles and fails.
294
                default:
×
295
                        return nil, fmt.Errorf("unknown resolution"+
×
296
                                " type: %v", e)
×
297
                }
298
        }
299

300
        var (
8✔
301
                hodlChan       <-chan interface{}
8✔
302
                witnessUpdates <-chan lntypes.Preimage
8✔
303
        )
8✔
304
        if payload.FwdInfo.NextHop == hop.Exit {
13✔
305
                // Create a buffered hodl chan to prevent deadlock.
5✔
306
                hodlQueue := queue.NewConcurrentQueue(10)
5✔
307
                hodlQueue.Start()
5✔
308

5✔
309
                hodlChan = hodlQueue.ChanOut()
5✔
310

5✔
311
                // Notify registry that we are potentially resolving as an exit
5✔
312
                // hop on-chain. If this HTLC indeed pays to an existing
5✔
313
                // invoice, the invoice registry will tell us what to do with
5✔
314
                // the HTLC. This is identical to HTLC resolution in the link.
5✔
315
                circuitKey := models.CircuitKey{
5✔
316
                        ChanID: h.ShortChanID,
5✔
317
                        HtlcID: h.htlc.HtlcIndex,
5✔
318
                }
5✔
319

5✔
320
                resolution, err := h.Registry.NotifyExitHopHtlc(
5✔
321
                        h.htlc.RHash, h.htlc.Amt, h.htlcExpiry, currentHeight,
5✔
322
                        circuitKey, hodlQueue.ChanIn(), nil, payload,
5✔
323
                )
5✔
324
                if err != nil {
5✔
325
                        return nil, err
×
326
                }
×
327

328
                defer func() {
10✔
329
                        h.Registry.HodlUnsubscribeAll(hodlQueue.ChanIn())
5✔
330

5✔
331
                        hodlQueue.Stop()
5✔
332
                }()
5✔
333

334
                // Take action based on the resolution we received. If the htlc
335
                // was settled, or a htlc for a known invoice failed we can
336
                // resolve it directly. If the resolution is nil, the htlc was
337
                // neither accepted nor failed, so we cannot take action yet.
338
                switch res := resolution.(type) {
5✔
339
                case *invoices.HtlcFailResolution:
1✔
340
                        // In the case where the htlc failed, but the invoice
1✔
341
                        // was known to the registry, we can directly resolve
1✔
342
                        // the htlc.
1✔
343
                        if res.Outcome != invoices.ResultInvoiceNotFound {
2✔
344
                                return processHtlcResolution(resolution)
1✔
345
                        }
1✔
346

347
                // If we settled the htlc, we can resolve it.
348
                case *invoices.HtlcSettleResolution:
1✔
349
                        return processHtlcResolution(resolution)
1✔
350

351
                // If the resolution is nil, the htlc was neither settled nor
352
                // failed so we cannot take action at present.
353
                case nil:
3✔
354

355
                default:
×
356
                        return nil, fmt.Errorf("unknown htlc resolution type: %T",
×
357
                                resolution)
×
358
                }
359
        } else {
3✔
360
                // If the HTLC hasn't expired yet, then we may still be able to
3✔
361
                // claim it if we learn of the pre-image, so we'll subscribe to
3✔
362
                // the preimage database to see if it turns up, or the HTLC
3✔
363
                // times out.
3✔
364
                //
3✔
365
                // NOTE: This is done BEFORE opportunistically querying the db,
3✔
366
                // to ensure the preimage can't be delivered between querying
3✔
367
                // and registering for the preimage subscription.
3✔
368
                preimageSubscription, err := h.PreimageDB.SubscribeUpdates(
3✔
369
                        h.htlcSuccessResolver.ShortChanID, &h.htlc,
3✔
370
                        payload, nextHopOnionBlob,
3✔
371
                )
3✔
372
                if err != nil {
3✔
373
                        return nil, err
×
374
                }
×
375
                defer preimageSubscription.CancelSubscription()
3✔
376

3✔
377
                // With the epochs and preimage subscriptions initialized, we'll
3✔
378
                // query to see if we already know the preimage.
3✔
379
                preimage, ok := h.PreimageDB.LookupPreimage(h.htlc.RHash)
3✔
380
                if ok {
4✔
381
                        // If we do, then this means we can claim the HTLC!
1✔
382
                        // However, we don't know how to ourselves, so we'll
1✔
383
                        // return our inner resolver which has the knowledge to
1✔
384
                        // do so.
1✔
385
                        if err := applyPreimage(preimage); err != nil {
1✔
386
                                return nil, err
×
387
                        }
×
388

389
                        return h.htlcSuccessResolver, nil
1✔
390
                }
391

392
                witnessUpdates = preimageSubscription.WitnessUpdates
2✔
393
        }
394

395
        for {
11✔
396
                select {
6✔
397
                case preimage := <-witnessUpdates:
1✔
398
                        // We received a new preimage, but we need to ignore
1✔
399
                        // all except the preimage we are waiting for.
1✔
400
                        if !preimage.Matches(h.htlc.RHash) {
1✔
UNCOV
401
                                continue
×
402
                        }
403

404
                        if err := applyPreimage(preimage); err != nil {
1✔
405
                                return nil, err
×
406
                        }
×
407

408
                        // We've learned of the preimage and this information
409
                        // has been added to our inner resolver. We return it so
410
                        // it can continue contract resolution.
411
                        return h.htlcSuccessResolver, nil
1✔
412

413
                case hodlItem := <-hodlChan:
2✔
414
                        htlcResolution := hodlItem.(invoices.HtlcResolution)
2✔
415
                        return processHtlcResolution(htlcResolution)
2✔
416

417
                case newBlock, ok := <-blockEpochs.Epochs:
3✔
418
                        if !ok {
3✔
419
                                return nil, errResolverShuttingDown
×
420
                        }
×
421

422
                        // If this new height expires the HTLC, then this means
423
                        // we never found out the preimage, so we can mark
424
                        // resolved and exit.
425
                        newHeight := uint32(newBlock.Height)
3✔
426
                        if newHeight >= h.htlcExpiry {
5✔
427
                                log.Infof("%T(%v): HTLC has timed out "+
2✔
428
                                        "(expiry=%v, height=%v), abandoning", h,
2✔
429
                                        h.htlcResolution.ClaimOutpoint,
2✔
430
                                        h.htlcExpiry, currentHeight)
2✔
431
                                h.resolved = true
2✔
432

2✔
433
                                if err := h.processFinalHtlcFail(); err != nil {
2✔
434
                                        return nil, err
×
435
                                }
×
436

437
                                report := h.report().resolverReport(
2✔
438
                                        nil,
2✔
439
                                        channeldb.ResolverTypeIncomingHtlc,
2✔
440
                                        channeldb.ResolverOutcomeTimeout,
2✔
441
                                )
2✔
442
                                return nil, h.Checkpoint(h, report)
2✔
443
                        }
444

UNCOV
445
                case <-h.quit:
×
UNCOV
446
                        return nil, errResolverShuttingDown
×
447
                }
448
        }
449
}
450

451
// report returns a report on the resolution state of the contract.
452
func (h *htlcIncomingContestResolver) report() *ContractReport {
5✔
453
        // No locking needed as these values are read-only.
5✔
454

5✔
455
        finalAmt := h.htlc.Amt.ToSatoshis()
5✔
456
        if h.htlcResolution.SignedSuccessTx != nil {
5✔
UNCOV
457
                finalAmt = btcutil.Amount(
×
UNCOV
458
                        h.htlcResolution.SignedSuccessTx.TxOut[0].Value,
×
UNCOV
459
                )
×
UNCOV
460
        }
×
461

462
        return &ContractReport{
5✔
463
                Outpoint:       h.htlcResolution.ClaimOutpoint,
5✔
464
                Type:           ReportOutputIncomingHtlc,
5✔
465
                Amount:         finalAmt,
5✔
466
                MaturityHeight: h.htlcExpiry,
5✔
467
                LimboBalance:   finalAmt,
5✔
468
                Stage:          1,
5✔
469
        }
5✔
470
}
471

472
// Stop signals the resolver to cancel any current resolution processes, and
473
// suspend.
474
//
475
// NOTE: Part of the ContractResolver interface.
UNCOV
476
func (h *htlcIncomingContestResolver) Stop() {
×
UNCOV
477
        close(h.quit)
×
UNCOV
478
}
×
479

480
// IsResolved returns true if the stored state in the resolve is fully
481
// resolved. In this case the target output can be forgotten.
482
//
483
// NOTE: Part of the ContractResolver interface.
UNCOV
484
func (h *htlcIncomingContestResolver) IsResolved() bool {
×
UNCOV
485
        return h.resolved
×
UNCOV
486
}
×
487

488
// Encode writes an encoded version of the ContractResolver into the passed
489
// Writer.
490
//
491
// NOTE: Part of the ContractResolver interface.
492
func (h *htlcIncomingContestResolver) Encode(w io.Writer) error {
1✔
493
        // We'll first write out the one field unique to this resolver.
1✔
494
        if err := binary.Write(w, endian, h.htlcExpiry); err != nil {
1✔
495
                return err
×
496
        }
×
497

498
        // Then we'll write out our internal resolver.
499
        return h.htlcSuccessResolver.Encode(w)
1✔
500
}
501

502
// newIncomingContestResolverFromReader attempts to decode an encoded ContractResolver
503
// from the passed Reader instance, returning an active ContractResolver
504
// instance.
505
func newIncomingContestResolverFromReader(r io.Reader, resCfg ResolverConfig) (
506
        *htlcIncomingContestResolver, error) {
1✔
507

1✔
508
        h := &htlcIncomingContestResolver{}
1✔
509

1✔
510
        // We'll first read the one field unique to this resolver.
1✔
511
        if err := binary.Read(r, endian, &h.htlcExpiry); err != nil {
1✔
512
                return nil, err
×
513
        }
×
514

515
        // Then we'll decode our internal resolver.
516
        successResolver, err := newSuccessResolverFromReader(r, resCfg)
1✔
517
        if err != nil {
1✔
518
                return nil, err
×
519
        }
×
520
        h.htlcSuccessResolver = successResolver
1✔
521

1✔
522
        return h, nil
1✔
523
}
524

525
// Supplement adds additional information to the resolver that is required
526
// before Resolve() is called.
527
//
528
// NOTE: Part of the htlcContractResolver interface.
UNCOV
529
func (h *htlcIncomingContestResolver) Supplement(htlc channeldb.HTLC) {
×
UNCOV
530
        h.htlc = htlc
×
UNCOV
531
}
×
532

533
// SupplementDeadline does nothing for an incoming htlc resolver.
534
//
535
// NOTE: Part of the htlcContractResolver interface.
536
func (h *htlcIncomingContestResolver) SupplementDeadline(_ fn.Option[int32]) {
×
537
}
×
538

539
// decodePayload (re)decodes the hop payload of a received htlc.
540
func (h *htlcIncomingContestResolver) decodePayload() (*hop.Payload,
541
        []byte, error) {
9✔
542

9✔
543
        blindingInfo := hop.ReconstructBlindingInfo{
9✔
544
                IncomingAmt:    h.htlc.Amt,
9✔
545
                IncomingExpiry: h.htlc.RefundTimeout,
9✔
546
                BlindingKey:    h.htlc.BlindingPoint,
9✔
547
        }
9✔
548

9✔
549
        onionReader := bytes.NewReader(h.htlc.OnionBlob[:])
9✔
550
        iterator, err := h.OnionProcessor.ReconstructHopIterator(
9✔
551
                onionReader, h.htlc.RHash[:], blindingInfo,
9✔
552
        )
9✔
553
        if err != nil {
9✔
554
                return nil, nil, err
×
555
        }
×
556

557
        payload, _, err := iterator.HopPayload()
9✔
558
        if err != nil {
9✔
559
                return nil, nil, err
×
560
        }
×
561

562
        // Transform onion blob for the next hop.
563
        var onionBlob [lnwire.OnionPacketSize]byte
9✔
564
        buf := bytes.NewBuffer(onionBlob[0:0])
9✔
565
        err = iterator.EncodeNextHop(buf)
9✔
566
        if err != nil {
9✔
567
                return nil, nil, err
×
568
        }
×
569

570
        return payload, onionBlob[:], nil
9✔
571
}
572

573
// A compile time assertion to ensure htlcIncomingContestResolver meets the
574
// ContractResolver interface.
575
var _ htlcContractResolver = (*htlcIncomingContestResolver)(nil)
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