• 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
/watchtower/wtclient/sess_close_min_heap.go
1
package wtclient
2

3
import (
4
        "sync"
5

6
        "github.com/lightningnetwork/lnd/queue"
7
        "github.com/lightningnetwork/lnd/watchtower/wtdb"
8
)
9

10
// sessionCloseMinHeap is a thread-safe min-heap implementation that stores
11
// sessionCloseItem items and prioritises the item with the lowest block height.
12
type sessionCloseMinHeap struct {
13
        queue queue.PriorityQueue
14
        mu    sync.Mutex
15
}
16

17
// newSessionCloseMinHeap constructs a new sessionCloseMineHeap.
18
func newSessionCloseMinHeap() *sessionCloseMinHeap {
40✔
19
        return &sessionCloseMinHeap{}
40✔
20
}
40✔
21

22
// Len returns the length of the queue.
23
func (h *sessionCloseMinHeap) Len() int {
3✔
24
        h.mu.Lock()
3✔
25
        defer h.mu.Unlock()
3✔
26

3✔
27
        return h.queue.Len()
3✔
28
}
3✔
29

30
// Empty returns true if the queue is empty.
31
func (h *sessionCloseMinHeap) Empty() bool {
2✔
32
        h.mu.Lock()
2✔
33
        defer h.mu.Unlock()
2✔
34

2✔
35
        return h.queue.Empty()
2✔
36
}
2✔
37

38
// Push adds an item to the priority queue.
39
func (h *sessionCloseMinHeap) Push(item *sessionCloseItem) {
15✔
40
        h.mu.Lock()
15✔
41
        defer h.mu.Unlock()
15✔
42

15✔
43
        h.queue.Push(item)
15✔
44
}
15✔
45

46
// Pop removes the top most item from the queue.
47
func (h *sessionCloseMinHeap) Pop() *sessionCloseItem {
17✔
48
        h.mu.Lock()
17✔
49
        defer h.mu.Unlock()
17✔
50

17✔
51
        if h.queue.Empty() {
19✔
52
                return nil
2✔
53
        }
2✔
54

55
        item := h.queue.Pop()
15✔
56

15✔
57
        return item.(*sessionCloseItem) //nolint:forcetypeassert
15✔
58
}
59

60
// Top returns the top most item from the queue without removing it.
61
func (h *sessionCloseMinHeap) Top() *sessionCloseItem {
15✔
62
        h.mu.Lock()
15✔
63
        defer h.mu.Unlock()
15✔
64

15✔
65
        if h.queue.Empty() {
25✔
66
                return nil
10✔
67
        }
10✔
68

69
        item := h.queue.Top()
8✔
70

8✔
71
        return item.(*sessionCloseItem) //nolint:forcetypeassert
8✔
72
}
73

74
// sessionCloseItem represents a session that is ready to be deleted.
75
type sessionCloseItem struct {
76
        // sessionID is the ID of the session in question.
77
        sessionID wtdb.SessionID
78

79
        // deleteHeight is the block height after which we can delete the
80
        // session.
81
        deleteHeight uint32
82
}
83

84
// Less returns true if the current item's delete height is less than the
85
// other sessionCloseItem's delete height. This results in lower block heights
86
// being popped first from the heap.
87
//
88
// NOTE: this is part of the queue.PriorityQueueItem interface.
89
func (s *sessionCloseItem) Less(other queue.PriorityQueueItem) bool {
28✔
90
        o := other.(*sessionCloseItem).deleteHeight //nolint:forcetypeassert
28✔
91

28✔
92
        return s.deleteHeight < o
28✔
93
}
28✔
94

95
var _ queue.PriorityQueueItem = (*sessionCloseItem)(nil)
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