@@ -32,6 +32,10 @@ const (
3232 // DefaultTransitionTimeout is the default timeout for transitions in
3333 // the deposit state machine.
3434 DefaultTransitionTimeout = 5 * time .Second
35+
36+ // PollInterval is the interval in which we poll for new deposits to our
37+ // static address.
38+ PollInterval = 10 * time .Second
3539)
3640
3741// ManagerConfig holds the configuration for the address manager.
@@ -116,14 +120,16 @@ func (m *Manager) Run(ctx context.Context, initChan chan struct{}) error {
116120 return err
117121 }
118122
119- // Initially reconcile new deposits after a restart, so we catch up with
120- // missed deposits while we were offline.
121- if err = m .reconcileDeposits (ctx ); err != nil {
123+ // Reconcile immediately on startup so deposits are available
124+ // before the first ticker fires.
125+ err = m .reconcileDeposits (ctx )
126+ if err != nil {
122127 log .Errorf ("unable to reconcile deposits: %v" , err )
123-
124- return err
125128 }
126129
130+ // Start the deposit notifier.
131+ m .pollDeposits (ctx )
132+
127133 // Communicate to the caller that the address manager has completed its
128134 // initialization.
129135 close (initChan )
@@ -151,15 +157,6 @@ func (m *Manager) Run(ctx context.Context, initChan chan struct{}) error {
151157 }
152158 }
153159
154- // Reconcile new deposits that might have just gotten
155- // confirmed.
156- if err = m .reconcileDeposits (ctx ); err != nil {
157- log .Errorf ("unable to reconcile deposits: %v" ,
158- err )
159-
160- return err
161- }
162-
163160 case outpoint := <- m .finalizedDepositChan :
164161 // If deposits notify us about their finalization, flush
165162 // the finalized deposit from memory.
@@ -224,6 +221,30 @@ func (m *Manager) recoverDeposits(ctx context.Context) error {
224221 return nil
225222}
226223
224+ // pollDeposits polls new deposits to our static address and notifies the
225+ // manager's event loop about them.
226+ func (m * Manager ) pollDeposits (ctx context.Context ) {
227+ log .Debugf ("Waiting for new static address deposits..." )
228+
229+ go func () {
230+ ticker := time .NewTicker (PollInterval )
231+ defer ticker .Stop ()
232+ for {
233+ select {
234+ case <- ticker .C :
235+ err := m .reconcileDeposits (ctx )
236+ if err != nil {
237+ log .Errorf ("unable to reconcile " +
238+ "deposits: %v" , err )
239+ }
240+
241+ case <- ctx .Done ():
242+ return
243+ }
244+ }
245+ }()
246+ }
247+
227248// reconcileDeposits fetches all spends to our static addresses from our lnd
228249// wallet and matches it against the deposits in our memory that we've seen so
229250// far. It picks the newly identified deposits and starts a state machine per
0 commit comments