diff --git a/loopd/daemon.go b/loopd/daemon.go index a7db601b..6c72440c 100644 --- a/loopd/daemon.go +++ b/loopd/daemon.go @@ -504,8 +504,8 @@ func (d *Daemon) initialize(withMacaroonService bool) error { // Start the notification manager. notificationCfg := ¬ifications.Config{ - Client: loop_swaprpc.NewSwapServerClient(swapClient.Conn), - FetchL402: swapClient.Server.FetchL402, + Client: loop_swaprpc.NewSwapServerClient(swapClient.Conn), + CurrentToken: swapClient.L402Store.CurrentToken, } notificationManager := notifications.NewManager(notificationCfg) diff --git a/notifications/manager.go b/notifications/manager.go index ac6e16a8..114ff87a 100644 --- a/notifications/manager.go +++ b/notifications/manager.go @@ -5,6 +5,7 @@ import ( "sync" "time" + "github.com/lightninglabs/aperture/l402" "github.com/lightninglabs/loop/swapserverrpc" "google.golang.org/grpc" ) @@ -37,8 +38,9 @@ type Config struct { // Client is the client used to communicate with the swap server. Client Client - // FetchL402 is the function used to fetch the l402 token. - FetchL402 func(context.Context) error + // CurrentToken returns the token that is currently contained in the + // store or an l402.ErrNoToken error if there is none. + CurrentToken func() (*l402.Token, error) } // Manager is a manager for notifications that the swap server sends to the @@ -113,9 +115,13 @@ func (m *Manager) Run(ctx context.Context) error { // the FetchL402 method. As a client might not have outbound capacity // yet, we'll retry until we get a valid response. if !m.hasL402 { - err := m.cfg.FetchL402(ctx) + _, err := m.cfg.CurrentToken() if err != nil { - log.Errorf("Error fetching L402: %v", err) + // We only log the error if it's not the case that we + // don't have a token yet to avoid spamming the logs. + if err != l402.ErrNoToken { + log.Errorf("Error getting L402 from store: %v", err) + } continue } m.hasL402 = true diff --git a/notifications/manager_test.go b/notifications/manager_test.go index ea756ff6..82af5e67 100644 --- a/notifications/manager_test.go +++ b/notifications/manager_test.go @@ -7,6 +7,7 @@ import ( "testing" "time" + "github.com/lightninglabs/aperture/l402" "github.com/lightninglabs/loop/swapserverrpc" "github.com/stretchr/testify/require" "google.golang.org/grpc" @@ -101,9 +102,9 @@ func TestManager_ReservationNotification(t *testing.T) { // Create a Manager with the mock client mgr := NewManager(&Config{ Client: mockClient, - FetchL402: func(ctx context.Context) error { + CurrentToken: func() (*l402.Token, error) { // Simulate successful fetching of L402 - return nil + return nil, nil }, })