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

lightningnetwork / lnd / 14351709291

09 Apr 2025 07:39AM UTC coverage: 58.609%. First build
14351709291

Pull #9691

github

web-flow
Merge defcae152 into ac052988c
Pull Request #9691: htlcswitch+peer: thread context through in preparation for passing to graph DB calls

193 of 265 new or added lines in 15 files covered. (72.83%)

97159 of 165774 relevant lines covered (58.61%)

1.82 hits per line

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

80.43
/htlcswitch/held_htlc_set.go
1
package htlcswitch
2

3
import (
4
        "context"
5
        "errors"
6
        "fmt"
7

8
        "github.com/lightningnetwork/lnd/graph/db/models"
9
)
10

11
// heldHtlcSet keeps track of outstanding intercepted forwards. It exposes
12
// several methods to manipulate the underlying map structure in a consistent
13
// way.
14
type heldHtlcSet struct {
15
        set map[models.CircuitKey]InterceptedForward
16
}
17

18
func newHeldHtlcSet() *heldHtlcSet {
3✔
19
        return &heldHtlcSet{
3✔
20
                set: make(map[models.CircuitKey]InterceptedForward),
3✔
21
        }
3✔
22
}
3✔
23

24
// forEach iterates over all held forwards and calls the given callback for each
25
// of them.
26
func (h *heldHtlcSet) forEach(cb func(InterceptedForward)) {
3✔
27
        for _, fwd := range h.set {
6✔
28
                cb(fwd)
3✔
29
        }
3✔
30
}
31

32
// popAll calls the callback for each forward and removes them from the set.
33
func (h *heldHtlcSet) popAll(cb func(InterceptedForward)) {
3✔
34
        for _, fwd := range h.set {
6✔
35
                cb(fwd)
3✔
36
        }
3✔
37

38
        h.set = make(map[models.CircuitKey]InterceptedForward)
3✔
39
}
40

41
// popAutoFails calls the callback for each forward that has an auto-fail height
42
// equal or less then the specified pop height and removes them from the set.
43
func (h *heldHtlcSet) popAutoFails(ctx context.Context, height uint32,
44
        cb func(context.Context, InterceptedForward)) {
3✔
45

3✔
46
        for key, fwd := range h.set {
6✔
47
                if uint32(fwd.Packet().AutoFailHeight) > height {
6✔
48
                        continue
3✔
49
                }
50

NEW
51
                cb(ctx, fwd)
×
52

×
53
                delete(h.set, key)
×
54
        }
55
}
56

57
// pop returns the specified forward and removes it from the set.
58
func (h *heldHtlcSet) pop(key models.CircuitKey) (InterceptedForward, error) {
3✔
59
        intercepted, ok := h.set[key]
3✔
60
        if !ok {
3✔
61
                return nil, fmt.Errorf("fwd %v not found", key)
×
62
        }
×
63

64
        delete(h.set, key)
3✔
65

3✔
66
        return intercepted, nil
3✔
67
}
68

69
// exists tests whether the specified forward is part of the set.
70
func (h *heldHtlcSet) exists(key models.CircuitKey) bool {
3✔
71
        _, ok := h.set[key]
3✔
72

3✔
73
        return ok
3✔
74
}
3✔
75

76
// push adds the specified forward to the set. An error is returned if the
77
// forward exists already.
78
func (h *heldHtlcSet) push(key models.CircuitKey,
79
        fwd InterceptedForward) error {
3✔
80

3✔
81
        if fwd == nil {
3✔
82
                return errors.New("nil fwd pushed")
×
83
        }
×
84

85
        if h.exists(key) {
3✔
86
                return errors.New("htlc already exists in set")
×
87
        }
×
88

89
        h.set[key] = fwd
3✔
90

3✔
91
        return nil
3✔
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