Skip to content

Commit 98e2697

Browse files
committed
supplyverifier+tapcfg: add supply verifier manager config validation
1 parent 1703846 commit 98e2697

File tree

2 files changed

+48
-3
lines changed

2 files changed

+48
-3
lines changed

tapcfg/server.go

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -549,7 +549,7 @@ func genServerConfig(cfg *Config, cfgLogger btclog.Logger,
549549

550550
// Set up the supply verifier, which validates supply commitment leaves
551551
// published by asset issuers.
552-
supplyVerifyManager := supplyverifier.NewManager(
552+
supplyVerifyManager, err := supplyverifier.NewManager(
553553
supplyverifier.ManagerCfg{
554554
Chain: chainBridge,
555555
AssetLookup: tapdbAddrBook,
@@ -561,6 +561,10 @@ func genServerConfig(cfg *Config, cfgLogger btclog.Logger,
561561
DaemonAdapters: lndFsmDaemonAdapters,
562562
},
563563
)
564+
if err != nil {
565+
return nil, fmt.Errorf("unable to create supply verifier: %w",
566+
err)
567+
}
564568

565569
// For the porter, we'll make a multi-notifier comprised of all the
566570
// possible proof file sources to ensure it can always fetch input

universe/supplyverifier/manager.go

Lines changed: 43 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,43 @@ type ManagerCfg struct {
8484
ErrChan chan<- error
8585
}
8686

87+
// Validate validates the ManagerCfg.
88+
func (m *ManagerCfg) Validate() error {
89+
if m.Chain == nil {
90+
return fmt.Errorf("chain is required")
91+
}
92+
93+
if m.AssetLookup == nil {
94+
return fmt.Errorf("asset lookup is required")
95+
}
96+
97+
if m.Lnd == nil {
98+
return fmt.Errorf("lnd is required")
99+
}
100+
101+
if m.SupplyCommitView == nil {
102+
return fmt.Errorf("supply commit view is required")
103+
}
104+
105+
if m.SupplyTreeView == nil {
106+
return fmt.Errorf("supply tree view is required")
107+
}
108+
109+
if m.GroupFetcher == nil {
110+
return fmt.Errorf("group fetcher is required")
111+
}
112+
113+
if m.IssuanceSubscriptions == nil {
114+
return fmt.Errorf("issuance subscriptions is required")
115+
}
116+
117+
if m.DaemonAdapters == nil {
118+
return fmt.Errorf("daemon adapters is required")
119+
}
120+
121+
return nil
122+
}
123+
87124
// Manager is a manager for multiple supply verifier state machines, one for
88125
// each asset group. It is responsible for starting and stopping the state
89126
// machines, as well as forwarding events to them.
@@ -104,14 +141,18 @@ type Manager struct {
104141
}
105142

106143
// NewManager creates a new multi state machine manager.
107-
func NewManager(cfg ManagerCfg) *Manager {
144+
func NewManager(cfg ManagerCfg) (*Manager, error) {
145+
if err := cfg.Validate(); err != nil {
146+
return nil, fmt.Errorf("invalid config: %w", err)
147+
}
148+
108149
return &Manager{
109150
cfg: cfg,
110151
ContextGuard: &fn.ContextGuard{
111152
DefaultTimeout: DefaultTimeout,
112153
Quit: make(chan struct{}),
113154
},
114-
}
155+
}, nil
115156
}
116157

117158
// InitStateMachines initializes state machines for all asset groups that

0 commit comments

Comments
 (0)