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

lightningnetwork / lnd / 13211764208

08 Feb 2025 03:08AM UTC coverage: 49.288% (-9.5%) from 58.815%
13211764208

Pull #9489

github

calvinrzachman
itest: verify switchrpc server enforces send then track

We prevent the rpc server from allowing onion dispatches for
attempt IDs which have already been tracked by rpc clients.

This helps protect the client from leaking a duplicate onion
attempt. NOTE: This is not the only method for solving this
issue! The issue could be addressed via careful client side
programming which accounts for the uncertainty and async
nature of dispatching onions to a remote process via RPC.
This would require some lnd ChannelRouter changes for how
we intend to use these RPCs though.
Pull Request #9489: multi: add BuildOnion, SendOnion, and TrackOnion RPCs

474 of 990 new or added lines in 11 files covered. (47.88%)

27321 existing lines in 435 files now uncovered.

101192 of 205306 relevant lines covered (49.29%)

1.54 hits per line

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

31.25
/intercepted_forward.go
1
package lnd
2

3
import (
4
        "errors"
5

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

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

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

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

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

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

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

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

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

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

×
60
        return ErrCannotResume
×
61
}
×
62

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

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

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

86
        // Add preimage to the preimage beacon. The onchain resolver will pick
87
        // up the preimage from the beacon.
UNCOV
88
        return f.beacon.AddPreimages(preimage)
×
89
}
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