channeldb: add optional meta and migration30

This commit enables the db to run optional migrations that are specified
by config flags. To achieve this, an optional meta is introduced to
manage the optional migrations. We distinguish the two types of
migrations here so it's easier to manage them for the concern a future
migration can cause trouble for us to determine the db version if we
don't.
This commit is contained in:
yyforyongyu committed 2022-07-12 21:01:11 +08:00
1 parent 1832a93d19
commit afb2f72ce2
4 files changed
+309 -17

No files matched your search

+24 -6
View File
@@ -25,9 +25,18 @@ const (
DefaultPreAllocCacheNumNodes = 15000
)
// OptionalMiragtionConfig defines the flags used to signal whether a
// particular migration needs to be applied.
type OptionalMiragtionConfig struct {
// PruneRevocationLog specifies that the revocation log migration needs
// to be applied.
PruneRevocationLog bool
}
// Options holds parameters for tuning and customizing a channeldb.DB.
type Options struct {
kvdb.BoltBackendConfig
OptionalMiragtionConfig
// RejectCacheSize is the maximum number of rejectCacheEntries to hold
// in the rejection cache.
@@ -76,12 +85,13 @@ func DefaultOptions() Options {
AutoCompactMinAge: kvdb.DefaultBoltAutoCompactMinAge,
DBTimeout: kvdb.DefaultDBTimeout,
},
RejectCacheSize: DefaultRejectCacheSize,
ChannelCacheSize: DefaultChannelCacheSize,
PreAllocCacheNumNodes: DefaultPreAllocCacheNumNodes,
UseGraphCache: true,
NoMigration: false,
clock: clock.NewDefaultClock(),
OptionalMiragtionConfig: OptionalMiragtionConfig{},
RejectCacheSize: DefaultRejectCacheSize,
ChannelCacheSize: DefaultChannelCacheSize,
PreAllocCacheNumNodes: DefaultPreAllocCacheNumNodes,
UseGraphCache: true,
NoMigration: false,
clock: clock.NewDefaultClock(),
}
}
@@ -176,3 +186,11 @@ func OptionKeepFailedPaymentAttempts(keepFailedPaymentAttempts bool) OptionModif
o.keepFailedPaymentAttempts = keepFailedPaymentAttempts
}
}
// OptionPruneRevocationLog specifies whether the migration for pruning
// revocation logs needs to be applied or not.
func OptionPruneRevocationLog(prune bool) OptionModifier {
return func(o *Options) {
o.OptionalMiragtionConfig.PruneRevocationLog = prune
}
}