mirror of
https://github.com/lightningnetwork/lnd.git
synced 2025-09-06 17:47:01 +02:00
Ensure chain notifier is started before accessed.
The use case comes from the RPC layer that is ready before the chain notifier which is used in the sub server.
This commit is contained in:
@@ -35,6 +35,7 @@ type BitcoindNotifier struct {
|
||||
epochClientCounter uint64 // To be used atomically.
|
||||
|
||||
start sync.Once
|
||||
active int32 // To be used atomically.
|
||||
stopped int32 // To be used atomically.
|
||||
|
||||
chainConn *chain.BitcoindClient
|
||||
@@ -130,6 +131,11 @@ func (b *BitcoindNotifier) Stop() error {
|
||||
return nil
|
||||
}
|
||||
|
||||
// Started returns true if this instance has been started, and false otherwise.
|
||||
func (b *BitcoindNotifier) Started() bool {
|
||||
return atomic.LoadInt32(&b.active) != 0
|
||||
}
|
||||
|
||||
func (b *BitcoindNotifier) startNotifier() error {
|
||||
// Connect to bitcoind, and register for notifications on connected,
|
||||
// and disconnected blocks.
|
||||
@@ -158,6 +164,10 @@ func (b *BitcoindNotifier) startNotifier() error {
|
||||
b.wg.Add(1)
|
||||
go b.notificationDispatcher()
|
||||
|
||||
// Set the active flag now that we've completed the full
|
||||
// startup.
|
||||
atomic.StoreInt32(&b.active, 1)
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user