• 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

53.33
/lntypes/preimage.go
1
package lntypes
2

3
import (
4
        "crypto/sha256"
5
        "encoding/hex"
6
        "fmt"
7
)
8

9
// PreimageSize of array used to store preimagees.
10
const PreimageSize = 32
11

12
// Preimage is used in several of the lightning messages and common structures.
13
// It represents a payment preimage.
14
type Preimage [PreimageSize]byte
15

16
// String returns the Preimage as a hexadecimal string.
17
func (p Preimage) String() string {
3✔
18
        return hex.EncodeToString(p[:])
3✔
19
}
3✔
20

21
// MakePreimage returns a new Preimage from a bytes slice. An error is returned
22
// if the number of bytes passed in is not PreimageSize.
23
func MakePreimage(newPreimage []byte) (Preimage, error) {
3✔
24
        nhlen := len(newPreimage)
3✔
25
        if nhlen != PreimageSize {
3✔
UNCOV
26
                return Preimage{}, fmt.Errorf("invalid preimage length of %v, "+
×
UNCOV
27
                        "want %v", nhlen, PreimageSize)
×
UNCOV
28
        }
×
29

30
        var preimage Preimage
3✔
31
        copy(preimage[:], newPreimage)
3✔
32

3✔
33
        return preimage, nil
3✔
34
}
35

36
// MakePreimageFromStr creates a Preimage from a hex preimage string.
UNCOV
37
func MakePreimageFromStr(newPreimage string) (Preimage, error) {
×
UNCOV
38
        // Return error if preimage string is of incorrect length.
×
UNCOV
39
        if len(newPreimage) != PreimageSize*2 {
×
40
                return Preimage{}, fmt.Errorf("invalid preimage string length "+
×
41
                        "of %v, want %v", len(newPreimage), PreimageSize*2)
×
42
        }
×
43

UNCOV
44
        preimage, err := hex.DecodeString(newPreimage)
×
UNCOV
45
        if err != nil {
×
46
                return Preimage{}, err
×
47
        }
×
48

UNCOV
49
        return MakePreimage(preimage)
×
50
}
51

52
// Hash returns the sha256 hash of the preimage.
53
func (p *Preimage) Hash() Hash {
3✔
54
        return Hash(sha256.Sum256(p[:]))
3✔
55
}
3✔
56

57
// Matches returns whether this preimage is the preimage of the given hash.
58
func (p *Preimage) Matches(h Hash) bool {
3✔
59
        return h == p.Hash()
3✔
60
}
3✔
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