@@ -23,6 +23,9 @@ type Manager struct {
23
23
// activeReservations contains all the active reservationsFSMs.
24
24
activeReservations map [ID ]* FSM
25
25
26
+ // hasL402 is true if the client has a valid L402.
27
+ hasL402 bool
28
+
26
29
runCtx context.Context
27
30
28
31
sync.Mutex
@@ -155,16 +158,39 @@ func (m *Manager) newReservation(ctx context.Context, currentHeight uint32,
155
158
return reservationFSM , nil
156
159
}
157
160
161
+ // fetchL402 fetches the L402 from the server. This method will keep on
162
+ // retrying until it gets a valid response.
163
+ func (m * Manager ) fetchL402 (ctx context.Context ) {
164
+ // Add a 0 timer so that we initially fetch the L402 immediately.
165
+ timer := time .NewTimer (0 )
166
+ for {
167
+ select {
168
+ case <- ctx .Done ():
169
+ return
170
+
171
+ case <- timer .C :
172
+ err := m .cfg .FetchL402 (ctx )
173
+ if err != nil {
174
+ log .Warnf ("Error fetching L402: %v" , err )
175
+ timer .Reset (time .Second * 10 )
176
+ continue
177
+ }
178
+ m .hasL402 = true
179
+ return
180
+ }
181
+ }
182
+ }
183
+
158
184
// RegisterReservationNotifications registers a new reservation notification
159
185
// stream.
160
186
func (m * Manager ) RegisterReservationNotifications (
161
187
reservationChan chan * reservationrpc.ServerReservationNotification ) error {
162
188
163
189
// In order to create a valid lsat we first are going to call
164
- // the FetchL402 method.
165
- err := m . cfg . FetchL402 ( m . runCtx )
166
- if err != nil {
167
- return err
190
+ // the FetchL402 method. As a client might not have outbound capacity
191
+ // yet, we'll retry until we get a valid response.
192
+ if ! m . hasL402 {
193
+ m . fetchL402 ( m . runCtx )
168
194
}
169
195
170
196
ctx , cancel := context .WithCancel (m .runCtx )
0 commit comments