test: avoid chain notifier mock deadlock

Release the mock LND lock before sending the initial block height. A
concurrent height notification can fill the buffered channel. Holding
the lock while sending would then block invoice lookups and make the
static loop-in test time out.
This commit is contained in:
Boris Nagaev 2026-08-11 11:56:04 -05:00
parent aa79fa5262
commit c5837506ea
No known key found for this signature in database

View file

@ -129,13 +129,18 @@ func (c *mockChainNotifier) RegisterBlockEpochNtfn(ctx context.Context) (
}
}()
// Send initial block height
// Snapshot the initial block height while holding the lock, but
// release it before sending. The buffered channel may already contain
// a concurrent height notification, and blocking on a full channel
// while holding the lock would deadlock other mock LND calls.
c.lnd.lock.Lock()
currentHeight := c.lnd.Height
c.lnd.lock.Unlock()
select {
case blockEpochChan <- c.lnd.Height:
case blockEpochChan <- currentHeight:
case <-ctx.Done():
}
c.lnd.lock.Unlock()
<-ctx.Done()
})