diff --git a/cmd/lotus-chainwatch/blockssub.go b/cmd/lotus-chainwatch/blockssub.go
index 9c5957f67..2147639a3 100644
--- a/cmd/lotus-chainwatch/blockssub.go
+++ b/cmd/lotus-chainwatch/blockssub.go
@@ -21,7 +21,7 @@ func subBlocks(ctx context.Context, api aapi.FullNode, st *storage) {
bh.Cid(): bh,
}, false)
if err != nil {
- log.Error(err)
+ //log.Errorf("%+v", err)
}
}
}
diff --git a/cmd/lotus-chainwatch/dot.go b/cmd/lotus-chainwatch/dot.go
index b3490d749..e898f7cc3 100644
--- a/cmd/lotus-chainwatch/dot.go
+++ b/cmd/lotus-chainwatch/dot.go
@@ -26,7 +26,7 @@ var dotCmd = &cli.Command{
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)
+where b.height > $1 and b.height < $2`, minH, maxH)
if err != nil {
return err
@@ -34,6 +34,8 @@ where b.height > ? and b.height < ?`, minH, maxH)
fmt.Println("digraph D {")
+ hl := st.hasList()
+
for res.Next() {
var block, parent, miner string
var height, ph uint64
@@ -46,7 +48,7 @@ where b.height > ? and b.height < ?`, minH, maxH)
return err
}
- has := st.hasBlock(bc)
+ _, has := hl[bc]
col := crc32.Checksum([]byte(miner), crc32.MakeTable(crc32.Castagnoli))&0xc0c0c0c0 + 0x30303030
diff --git a/cmd/lotus-chainwatch/main.go b/cmd/lotus-chainwatch/main.go
index 0b7365d8b..4e67706fd 100644
--- a/cmd/lotus-chainwatch/main.go
+++ b/cmd/lotus-chainwatch/main.go
@@ -38,7 +38,7 @@ func main() {
&cli.StringFlag{
Name: "db",
EnvVars: []string{"LOTUS_DB"},
- Value: "./chainwatch.db",
+ Value: "",
},
},
@@ -82,8 +82,6 @@ var runCmd = &cli.Command{
defer st.close()
runSyncer(ctx, api, st)
- go subMpool(ctx, api, st)
- go subBlocks(ctx, api, st)
h, err := newHandler(api, st)
if err != nil {
diff --git a/cmd/lotus-chainwatch/mpool.go b/cmd/lotus-chainwatch/mpool.go
index ce9e39b84..ea45380b7 100644
--- a/cmd/lotus-chainwatch/mpool.go
+++ b/cmd/lotus-chainwatch/mpool.go
@@ -2,6 +2,7 @@ package main
import (
"context"
+ "time"
"github.com/ipfs/go-cid"
@@ -15,24 +16,45 @@ func subMpool(ctx context.Context, api aapi.FullNode, st *storage) {
return
}
- for change := range sub {
- if change.Type != aapi.MpoolAdd {
- continue
+ for {
+ var updates []aapi.MpoolUpdate
+
+ select {
+ case update := <-sub:
+ updates = append(updates, update)
+ case <-ctx.Done():
+ return
}
- log.Info("mpool message")
+ loop:
+ for {
+ time.Sleep(10 * time.Millisecond)
+ select {
+ case update := <-sub:
+ updates = append(updates, update)
+ default:
+ break loop
+ }
+ }
- err := st.storeMessages(map[cid.Cid]*types.Message{
- change.Message.Message.Cid(): &change.Message.Message,
- })
+ msgs := map[cid.Cid]*types.Message{}
+ for _, v := range updates {
+ if v.Type != aapi.MpoolAdd {
+ continue
+ }
+
+ msgs[v.Message.Message.Cid()] = &v.Message.Message
+ }
+
+ log.Infof("Processing %d mpool updates", len(msgs))
+
+ err := st.storeMessages(msgs)
if err != nil {
log.Error(err)
- continue
}
- if err := st.storeMpoolInclusion(change.Message.Message.Cid()); err != nil {
+ if err := st.storeMpoolInclusions(updates); err != nil {
log.Error(err)
- continue
}
}
}
diff --git a/cmd/lotus-chainwatch/site/block.html b/cmd/lotus-chainwatch/site/block.html
new file mode 100644
index 000000000..9d247b88b
--- /dev/null
+++ b/cmd/lotus-chainwatch/site/block.html
@@ -0,0 +1,61 @@
+
+
+
+ Lotus ChainWatch
+
+
+
+{{$cid := param "cid"}}
+
+
+
+
+
+
Miner: {{index (strings "blocks" "miner" "cid=$1" $cid) 0}}
+
Parents:
+
+ {{range strings "block_parents" "parent" "block=$1" $cid}}
+ {{$parent := .}}
+
{{. | substr 54 62}}
+ {{end}}
+
+
Messages:
+
+ {{range strings "block_messages" "message" "block=$1" $cid}}
+ {{$msg := .}}
+
+ {{$msg | substr 54 62}} |
+
+ {{$from := qstr "select \"from\" from messages where cid=$1" $msg}}
+ {{$nonce := qstr "select nonce from messages where cid=$1" $msg}}
+ {{$from}} (N:{{$nonce}})
+ |
+ -> |
+
+ {{$to := qstr "select \"to\" from messages where cid=$1" $msg}}
+ {{$to}}
+ |
+
+ Method:{{qstr "select method from messages where cid=$1" $msg}}
+ |
+ {{$rec := qstrs `select r.exit, r.gas_used from messages
+ inner join block_messages bm on messages.cid = bm.message
+ inner join blocks b on bm.block = b.cid
+ inner join block_parents bp on b.cid = bp.parent
+ inner join blocks chd on bp.block = chd.cid
+ inner join receipts r on messages.cid = r.msg and chd.parentStateRoot = r.state
+ where messages.cid=$1 and b.cid=$2` 2 $msg $cid}}
+ exit:{{index $rec 0}} |
+ gasUsed:{{index $rec 1}} |
+
+ {{end}}
+
+
+
+
+
+
\ No newline at end of file
diff --git a/cmd/lotus-chainwatch/site/blocks.html b/cmd/lotus-chainwatch/site/blocks.html
new file mode 100644
index 000000000..296d0d460
--- /dev/null
+++ b/cmd/lotus-chainwatch/site/blocks.html
@@ -0,0 +1,43 @@
+
+
+
+ Lotus ChainWatch
+
+
+
+{{$start := param "start" | parseInt}}
+
+
+
+
+
+
+ {{range pageDown $start 50}}
+
+
+ {{$h := .}}
+ {{$h}};
+ |
+
+ {{qstr `select count(distinct block_messages.message) from block_messages
+ inner join blocks b on block_messages.block = b.cid
+ where b.height = $1` $h}} Msgs
+ |
+
+ {{range strings "blocks" "cid" "height = $1" $h}}
+ {{. | substr 54 62}}
+ {{end}}
+ |
+
+ {{end}}
+
+
Next 50
+
+
+
+
+
diff --git a/cmd/lotus-chainwatch/site/index.html b/cmd/lotus-chainwatch/site/index.html
index 1a1c2813a..315ba5705 100644
--- a/cmd/lotus-chainwatch/site/index.html
+++ b/cmd/lotus-chainwatch/site/index.html
@@ -26,6 +26,11 @@
{{count "id_address_map" "id != address"}} Keys;
E% FIL in wallets; F% FIL in miners; M% in market; %G Other actors; %H FIL it treasury
+
+ {{$maxH := queryNum "select max(height) from blocks inner join blocks_synced bs on blocks.cid = bs.cid"}}
+
+ {{count "blocks"}}
Blocks; Current Height: {{$maxH}};
+