chainsync: make batch size configurable

This commit is contained in:
Travis Person 2020-02-21 18:49:49 +00:00
parent ec50048a29
commit 837dd0d241
2 changed files with 11 additions and 7 deletions

View File

@ -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 {

View File

@ -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
}