Merge pull request #564 from filecoin-project/feat/add-time-to-townhall
add time of block acceptance to townhall
This commit is contained in:
commit
7906be5a4e
@ -3,6 +3,7 @@ package metrics
|
|||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
|
"time"
|
||||||
|
|
||||||
"github.com/ipfs/go-cid"
|
"github.com/ipfs/go-cid"
|
||||||
logging "github.com/ipfs/go-log"
|
logging "github.com/ipfs/go-log"
|
||||||
@ -69,6 +70,7 @@ type message struct {
|
|||||||
Blocks []*types.BlockHeader
|
Blocks []*types.BlockHeader
|
||||||
Height uint64
|
Height uint64
|
||||||
Weight types.BigInt
|
Weight types.BigInt
|
||||||
|
Time uint64
|
||||||
|
|
||||||
// Meta
|
// Meta
|
||||||
|
|
||||||
@ -100,6 +102,7 @@ func sendHeadNotifs(ctx context.Context, ps *pubsub.PubSub, topic string, chain
|
|||||||
Height: n.Val.Height(),
|
Height: n.Val.Height(),
|
||||||
Weight: w,
|
Weight: w,
|
||||||
NodeName: nickname,
|
NodeName: nickname,
|
||||||
|
Time: uint64(time.Now().UnixNano() / 1000_000),
|
||||||
}
|
}
|
||||||
|
|
||||||
b, err := json.Marshal(m)
|
b, err := json.Marshal(m)
|
||||||
|
@ -5,20 +5,21 @@ import (
|
|||||||
"context"
|
"context"
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
"fmt"
|
"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"
|
"net/http"
|
||||||
"strings"
|
"strings"
|
||||||
|
"time"
|
||||||
|
|
||||||
rice "github.com/GeertJohan/go.rice"
|
rice "github.com/GeertJohan/go.rice"
|
||||||
"github.com/gorilla/websocket"
|
"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"
|
||||||
"github.com/libp2p/go-libp2p-core/peer"
|
"github.com/libp2p/go-libp2p-core/peer"
|
||||||
pnet "github.com/libp2p/go-libp2p-pnet"
|
pnet "github.com/libp2p/go-libp2p-pnet"
|
||||||
pubsub "github.com/libp2p/go-libp2p-pubsub"
|
pubsub "github.com/libp2p/go-libp2p-pubsub"
|
||||||
|
|
||||||
|
"github.com/filecoin-project/lotus/build"
|
||||||
"github.com/filecoin-project/lotus/node/modules/lp2p"
|
"github.com/filecoin-project/lotus/node/modules/lp2p"
|
||||||
)
|
)
|
||||||
|
|
||||||
@ -90,6 +91,7 @@ func main() {
|
|||||||
type update struct {
|
type update struct {
|
||||||
From peer.ID
|
From peer.ID
|
||||||
Update json.RawMessage
|
Update json.RawMessage
|
||||||
|
Time uint64
|
||||||
}
|
}
|
||||||
|
|
||||||
func handler(ps *pubsub.PubSub) func(w http.ResponseWriter, r *http.Request) {
|
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
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fmt.Println("new conn")
|
||||||
|
|
||||||
for {
|
for {
|
||||||
msg, err := sub.Next(r.Context())
|
msg, err := sub.Next(r.Context())
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
fmt.Println(msg)
|
//fmt.Println(msg)
|
||||||
|
|
||||||
if err := conn.WriteJSON(update{
|
if err := conn.WriteJSON(update{
|
||||||
From: peer.ID(msg.From),
|
From: peer.ID(msg.From),
|
||||||
Update: msg.Data,
|
Update: msg.Data,
|
||||||
|
Time: uint64(time.Now().UnixNano() / 1000_000),
|
||||||
}); err != nil {
|
}); err != nil {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
@ -10,6 +10,21 @@ function colForH(besth, height) {
|
|||||||
return '#f00'
|
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 <span>
|
||||||
|
<span style={{color: colLag(lag)}}>{lag}</span>
|
||||||
|
<span style={{color: good ? '#f0f0f0' : '#f60'}}>ms</span>
|
||||||
|
</span>
|
||||||
|
}
|
||||||
|
|
||||||
class App extends React.Component {
|
class App extends React.Component {
|
||||||
constructor(props) {
|
constructor(props) {
|
||||||
super(props);
|
super(props);
|
||||||
@ -21,31 +36,49 @@ class App extends React.Component {
|
|||||||
console.log(ev)
|
console.log(ev)
|
||||||
let update = JSON.parse(ev.data)
|
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 = <span style={{color: wdiff < 0 ? '#f00' : '#f0f0f0'}}>{wdiff}</span>
|
||||||
|
|
||||||
this.setState( prev => ({
|
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 = {}
|
this.state = {}
|
||||||
}
|
}
|
||||||
|
|
||||||
render() {
|
render() {
|
||||||
|
if(this.state.disconnected) {
|
||||||
|
return <span>Error: disconnected</span>
|
||||||
|
}
|
||||||
|
|
||||||
let besth = Object.keys(this.state).map(k => this.state[k]).reduce((p, n) => p > n.Height ? p : n.Height, -1)
|
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)
|
let bestw = Object.keys(this.state).map(k => this.state[k]).reduce((p, n) => p > n.Weight ? p : n.Weight, -1)
|
||||||
|
|
||||||
return <table>{Object.keys(this.state).map(k => [k, this.state[k]]).map(([k, v]) => {
|
return <table>
|
||||||
|
<tr><td>PeerID</td><td>Nickname</td><td>Lag</td><td>Weight(best, prev)</td><td>Height</td><td>Blocks</td></tr>
|
||||||
|
{Object.keys(this.state).map(k => [k, this.state[k]]).map(([k, v]) => {
|
||||||
|
let mnrs = v.Blocks.map(b => <td> m:{b.Miner}({lagCol(v.Time ? v.Time - (b.Timestamp*1000) : v.utime - (b.Timestamp*1000), v.Time)})</td>)
|
||||||
|
let l = [
|
||||||
|
<td>{k}</td>,
|
||||||
|
<td>{v.NodeName}</td>,
|
||||||
|
<td>{v.Time ? lagCol(v.utime - v.Time, true) : ""}</td>,
|
||||||
|
<td style={{color: bestw !== v.Weight ? '#f00' : '#afa'}}>{v.Weight}({bestw - v.Weight}, {v.wdiff})</td>,
|
||||||
|
<td style={{color: colForH(besth, v.Height)}}>{v.Height}({besth - v.Height})</td>,
|
||||||
|
...mnrs,
|
||||||
|
]
|
||||||
|
|
||||||
let mnrs = v.Blocks.map(b => <span> m:{b.Miner}</span>)
|
|
||||||
let l = [<td>{k}</td>,
|
|
||||||
<td>{v.NodeName}</td>,
|
|
||||||
<td style={{color: bestw !== v.Weight ? '#f00' : '#afa'}}>{v.Weight}({bestw - v.Weight})</td>,
|
|
||||||
<td style={{color: colForH(besth, v.Height)}}>{v.Height}({besth - v.Height})</td>,
|
|
||||||
<td>{mnrs}</td>]
|
|
||||||
l = <tr>{l}</tr>
|
l = <tr>{l}</tr>
|
||||||
|
|
||||||
return l
|
return l
|
||||||
})
|
})
|
||||||
}</table>
|
}
|
||||||
|
</table>
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
export default App;
|
export default App;
|
||||||
|
Loading…
Reference in New Issue
Block a user