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

lightningnetwork / lnd / 20088220763

10 Dec 2025 05:19AM UTC coverage: 65.185% (+0.009%) from 65.176%
20088220763

Pull #10436

github

web-flow
Merge a7b61f3ec into 456d7dcf0
Pull Request #10436: multi: add `CombinedNonce` functionality to Musig2 Signers

66 of 199 new or added lines in 8 files covered. (33.17%)

29408 existing lines in 461 files now uncovered.

137799 of 211398 relevant lines covered (65.18%)

20752.71 hits per line

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

100.0
/graph/db/reject_cache.go
1
package graphdb
2

3
// rejectFlags is a compact representation of various metadata stored by the
4
// reject cache about a particular channel.
5
type rejectFlags uint8
6

7
const (
8
        // rejectFlagExists is a flag indicating whether the channel exists,
9
        // i.e. the channel is open and has a recent channel update. If this
10
        // flag is not set, the channel is either a zombie or unknown.
11
        rejectFlagExists rejectFlags = 1 << iota
12

13
        // rejectFlagZombie is a flag indicating whether the channel is a
14
        // zombie, i.e. the channel is open but has no recent channel updates.
15
        rejectFlagZombie
16
)
17

18
// packRejectFlags computes the rejectFlags corresponding to the passed boolean
19
// values indicating whether the edge exists or is a zombie.
20
func packRejectFlags(exists, isZombie bool) rejectFlags {
645✔
21
        var flags rejectFlags
645✔
22
        if exists {
945✔
23
                flags |= rejectFlagExists
300✔
24
        }
300✔
25
        if isZombie {
851✔
UNCOV
26
                flags |= rejectFlagZombie
206✔
UNCOV
27
        }
206✔
28

29
        return flags
645✔
30
}
31

32
// unpack returns the booleans packed into the rejectFlags. The first indicates
33
// if the edge exists in our graph, the second indicates if the edge is a
34
// zombie.
35
func (f rejectFlags) unpack() (bool, bool) {
78✔
36
        return f&rejectFlagExists == rejectFlagExists,
78✔
37
                f&rejectFlagZombie == rejectFlagZombie
78✔
38
}
78✔
39

40
// rejectCacheEntry caches frequently accessed information about a channel,
41
// including the timestamps of its latest edge policies and whether or not the
42
// channel exists in the graph.
43
type rejectCacheEntry struct {
44
        upd1Time int64
45
        upd2Time int64
46
        flags    rejectFlags
47
}
48

49
// rejectCache is an in-memory cache used to improve the performance of
50
// HasChannelEdge. It caches information about the whether or channel exists, as
51
// well as the most recent timestamps for each policy (if they exists).
52
type rejectCache struct {
53
        n     int
54
        edges map[uint64]rejectCacheEntry
55
}
56

57
// newRejectCache creates a new rejectCache with maximum capacity of n entries.
58
func newRejectCache(n int) *rejectCache {
186✔
59
        return &rejectCache{
186✔
60
                n:     n,
186✔
61
                edges: make(map[uint64]rejectCacheEntry, n),
186✔
62
        }
186✔
63
}
186✔
64

65
// get returns the entry from the cache for chanid, if it exists.
66
func (c *rejectCache) get(chanid uint64) (rejectCacheEntry, bool) {
3,633✔
67
        entry, ok := c.edges[chanid]
3,633✔
68
        return entry, ok
3,633✔
69
}
3,633✔
70

71
// insert adds the entry to the reject cache. If an entry for chanid already
72
// exists, it will be replaced with the new entry. If the entry doesn't exists,
73
// it will be inserted to the cache, performing a random eviction if the cache
74
// is at capacity.
75
func (c *rejectCache) insert(chanid uint64, entry rejectCacheEntry) {
350✔
76
        // If entry exists, replace it.
350✔
77
        if _, ok := c.edges[chanid]; ok {
458✔
78
                c.edges[chanid] = entry
108✔
79
                return
108✔
80
        }
108✔
81

82
        // Otherwise, evict an entry at random and insert.
83
        if len(c.edges) == c.n {
246✔
UNCOV
84
                for id := range c.edges {
2✔
UNCOV
85
                        delete(c.edges, id)
1✔
UNCOV
86
                        break
1✔
87
                }
88
        }
89
        c.edges[chanid] = entry
245✔
90
}
91

92
// remove deletes an entry for chanid from the cache, if it exists.
93
func (c *rejectCache) remove(chanid uint64) {
1,869✔
94
        delete(c.edges, chanid)
1,869✔
95
}
1,869✔
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

© 2026 Coveralls, Inc