From 6e7de3c8d922b4b75db0ba1f80f2c676c4b36e4f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Albert=C2=B7Gou?= Date: Fri, 11 Sep 2020 16:52:48 +0800 Subject: [PATCH 1/3] optimize definition of state_heights In the same parentstateroot, the one with the smallest height should be selected --- cmd/lotus-chainwatch/syncer/sync.go | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/cmd/lotus-chainwatch/syncer/sync.go b/cmd/lotus-chainwatch/syncer/sync.go index 52a36fc9e..306cf8b3e 100644 --- a/cmd/lotus-chainwatch/syncer/sync.go +++ b/cmd/lotus-chainwatch/syncer/sync.go @@ -136,7 +136,8 @@ create unique index if not exists block_cid_uindex on blocks (cid,height); create materialized view if not exists state_heights - as select distinct height, parentstateroot from blocks; + as select b.parentstateroot, min(b.height) height + from blocks b group by b.parentstateroot; create index if not exists state_heights_height_index on state_heights (height); From e45a7749b0d03c98fef4dd160edefff89306fe42 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Albert=C2=B7Gou?= Date: Mon, 14 Sep 2020 16:20:01 +0800 Subject: [PATCH 2/3] Update sync.go --- cmd/lotus-chainwatch/syncer/sync.go | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/cmd/lotus-chainwatch/syncer/sync.go b/cmd/lotus-chainwatch/syncer/sync.go index 306cf8b3e..19ceddda9 100644 --- a/cmd/lotus-chainwatch/syncer/sync.go +++ b/cmd/lotus-chainwatch/syncer/sync.go @@ -5,6 +5,7 @@ import ( "context" "database/sql" "fmt" + cid "github.com/ipfs/go-cid/_rsrch/cidiface" "sync" "time" @@ -136,7 +137,7 @@ create unique index if not exists block_cid_uindex on blocks (cid,height); create materialized view if not exists state_heights - as select b.parentstateroot, min(b.height) height + as select min(b.height) height, b.parentstateroot from blocks b group by b.parentstateroot; create index if not exists state_heights_height_index From 747b34c2c89d83b91bdb45d279e58c4329aa181a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Albert=C2=B7Gou?= Date: Mon, 14 Sep 2020 18:00:17 +0800 Subject: [PATCH 3/3] Update sync.go --- cmd/lotus-chainwatch/syncer/sync.go | 1 - 1 file changed, 1 deletion(-) diff --git a/cmd/lotus-chainwatch/syncer/sync.go b/cmd/lotus-chainwatch/syncer/sync.go index 19ceddda9..609b71088 100644 --- a/cmd/lotus-chainwatch/syncer/sync.go +++ b/cmd/lotus-chainwatch/syncer/sync.go @@ -5,7 +5,6 @@ import ( "context" "database/sql" "fmt" - cid "github.com/ipfs/go-cid/_rsrch/cidiface" "sync" "time"