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

lightningnetwork / lnd / 14378973393

10 Apr 2025 11:10AM UTC coverage: 68.977%. First build
14378973393

Pull #9691

github

web-flow
Merge 00150d64e into e214b579e
Pull Request #9691: htlcswitch+peer [1/2]: thread context through in preparation for passing to graph DB calls

218 of 244 new or added lines in 14 files covered. (89.34%)

133429 of 193439 relevant lines covered (68.98%)

22122.86 hits per line

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

39.39
/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 {
2✔
46
        return *f.packet
2✔
47
}
2✔
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.
52
func (f *interceptedForward) Resume() 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(_, _ fn.Option[lnwire.MilliSatoshi],
59
        _ fn.Option[lnwire.CustomRecords]) error {
×
60

×
61
        return ErrCannotResume
×
62
}
×
63

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

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

×
79
        return ErrCannotFail
×
80
}
×
81

82
// Settle notifies the intention to settle an existing hold forward with a given
83
// preimage.
84
func (f *interceptedForward) Settle(preimage lntypes.Preimage) error {
1✔
85
        if !preimage.Matches(f.packet.Hash) {
1✔
86
                return ErrPreimageMismatch
×
87
        }
×
88

89
        // Add preimage to the preimage beacon. The onchain resolver will pick
90
        // up the preimage from the beacon.
91
        return f.beacon.AddPreimages(preimage)
1✔
92
}
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