github.com/decred/dcrlnd@v0.7.6/lncfg/caches.go (about)

     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  type Caches struct {
    24  	// RejectCacheSize is the maximum number of entries stored in lnd's
    25  	// reject cache, which is used for efficiently rejecting gossip updates.
    26  	// Memory usage is roughly 25b per entry.
    27  	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."`
    28  
    29  	// ChannelCacheSize is the maximum number of entries stored in lnd's
    30  	// channel cache, which is used reduce memory allocations in reply to
    31  	// peers querying for gossip traffic. Memory usage is roughly 2Kb per
    32  	// entry.
    33  	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."`
    34  
    35  	// RPCGraphCacheDuration is used to control the flush interval of the
    36  	// channel graph cache.
    37  	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."`
    38  }
    39  
    40  // Validate checks the Caches configuration for values that are too small to be
    41  // sane.
    42  func (c *Caches) Validate() error {
    43  	if c.RejectCacheSize < MinRejectCacheSize {
    44  		return fmt.Errorf("reject cache size %d is less than min: %d",
    45  			c.RejectCacheSize, MinRejectCacheSize)
    46  	}
    47  	if c.ChannelCacheSize < MinChannelCacheSize {
    48  		return fmt.Errorf("channel cache size %d is less than min: %d",
    49  			c.ChannelCacheSize, MinChannelCacheSize)
    50  	}
    51  
    52  	return nil
    53  }
    54  
    55  // Compile-time constraint to ensure Caches implements the Validator interface.
    56  var _ Validator = (*Caches)(nil)