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

lightningnetwork / lnd / 13211764208

08 Feb 2025 03:08AM UTC coverage: 49.288% (-9.5%) from 58.815%
13211764208

Pull #9489

github

calvinrzachman
itest: verify switchrpc server enforces send then track

We prevent the rpc server from allowing onion dispatches for
attempt IDs which have already been tracked by rpc clients.

This helps protect the client from leaking a duplicate onion
attempt. NOTE: This is not the only method for solving this
issue! The issue could be addressed via careful client side
programming which accounts for the uncertainty and async
nature of dispatching onions to a remote process via RPC.
This would require some lnd ChannelRouter changes for how
we intend to use these RPCs though.
Pull Request #9489: multi: add BuildOnion, SendOnion, and TrackOnion RPCs

474 of 990 new or added lines in 11 files covered. (47.88%)

27321 existing lines in 435 files now uncovered.

101192 of 205306 relevant lines covered (49.29%)

1.54 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 {
3✔
19
        return &sessionCloseMinHeap{}
3✔
20
}
3✔
21

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

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

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

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

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

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

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

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

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

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

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

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

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

3✔
71
        return item.(*sessionCloseItem) //nolint:forcetypeassert
3✔
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.
UNCOV
89
func (s *sessionCloseItem) Less(other queue.PriorityQueueItem) bool {
×
UNCOV
90
        o := other.(*sessionCloseItem).deleteHeight //nolint:forcetypeassert
×
UNCOV
91

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