Skip to content

Commit 4f5d84c

Browse files
committed
staticaddr: poll deposits on block arrival
In this commit we remove the ticker-based polling of new deposits as this is wasteful, and we replace it by polling on the arrival of new blocks.
1 parent cef0fae commit 4f5d84c

File tree

1 file changed

+16
-22
lines changed

1 file changed

+16
-22
lines changed

staticaddr/deposit/manager.go

Lines changed: 16 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -119,17 +119,18 @@ func (m *Manager) Run(ctx context.Context, initChan chan struct{}) error {
119119
return err
120120
}
121121

122-
// Start the deposit notifier.
123-
m.pollDeposits(ctx)
124-
125122
// Communicate to the caller that the address manager has completed its
126123
// initialization.
127124
close(initChan)
128125

129126
for {
130127
select {
131128
case height := <-newBlockChan:
132-
// Inform all active deposits about a new block arrival.
129+
// Poll for new deposits and spin up fsms for them.
130+
go m.pollDeposits(ctx)
131+
132+
// Now inform all active deposits about a new block
133+
// arrival.
133134
m.mu.Lock()
134135
activeDeposits := make([]*FSM, 0, len(m.activeDeposits))
135136
for _, fsm := range m.activeDeposits {
@@ -213,28 +214,21 @@ func (m *Manager) recoverDeposits(ctx context.Context) error {
213214
return nil
214215
}
215216

216-
// pollDeposits polls new deposits to our static address and notifies the
217-
// manager's event loop about them.
217+
// pollDeposits polls new deposits to our static addresses.
218218
func (m *Manager) pollDeposits(ctx context.Context) {
219-
log.Debugf("Waiting for new static address deposits...")
219+
log.Debugf("Polling new static address deposits...")
220220

221-
go func() {
222-
ticker := time.NewTicker(PollInterval)
223-
defer ticker.Stop()
224-
for {
225-
select {
226-
case <-ticker.C:
227-
err := m.reconcileDeposits(ctx)
228-
if err != nil {
229-
log.Errorf("unable to reconcile "+
230-
"deposits: %v", err)
231-
}
221+
select {
222+
case <-ctx.Done():
223+
return
232224

233-
case <-ctx.Done():
234-
return
235-
}
225+
default:
226+
err := m.reconcileDeposits(ctx)
227+
if err != nil {
228+
log.Errorf("unable to reconcile deposits: %v",
229+
err)
236230
}
237-
}()
231+
}
238232
}
239233

240234
// reconcileDeposits fetches all spends to our static address from our lnd

0 commit comments

Comments
 (0)