@@ -23,6 +23,9 @@ type Manager struct {
2323 // activeReservations contains all the active reservationsFSMs.
2424 activeReservations map [ID ]* FSM
2525
26+ // hasL402 is true if the client has a valid L402.
27+ hasL402 bool
28+
2629 runCtx context.Context
2730
2831 sync.Mutex
@@ -155,16 +158,39 @@ func (m *Manager) newReservation(ctx context.Context, currentHeight uint32,
155158 return reservationFSM , nil
156159}
157160
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+
158184// RegisterReservationNotifications registers a new reservation notification
159185// stream.
160186func (m * Manager ) RegisterReservationNotifications (
161187 reservationChan chan * reservationrpc.ServerReservationNotification ) error {
162188
163189 // 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 )
168194 }
169195
170196 ctx , cancel := context .WithCancel (m .runCtx )
0 commit comments