diff --git a/cmd/lotus-chainwatch/main.go b/cmd/lotus-chainwatch/main.go index 6d6340b64..033956c86 100644 --- a/cmd/lotus-chainwatch/main.go +++ b/cmd/lotus-chainwatch/main.go @@ -60,6 +60,10 @@ var runCmd = &cli.Command{ Name: "front", Value: "127.0.0.1:8418", }, + &cli.IntFlag{ + Name: "max-batch", + Value: 1000, + }, }, Action: func(cctx *cli.Context) error { api, closer, err := lcli.GetFullNodeAPI(cctx) @@ -76,13 +80,15 @@ var runCmd = &cli.Command{ log.Info("Remote version: %s", v.Version) + maxBatch := cctx.Int("max-batch") + st, err := openStorage(cctx.String("db")) if err != nil { return err } defer st.close() - runSyncer(ctx, api, st) + runSyncer(ctx, api, st, maxBatch) h, err := newHandler(api, st) if err != nil { diff --git a/cmd/lotus-chainwatch/sync.go b/cmd/lotus-chainwatch/sync.go index a9c4415c1..547fd0d45 100644 --- a/cmd/lotus-chainwatch/sync.go +++ b/cmd/lotus-chainwatch/sync.go @@ -18,9 +18,7 @@ import ( "github.com/filecoin-project/lotus/chain/types" ) -const maxBatch = 3000 - -func runSyncer(ctx context.Context, api api.FullNode, st *storage) { +func runSyncer(ctx context.Context, api api.FullNode, st *storage, maxBatch int) { notifs, err := api.ChainNotify(ctx) if err != nil { panic(err) @@ -32,7 +30,7 @@ func runSyncer(ctx context.Context, api api.FullNode, st *storage) { case store.HCCurrent: fallthrough case store.HCApply: - syncHead(ctx, api, st, change.Val) + syncHead(ctx, api, st, change.Val, maxBatch) case store.HCRevert: log.Warnf("revert todo") } @@ -65,7 +63,7 @@ type actorInfo struct { state string } -func syncHead(ctx context.Context, api api.FullNode, st *storage, ts *types.TipSet) { +func syncHead(ctx context.Context, api api.FullNode, st *storage, ts *types.TipSet, maxBatch int) { var alk sync.Mutex log.Infof("Getting synced block list") @@ -123,7 +121,7 @@ func syncHead(ctx context.Context, api api.FullNode, st *storage, ts *types.TipS toSync := map[cid.Cid]*types.BlockHeader{} for c, header := range allToSync { - if header.Height < minH+maxBatch { + if header.Height < minH+uint64(maxBatch) { toSync[c] = header addresses[header.Miner] = address.Undef }