mirror of
https://github.com/LBRYFoundation/lbcwallet.git
synced 2025-09-01 17:55:15 +00:00
Merge pull request #526 from wpaulino/improve-bitcoind-zmq-errors
chain: improve bitcoind zmq errors
This commit is contained in:
commit
635b1bb9b2
2 changed files with 41 additions and 16 deletions
|
@ -549,7 +549,8 @@ func (c *BitcoindClient) ntfnHandler() {
|
||||||
select {
|
select {
|
||||||
case tx := <-c.zmqTxNtfns:
|
case tx := <-c.zmqTxNtfns:
|
||||||
if _, _, err := c.filterTx(tx, nil, true); err != nil {
|
if _, _, err := c.filterTx(tx, nil, true); err != nil {
|
||||||
log.Error(err)
|
log.Errorf("Unable to filter transaction %v: %v",
|
||||||
|
tx.TxHash(), err)
|
||||||
}
|
}
|
||||||
case newBlock := <-c.zmqBlockNtfns:
|
case newBlock := <-c.zmqBlockNtfns:
|
||||||
// If the new block's previous hash matches the best
|
// If the new block's previous hash matches the best
|
||||||
|
@ -566,7 +567,8 @@ func (c *BitcoindClient) ntfnHandler() {
|
||||||
newBlock, newBlockHeight, true,
|
newBlock, newBlockHeight, true,
|
||||||
)
|
)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Error(err)
|
log.Errorf("Unable to filter block %v: %v",
|
||||||
|
newBlock.BlockHash(), err)
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -168,7 +168,7 @@ func (c *BitcoindConn) blockEventHandler(conn *gozmq.Conn) {
|
||||||
defer c.wg.Done()
|
defer c.wg.Done()
|
||||||
defer conn.Close()
|
defer conn.Close()
|
||||||
|
|
||||||
log.Info("Started listening for bitcoind block notifications via ZMQ ",
|
log.Info("Started listening for bitcoind block notifications via ZMQ "+
|
||||||
"on", c.zmqBlockHost)
|
"on", c.zmqBlockHost)
|
||||||
|
|
||||||
for {
|
for {
|
||||||
|
@ -180,16 +180,18 @@ func (c *BitcoindConn) blockEventHandler(conn *gozmq.Conn) {
|
||||||
default:
|
default:
|
||||||
}
|
}
|
||||||
|
|
||||||
// Poll an event from the ZMQ socket. It's possible that the
|
// Poll an event from the ZMQ socket.
|
||||||
// connection to the socket continuously times out, so we'll
|
|
||||||
// prevent logging this error to prevent spamming the logs.
|
|
||||||
msgBytes, err := conn.Receive()
|
msgBytes, err := conn.Receive()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
err, ok := err.(net.Error)
|
// It's possible that the connection to the socket
|
||||||
if !ok || !err.Timeout() {
|
// continuously times out, so we'll prevent logging this
|
||||||
log.Error(err)
|
// error to prevent spamming the logs.
|
||||||
|
netErr, ok := err.(net.Error)
|
||||||
|
if ok && netErr.Timeout() {
|
||||||
|
continue
|
||||||
}
|
}
|
||||||
|
|
||||||
|
log.Errorf("Unable to receive ZMQ message: %v", err)
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -219,6 +221,14 @@ func (c *BitcoindConn) blockEventHandler(conn *gozmq.Conn) {
|
||||||
}
|
}
|
||||||
c.rescanClientsMtx.Unlock()
|
c.rescanClientsMtx.Unlock()
|
||||||
default:
|
default:
|
||||||
|
// It's possible that the message wasn't fully read if
|
||||||
|
// bitcoind shuts down, which will produce an unreadable
|
||||||
|
// event type. To prevent from logging it, we'll make
|
||||||
|
// sure it conforms to the ASCII standard.
|
||||||
|
if !isASCII(eventType) {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
|
||||||
log.Warnf("Received unexpected event type from "+
|
log.Warnf("Received unexpected event type from "+
|
||||||
"rawblock subscription: %v", eventType)
|
"rawblock subscription: %v", eventType)
|
||||||
}
|
}
|
||||||
|
@ -234,7 +244,7 @@ func (c *BitcoindConn) txEventHandler(conn *gozmq.Conn) {
|
||||||
defer conn.Close()
|
defer conn.Close()
|
||||||
|
|
||||||
log.Info("Started listening for bitcoind transaction notifications "+
|
log.Info("Started listening for bitcoind transaction notifications "+
|
||||||
"via ZMQ on ", c.zmqTxHost)
|
"via ZMQ on", c.zmqTxHost)
|
||||||
|
|
||||||
for {
|
for {
|
||||||
// Before attempting to read from the ZMQ socket, we'll make
|
// Before attempting to read from the ZMQ socket, we'll make
|
||||||
|
@ -245,16 +255,18 @@ func (c *BitcoindConn) txEventHandler(conn *gozmq.Conn) {
|
||||||
default:
|
default:
|
||||||
}
|
}
|
||||||
|
|
||||||
// Poll an event from the ZMQ socket. It's possible that the
|
// Poll an event from the ZMQ socket.
|
||||||
// connection to the socket continuously times out, so we'll
|
|
||||||
// prevent logging this error to prevent spamming the logs.
|
|
||||||
msgBytes, err := conn.Receive()
|
msgBytes, err := conn.Receive()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
err, ok := err.(net.Error)
|
// It's possible that the connection to the socket
|
||||||
if !ok || !err.Timeout() {
|
// continuously times out, so we'll prevent logging this
|
||||||
log.Error(err)
|
// error to prevent spamming the logs.
|
||||||
|
netErr, ok := err.(net.Error)
|
||||||
|
if ok && netErr.Timeout() {
|
||||||
|
continue
|
||||||
}
|
}
|
||||||
|
|
||||||
|
log.Errorf("Unable to receive ZMQ message: %v", err)
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -360,3 +372,14 @@ func (c *BitcoindConn) RemoveClient(id uint64) {
|
||||||
|
|
||||||
delete(c.rescanClients, id)
|
delete(c.rescanClients, id)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// isASCII is a helper method that checks whether all bytes in `data` would be
|
||||||
|
// printable ASCII characters if interpreted as a string.
|
||||||
|
func isASCII(s string) bool {
|
||||||
|
for _, c := range s {
|
||||||
|
if c < 32 || c > 126 {
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
|
Loading…
Add table
Reference in a new issue