OSDN Git Service

fix bug for websocket (#1508)
authorwz <mars@bytom.io>
Thu, 6 Dec 2018 08:42:12 +0000 (16:42 +0800)
committerPaladz <yzhu101@uottawa.ca>
Thu, 6 Dec 2018 08:42:12 +0000 (16:42 +0800)
net/websocket/wsnotificationmaneger.go

index 6030d9a..87ac8ff 100644 (file)
@@ -170,7 +170,8 @@ func (m *WSNotificationManager) sendNotification(typ NotificationType, data inte
                        log.WithField("module", logModule).Error("Chain connected notification is not a block")
                        break
                }
-
+               m.status.BestHeight = block.Height
+               m.status.BestHash = block.Hash()
                // Notify registered websocket clients of incoming block.
                m.NotifyBlockConnected(block)
 
@@ -180,7 +181,8 @@ func (m *WSNotificationManager) sendNotification(typ NotificationType, data inte
                        log.WithField("module", logModule).Error("Chain disconnected notification is not a block")
                        break
                }
-
+               m.status.BestHeight = block.Height - 1
+               m.status.BestHash = block.PreviousBlockHash
                // Notify registered websocket clients.
                m.NotifyBlockDisconnected(block)
        }
@@ -407,7 +409,7 @@ out:
                                log.WithFields(log.Fields{"module": logModule, "err": err}).Error("blockNotify GetBlockByHash")
                                return
                        }
-                       m.updateStatus(block)
+
                        m.sendNotification(NTRawBlockDisconnected, block)
                }
 
@@ -422,7 +424,6 @@ out:
                        continue
                }
 
-               m.updateStatus(block)
                m.sendNotification(NTRawBlockConnected, block)
        }
        m.wg.Done()
@@ -435,11 +436,6 @@ func (m *WSNotificationManager) blockWaiter() {
        }
 }
 
-func (m *WSNotificationManager) updateStatus(block *types.Block) {
-       m.status.BestHeight = block.Height
-       m.status.BestHash = block.Hash()
-}
-
 // Start starts the goroutines required for the manager to queue and process websocket client notifications.
 func (m *WSNotificationManager) Start() {
        m.wg.Add(3)