staticaddr/deposit: factor active deposit notifications

Move active-deposit block notification fan-out into a helper.

This keeps the event loop small and gives later startup replay logic
a single path for notifying recovered deposit FSMs.
This commit is contained in:
Slyghtning 2026-07-01 12:06:11 +02:00
parent 6ce13ba8a4
commit 38dce3685f
No known key found for this signature in database
GPG key ID: F82D456EA023C9BF

View file

@ -127,24 +127,9 @@ func (m *Manager) Run(ctx context.Context, initChan chan struct{}) error {
for {
select {
case height := <-newBlockChan:
// Inform all active deposits about a new block arrival.
m.mu.Lock()
activeDeposits := make([]*FSM, 0, len(m.activeDeposits))
for _, fsm := range m.activeDeposits {
activeDeposits = append(activeDeposits, fsm)
}
m.mu.Unlock()
for _, fsm := range activeDeposits {
select {
case fsm.blockNtfnChan <- uint32(height):
case <-fsm.quitChan:
continue
case <-ctx.Done():
return ctx.Err()
}
err := m.notifyActiveDeposits(ctx, uint32(height))
if err != nil {
return err
}
case outpoint := <-m.finalizedDepositChan:
@ -161,6 +146,33 @@ func (m *Manager) Run(ctx context.Context, initChan chan struct{}) error {
}
}
// notifyActiveDeposits informs all active deposit FSMs about a new block
// height.
func (m *Manager) notifyActiveDeposits(ctx context.Context,
height uint32) error {
m.mu.Lock()
activeDeposits := make([]*FSM, 0, len(m.activeDeposits))
for _, fsm := range m.activeDeposits {
activeDeposits = append(activeDeposits, fsm)
}
m.mu.Unlock()
for _, fsm := range activeDeposits {
select {
case fsm.blockNtfnChan <- height:
case <-fsm.quitChan:
continue
case <-ctx.Done():
return ctx.Err()
}
}
return nil
}
// recoverDeposits recovers static address parameters, previous deposits and
// state machines from the database and starts the deposit notifier.
func (m *Manager) recoverDeposits(ctx context.Context) error {