• 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

63.04
/shachain/utils.go
1
package shachain
2

3
import (
4
        "encoding/hex"
5

6
        "github.com/btcsuite/btcd/chaincfg/chainhash"
7
)
8

9
// getBit return bit on index at position.
10
func getBit(index index, position uint8) uint8 {
3✔
11
        return uint8((uint64(index) >> position) & 1)
3✔
12
}
3✔
13

14
func getPrefix(index index, position uint8) uint64 {
3✔
15
        //        + -------------------------- +
3✔
16
        //         | №  | value | mask | return |
3✔
17
        //        + -- + ----- + ---- + ------ +
3✔
18
        //        | 63 |         1   |  0   |         0   |
3✔
19
        //        | 62 |         0   |  0   |         0   |
3✔
20
        //        | 61 |   1   |  0   |         0   |
3✔
21
        //                ....
3✔
22
        //        |  4 |         1   |  0   |         0   |
3✔
23
        //        |  3 |   1   |  0   |         0   |
3✔
24
        //        |  2 |   1   |  1   |         1   | <--- position
3✔
25
        //        |  1 |   0   |  1   |         0   |
3✔
26
        //        |  0 |   1   |  1   |         1   |
3✔
27
        //        + -- + ----- + ---- + ------ +
3✔
28

3✔
29
        var zero uint64
3✔
30
        mask := (zero - 1) - uint64((1<<position)-1)
3✔
31
        return (uint64(index) & mask)
3✔
32
}
3✔
33

34
// countTrailingZeros counts number of trailing zero bits, this function is
35
// used to determine the number of element bucket.
36
func countTrailingZeros(index index) uint8 {
3✔
37
        var zeros uint8
3✔
38
        for ; zeros < maxHeight; zeros++ {
6✔
39

3✔
40
                if getBit(index, zeros) != 0 {
6✔
41
                        break
3✔
42
                }
43
        }
44

45
        return zeros
3✔
46
}
47

48
// hashFromString takes a hex-encoded string as input and creates an instance of
49
// chainhash.Hash. The chainhash.NewHashFromStr function not suitable because
50
// it reverse the given hash.
UNCOV
51
func hashFromString(s string) (*chainhash.Hash, error) {
×
UNCOV
52
        // Return an error if hash string is too long.
×
UNCOV
53
        if len(s) > chainhash.MaxHashStringSize {
×
54
                return nil, chainhash.ErrHashStrSize
×
55
        }
×
56

57
        // Hex decoder expects the hash to be a multiple of two.
UNCOV
58
        if len(s)%2 != 0 {
×
59
                s = "0" + s
×
60
        }
×
61

62
        // Convert string hash to bytes.
UNCOV
63
        buf, err := hex.DecodeString(s)
×
UNCOV
64
        if err != nil {
×
65
                return nil, err
×
66
        }
×
67

UNCOV
68
        hash, err := chainhash.NewHash(buf)
×
UNCOV
69
        if err != nil {
×
70
                return nil, err
×
71
        }
×
72

UNCOV
73
        return hash, nil
×
74
}
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