From 53ba22943659f54991022d4f0e4aff2c5c80cdf5 Mon Sep 17 00:00:00 2001 From: Elle Mouton Date: Mon, 7 Apr 2025 09:34:26 +0200 Subject: [PATCH] lnd: pass context to `newServer` and `server.Start` In preparation for starting to thread a single parent context through LND, we update the main `server.Start` method to take a context so that it can later pass it to any subsytem's Start method it calls. We also pass the context to `newServer` since it makes some calls that will eventually reach the DB (for example the graph db). --- lnd.go | 4 ++-- server.go | 6 ++++-- 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/lnd.go b/lnd.go index e63ddc196..3afa8c2fb 100644 --- a/lnd.go +++ b/lnd.go @@ -626,7 +626,7 @@ func Main(cfg *Config, lisCfg ListenerCfg, implCfg *ImplementationCfg, // Set up the core server which will listen for incoming peer // connections. server, err := newServer( - cfg, cfg.Listeners, dbs, activeChainControl, &idKeyDesc, + ctx, cfg, cfg.Listeners, dbs, activeChainControl, &idKeyDesc, activeChainControl.Cfg.WalletUnlockParams.ChansToRestore, multiAcceptor, torController, tlsManager, leaderElector, implCfg, @@ -758,7 +758,7 @@ func Main(cfg *Config, lisCfg ListenerCfg, implCfg *ImplementationCfg, // case the startup of the subservers do not behave as expected. errChan := make(chan error) go func() { - errChan <- server.Start() + errChan <- server.Start(ctx) }() defer func() { diff --git a/server.go b/server.go index 3a077a28f..aa0ad4e5f 100644 --- a/server.go +++ b/server.go @@ -554,7 +554,9 @@ func noiseDial(idKey keychain.SingleKeyECDH, // newServer creates a new instance of the server which is to listen using the // passed listener address. -func newServer(cfg *Config, listenAddrs []net.Addr, +// +//nolint:funlen +func newServer(_ context.Context, cfg *Config, listenAddrs []net.Addr, dbs *DatabaseInstances, cc *chainreg.ChainControl, nodeKeyDesc *keychain.KeyDescriptor, chansToRestore walletunlocker.ChannelsToRecover, @@ -2217,7 +2219,7 @@ func (s *server) startLowLevelServices() error { // NOTE: This function is safe for concurrent access. // //nolint:funlen -func (s *server) Start() error { +func (s *server) Start(_ context.Context) error { // Get the current blockbeat. beat, err := s.getStartingBeat() if err != nil {