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

lightningnetwork / lnd / 12312390362

13 Dec 2024 08:44AM UTC coverage: 57.458% (+8.5%) from 48.92%
12312390362

Pull #9343

github

ellemouton
fn: rework the ContextGuard and add tests

In this commit, the ContextGuard struct is re-worked such that the
context that its new main WithCtx method provides is cancelled in sync
with a parent context being cancelled or with it's quit channel being
cancelled. Tests are added to assert the behaviour. In order for the
close of the quit channel to be consistent with the cancelling of the
derived context, the quit channel _must_ be contained internal to the
ContextGuard so that callers are only able to close the channel via the
exposed Quit method which will then take care to first cancel any
derived context that depend on the quit channel before returning.
Pull Request #9343: fn: expand the ContextGuard and add tests

101853 of 177264 relevant lines covered (57.46%)

24972.93 hits per line

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

0.0
/lncfg/caches.go
1
package lncfg
2

3
import (
4
        "fmt"
5
        "time"
6
)
7

8
const (
9
        // MinRejectCacheSize is a floor on the maximum capacity allowed for
10
        // channeldb's reject cache. This amounts to roughly 125 KB when full.
11
        MinRejectCacheSize = 5000
12

13
        // MinChannelCacheSize is a floor on the maximum capacity allowed for
14
        // channeldb's channel cache. This amounts to roughly 2 MB when full.
15
        MinChannelCacheSize = 1000
16

17
        // DefaultRPCGraphCacheDuration is the default interval that the RPC
18
        // response to DescribeGraph should be cached for.
19
        DefaultRPCGraphCacheDuration = time.Minute
20
)
21

22
// Caches holds the configuration for various caches within lnd.
23
//
24
//nolint:ll
25
type Caches struct {
26
        // RejectCacheSize is the maximum number of entries stored in lnd's
27
        // reject cache, which is used for efficiently rejecting gossip updates.
28
        // Memory usage is roughly 25b per entry.
29
        RejectCacheSize int `long:"reject-cache-size" description:"Maximum number of entries contained in the reject cache, which is used to speed up filtering of new channel announcements and channel updates from peers. Each entry requires 25 bytes."`
30

31
        // ChannelCacheSize is the maximum number of entries stored in lnd's
32
        // channel cache, which is used reduce memory allocations in reply to
33
        // peers querying for gossip traffic. Memory usage is roughly 2Kb per
34
        // entry.
35
        ChannelCacheSize int `long:"channel-cache-size" description:"Maximum number of entries contained in the channel cache, which is used to reduce memory allocations from gossip queries from peers. Each entry requires roughly 2Kb."`
36

37
        // RPCGraphCacheDuration is used to control the flush interval of the
38
        // channel graph cache.
39
        RPCGraphCacheDuration time.Duration `long:"rpc-graph-cache-duration" description:"The period of time expressed as a duration (1s, 1m, 1h, etc) that the RPC response to DescribeGraph should be cached for."`
40
}
41

42
// Validate checks the Caches configuration for values that are too small to be
43
// sane.
44
func (c *Caches) Validate() error {
×
45
        if c.RejectCacheSize < MinRejectCacheSize {
×
46
                return fmt.Errorf("reject cache size %d is less than min: %d",
×
47
                        c.RejectCacheSize, MinRejectCacheSize)
×
48
        }
×
49
        if c.ChannelCacheSize < MinChannelCacheSize {
×
50
                return fmt.Errorf("channel cache size %d is less than min: %d",
×
51
                        c.ChannelCacheSize, MinChannelCacheSize)
×
52
        }
×
53

54
        return nil
×
55
}
56

57
// Compile-time constraint to ensure Caches implements the Validator interface.
58
var _ Validator = (*Caches)(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