chain/bitcoind: connect to zmq in Start() to return error

This commit is contained in:
Conner Fromknecht 2018-01-16 17:14:26 -08:00 committed by Olaoluwa Osuntokun
parent 2c34216319
commit 2bd4130581

View file

@ -359,13 +359,20 @@ func (c *BitcoindClient) Start() error {
return errors.New("mismatched networks") return errors.New("mismatched networks")
} }
// Connect a ZMQ socket for block notifications
zmqClient, err := gozmq.Subscribe(c.zmqConnect, []string{"rawblock",
"rawtx"}, c.zmqPollInterval)
if err != nil {
return err
}
c.quitMtx.Lock() c.quitMtx.Lock()
c.started = true c.started = true
c.quitMtx.Unlock() c.quitMtx.Unlock()
c.wg.Add(2) c.wg.Add(2)
go c.handler() go c.handler()
go c.socketHandler() go c.socketHandler(zmqClient)
return nil return nil
} }
@ -508,17 +515,10 @@ func (c *BitcoindClient) onRescanFinished(hash *chainhash.Hash, height int32, bl
// socketHandler reads events from the ZMQ socket, processes them as // socketHandler reads events from the ZMQ socket, processes them as
// appropriate, and queues them as btcd or neutrino would. // appropriate, and queues them as btcd or neutrino would.
func (c *BitcoindClient) socketHandler() { func (c *BitcoindClient) socketHandler(zmqClient *gozmq.Conn) {
defer c.wg.Done() defer c.wg.Done()
// Connect a ZMQ socket for block notifications
zmqClient, err := gozmq.Subscribe(c.zmqConnect, []string{"rawblock",
"rawtx"}, c.zmqPollInterval)
if err != nil {
log.Error(err)
return
}
defer zmqClient.Close() defer zmqClient.Close()
log.Infof("Started listening for blocks via ZMQ on %s", c.zmqConnect) log.Infof("Started listening for blocks via ZMQ on %s", c.zmqConnect)
c.onClientConnect() c.onClientConnect()