vspd: Listen for dcrd notifs after startup.
Only attach the dcrd notification listener after all other startup tasks have been completed. Attaching the listener before this can result in the notification handler being invoked whilst startup tasks are still running, which isn't necessarily a problem, but it is unnecessary and makes a mess of logging.
This commit is contained in:
parent
2db761e072
commit
bd41dbee63
@ -100,44 +100,6 @@ func run() int {
|
||||
wallets := rpc.SetupWallet(cfg.walletUsers, cfg.walletPasswords, cfg.walletHosts, cfg.walletCerts, cfg.netParams.Params, rpcLog)
|
||||
defer wallets.Close()
|
||||
|
||||
// Create a channel to receive blockConnected notifications from dcrd.
|
||||
notifChan := make(chan *wire.BlockHeader)
|
||||
shutdownWg.Add(1)
|
||||
go func() {
|
||||
for {
|
||||
select {
|
||||
case <-shutdownCtx.Done():
|
||||
shutdownWg.Done()
|
||||
return
|
||||
case header := <-notifChan:
|
||||
log.Debugf("Block notification %d (%s)", header.Height, header.BlockHash().String())
|
||||
blockConnected(dcrd, wallets, db, log)
|
||||
}
|
||||
}
|
||||
}()
|
||||
|
||||
// Attach notification listener to dcrd client.
|
||||
dcrd.BlockConnectedHandler(notifChan)
|
||||
|
||||
// Loop forever attempting ensuring a dcrd connection is available, so
|
||||
// notifications are received.
|
||||
shutdownWg.Add(1)
|
||||
go func() {
|
||||
for {
|
||||
select {
|
||||
case <-shutdownCtx.Done():
|
||||
shutdownWg.Done()
|
||||
return
|
||||
case <-time.After(time.Second * 15):
|
||||
// Ensure dcrd client is still connected.
|
||||
_, _, err := dcrd.Client()
|
||||
if err != nil {
|
||||
log.Errorf("dcrd connect error: %v", err)
|
||||
}
|
||||
}
|
||||
}
|
||||
}()
|
||||
|
||||
// Ensure all data in database is present and up-to-date.
|
||||
err = db.CheckIntegrity(dcrd)
|
||||
if err != nil {
|
||||
@ -190,6 +152,44 @@ func run() int {
|
||||
return 1
|
||||
}
|
||||
|
||||
// Create a channel to receive blockConnected notifications from dcrd.
|
||||
notifChan := make(chan *wire.BlockHeader)
|
||||
shutdownWg.Add(1)
|
||||
go func() {
|
||||
for {
|
||||
select {
|
||||
case <-shutdownCtx.Done():
|
||||
shutdownWg.Done()
|
||||
return
|
||||
case header := <-notifChan:
|
||||
log.Debugf("Block notification %d (%s)", header.Height, header.BlockHash().String())
|
||||
blockConnected(dcrd, wallets, db, log)
|
||||
}
|
||||
}
|
||||
}()
|
||||
|
||||
// Attach notification listener to dcrd client.
|
||||
dcrd.BlockConnectedHandler(notifChan)
|
||||
|
||||
// Loop forever attempting ensuring a dcrd connection is available, so
|
||||
// notifications are received.
|
||||
shutdownWg.Add(1)
|
||||
go func() {
|
||||
for {
|
||||
select {
|
||||
case <-shutdownCtx.Done():
|
||||
shutdownWg.Done()
|
||||
return
|
||||
case <-time.After(time.Second * 15):
|
||||
// Ensure dcrd client is still connected.
|
||||
_, _, err := dcrd.Client()
|
||||
if err != nil {
|
||||
log.Errorf("dcrd connect error: %v", err)
|
||||
}
|
||||
}
|
||||
}
|
||||
}()
|
||||
|
||||
// Wait for shutdown tasks to complete before running deferred tasks and
|
||||
// returning.
|
||||
shutdownWg.Wait()
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user