lnd+kvdb: pass LND abort context to etcd
This commit is contained in:
parent
d3545830c9
commit
3e5e60cac4
@ -3,6 +3,8 @@
|
|||||||
package kvdb
|
package kvdb
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"context"
|
||||||
|
|
||||||
"github.com/lightningnetwork/lnd/channeldb/kvdb/etcd"
|
"github.com/lightningnetwork/lnd/channeldb/kvdb/etcd"
|
||||||
)
|
)
|
||||||
|
|
||||||
@ -12,10 +14,13 @@ const TestBackend = EtcdBackendName
|
|||||||
|
|
||||||
// GetEtcdBackend returns an etcd backend configured according to the
|
// GetEtcdBackend returns an etcd backend configured according to the
|
||||||
// passed etcdConfig.
|
// passed etcdConfig.
|
||||||
func GetEtcdBackend(prefix string, etcdConfig *EtcdConfig) (Backend, error) {
|
func GetEtcdBackend(ctx context.Context, prefix string,
|
||||||
|
etcdConfig *EtcdConfig) (Backend, error) {
|
||||||
|
|
||||||
// Config translation is needed here in order to keep the
|
// Config translation is needed here in order to keep the
|
||||||
// etcd package fully independent from the rest of the source tree.
|
// etcd package fully independent from the rest of the source tree.
|
||||||
backendConfig := etcd.BackendConfig{
|
backendConfig := etcd.BackendConfig{
|
||||||
|
Ctx: ctx,
|
||||||
Host: etcdConfig.Host,
|
Host: etcdConfig.Host,
|
||||||
User: etcdConfig.User,
|
User: etcdConfig.User,
|
||||||
Pass: etcdConfig.Pass,
|
Pass: etcdConfig.Pass,
|
||||||
|
@ -3,6 +3,7 @@
|
|||||||
package kvdb
|
package kvdb
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"context"
|
||||||
"fmt"
|
"fmt"
|
||||||
)
|
)
|
||||||
|
|
||||||
@ -13,7 +14,9 @@ const TestBackend = BoltBackendName
|
|||||||
var errEtcdNotAvailable = fmt.Errorf("etcd backend not available")
|
var errEtcdNotAvailable = fmt.Errorf("etcd backend not available")
|
||||||
|
|
||||||
// GetEtcdBackend is a stub returning nil and errEtcdNotAvailable error.
|
// GetEtcdBackend is a stub returning nil and errEtcdNotAvailable error.
|
||||||
func GetEtcdBackend(prefix string, etcdConfig *EtcdConfig) (Backend, error) {
|
func GetEtcdBackend(ctx context.Context, prefix string,
|
||||||
|
etcdConfig *EtcdConfig) (Backend, error) {
|
||||||
|
|
||||||
return nil, errEtcdNotAvailable
|
return nil, errEtcdNotAvailable
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1,6 +1,7 @@
|
|||||||
package lncfg
|
package lncfg
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"context"
|
||||||
"fmt"
|
"fmt"
|
||||||
|
|
||||||
"github.com/lightningnetwork/lnd/channeldb/kvdb"
|
"github.com/lightningnetwork/lnd/channeldb/kvdb"
|
||||||
@ -50,12 +51,12 @@ func (db *DB) Validate() error {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// GetBackend returns a kvdb.Backend as set in the DB config.
|
// GetBackend returns a kvdb.Backend as set in the DB config.
|
||||||
func (db *DB) GetBackend(dbPath string, networkName string) (
|
func (db *DB) GetBackend(ctx context.Context, dbPath string,
|
||||||
kvdb.Backend, error) {
|
networkName string) (kvdb.Backend, error) {
|
||||||
|
|
||||||
if db.Backend == etcdBackend {
|
if db.Backend == etcdBackend {
|
||||||
// Prefix will separate key/values in the db.
|
// Prefix will separate key/values in the db.
|
||||||
return kvdb.GetEtcdBackend(networkName, db.Etcd)
|
return kvdb.GetEtcdBackend(ctx, networkName, db.Etcd)
|
||||||
}
|
}
|
||||||
|
|
||||||
return kvdb.GetBoltBackend(dbPath, dbName, db.Bolt.NoFreeListSync)
|
return kvdb.GetBoltBackend(dbPath, dbName, db.Bolt.NoFreeListSync)
|
||||||
|
10
lnd.go
10
lnd.go
@ -251,7 +251,11 @@ func Main(cfg *Config, lisCfg ListenerCfg, shutdownChan <-chan struct{}) error {
|
|||||||
"minutes...")
|
"minutes...")
|
||||||
|
|
||||||
startOpenTime := time.Now()
|
startOpenTime := time.Now()
|
||||||
chanDbBackend, err := cfg.DB.GetBackend(
|
ctx := context.Background()
|
||||||
|
ctx, cancel := context.WithCancel(ctx)
|
||||||
|
defer cancel()
|
||||||
|
|
||||||
|
chanDbBackend, err := cfg.DB.GetBackend(ctx,
|
||||||
cfg.localDatabaseDir(), cfg.networkName(),
|
cfg.localDatabaseDir(), cfg.networkName(),
|
||||||
)
|
)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@ -283,10 +287,6 @@ func Main(cfg *Config, lisCfg ListenerCfg, shutdownChan <-chan struct{}) error {
|
|||||||
ltndLog.Infof("Database now open (time_to_open=%v)!", openTime)
|
ltndLog.Infof("Database now open (time_to_open=%v)!", openTime)
|
||||||
|
|
||||||
// Only process macaroons if --no-macaroons isn't set.
|
// Only process macaroons if --no-macaroons isn't set.
|
||||||
ctx := context.Background()
|
|
||||||
ctx, cancel := context.WithCancel(ctx)
|
|
||||||
defer cancel()
|
|
||||||
|
|
||||||
tlsCfg, restCreds, restProxyDest, err := getTLSConfig(cfg)
|
tlsCfg, restCreds, restProxyDest, err := getTLSConfig(cfg)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
err := fmt.Errorf("unable to load TLS credentials: %v", err)
|
err := fmt.Errorf("unable to load TLS credentials: %v", err)
|
||||||
|
Loading…
Reference in New Issue
Block a user