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

lightningnetwork / lnd / 13586005509

28 Feb 2025 10:14AM UTC coverage: 68.629% (+9.9%) from 58.77%
13586005509

Pull #9521

github

web-flow
Merge 37d3a70a5 into 8532955b3
Pull Request #9521: unit: remove GOACC, use Go 1.20 native coverage functionality

129950 of 189351 relevant lines covered (68.63%)

23726.46 hits per line

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

100.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 {
30✔
18
        return &heldHtlcSet{
30✔
19
                set: make(map[models.CircuitKey]InterceptedForward),
30✔
20
        }
30✔
21
}
30✔
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)) {
11✔
26
        for _, fwd := range h.set {
17✔
27
                cb(fwd)
6✔
28
        }
6✔
29
}
30

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

37
        h.set = make(map[models.CircuitKey]InterceptedForward)
6✔
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)) {
7✔
43
        for key, fwd := range h.set {
13✔
44
                if uint32(fwd.Packet().AutoFailHeight) > height {
10✔
45
                        continue
4✔
46
                }
47

48
                cb(fwd)
2✔
49

2✔
50
                delete(h.set, key)
2✔
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) {
16✔
56
        intercepted, ok := h.set[key]
16✔
57
        if !ok {
23✔
58
                return nil, fmt.Errorf("fwd %v not found", key)
7✔
59
        }
7✔
60

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

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

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

29✔
70
        return ok
29✔
71
}
29✔
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 {
18✔
77

18✔
78
        if fwd == nil {
19✔
79
                return errors.New("nil fwd pushed")
1✔
80
        }
1✔
81

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

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

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