Skip to content

Commit 8b818b9

Browse files
committed
(fixup) quitChan
1 parent 3747d69 commit 8b818b9

File tree

2 files changed

+12
-13
lines changed

2 files changed

+12
-13
lines changed

staticaddr/deposit/fsm.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -141,6 +141,7 @@ type FSM struct {
141141

142142
blockNtfnChan chan uint32
143143

144+
// quitChan stops after the FSM stops consuming blockNtfnChan.
144145
quitChan chan struct{}
145146

146147
finalizedDepositChan chan wire.OutPoint
@@ -195,16 +196,15 @@ func NewFSM(ctx context.Context, deposit *Deposit, cfg *ManagerConfig,
195196
depoFsm.ActionEntryFunc = depoFsm.updateDeposit
196197

197198
go func() {
199+
defer close(depoFsm.quitChan)
200+
198201
for {
199202
select {
200203
case currentHeight := <-depoFsm.blockNtfnChan:
201204
depoFsm.handleBlockNotification(
202205
ctx, currentHeight,
203206
)
204207

205-
case <-depoFsm.quitChan:
206-
return
207-
208208
case <-ctx.Done():
209209
return
210210
}

staticaddr/deposit/manager.go

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -132,31 +132,30 @@ func (m *Manager) Run(ctx context.Context) error {
132132
case height := <-newBlockChan:
133133
// Inform all active deposits about a new block arrival.
134134
m.mu.Lock()
135+
activeDeposits := make([]*FSM, 0, len(m.activeDeposits))
135136
for _, fsm := range m.activeDeposits {
137+
activeDeposits = append(activeDeposits, fsm)
138+
}
139+
m.mu.Unlock()
140+
141+
for _, fsm := range activeDeposits {
136142
select {
137143
case fsm.blockNtfnChan <- uint32(height):
138144

145+
case <-fsm.quitChan:
146+
continue
147+
139148
case <-ctx.Done():
140149
return ctx.Err()
141150
}
142151
}
143-
m.mu.Unlock()
144152

145153
case outpoint := <-m.finalizedDepositChan:
146154
// If deposits notify us about their finalization, we
147155
// quit the block notification handler of the fsm,
148156
// update the manager's internal state and flush the
149157
// finalized deposit from memory.
150158
m.mu.Lock()
151-
if fsm := m.activeDeposits[outpoint]; fsm != nil {
152-
select {
153-
case fsm.quitChan <- struct{}{}:
154-
155-
case <-ctx.Done():
156-
return ctx.Err()
157-
}
158-
}
159-
160159
delete(m.activeDeposits, outpoint)
161160
m.mu.Unlock()
162161

0 commit comments

Comments
 (0)