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

lightningnetwork / lnd / 15736109134

18 Jun 2025 02:46PM UTC coverage: 58.197% (-10.1%) from 68.248%
15736109134

Pull #9752

github

web-flow
Merge d2634a68c into 31c74f20f
Pull Request #9752: routerrpc: reject payment to invoice that don't have payment secret or blinded paths

6 of 13 new or added lines in 2 files covered. (46.15%)

28331 existing lines in 455 files now uncovered.

97860 of 168153 relevant lines covered (58.2%)

1.81 hits per line

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

85.71
/lnutils/sync_map.go
1
package lnutils
2

3
import "sync"
4

5
// SyncMap wraps a sync.Map with type parameters such that it's easier to
6
// access the items stored in the map since no type assertion is needed. It
7
// also requires explicit type definition when declaring and initiating the
8
// variables, which helps us understanding what's stored in a given map.
9
type SyncMap[K comparable, V any] struct {
10
        sync.Map
11
}
12

13
// Store puts an item in the map.
14
func (m *SyncMap[K, V]) Store(key K, value V) {
3✔
15
        m.Map.Store(key, value)
3✔
16
}
3✔
17

18
// Load queries an item from the map using the specified key. If the item
19
// cannot be found, an empty value and false will be returned. If the stored
20
// item fails the type assertion, a nil value and false will be returned.
21
func (m *SyncMap[K, V]) Load(key K) (V, bool) {
3✔
22
        result, ok := m.Map.Load(key)
3✔
23
        if !ok {
6✔
24
                return *new(V), false // nolint: gocritic
3✔
25
        }
3✔
26

27
        item, ok := result.(V)
3✔
28
        return item, ok
3✔
29
}
30

31
// Delete removes an item from the map specified by the key.
32
func (m *SyncMap[K, V]) Delete(key K) {
3✔
33
        m.Map.Delete(key)
3✔
34
}
3✔
35

36
// LoadAndDelete queries an item and deletes it from the map using the
37
// specified key.
38
func (m *SyncMap[K, V]) LoadAndDelete(key K) (V, bool) {
3✔
39
        result, loaded := m.Map.LoadAndDelete(key)
3✔
40
        if !loaded {
3✔
UNCOV
41
                return *new(V), loaded // nolint: gocritic
×
UNCOV
42
        }
×
43

44
        item, ok := result.(V)
3✔
45
        return item, ok
3✔
46
}
47

48
// Range iterates the map and applies the `visitor` function. If the `visitor`
49
// returns false, the iteration will be stopped.
50
func (m *SyncMap[K, V]) Range(visitor func(K, V) bool) {
3✔
51
        m.Map.Range(func(k any, v any) bool {
6✔
52
                return visitor(k.(K), v.(V))
3✔
53
        })
3✔
54
}
55

56
// ForEach iterates the map and applies the `visitor` function. Unlike the
57
// `Range` method, the `visitor` function will be applied to all the items
58
// unless there's an error.
59
func (m *SyncMap[K, V]) ForEach(visitor func(K, V) error) {
3✔
60
        // rangeVisitor wraps the `visitor` function and returns false if
3✔
61
        // there's an error returned from the `visitor` function.
3✔
62
        rangeVisitor := func(k K, v V) bool {
6✔
63
                if err := visitor(k, v); err != nil {
3✔
UNCOV
64
                        // Break the iteration if there's an error.
×
UNCOV
65
                        return false
×
UNCOV
66
                }
×
67

68
                return true
3✔
69
        }
70

71
        m.Range(rangeVisitor)
3✔
72
}
73

74
// Len returns the number of items in the map.
75
func (m *SyncMap[K, V]) Len() int {
3✔
76
        var count int
3✔
77
        m.Range(func(_ K, _ V) bool {
6✔
78
                count++
3✔
79

3✔
80
                return true
3✔
81
        })
3✔
82

83
        return count
3✔
84
}
85

86
// LoadOrStore queries an item from the map using the specified key. If the
87
// item cannot be found, the `value` will be stored in the map and returned.
88
// If the stored item fails the type assertion, a nil value and false will be
89
// returned.
90
func (m *SyncMap[K, V]) LoadOrStore(key K, value V) (V, bool) {
3✔
91
        result, loaded := m.Map.LoadOrStore(key, value)
3✔
92
        item, ok := result.(V)
3✔
93
        if !ok {
3✔
94
                return *new(V), false
×
95
        }
×
96

97
        return item, loaded
3✔
98
}
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