chainntfns: rename to CacheConfig and QueryDisabled

This commit is contained in:
Conner Fromknecht 2020-07-14 19:19:33 -07:00
parent b907035438
commit 7e08322d40
No known key found for this signature in database
GPG Key ID: E7D737B67FA592C7
7 changed files with 23 additions and 23 deletions

@ -40,8 +40,8 @@ func initHintCache(t *testing.T) *chainntnfs.HeightHintCache {
if err != nil { if err != nil {
t.Fatalf("unable to create db: %v", err) t.Fatalf("unable to create db: %v", err)
} }
testCfg := chainntnfs.Config{ testCfg := chainntnfs.CacheConfig{
HeightHintCacheQueryDisable: false, QueryDisable: false,
} }
hintCache, err := chainntnfs.NewHeightHintCache(testCfg, db) hintCache, err := chainntnfs.NewHeightHintCache(testCfg, db)
if err != nil { if err != nil {

@ -38,8 +38,8 @@ func initHintCache(t *testing.T) *chainntnfs.HeightHintCache {
if err != nil { if err != nil {
t.Fatalf("unable to create db: %v", err) t.Fatalf("unable to create db: %v", err)
} }
testCfg := chainntnfs.Config{ testCfg := chainntnfs.CacheConfig{
HeightHintCacheQueryDisable: false, QueryDisable: false,
} }
hintCache, err := chainntnfs.NewHeightHintCache(testCfg, db) hintCache, err := chainntnfs.NewHeightHintCache(testCfg, db)
if err != nil { if err != nil {

@ -35,13 +35,13 @@ var (
ErrConfirmHintNotFound = errors.New("confirm hint not found") ErrConfirmHintNotFound = errors.New("confirm hint not found")
) )
// Config contains the HeightHintCache configuration // CacheConfig contains the HeightHintCache configuration
type Config struct { type CacheConfig struct {
// HeightHintCacheQueryDisable prevents reliance on the Height Hint Cache. // QueryDisable prevents reliance on the Height Hint Cache. This is
// This is necessary to recover from an edge case when the height // necessary to recover from an edge case when the height recorded in
// recorded in the cache is higher than the actual height of a spend, // the cache is higher than the actual height of a spend, causing a
// causing a channel to become "stuck" in a pending close state. // channel to become "stuck" in a pending close state.
HeightHintCacheQueryDisable bool QueryDisable bool
} }
// SpendHintCache is an interface whose duty is to cache spend hints for // SpendHintCache is an interface whose duty is to cache spend hints for
@ -83,7 +83,7 @@ type ConfirmHintCache interface {
// ConfirmHintCache interfaces backed by a channeldb DB instance where the hints // ConfirmHintCache interfaces backed by a channeldb DB instance where the hints
// will be stored. // will be stored.
type HeightHintCache struct { type HeightHintCache struct {
cfg Config cfg CacheConfig
db *channeldb.DB db *channeldb.DB
} }
@ -93,7 +93,7 @@ var _ SpendHintCache = (*HeightHintCache)(nil)
var _ ConfirmHintCache = (*HeightHintCache)(nil) var _ ConfirmHintCache = (*HeightHintCache)(nil)
// NewHeightHintCache returns a new height hint cache backed by a database. // NewHeightHintCache returns a new height hint cache backed by a database.
func NewHeightHintCache(cfg Config, db *channeldb.DB) (*HeightHintCache, error) { func NewHeightHintCache(cfg CacheConfig, db *channeldb.DB) (*HeightHintCache, error) {
cache := &HeightHintCache{cfg, db} cache := &HeightHintCache{cfg, db}
if err := cache.initBuckets(); err != nil { if err := cache.initBuckets(); err != nil {
return nil, err return nil, err
@ -158,8 +158,8 @@ func (c *HeightHintCache) CommitSpendHint(height uint32,
// cache for the outpoint. // cache for the outpoint.
func (c *HeightHintCache) QuerySpendHint(spendRequest SpendRequest) (uint32, error) { func (c *HeightHintCache) QuerySpendHint(spendRequest SpendRequest) (uint32, error) {
var hint uint32 var hint uint32
if c.cfg.HeightHintCacheQueryDisable {
Log.Debugf("Ignoring spend height hint for %v (height hint cache query disabled)", spendRequest) Log.Debugf("Ignoring spend height hint for %v (height hint cache query disabled)", spendRequest)
if c.cfg.QueryDisable {
return 0, nil return 0, nil
} }
err := kvdb.View(c.db, func(tx kvdb.RTx) error { err := kvdb.View(c.db, func(tx kvdb.RTx) error {
@ -256,8 +256,8 @@ func (c *HeightHintCache) CommitConfirmHint(height uint32,
// the cache for the transaction hash. // the cache for the transaction hash.
func (c *HeightHintCache) QueryConfirmHint(confRequest ConfRequest) (uint32, error) { func (c *HeightHintCache) QueryConfirmHint(confRequest ConfRequest) (uint32, error) {
var hint uint32 var hint uint32
if c.cfg.HeightHintCacheQueryDisable {
Log.Debugf("Ignoring confirmation height hint for %v (height hint cache query disabled)", confRequest) Log.Debugf("Ignoring confirmation height hint for %v (height hint cache query disabled)", confRequest)
if c.cfg.QueryDisable {
return 0, nil return 0, nil
} }
err := kvdb.View(c.db, func(tx kvdb.RTx) error { err := kvdb.View(c.db, func(tx kvdb.RTx) error {

@ -21,8 +21,8 @@ func initHintCache(t *testing.T) *HeightHintCache {
if err != nil { if err != nil {
t.Fatalf("unable to create db: %v", err) t.Fatalf("unable to create db: %v", err)
} }
testCfg := Config{ testCfg := CacheConfig{
HeightHintCacheQueryDisable: false, QueryDisable: false,
} }
hintCache, err := NewHeightHintCache(testCfg, db) hintCache, err := NewHeightHintCache(testCfg, db)
if err != nil { if err != nil {

@ -1911,8 +1911,8 @@ func TestInterfaces(t *testing.T) {
if err != nil { if err != nil {
t.Fatalf("unable to create db: %v", err) t.Fatalf("unable to create db: %v", err)
} }
testCfg := chainntnfs.Config{ testCfg := chainntnfs.CacheConfig{
HeightHintCacheQueryDisable: false, QueryDisable: false,
} }
hintCache, err := chainntnfs.NewHeightHintCache(testCfg, db) hintCache, err := chainntnfs.NewHeightHintCache(testCfg, db)
if err != nil { if err != nil {

@ -219,8 +219,8 @@ func newChainControlFromConfig(cfg *Config, chanDB *channeldb.DB,
var err error var err error
heightHintCacheConfig := chainntnfs.Config{ heightHintCacheConfig := chainntnfs.CacheConfig{
HeightHintCacheQueryDisable: cfg.HeightHintCacheQueryDisable, QueryDisable: cfg.HeightHintCacheQueryDisable,
} }
if cfg.HeightHintCacheQueryDisable { if cfg.HeightHintCacheQueryDisable {
ltndLog.Infof("Height Hint Cache Queries disabled") ltndLog.Infof("Height Hint Cache Queries disabled")

@ -3014,8 +3014,8 @@ func TestLightningWallet(t *testing.T) {
if err != nil { if err != nil {
t.Fatalf("unable to create db: %v", err) t.Fatalf("unable to create db: %v", err)
} }
testCfg := chainntnfs.Config{ testCfg := chainntnfs.CacheConfig{
HeightHintCacheQueryDisable: false, QueryDisable: false,
} }
hintCache, err := chainntnfs.NewHeightHintCache(testCfg, db) hintCache, err := chainntnfs.NewHeightHintCache(testCfg, db)
if err != nil { if err != nil {