Skip to content

Commit 7a091fc

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 a06bade commit 7a091fc

File tree

4 files changed

+87
-2
lines changed

4 files changed

+87
-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
@@ -237,6 +237,13 @@ type Config struct {
237237
// over an in-memory connection on startup. This is only set in
238238
// integrated lnd mode.
239239
lndAdminMacaroon []byte
240+
241+
// DevConfig is a config struct that is empty if lit is built without
242+
// the `dev` flag (in other words when it is build for a production
243+
// environment). This allows us to have config values that are then
244+
// only available in development mode which lets us run itests against
245+
// features not yet available in production.
246+
*DevConfig
240247
}
241248

242249
// lndConnectParams returns the connection parameters to connect to the local
@@ -337,8 +344,9 @@ func defaultConfig() *Config {
337344
Autopilot: &autopilotserver.Config{
338345
PingCadence: time.Hour,
339346
},
340-
Firewall: firewall.DefaultConfig(),
341-
Accounts: &accounts.Config{},
347+
Firewall: firewall.DefaultConfig(),
348+
Accounts: &accounts.Config{},
349+
DevConfig: defaultDevConfig(),
342350
}
343351
}
344352

@@ -467,6 +475,11 @@ func loadAndValidateConfig(interceptor signal.Interceptor) (*Config, error) {
467475
)
468476
}
469477

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

config_dev.go

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
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, clock clock.Clock) (accounts.Store, error) {
35+
return accounts.NewBoltStore(
36+
filepath.Dir(cfg.MacaroonPath), accounts.DBFilename, clock,
37+
)
38+
}

config_prod.go

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
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, clock clock.Clock) (accounts.Store, error) {
30+
return accounts.NewBoltStore(
31+
filepath.Dir(cfg.MacaroonPath), accounts.DBFilename, clock,
32+
)
33+
}

0 commit comments

Comments
 (0)