• 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

93.33
/record/hop.go
1
package record
2

3
import (
4
        "github.com/btcsuite/btcd/btcec/v2"
5
        "github.com/lightningnetwork/lnd/tlv"
6
)
7

8
const (
9
        // AmtOnionType is the type used in the onion to reference the amount to
10
        // send to the next hop.
11
        AmtOnionType tlv.Type = 2
12

13
        // LockTimeTLV is the type used in the onion to reference the CLTV
14
        // value that should be used for the next hop's HTLC.
15
        LockTimeOnionType tlv.Type = 4
16

17
        // NextHopOnionType is the type used in the onion to reference the ID
18
        // of the next hop.
19
        NextHopOnionType tlv.Type = 6
20

21
        // EncryptedDataOnionType is the type used to include encrypted data
22
        // provided by the receiver in the onion for use in blinded paths.
23
        EncryptedDataOnionType tlv.Type = 10
24

25
        // BlindingPointOnionType is the type used to include receiver provided
26
        // ephemeral keys in the onion that are used in blinded paths.
27
        BlindingPointOnionType tlv.Type = 12
28

29
        // MetadataOnionType is the type used in the onion for the payment
30
        // metadata.
31
        MetadataOnionType tlv.Type = 16
32

33
        // TotalAmtMsatBlindedType is the type used in the onion for the total
34
        // amount field that is included in the final hop for blinded payments.
35
        TotalAmtMsatBlindedType tlv.Type = 18
36
)
37

38
// NewAmtToFwdRecord creates a tlv.Record that encodes the amount_to_forward
39
// (type 2) for an onion payload.
40
func NewAmtToFwdRecord(amt *uint64) tlv.Record {
3✔
41
        return tlv.MakeDynamicRecord(
3✔
42
                AmtOnionType, amt, func() uint64 {
6✔
43
                        return tlv.SizeTUint64(*amt)
3✔
44
                },
3✔
45
                tlv.ETUint64, tlv.DTUint64,
46
        )
47
}
48

49
// NewLockTimeRecord creates a tlv.Record that encodes the outgoing_cltv_value
50
// (type 4) for an onion payload.
51
func NewLockTimeRecord(lockTime *uint32) tlv.Record {
3✔
52
        return tlv.MakeDynamicRecord(
3✔
53
                LockTimeOnionType, lockTime, func() uint64 {
6✔
54
                        return tlv.SizeTUint32(*lockTime)
3✔
55
                },
3✔
56
                tlv.ETUint32, tlv.DTUint32,
57
        )
58
}
59

60
// NewNextHopIDRecord creates a tlv.Record that encodes the short_channel_id
61
// (type 6) for an onion payload.
62
func NewNextHopIDRecord(cid *uint64) tlv.Record {
3✔
63
        return tlv.MakePrimitiveRecord(NextHopOnionType, cid)
3✔
64
}
3✔
65

66
// NewEncryptedDataRecord creates a tlv.Record that encodes the encrypted_data
67
// (type 10) record for an onion payload.
68
func NewEncryptedDataRecord(data *[]byte) tlv.Record {
3✔
69
        return tlv.MakePrimitiveRecord(EncryptedDataOnionType, data)
3✔
70
}
3✔
71

72
// NewBlindingPointRecord creates a tlv.Record that encodes the blinding_point
73
// (type 12) record for an onion payload.
74
func NewBlindingPointRecord(point **btcec.PublicKey) tlv.Record {
3✔
75
        return tlv.MakePrimitiveRecord(BlindingPointOnionType, point)
3✔
76
}
3✔
77

78
// NewMetadataRecord creates a tlv.Record that encodes the metadata (type 10)
79
// for an onion payload.
80
func NewMetadataRecord(metadata *[]byte) tlv.Record {
3✔
81
        return tlv.MakeDynamicRecord(
3✔
82
                MetadataOnionType, metadata,
3✔
83
                func() uint64 {
3✔
UNCOV
84
                        return uint64(len(*metadata))
×
UNCOV
85
                },
×
86
                tlv.EVarBytes, tlv.DVarBytes,
87
        )
88
}
89

90
// NewTotalAmtMsatBlinded creates a tlv.Record that encodes the
91
// total_amount_msat for the final an onion payload within a blinded route.
92
func NewTotalAmtMsatBlinded(amt *uint64) tlv.Record {
3✔
93
        return tlv.MakeDynamicRecord(
3✔
94
                TotalAmtMsatBlindedType, amt, func() uint64 {
6✔
95
                        return tlv.SizeTUint64(*amt)
3✔
96
                },
3✔
97
                tlv.ETUint64, tlv.DTUint64,
98
        )
99
}
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