diff --git a/loopd/daemon.go b/loopd/daemon.go index 12e2c2192..f0882892d 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,48 @@ func (d *Daemon) initialize(withMacaroonService bool) error { } } + // Start the notification manager. + notificationCfg := ¬ifications.Config{ + Client: loop_swaprpc.NewSwapServerClient(swapClient.Conn), + } + notificationManager := notifications.NewManager(notificationCfg) + + d.wg.Add(1) + notificationInitChan := make(chan struct{}) + go func() { + defer d.wg.Done() + err = notificationManager.Run(d.mainCtx, notificationInitChan) + if err != nil { + d.internalErrChan <- err + } + }() + + select { + case <-notificationInitChan: + break + case <-time.After(15 * time.Second): + return fmt.Errorf("notification manager not ready") + case <-d.mainCtx.Done(): + return fmt.Errorf("notification manager not ready: %v", d.mainCtx.Err()) + } + 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