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

lightningnetwork / lnd / 14350609076

09 Apr 2025 06:35AM UTC coverage: 58.66%. First build
14350609076

Pull #9691

github

web-flow
Merge 001660a9d into ac052988c
Pull Request #9691: htlcswitch+peer: thread context through in preparation for passing to graph DB calls

192 of 264 new or added lines in 15 files covered. (72.73%)

97242 of 165773 relevant lines covered (58.66%)

1.82 hits per line

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

29.41
/intercepted_forward.go
1
package lnd
2

3
import (
4
        "context"
5
        "errors"
6

7
        "github.com/lightningnetwork/lnd/fn/v2"
8
        "github.com/lightningnetwork/lnd/htlcswitch"
9
        "github.com/lightningnetwork/lnd/lntypes"
10
        "github.com/lightningnetwork/lnd/lnwire"
11
)
12

13
var (
14
        // ErrCannotResume is returned when an intercepted forward cannot be
15
        // resumed. This is the case in the on-chain resolution flow.
16
        ErrCannotResume = errors.New("cannot resume in the on-chain flow")
17

18
        // ErrCannotFail is returned when an intercepted forward cannot be failed.
19
        // This is the case in the on-chain resolution flow.
20
        ErrCannotFail = errors.New("cannot fail in the on-chain flow")
21

22
        // ErrPreimageMismatch is returned when the preimage that is specified to
23
        // settle an htlc doesn't match the htlc hash.
24
        ErrPreimageMismatch = errors.New("preimage does not match hash")
25
)
26

27
// interceptedForward implements the on-chain behavior for the resolution of
28
// a forwarded htlc.
29
type interceptedForward struct {
30
        packet *htlcswitch.InterceptedPacket
31
        beacon *preimageBeacon
32
}
33

34
func newInterceptedForward(
35
        packet *htlcswitch.InterceptedPacket,
36
        beacon *preimageBeacon) *interceptedForward {
3✔
37

3✔
38
        return &interceptedForward{
3✔
39
                beacon: beacon,
3✔
40
                packet: packet,
3✔
41
        }
3✔
42
}
3✔
43

44
// Packet returns the intercepted htlc packet.
45
func (f *interceptedForward) Packet() htlcswitch.InterceptedPacket {
3✔
46
        return *f.packet
3✔
47
}
3✔
48

49
// Resume notifies the intention to resume an existing hold forward. This
50
// basically means the caller wants to resume with the default behavior for this
51
// htlc which usually means forward it.
NEW
52
func (f *interceptedForward) Resume(context.Context) error {
×
53
        return ErrCannotResume
×
54
}
×
55

56
// ResumeModified notifies the intention to resume an existing hold forward with
57
// a modified htlc.
58
func (f *interceptedForward) ResumeModified(_ context.Context, _,
59
        _ fn.Option[lnwire.MilliSatoshi],
60
        _ fn.Option[lnwire.CustomRecords]) error {
×
61

×
62
        return ErrCannotResume
×
63
}
×
64

65
// Fail notifies the intention to fail an existing hold forward with an
66
// encrypted failure reason.
NEW
67
func (f *interceptedForward) Fail(_ context.Context, _ []byte) error {
×
68
        // We can't actively fail an htlc. The best we could do is abandon the
×
69
        // resolver, but this wouldn't be a safe operation. There may be a race
×
70
        // with the preimage beacon supplying a preimage. Therefore we don't
×
71
        // attempt to fail and just return an error here.
×
72
        return ErrCannotFail
×
73
}
×
74

75
// FailWithCode notifies the intention to fail an existing hold forward with the
76
// specified failure code.
77
func (f *interceptedForward) FailWithCode(_ context.Context,
NEW
78
        _ lnwire.FailCode) error {
×
NEW
79

×
80
        return ErrCannotFail
×
81
}
×
82

83
// Settle notifies the intention to settle an existing hold forward with a given
84
// preimage.
85
func (f *interceptedForward) Settle(_ context.Context,
NEW
86
        preimage lntypes.Preimage) error {
×
NEW
87

×
88
        if !preimage.Matches(f.packet.Hash) {
×
89
                return ErrPreimageMismatch
×
90
        }
×
91

92
        // Add preimage to the preimage beacon. The onchain resolver will pick
93
        // up the preimage from the beacon.
94
        return f.beacon.AddPreimages(preimage)
×
95
}
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