From a4152d17761c278653933c875e6ca1e5152d0d2e Mon Sep 17 00:00:00 2001 From: sputn1ck Date: Tue, 10 Sep 2024 18:26:52 +0200 Subject: [PATCH] loopd: add notification manager This commit adds the notification manager to the loopd daemon. --- loopd/daemon.go | 43 ++++++++++++++++++++++++++++++++++++++----- loopd/log.go | 4 ++++ 2 files changed, 42 insertions(+), 5 deletions(-) diff --git a/loopd/daemon.go b/loopd/daemon.go index 12e2c2192..c0862992c 100644 --- a/loopd/daemon.go +++ b/loopd/daemon.go @@ -21,6 +21,7 @@ import ( "github.com/lightninglabs/loop/loopd/perms" "github.com/lightninglabs/loop/loopdb" loop_looprpc "github.com/lightninglabs/loop/looprpc" + "github.com/lightninglabs/loop/notifications" loop_swaprpc "github.com/lightninglabs/loop/swapserverrpc" "github.com/lightninglabs/loop/sweepbatcher" "github.com/lightningnetwork/lnd/clock" @@ -498,21 +499,53 @@ func (d *Daemon) initialize(withMacaroonService bool) error { } } + // Start the notification manager. + notificationCfg := ¬ifications.Config{ + Client: loop_swaprpc.NewSwapServerClient(swapClient.Conn), + FetchL402: d.impl.Server.FetchL402, + } + notificationManager := notifications.NewManager(notificationCfg) + + d.wg.Add(1) + initChan := make(chan struct{}) + go func() { + defer d.wg.Done() + + log.Info("Starting notification manager") + err := notificationManager.Run(d.mainCtx, initChan) + if err != nil { + d.internalErrChan <- err + log.Errorf("Notification manager stopped: %v", err) + } + }() + + select { + case <-time.After(10 * time.Second): + return fmt.Errorf("notification manager not ready") + + case <-d.mainCtx.Done(): + return nil + + case <-initChan: + } + var ( reservationManager *reservation.Manager instantOutManager *instantout.Manager ) + // Create the reservation and instantout managers. if d.cfg.EnableExperimental { reservationStore := reservation.NewSQLStore( loopdb.NewTypedStore[reservation.Querier](baseDb), ) reservationConfig := &reservation.Config{ - Store: reservationStore, - Wallet: d.lnd.WalletKit, - ChainNotifier: d.lnd.ChainNotifier, - ReservationClient: reservationClient, - FetchL402: swapClient.Server.FetchL402, + Store: reservationStore, + Wallet: d.lnd.WalletKit, + ChainNotifier: d.lnd.ChainNotifier, + ReservationClient: reservationClient, + FetchL402: swapClient.Server.FetchL402, + NotificationManager: notificationManager, } reservationManager = reservation.NewManager( diff --git a/loopd/log.go b/loopd/log.go index 970bd806b..a4f433f01 100644 --- a/loopd/log.go +++ b/loopd/log.go @@ -10,6 +10,7 @@ import ( "github.com/lightninglabs/loop/instantout/reservation" "github.com/lightninglabs/loop/liquidity" "github.com/lightninglabs/loop/loopdb" + "github.com/lightninglabs/loop/notifications" "github.com/lightninglabs/loop/sweepbatcher" "github.com/lightningnetwork/lnd" "github.com/lightningnetwork/lnd/build" @@ -48,6 +49,9 @@ func SetupLoggers(root *build.RotatingLogWriter, intercept signal.Interceptor) { lnd.AddSubLogger( root, instantout.Subsystem, intercept, instantout.UseLogger, ) + lnd.AddSubLogger( + root, notifications.Subsystem, intercept, notifications.UseLogger, + ) } // genSubLogger creates a logger for a subsystem. We provide an instance of