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

lightningnetwork / lnd / 12583319996

02 Jan 2025 01:38PM UTC coverage: 57.522% (-1.1%) from 58.598%
12583319996

Pull #9361

github

starius
fn/ContextGuard: use context.AfterFunc to wait

Simplifies context cancellation handling by using context.AfterFunc instead of a
goroutine to wait for context cancellation. This approach avoids the overhead of
a goroutine during the waiting period.

For ctxQuitUnsafe, since g.quit is closed only in the Quit method (which also
cancels all associated contexts), waiting on context cancellation ensures the
same behavior without unnecessary dependency on g.quit.

Added a test to ensure that the Create method does not launch any goroutines.
Pull Request #9361: fn: optimize context guard

102587 of 178344 relevant lines covered (57.52%)

24734.33 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