Skip to content

Commit 6635a21

Browse files
authored
Merge pull request #7360 from onflow/peter/7338-allow-stream-start-before-indexed-sealed-v0.40
[Access] Allow small gap between streaming start and indexed height - v0.40
2 parents 2649d21 + 3f1cf33 commit 6635a21

File tree

1 file changed

+13
-2
lines changed

1 file changed

+13
-2
lines changed

engine/access/subscription/tracker/execution_data_tracker.go

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,14 @@ import (
2121
"github.com/onflow/flow-go/utils/logging"
2222
)
2323

24+
const (
25+
// maxIndexBlockDiff is the maximum difference between the highest indexed block height and the
26+
// provided start height to allow when starting a new stream.
27+
// this is used to account for small delays indexing or requests made to different ANs behind a
28+
// load balancer. The diff will result in the stream waiting a few blocks before starting.
29+
maxIndexBlockDiff = 30
30+
)
31+
2432
// ExecutionDataTracker is an interface for tracking the highest consecutive block height for which we have received a
2533
// new Execution Data notification
2634
type ExecutionDataTracker interface {
@@ -273,8 +281,11 @@ func (e *ExecutionDataTrackerImpl) checkStartHeight(height uint64) (uint64, erro
273281
return 0, status.Errorf(codes.InvalidArgument, "start height %d is lower than lowest indexed height %d", height, lowestHeight)
274282
}
275283

276-
if height > highestHeight {
277-
return 0, status.Errorf(codes.InvalidArgument, "start height %d is higher than highest indexed height %d", height, highestHeight)
284+
// allow for a small difference between the highest indexed height and the provided height to
285+
// account for small delays indexing or requests made to different ANs behind a load balancer.
286+
// this will just result in the stream waiting a few blocks before starting.
287+
if height > highestHeight+maxIndexBlockDiff {
288+
return 0, status.Errorf(codes.InvalidArgument, "start height %d is higher than highest indexed height %d (maxIndexBlockDiff: %d)", height, highestHeight, maxIndexBlockDiff)
278289
}
279290

280291
return height, nil

0 commit comments

Comments
 (0)