Skip to content

Commit 3924318

Browse files
committed
staticaddr: quit deposit fsm handler when finialized
1 parent 14f6f26 commit 3924318

File tree

2 files changed

+17
-0
lines changed

2 files changed

+17
-0
lines changed

staticaddr/deposit/fsm.go

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

142142
blockNtfnChan chan uint32
143143

144+
quitChan chan struct{}
145+
144146
finalizedDepositChan chan wire.OutPoint
145147
}
146148

@@ -167,6 +169,7 @@ func NewFSM(ctx context.Context, deposit *Deposit, cfg *ManagerConfig,
167169
params: params,
168170
address: address,
169171
blockNtfnChan: make(chan uint32),
172+
quitChan: make(chan struct{}),
170173
finalizedDepositChan: finalizedDepositChan,
171174
}
172175

@@ -199,6 +202,9 @@ func NewFSM(ctx context.Context, deposit *Deposit, cfg *ManagerConfig,
199202
ctx, currentHeight,
200203
)
201204

205+
case <-depoFsm.quitChan:
206+
return
207+
202208
case <-ctx.Done():
203209
return
204210
}

staticaddr/deposit/manager.go

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -141,10 +141,21 @@ func (m *Manager) Run(ctx context.Context) error {
141141
}
142142
}
143143
m.mu.Unlock()
144+
144145
case outpoint := <-m.finalizedDepositChan:
145146
// If deposits notify us about their finalization, we
147+
// quit the block notification handler of the fsm,
146148
// update the manager's internal state and flush the
147149
// finalized deposit from memory.
150+
if fsm := m.activeDeposits[outpoint]; fsm != nil {
151+
select {
152+
case fsm.quitChan <- struct{}{}:
153+
154+
case <-ctx.Done():
155+
return ctx.Err()
156+
}
157+
}
158+
148159
m.mu.Lock()
149160
delete(m.activeDeposits, outpoint)
150161
m.mu.Unlock()

0 commit comments

Comments
 (0)