chainwatch: show null blocks

This commit is contained in:
Łukasz Magiera 2019-12-18 18:40:05 +01:00
parent 7fd31192d2
commit 9f886a7eb0

View File

@ -23,7 +23,11 @@ var dotCmd = &cli.Command{
tosee, err := strconv.ParseInt(cctx.Args().Get(1), 10, 32) tosee, err := strconv.ParseInt(cctx.Args().Get(1), 10, 32)
maxH := minH + tosee maxH := minH + tosee
res, err := st.db.Query("select block, parent, b.miner, b.height from block_parents inner join blocks b on block_parents.block = b.cid where b.height > ? and b.height < ?", minH, maxH) res, err := st.db.Query(`select block, parent, b.miner, b.height, p.height from block_parents
inner join blocks b on block_parents.block = b.cid
inner join blocks p on block_parents.parent = p.cid
where b.height > ? and b.height < ?`, minH, maxH)
if err != nil { if err != nil {
return err return err
} }
@ -32,8 +36,8 @@ var dotCmd = &cli.Command{
for res.Next() { for res.Next() {
var block, parent, miner string var block, parent, miner string
var height uint64 var height, ph uint64
if err := res.Scan(&block, &parent, &miner, &height); err != nil { if err := res.Scan(&block, &parent, &miner, &height, &ph); err != nil {
return err return err
} }
@ -48,10 +52,20 @@ var dotCmd = &cli.Command{
hasstr := "" hasstr := ""
if !has { if !has {
col = 0xffffffff //col = 0xffffffff
hasstr = " UNSYNCED" hasstr = " UNSYNCED"
} }
nulls := height - ph - 1
for i := uint64(0); i < nulls; i++ {
name := block+"NP"+fmt.Sprint(i)
fmt.Printf("%s [label = \"NULL:%d\", fillcolor = \"#ffddff\", style=filled, forcelabels=true]\n%s -> %s\n",
name, height - nulls + i, name, parent)
parent = name
}
fmt.Printf("%s [label = \"%s:%d%s\", fillcolor = \"#%06x\", style=filled, forcelabels=true]\n%s -> %s\n", block, miner, height, hasstr, col, block, parent) fmt.Printf("%s [label = \"%s:%d%s\", fillcolor = \"#%06x\", style=filled, forcelabels=true]\n%s -> %s\n", block, miner, height, hasstr, col, block, parent)
} }
if res.Err() != nil { if res.Err() != nil {