Skip to content

Commit d66fd09

Browse files
authored
Merge pull request #877 from ellemouton/mapSubservers
2 parents 9eb11e2 + db7d365 commit d66fd09

File tree

4 files changed

+100
-29
lines changed

4 files changed

+100
-29
lines changed

docs/release-notes/release-notes-0.13.5.md

Lines changed: 28 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,44 @@
11
# Release Notes
22

3-
# Integrated Binary Updates
4-
5-
### Lightning Terminal
3+
- [Lightning Terminal](#lightning-terminal)
4+
- [Bug Fixes](#bug-fixes)
5+
- [Functional Changes/Additions](#functional-changesadditions)
6+
- [Technical and Architectural Updates](#technical-and-architectural-updates)
7+
- [Integrated Binary Updates](#integrated-binary-updates)
8+
- [LND](#lnd)
9+
- [Loop](#loop)
10+
- [Pool](#pool)
11+
- [Faraday](#faraday)
12+
- [Taproot Assets](#taproot-assets)
13+
- [Contributors](#contributors-alphabetical-order)
14+
15+
## Lightning Terminal
16+
17+
### Bug Fixes
618

719
* [Fixed a bug](https://github.com/lightninglabs/lightning-terminal/pull/850)
820
due to google-protobuf where a channel with SCID aliases on would cause
921
terminal frontend to be unable to call the `ListChannels` RPC].
1022

11-
* Add a new [`litcli bakesupermacaroon`](https://github.com/lightninglabs/lightning-terminal/pull/858)
23+
### Functional Changes/Additions
24+
25+
* [Add a new `litcli bakesupermacaroon`](https://github.com/lightninglabs/lightning-terminal/pull/858)
1226
helper command. This new command can be used either with a LiT macaroon which
1327
has the appropriate permissions or with an LND macaroon which has the
1428
permissions required to call the LND `BakeMacaroon` call. This later case is
1529
especially useful in stateless-init mode where users will not have access to
1630
a LiT macaroon to perform this call with.
1731

18-
- [Convert litrpc package into a module](https://github.com/lightninglabs/lightning-terminal/pull/823).
32+
### Technical and Architectural Updates
33+
34+
* [Convert litrpc package into a module](https://github.com/lightninglabs/lightning-terminal/pull/823).
35+
36+
* Check internal maps before registering new sub-servers for both the
37+
[status and sub-server manager.](https://github.com/lightninglabs/lightning-terminal/pull/877)
38+
39+
### Autopilot
40+
41+
## Integrated Binary Updates
1942

2043
### LND
2144

@@ -27,8 +50,6 @@
2750

2851
### Taproot Assets
2952

30-
# Autopilot
31-
3253
# Contributors (Alphabetical Order)
3354

3455
* Andras Banki-Horvath

status/manager.go

Lines changed: 15 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -145,30 +145,38 @@ func (s *Manager) SubServerStatus(_ context.Context,
145145

146146
// RegisterSubServer will create a new sub-server entry for the Manager to
147147
// keep track of.
148-
func (s *Manager) RegisterSubServer(name string, opts ...SubServerOption) {
148+
func (s *Manager) RegisterSubServer(name string,
149+
opts ...SubServerOption) error {
150+
149151
s.mu.RLock()
150152
defer s.mu.RUnlock()
151153

152-
s.registerSubServerUnsafe(name, true, opts...)
154+
return s.registerSubServerUnsafe(name, true, opts...)
153155
}
154156

155157
// RegisterAndEnableSubServer will create a new sub-server entry for the
156158
// Manager to keep track of and will set it as enabled.
157159
func (s *Manager) RegisterAndEnableSubServer(name string,
158-
opts ...SubServerOption) {
160+
opts ...SubServerOption) error {
159161

160162
s.mu.RLock()
161163
defer s.mu.RUnlock()
162164

163-
s.registerSubServerUnsafe(name, false, opts...)
165+
return s.registerSubServerUnsafe(name, false, opts...)
164166
}
165167

166168
func (s *Manager) registerSubServerUnsafe(name string, disabled bool,
167-
opts ...SubServerOption) {
169+
opts ...SubServerOption) error {
170+
171+
_, ok := s.subServers[name]
172+
if ok {
173+
return fmt.Errorf("a subserver with name %s has already "+
174+
"been registered with the status manager", name)
175+
}
168176

169-
ss := newSubServer(disabled, opts...)
177+
s.subServers[name] = newSubServer(disabled, opts...)
170178

171-
s.subServers[name] = ss
179+
return nil
172180
}
173181

174182
// SetCustomStatus updates the custom status of the given sub-server to the

subservers/manager.go

Lines changed: 18 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ var (
3333

3434
// Manager manages a set of subServer objects.
3535
type Manager struct {
36-
servers []*subServerWrapper
36+
servers map[string]*subServerWrapper
3737
permsMgr *perms.Manager
3838
statusServer *status.Manager
3939
mu sync.RWMutex
@@ -44,30 +44,40 @@ func NewManager(permsMgr *perms.Manager,
4444
statusServer *status.Manager) *Manager {
4545

4646
return &Manager{
47+
servers: make(map[string]*subServerWrapper),
4748
permsMgr: permsMgr,
4849
statusServer: statusServer,
4950
}
5051
}
5152

5253
// AddServer adds a new subServer to the manager's set.
53-
func (s *Manager) AddServer(ss SubServer, enable bool) {
54+
func (s *Manager) AddServer(ss SubServer, enable bool) error {
5455
// Register all sub-servers with the status server.
55-
s.statusServer.RegisterSubServer(ss.Name())
56+
err := s.statusServer.RegisterSubServer(ss.Name())
57+
if err != nil {
58+
return err
59+
}
5660

5761
// If the sub-server has explicitly been disabled, then we don't add it
5862
// to the set of servers tracked by the Manager.
5963
if !enable {
60-
return
64+
return nil
6165
}
6266

6367
s.mu.Lock()
6468
defer s.mu.Unlock()
6569

70+
_, ok := s.servers[ss.Name()]
71+
if ok {
72+
return fmt.Errorf("a subserver with name %s has already "+
73+
"been registered with the subserver manager", ss.Name())
74+
}
75+
6676
// Add the enabled server to the set of servers tracked by the Manager.
67-
s.servers = append(s.servers, &subServerWrapper{
77+
s.servers[ss.Name()] = &subServerWrapper{
6878
SubServer: ss,
6979
quit: make(chan struct{}),
70-
})
80+
}
7181

7282
// Register the sub-server's permissions with the permission manager.
7383
s.permsMgr.RegisterSubServer(
@@ -76,6 +86,8 @@ func (s *Manager) AddServer(ss SubServer, enable bool) {
7686

7787
// Mark the sub-server as enabled with the status manager.
7888
s.statusServer.SetEnabled(ss.Name())
89+
90+
return nil
7991
}
8092

8193
// StartIntegratedServers starts all the manager's sub-servers that should be

terminal.go

Lines changed: 39 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -279,11 +279,22 @@ func (g *LightningTerminal) Run() error {
279279
}
280280

281281
// Register LND, LiT and Accounts with the status manager.
282-
g.statusMgr.RegisterAndEnableSubServer(
282+
err = g.statusMgr.RegisterAndEnableSubServer(
283283
subservers.LND, status.WithIsReadyOverride(lndOverride),
284284
)
285-
g.statusMgr.RegisterAndEnableSubServer(subservers.LIT)
286-
g.statusMgr.RegisterSubServer(subservers.ACCOUNTS)
285+
if err != nil {
286+
return err
287+
}
288+
289+
err = g.statusMgr.RegisterAndEnableSubServer(subservers.LIT)
290+
if err != nil {
291+
return err
292+
}
293+
294+
err = g.statusMgr.RegisterSubServer(subservers.ACCOUNTS)
295+
if err != nil {
296+
return err
297+
}
287298

288299
// Also enable the accounts subserver if it's not disabled.
289300
if !g.cfg.Accounts.Disable {
@@ -296,7 +307,10 @@ func (g *LightningTerminal) Run() error {
296307

297308
// Register our sub-servers. This must be done before the REST proxy is
298309
// set up so that the correct REST handlers are registered.
299-
g.initSubServers()
310+
err = g.initSubServers()
311+
if err != nil {
312+
return fmt.Errorf("could not initialise sub-servers: %w", err)
313+
}
300314

301315
// Construct the rpcProxy. It must be initialised before the main web
302316
// server is started.
@@ -1677,33 +1691,49 @@ func (g *LightningTerminal) validateSuperMacaroon(ctx context.Context,
16771691

16781692
// initSubServers registers the faraday and loop sub-servers with the
16791693
// subServerMgr.
1680-
func (g *LightningTerminal) initSubServers() {
1681-
g.subServerMgr.AddServer(
1694+
func (g *LightningTerminal) initSubServers() error {
1695+
err := g.subServerMgr.AddServer(
16821696
subservers.NewFaradaySubServer(
16831697
g.cfg.Faraday, g.cfg.faradayRpcConfig,
16841698
g.cfg.Remote.Faraday, g.cfg.faradayRemote,
16851699
), g.cfg.FaradayMode != ModeDisable,
16861700
)
1701+
if err != nil {
1702+
return fmt.Errorf("could not register Faraday subserver: %w",
1703+
err)
1704+
}
16871705

1688-
g.subServerMgr.AddServer(
1706+
err = g.subServerMgr.AddServer(
16891707
subservers.NewLoopSubServer(
16901708
g.cfg.Loop, g.cfg.Remote.Loop, g.cfg.loopRemote,
16911709
), g.cfg.LoopMode != ModeDisable,
16921710
)
1711+
if err != nil {
1712+
return fmt.Errorf("could not register Loop subserver: %w", err)
1713+
}
16931714

1694-
g.subServerMgr.AddServer(
1715+
err = g.subServerMgr.AddServer(
16951716
subservers.NewPoolSubServer(
16961717
g.cfg.Pool, g.cfg.Remote.Pool, g.cfg.poolRemote,
16971718
), g.cfg.PoolMode != ModeDisable,
16981719
)
1720+
if err != nil {
1721+
return fmt.Errorf("could not register Pool subserver: %w", err)
1722+
}
16991723

1700-
g.subServerMgr.AddServer(
1724+
err = g.subServerMgr.AddServer(
17011725
subservers.NewTaprootAssetsSubServer(
17021726
g.cfg.Network, g.cfg.TaprootAssets,
17031727
g.cfg.Remote.TaprootAssets,
17041728
g.cfg.tapRemote, g.cfg.lndRemote,
17051729
), g.cfg.TaprootAssetsMode != ModeDisable,
17061730
)
1731+
if err != nil {
1732+
return fmt.Errorf("could not register Taproot Assets "+
1733+
"subserver: %w", err)
1734+
}
1735+
1736+
return nil
17071737
}
17081738

17091739
// BakeSuperMacaroon uses the lnd client to bake a macaroon that can include

0 commit comments

Comments
 (0)