diff --git a/chain/blocksync/client.go b/chain/blocksync/client.go index f5a88a525..38e1f6d2c 100644 --- a/chain/blocksync/client.go +++ b/chain/blocksync/client.go @@ -308,6 +308,12 @@ func (client *BlockSync) GetChainMessages( length uint64, ) ([]*CompactedMessages, error) { ctx, span := trace.StartSpan(ctx, "GetChainMessages") + if span.IsRecordingEvents() { + span.AddAttributes( + trace.StringAttribute("tipset", fmt.Sprint(head.Cids())), + trace.Int64Attribute("count", int64(length)), + ) + } defer span.End() req := &Request{ diff --git a/chain/sync.go b/chain/sync.go index b0ae185b0..eae5dfcff 100644 --- a/chain/sync.go +++ b/chain/sync.go @@ -7,6 +7,7 @@ import ( "fmt" "os" "sort" + "strconv" "strings" "time" @@ -52,6 +53,19 @@ import ( //the theoretical max height based on systime are quickly rejected const MaxHeightDrift = 5 +var defaultMessageFetchWindowSize = 200 + +func init() { + if s := os.Getenv("LOTUS_BSYNC_MSG_WINDOW"); s != "" { + val, err := strconv.Atoi(s) + if err != nil { + log.Errorf("failed to parse LOTUS_BSYNC_MSG_WINDOW: %s", err) + return + } + defaultMessageFetchWindowSize = val + } +} + var log = logging.Logger("chain") var LocalIncoming = "incoming" @@ -1399,7 +1413,7 @@ func (syncer *Syncer) iterFullTipsets(ctx context.Context, headers []*types.TipS span.AddAttributes(trace.Int64Attribute("num_headers", int64(len(headers)))) - windowSize := 200 + windowSize := defaultMessageFetchWindowSize for i := len(headers) - 1; i >= 0; { fts, err := syncer.store.TryFillTipSet(headers[i]) if err != nil { diff --git a/documentation/en/environment-vars.md b/documentation/en/environment-vars.md index f5247af1a..9d455a74d 100644 --- a/documentation/en/environment-vars.md +++ b/documentation/en/environment-vars.md @@ -48,6 +48,11 @@ block heights that are very far from the current chain height, you may want to increase this. +### `LOTUS_BSYNC_MSG_WINDOW` + +Set the initial maximum window size for message fetching blocksync requests. If +you have a slower internet connection and are having trouble syncing, you might +try lowering this down to 10-20 for a 'poor' internet connection. ## Lotus Miner