lnrpc/watchtowerrpc: prevent watchtowerrpc panic when tower not active

This commit is contained in:
Conner Fromknecht 2019-07-02 22:03:16 +00:00 committed by Conner Fromknecht
parent 36983214e8
commit f727b94e12
No known key found for this signature in database
GPG Key ID: E7D737B67FA592C7
3 changed files with 7 additions and 1 deletions

@ -7,6 +7,9 @@ package watchtowerrpc
// fields with struct tags are meant to parsed as normal configuration options, // fields with struct tags are meant to parsed as normal configuration options,
// while if able to be populated, the latter fields MUST also be specified. // while if able to be populated, the latter fields MUST also be specified.
type Config struct { type Config struct {
// Active indicates if the watchtower is enabled.
Active bool
// Tower is the active watchtower which serves as the primary source for // Tower is the active watchtower which serves as the primary source for
// information presented via RPC. // information presented via RPC.
Tower WatchtowerBackend Tower WatchtowerBackend

@ -124,7 +124,7 @@ func (c *Handler) GetInfo(ctx context.Context,
// isActive returns nil if the tower backend is initialized, and the Handler can // isActive returns nil if the tower backend is initialized, and the Handler can
// proccess RPC requests. // proccess RPC requests.
func (c *Handler) isActive() error { func (c *Handler) isActive() error {
if c.cfg.Tower != nil { if c.cfg.Active {
return nil return nil
} }
return ErrTowerNotActive return ErrTowerNotActive

@ -216,6 +216,9 @@ func (s *subRPCServerConfigs) PopulateDependencies(cc *chainControl,
case *watchtowerrpc.Config: case *watchtowerrpc.Config:
subCfgValue := extractReflectValue(subCfg) subCfgValue := extractReflectValue(subCfg)
subCfgValue.FieldByName("Active").Set(
reflect.ValueOf(tower != nil),
)
subCfgValue.FieldByName("Tower").Set( subCfgValue.FieldByName("Tower").Set(
reflect.ValueOf(tower), reflect.ValueOf(tower),
) )