OSDN Git Service

fix
authorHAOYUatHZ <haoyu@protonmail.com>
Sat, 31 Aug 2019 10:56:39 +0000 (18:56 +0800)
committerHAOYUatHZ <haoyu@protonmail.com>
Sat, 31 Aug 2019 10:56:39 +0000 (18:56 +0800)
toolbar/precog/database/orm/node.go
toolbar/precog/database/orm/node_liveness.go
toolbar/precog/monitor/stats.go

index 05a2cc4..c5964f6 100644 (file)
@@ -1,6 +1,7 @@
 package orm
 
 import (
+       "database/sql"
        "encoding/json"
        "errors"
        "fmt"
@@ -30,9 +31,9 @@ func (n *Node) MarshalJSON() ([]byte, error) {
                return nil, errors.New("fail to look up status")
        }
 
-       avgLantencyMS := 0
+       avgLantencyMS := uint64(0)
        if n.AvgLantencyMS.Valid {
-               avgLantencyMS = n.AvgLantencyMS.Int64
+               avgLantencyMS = uint64(n.AvgLantencyMS.Int64)
        }
 
        return json.Marshal(&struct {
@@ -40,7 +41,7 @@ func (n *Node) MarshalJSON() ([]byte, error) {
                PublicKey                string    `json:"publickey"`
                Address                  string    `json:"address"`
                BestHeight               uint64    `json:"best_height"`
-               AvgLantencyMS            int64     `json:"avg_lantency_ms"`
+               AvgLantencyMS            uint64    `json:"avg_lantency_ms"`
                LatestDailyUptimeMinutes uint64    `json:"latest_daily_uptime_minutes"`
                Status                   string    `json:"status"`
                UpdatedAt                time.Time `json:"updated_at"`
index 91ff4ce..307f8ba 100644 (file)
@@ -1,7 +1,6 @@
 package orm
 
 import (
-       "database/sql"
        "time"
 )
 
index 2dd2729..7502a13 100644 (file)
@@ -148,8 +148,8 @@ func (m *monitor) processPeerInfo(dbTx *gorm.DB, peerInfo *peers.PeerInfo) error
        latestLiveness := ormNodeLivenesses[0]
        lantencyMS := ping.Nanoseconds() / 1000
        if lantencyMS != 0 {
-               latestLiveness.AvgLantencyMS = sql.NullInt64{
-                       Int64: (latestLiveness.AvgLantencyMS.Int64*int64(latestLiveness.PongTimes) + lantencyMS) / int64(latestLiveness.PongTimes+1),
+               ormNode.AvgLantencyMS = sql.NullInt64{
+                       Int64: (ormNode.AvgLantencyMS.Int64*int64(latestLiveness.PongTimes) + lantencyMS) / int64(latestLiveness.PongTimes+1),
                        Valid: true,
                }
        }