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

lightningnetwork / lnd / 14885280210

07 May 2025 01:59PM UTC coverage: 58.038% (-11.0%) from 68.992%
14885280210

Pull #9789

github

web-flow
Merge b72813120 into 67a40c90a
Pull Request #9789: multi: use updated TLV SizeFunc signature

3 of 6 new or added lines in 2 files covered. (50.0%)

29137 existing lines in 453 files now uncovered.

96491 of 166256 relevant lines covered (58.04%)

1.22 hits per line

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

80.0
/htlcswitch/held_htlc_set.go
1
package htlcswitch
2

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

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

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

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

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

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

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

40
// popAutoFails calls the callback for each forward that has an auto-fail height
41
// equal or less then the specified pop height and removes them from the set.
42
func (h *heldHtlcSet) popAutoFails(height uint32, cb func(InterceptedForward)) {
2✔
43
        for key, fwd := range h.set {
4✔
44
                if uint32(fwd.Packet().AutoFailHeight) > height {
4✔
45
                        continue
2✔
46
                }
47

UNCOV
48
                cb(fwd)
×
UNCOV
49

×
UNCOV
50
                delete(h.set, key)
×
51
        }
52
}
53

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

61
        delete(h.set, key)
2✔
62

2✔
63
        return intercepted, nil
2✔
64
}
65

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

2✔
70
        return ok
2✔
71
}
2✔
72

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

2✔
78
        if fwd == nil {
2✔
UNCOV
79
                return errors.New("nil fwd pushed")
×
UNCOV
80
        }
×
81

82
        if h.exists(key) {
2✔
UNCOV
83
                return errors.New("htlc already exists in set")
×
UNCOV
84
        }
×
85

86
        h.set[key] = fwd
2✔
87

2✔
88
        return nil
2✔
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