Skip to content

Commit 9160f84

Browse files
committed
notifications: handle pending L402 payment
1 parent 43aa566 commit 9160f84

File tree

2 files changed

+23
-4
lines changed

2 files changed

+23
-4
lines changed

notifications/manager.go

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import (
77

88
"github.com/lightninglabs/aperture/l402"
99
"github.com/lightninglabs/loop/swapserverrpc"
10+
"github.com/lightningnetwork/lnd/lntypes"
1011
"google.golang.org/grpc"
1112
)
1213

@@ -169,7 +170,7 @@ func (m *Manager) Run(ctx context.Context) error {
169170
// the FetchL402 method. As a client might not have outbound
170171
// capacity yet, we'll retry until we get a valid response.
171172
if !m.hasL402 {
172-
_, err := m.cfg.CurrentToken()
173+
token, err := m.cfg.CurrentToken()
173174
if err != nil {
174175
// We only log the error if it's not the case
175176
// that we don't have a token yet to avoid
@@ -180,6 +181,15 @@ func (m *Manager) Run(ctx context.Context) error {
180181
}
181182
continue
182183
}
184+
185+
// If the preimage is empty, we don't have a valid L402
186+
// yet so we'll continue to retry with the incremental
187+
// backoff.
188+
emptyPreimage := lntypes.Preimage{}
189+
if token.Preimage == emptyPreimage {
190+
continue
191+
}
192+
183193
m.hasL402 = true
184194
}
185195

notifications/manager_test.go

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ import (
1010

1111
"github.com/lightninglabs/aperture/l402"
1212
"github.com/lightninglabs/loop/swapserverrpc"
13+
"github.com/lightningnetwork/lnd/lntypes"
1314
"github.com/stretchr/testify/require"
1415
"google.golang.org/grpc"
1516
"google.golang.org/grpc/metadata"
@@ -111,7 +112,9 @@ func TestManager_ReservationNotification(t *testing.T) {
111112
Client: mockClient,
112113
CurrentToken: func() (*l402.Token, error) {
113114
// Simulate successful fetching of L402
114-
return nil, nil
115+
return &l402.Token{
116+
Preimage: lntypes.Preimage{1, 2, 3},
117+
}, nil
115118
},
116119
})
117120

@@ -208,7 +211,10 @@ func TestManager_Backoff(t *testing.T) {
208211
mgr := NewManager(&Config{
209212
Client: mockClient,
210213
CurrentToken: func() (*l402.Token, error) {
211-
return &l402.Token{}, nil
214+
// Simulate successful fetching of L402
215+
return &l402.Token{
216+
Preimage: lntypes.Preimage{1, 2, 3},
217+
}, nil
212218
},
213219
})
214220

@@ -297,7 +303,10 @@ func TestManager_MinAliveConnTime(t *testing.T) {
297303
Client: mockClient,
298304
MinAliveConnTime: minAlive,
299305
CurrentToken: func() (*l402.Token, error) {
300-
return &l402.Token{}, nil
306+
// Simulate successful fetching of L402
307+
return &l402.Token{
308+
Preimage: lntypes.Preimage{1, 2, 3},
309+
}, nil
301310
},
302311
})
303312

0 commit comments

Comments
 (0)