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

lightningnetwork / lnd / 12199391122

06 Dec 2024 01:10PM UTC coverage: 49.807% (-9.1%) from 58.933%
12199391122

push

github

web-flow
Merge pull request #9337 from Guayaba221/patch-1

chore: fix typo in ruby.md

100137 of 201051 relevant lines covered (49.81%)

2.07 hits per line

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

58.7
/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 {
4✔
19
        return &sessionCloseMinHeap{}
4✔
20
}
4✔
21

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

×
27
        return h.queue.Len()
×
28
}
×
29

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

×
35
        return h.queue.Empty()
×
36
}
×
37

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

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

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

4✔
51
        if h.queue.Empty() {
4✔
52
                return nil
×
53
        }
×
54

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

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

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

4✔
65
        if h.queue.Empty() {
8✔
66
                return nil
4✔
67
        }
4✔
68

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

4✔
71
        return item.(*sessionCloseItem) //nolint:forcetypeassert
4✔
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 {
×
90
        o := other.(*sessionCloseItem).deleteHeight //nolint:forcetypeassert
×
91

×
92
        return s.deleteHeight < o
×
93
}
×
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