diff --git a/chain/metrics/consensus.go b/chain/metrics/consensus.go index 8fba65b05..e8f0d7c87 100644 --- a/chain/metrics/consensus.go +++ b/chain/metrics/consensus.go @@ -3,6 +3,7 @@ package metrics import ( "context" "encoding/json" + "time" "github.com/ipfs/go-cid" logging "github.com/ipfs/go-log" @@ -69,6 +70,7 @@ type message struct { Blocks []*types.BlockHeader Height uint64 Weight types.BigInt + Time uint64 // Meta @@ -100,6 +102,7 @@ func sendHeadNotifs(ctx context.Context, ps *pubsub.PubSub, topic string, chain Height: n.Val.Height(), Weight: w, NodeName: nickname, + Time: uint64(time.Now().UnixNano() / 1000_000), } b, err := json.Marshal(m) diff --git a/cmd/lotus-townhall/main.go b/cmd/lotus-townhall/main.go index e45b8e8e4..8e7e78008 100644 --- a/cmd/lotus-townhall/main.go +++ b/cmd/lotus-townhall/main.go @@ -5,20 +5,21 @@ import ( "context" "encoding/json" "fmt" - "github.com/filecoin-project/lotus/build" - "github.com/ipfs/go-car" - "github.com/ipfs/go-datastore" - blockstore "github.com/ipfs/go-ipfs-blockstore" "net/http" "strings" + "time" rice "github.com/GeertJohan/go.rice" "github.com/gorilla/websocket" + "github.com/ipfs/go-car" + "github.com/ipfs/go-datastore" + blockstore "github.com/ipfs/go-ipfs-blockstore" "github.com/libp2p/go-libp2p" "github.com/libp2p/go-libp2p-core/peer" pnet "github.com/libp2p/go-libp2p-pnet" pubsub "github.com/libp2p/go-libp2p-pubsub" + "github.com/filecoin-project/lotus/build" "github.com/filecoin-project/lotus/node/modules/lp2p" ) @@ -90,6 +91,7 @@ func main() { type update struct { From peer.ID Update json.RawMessage + Time uint64 } func handler(ps *pubsub.PubSub) func(w http.ResponseWriter, r *http.Request) { @@ -109,17 +111,20 @@ func handler(ps *pubsub.PubSub) func(w http.ResponseWriter, r *http.Request) { return } + fmt.Println("new conn") + for { msg, err := sub.Next(r.Context()) if err != nil { return } - fmt.Println(msg) + //fmt.Println(msg) if err := conn.WriteJSON(update{ From: peer.ID(msg.From), Update: msg.Data, + Time: uint64(time.Now().UnixNano() / 1000_000), }); err != nil { return } diff --git a/cmd/lotus-townhall/townhall/src/App.js b/cmd/lotus-townhall/townhall/src/App.js index aa6c78996..9335184e2 100644 --- a/cmd/lotus-townhall/townhall/src/App.js +++ b/cmd/lotus-townhall/townhall/src/App.js @@ -10,6 +10,21 @@ function colForH(besth, height) { return '#f00' } +function colLag(lag) { + if(lag < 100) return '#6f6' + if(lag < 400) return '#df4' + if(lag < 1000) return '#ff0' + if(lag < 4000) return '#f60' + return '#f00' +} + +function lagCol(lag, good) { + return + {lag} + ms + +} + class App extends React.Component { constructor(props) { super(props); @@ -21,31 +36,49 @@ class App extends React.Component { console.log(ev) let update = JSON.parse(ev.data) + update.Update.Weight = Number(update.Update.Weight) + + let wdiff = update.Update.Weight - (this.state[update.From] || {Weight: update.Update.Weight}).Weight + wdiff = {wdiff} + this.setState( prev => ({ - ...prev, [update.From]: update.Update, + ...prev, [update.From]: {...update.Update, utime: update.Time, wdiff: wdiff}, })) } + ws.onclose = () => { + this.setState({disconnected: true}) + } + this.state = {} } render() { + if(this.state.disconnected) { + return Error: disconnected + } + let besth = Object.keys(this.state).map(k => this.state[k]).reduce((p, n) => p > n.Height ? p : n.Height, -1) let bestw = Object.keys(this.state).map(k => this.state[k]).reduce((p, n) => p > n.Weight ? p : n.Weight, -1) - return
PeerID | Nickname | Lag | Weight(best, prev) | Height | Blocks | m:{b.Miner}({lagCol(v.Time ? v.Time - (b.Timestamp*1000) : v.utime - (b.Timestamp*1000), v.Time)}) | ) + let l = [ +{k} | , +{v.NodeName} | , +{v.Time ? lagCol(v.utime - v.Time, true) : ""} | , +{v.Weight}({bestw - v.Weight}, {v.wdiff}) | , +{v.Height}({besth - v.Height}) | , + ...mnrs, + ] - let mnrs = v.Blocks.map(b => m:{b.Miner}) - let l = [{k} | , -{v.NodeName} | , -{v.Weight}({bestw - v.Weight}) | , -{v.Height}({besth - v.Height}) | , -{mnrs} | ] l =