Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
46 changes: 45 additions & 1 deletion itest/litd_node.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import (
"encoding/hex"
"encoding/json"
"errors"
"flag"
"fmt"
"io"
"io/ioutil"
Expand All @@ -25,6 +26,7 @@ import (
"github.com/btcsuite/btcd/wire"
"github.com/lightninglabs/faraday/frdrpc"
terminal "github.com/lightninglabs/lightning-terminal"
"github.com/lightninglabs/lightning-terminal/db"
"github.com/lightninglabs/lightning-terminal/litrpc"
"github.com/lightninglabs/lightning-terminal/subservers"
"github.com/lightninglabs/loop/looprpc"
Expand Down Expand Up @@ -60,7 +62,12 @@ var (
numActiveNodes = 0
numActiveNodesMtx sync.Mutex

defaultLndPassphrase = []byte("default-wallet-password")
// litDBBackend is a command line flag for specifying the database
// backend to use when starting a LiT daemon.
litDBBackend = flag.String(
"litdbbackend", terminal.DatabaseBackendBbolt, "Set the "+
"database backend to use when starting a LiT daemon.",
)
)

type LitNodeConfig struct {
Expand All @@ -80,6 +87,9 @@ type LitNodeConfig struct {
LitTLSCertPath string
LitMacPath string

DBBackend string
PostgresConfig *db.PostgresConfig

UIPassword string
LitDir string
FaradayDir string
Expand Down Expand Up @@ -220,8 +230,20 @@ func (cfg *LitNodeConfig) defaultLitdArgs() *litArgs {
"restcors": "*",
"lnd.debuglevel": "trace,GRPC=error,PEER=info",
"lndconnectinterval": "200ms",
"databasebackend": cfg.DBBackend,
}
)

if cfg.DBBackend == terminal.DatabaseBackendPostgres {
args["postgres.host"] = cfg.PostgresConfig.Host
args["postgres.port"] = fmt.Sprintf(
"%d", cfg.PostgresConfig.Port,
)
args["postgres.user"] = cfg.PostgresConfig.User
args["postgres.password"] = cfg.PostgresConfig.Password
args["postgres.dbname"] = cfg.PostgresConfig.DBName
}

for _, arg := range cfg.LitArgs {
parts := strings.Split(arg, "=")
option := strings.TrimLeft(parts[0], "--")
Expand Down Expand Up @@ -417,6 +439,28 @@ func NewNode(t *testing.T, cfg *LitNodeConfig,
cfg.LitTLSCertPath = filepath.Join(cfg.LitDir, "tls.cert")
cfg.GenerateListeningPorts()

// Decide which DB backend to use.
switch *litDBBackend {
case terminal.DatabaseBackendSqlite:
cfg.DBBackend = terminal.DatabaseBackendSqlite

case terminal.DatabaseBackendPostgres:
fixture := db.NewTestPgFixture(
t, db.DefaultPostgresFixtureLifetime, true,
)
t.Cleanup(func() {
fixture.TearDown(t)
})

cfg.DBBackend = terminal.DatabaseBackendPostgres
cfg.PostgresConfig = fixture.GetConfig()

default:
cfg.DBBackend = terminal.DatabaseBackendBbolt
}

t.Logf("Using %v database backend", cfg.DBBackend)

// Generate a random UI password by reading 16 random bytes and base64
// encoding them.
var randomBytes [16]byte
Expand Down
6 changes: 5 additions & 1 deletion make/testing_flags.mk
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
include make/compile_flags.mk

ITEST_FLAGS =
TEST_FLAGS =
DEV_TAGS = dev

Expand All @@ -9,6 +8,11 @@ ifneq ($(icase),)
ITEST_FLAGS += -test.run="TestLightningTerminal/$(icase)"
endif

# Run itests with specified db backend.
ifneq ($(dbbackend),)
ITEST_FLAGS += -litdbbackend=$(dbbackend)
endif

# If a specific unit test case is being targeted, construct test.run filter.
ifneq ($(case),)
TEST_FLAGS += -test.run=$(case)
Expand Down
19 changes: 10 additions & 9 deletions terminal.go
Original file line number Diff line number Diff line change
Expand Up @@ -216,7 +216,7 @@ type LightningTerminal struct {
middleware *mid.Manager
middlewareStarted bool

accountsStore *accounts.BoltStore
accountsStore accounts.Store
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🎉

accountService *accounts.InterceptorService
accountServiceStarted bool

Expand Down Expand Up @@ -415,10 +415,14 @@ func (g *LightningTerminal) start(ctx context.Context) error {
)
}

g.accountsStore, err = accounts.NewBoltStore(
filepath.Dir(g.cfg.MacaroonPath), accounts.DBFilename,
clock.NewDefaultClock(),
)
networkDir := filepath.Join(g.cfg.LitDir, g.cfg.Network)
err = makeDirectories(networkDir)
if err != nil {
return fmt.Errorf("could not create network directory: %v", err)
}

clock := clock.NewDefaultClock()
g.accountsStore, err = NewAccountStore(g.cfg, clock)
if err != nil {
return fmt.Errorf("error creating accounts store: %w", err)
}
Expand All @@ -445,10 +449,7 @@ func (g *LightningTerminal) start(ctx context.Context) error {
g.ruleMgrs = rules.NewRuleManagerSet()

// Create an instance of the local Terminal Connect session store DB.
networkDir := filepath.Join(g.cfg.LitDir, g.cfg.Network)
g.sessionDB, err = session.NewDB(
networkDir, session.DBFilename, clock.NewDefaultClock(),
)
g.sessionDB, err = session.NewDB(networkDir, session.DBFilename, clock)
if err != nil {
return fmt.Errorf("error creating session DB: %v", err)
}
Expand Down