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:
Roei Erez
2020-04-30 12:54:33 +03:00
parent cfe0babd78
commit ae2c37e043
11 changed files with 75 additions and 0 deletions

View File

@@ -40,6 +40,7 @@ type NeutrinoNotifier struct {
epochClientCounter uint64 // To be used atomically.
start sync.Once
active int32 // To be used atomically.
stopped int32 // To be used atomically.
bestBlockMtx sync.RWMutex
@@ -144,6 +145,11 @@ func (n *NeutrinoNotifier) Stop() error {
return nil
}
// Started returns true if this instance has been started, and false otherwise.
func (n *NeutrinoNotifier) Started() bool {
return atomic.LoadInt32(&n.active) != 0
}
func (n *NeutrinoNotifier) startNotifier() error {
// Start our concurrent queues before starting the rescan, to ensure
// onFilteredBlockConnected and onRelavantTx callbacks won't be
@@ -200,6 +206,10 @@ func (n *NeutrinoNotifier) startNotifier() error {
n.wg.Add(1)
go n.notificationDispatcher()
// Set the active flag now that we've completed the full
// startup.
atomic.StoreInt32(&n.active, 1)
return nil
}