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

lightningnetwork / lnd / 11965896165

22 Nov 2024 03:26AM UTC coverage: 49.579% (-9.4%) from 58.98%
11965896165

Pull #8512

github

Roasbeef
lnwallet/chancloser: add unit tests for new rbf coop close
Pull Request #8512: [3/4] - lnwallet/chancloser: add new protofsm based RBF chan closer

30 of 1081 new or added lines in 8 files covered. (2.78%)

25859 existing lines in 424 files now uncovered.

99910 of 201515 relevant lines covered (49.58%)

2.06 hits per line

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

87.5
/channeldb/channel_cache.go
1
package channeldb
2

3
// channelCache is an in-memory cache used to improve the performance of
4
// ChanUpdatesInHorizon. It caches the chan info and edge policies for a
5
// particular channel.
6
type channelCache struct {
7
        n        int
8
        channels map[uint64]ChannelEdge
9
}
10

11
// newChannelCache creates a new channelCache with maximum capacity of n
12
// channels.
13
func newChannelCache(n int) *channelCache {
4✔
14
        return &channelCache{
4✔
15
                n:        n,
4✔
16
                channels: make(map[uint64]ChannelEdge),
4✔
17
        }
4✔
18
}
4✔
19

20
// get returns the channel from the cache, if it exists.
21
func (c *channelCache) get(chanid uint64) (ChannelEdge, bool) {
4✔
22
        channel, ok := c.channels[chanid]
4✔
23
        return channel, ok
4✔
24
}
4✔
25

26
// insert adds the entry to the channel cache. If an entry for chanid already
27
// exists, it will be replaced with the new entry. If the entry doesn't exist,
28
// it will be inserted to the cache, performing a random eviction if the cache
29
// is at capacity.
30
func (c *channelCache) insert(chanid uint64, channel ChannelEdge) {
4✔
31
        // If entry exists, replace it.
4✔
32
        if _, ok := c.channels[chanid]; ok {
8✔
33
                c.channels[chanid] = channel
4✔
34
                return
4✔
35
        }
4✔
36

37
        // Otherwise, evict an entry at random and insert.
38
        if len(c.channels) == c.n {
4✔
UNCOV
39
                for id := range c.channels {
×
UNCOV
40
                        delete(c.channels, id)
×
UNCOV
41
                        break
×
42
                }
43
        }
44
        c.channels[chanid] = channel
4✔
45
}
46

47
// remove deletes an edge for chanid from the cache, if it exists.
48
func (c *channelCache) remove(chanid uint64) {
4✔
49
        delete(c.channels, chanid)
4✔
50
}
4✔
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