github.com/decred/dcrlnd@v0.7.6/channeldb/options.go (about) 1 package channeldb 2 3 import ( 4 "time" 5 6 "github.com/decred/dcrlnd/clock" 7 "github.com/decred/dcrlnd/kvdb" 8 ) 9 10 const ( 11 // DefaultRejectCacheSize is the default number of rejectCacheEntries to 12 // cache for use in the rejection cache of incoming gossip traffic. This 13 // produces a cache size of around 1MB. 14 DefaultRejectCacheSize = 50000 15 16 // DefaultChannelCacheSize is the default number of ChannelEdges cached 17 // in order to reply to gossip queries. This produces a cache size of 18 // around 40MB. 19 DefaultChannelCacheSize = 20000 20 21 // DefaultPreAllocCacheNumNodes is the default number of channels we 22 // assume for mainnet for pre-allocating the graph cache. Decred's 23 // LN is significantly smaller than Bitcoin's, therefore this number 24 // is smaller than lnd's default. 25 DefaultPreAllocCacheNumNodes = 1000 26 ) 27 28 // Options holds parameters for tuning and customizing a channeldb.DB. 29 type Options struct { 30 kvdb.BoltBackendConfig 31 32 // RejectCacheSize is the maximum number of rejectCacheEntries to hold 33 // in the rejection cache. 34 RejectCacheSize int 35 36 // ChannelCacheSize is the maximum number of ChannelEdges to hold in the 37 // channel cache. 38 ChannelCacheSize int 39 40 // BatchCommitInterval is the maximum duration the batch schedulers will 41 // wait before attempting to commit a pending set of updates. 42 BatchCommitInterval time.Duration 43 44 // PreAllocCacheNumNodes is the number of nodes we expect to be in the 45 // graph cache, so we can pre-allocate the map accordingly. 46 PreAllocCacheNumNodes int 47 48 // UseGraphCache denotes whether the in-memory graph cache should be 49 // used or a fallback version that uses the underlying database for 50 // path finding. 51 UseGraphCache bool 52 53 // clock is the time source used by the database. 54 clock clock.Clock 55 56 // dryRun will fail to commit a successful migration when opening the 57 // database if set to true. 58 dryRun bool 59 } 60 61 // DefaultOptions returns an Options populated with default values. 62 func DefaultOptions() Options { 63 return Options{ 64 BoltBackendConfig: kvdb.BoltBackendConfig{ 65 NoFreelistSync: true, 66 AutoCompact: false, 67 AutoCompactMinAge: kvdb.DefaultBoltAutoCompactMinAge, 68 DBTimeout: kvdb.DefaultDBTimeout, 69 }, 70 RejectCacheSize: DefaultRejectCacheSize, 71 ChannelCacheSize: DefaultChannelCacheSize, 72 PreAllocCacheNumNodes: DefaultPreAllocCacheNumNodes, 73 UseGraphCache: true, 74 clock: clock.NewDefaultClock(), 75 } 76 } 77 78 // OptionModifier is a function signature for modifying the default Options. 79 type OptionModifier func(*Options) 80 81 // OptionSetRejectCacheSize sets the RejectCacheSize to n. 82 func OptionSetRejectCacheSize(n int) OptionModifier { 83 return func(o *Options) { 84 o.RejectCacheSize = n 85 } 86 } 87 88 // OptionSetChannelCacheSize sets the ChannelCacheSize to n. 89 func OptionSetChannelCacheSize(n int) OptionModifier { 90 return func(o *Options) { 91 o.ChannelCacheSize = n 92 } 93 } 94 95 // OptionSetPreAllocCacheNumNodes sets the PreAllocCacheNumNodes to n. 96 func OptionSetPreAllocCacheNumNodes(n int) OptionModifier { 97 return func(o *Options) { 98 o.PreAllocCacheNumNodes = n 99 } 100 } 101 102 // OptionSetUseGraphCache sets the UseGraphCache option to the given value. 103 func OptionSetUseGraphCache(use bool) OptionModifier { 104 return func(o *Options) { 105 o.UseGraphCache = use 106 } 107 } 108 109 // OptionSetSyncFreelist allows the database to sync its freelist. 110 func OptionSetSyncFreelist(b bool) OptionModifier { 111 return func(o *Options) { 112 o.NoFreelistSync = !b 113 } 114 } 115 116 // OptionAutoCompact turns on automatic database compaction on startup. 117 func OptionAutoCompact() OptionModifier { 118 return func(o *Options) { 119 o.AutoCompact = true 120 } 121 } 122 123 // OptionAutoCompactMinAge sets the minimum age for automatic database 124 // compaction. 125 func OptionAutoCompactMinAge(minAge time.Duration) OptionModifier { 126 return func(o *Options) { 127 o.AutoCompactMinAge = minAge 128 } 129 } 130 131 // OptionSetBatchCommitInterval sets the batch commit interval for the internval 132 // batch schedulers. 133 func OptionSetBatchCommitInterval(interval time.Duration) OptionModifier { 134 return func(o *Options) { 135 o.BatchCommitInterval = interval 136 } 137 } 138 139 // OptionClock sets a non-default clock dependency. 140 func OptionClock(clock clock.Clock) OptionModifier { 141 return func(o *Options) { 142 o.clock = clock 143 } 144 } 145 146 // OptionDryRunMigration controls whether or not to intentially fail to commit a 147 // successful migration that occurs when opening the database. 148 func OptionDryRunMigration(dryRun bool) OptionModifier { 149 return func(o *Options) { 150 o.dryRun = dryRun 151 } 152 }