Skip to content

Commit a79c59d

Browse files
committed
config: introduce the concept of DevConfig
In this commit, we introduce a DevConfig struct which is embedded in the main lit Config struct. It is defined in two separate files that are made mutually exclusive using the `dev` build tag. The idea of this struct is that it allows us to expose additional config options to LiT if we build in a development environment such as our itests. In other words, we will be able to start developing features and testing them before making them available to users via the production build. As of this commit, both implementations of the struct are the same.
1 parent 9207179 commit a79c59d

File tree

4 files changed

+89
-2
lines changed

4 files changed

+89
-2
lines changed

.golangci.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ run:
1111
- watchtowerrpc
1212
- neutrinorpc
1313
- peersrpc
14+
- dev
1415

1516
linters-settings:
1617
govet:

config.go

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -235,6 +235,13 @@ type Config struct {
235235
// over an in-memory connection on startup. This is only set in
236236
// integrated lnd mode.
237237
lndAdminMacaroon []byte
238+
239+
// DevConfig is a config struct that is empty if lit is built without
240+
// the `dev` flag (in other words when it is build for a production
241+
// environment). This allows us to have config values that are then
242+
// only available in development mode which lets us run itests against
243+
// features not yet available in production.
244+
*DevConfig
238245
}
239246

240247
// lndConnectParams returns the connection parameters to connect to the local
@@ -335,8 +342,9 @@ func defaultConfig() *Config {
335342
Autopilot: &autopilotserver.Config{
336343
PingCadence: time.Hour,
337344
},
338-
Firewall: firewall.DefaultConfig(),
339-
Accounts: &accounts.Config{},
345+
Firewall: firewall.DefaultConfig(),
346+
Accounts: &accounts.Config{},
347+
DevConfig: defaultDevConfig(),
340348
}
341349
}
342350

@@ -465,6 +473,11 @@ func loadAndValidateConfig(interceptor signal.Interceptor) (*Config, error) {
465473
)
466474
}
467475

476+
err = cfg.DevConfig.Validate(litDir, cfg.Network)
477+
if err != nil {
478+
return nil, err
479+
}
480+
468481
// Initiate our listeners. For now, we only support listening on one
469482
// port at a time because we can only pass in one pre-configured RPC
470483
// listener into lnd.

config_dev.go

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
//go:build dev
2+
3+
package terminal
4+
5+
import (
6+
"path/filepath"
7+
8+
"github.com/lightninglabs/lightning-terminal/accounts"
9+
"github.com/lightningnetwork/lnd/clock"
10+
)
11+
12+
// DevConfig is a struct that holds the configuration options for a development
13+
// environment. The purpose of this struct is to hold config options for
14+
// features not yet available in production. Since our itests are built with
15+
// the dev tag, we can test these features in our itests.
16+
//
17+
// nolint:lll
18+
type DevConfig struct {
19+
}
20+
21+
// Validate checks that all the values set in our DevConfig are valid and uses
22+
// the passed parameters to override any defaults if necessary.
23+
func (c *DevConfig) Validate(dbDir, network string) error {
24+
return nil
25+
}
26+
27+
// defaultDevConfig returns a new DevConfig with default values set.
28+
func defaultDevConfig() *DevConfig {
29+
return &DevConfig{}
30+
}
31+
32+
// NewAccountStore creates a new account store based on the chosen database
33+
// backend.
34+
func NewAccountStore(cfg *Config) (accounts.Store, error) {
35+
return accounts.NewBoltStore(
36+
filepath.Dir(cfg.MacaroonPath), accounts.DBFilename,
37+
clock.NewDefaultClock(),
38+
)
39+
}

config_prod.go

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
//go:build !dev
2+
3+
package terminal
4+
5+
import (
6+
"path/filepath"
7+
8+
"github.com/lightninglabs/lightning-terminal/accounts"
9+
"github.com/lightningnetwork/lnd/clock"
10+
)
11+
12+
// DevConfig is an empty shell struct that allows us to build without the dev
13+
// tag. This struct is embedded in the main Config struct, and it adds no new
14+
// functionality in a production build.
15+
type DevConfig struct{}
16+
17+
// defaultDevConfig returns an empty DevConfig struct.
18+
func defaultDevConfig() *DevConfig {
19+
return &DevConfig{}
20+
}
21+
22+
// Validate is a no-op function during a production build.
23+
func (c *DevConfig) Validate(_, _ string) error {
24+
return nil
25+
}
26+
27+
// NewAccountStore creates a new account store using the default Bolt backend
28+
// since in production, this is the only backend supported currently.
29+
func NewAccountStore(cfg *Config) (accounts.Store, error) {
30+
return accounts.NewBoltStore(
31+
filepath.Dir(cfg.MacaroonPath), accounts.DBFilename,
32+
clock.NewDefaultClock(),
33+
)
34+
}

0 commit comments

Comments
 (0)