Skip to content

Commit

Permalink
Add validation for start block number in tier1 service
Browse files Browse the repository at this point in the history
Added checks in blocks method of Tier1 service to ensure that the requested start block number is equal to or greater than the first streamable block of the chain. This prevents errors caused by invalid block number requests.
  • Loading branch information
colindickson committed Sep 2, 2023
1 parent ee1ba18 commit 1ec1e77
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 0 deletions.
8 changes: 8 additions & 0 deletions docs/release-notes/change-log.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,14 @@ All notable changes to this project will be documented in this file.

The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/), and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).

## Unreleased

### Bug fixes

* If the initial block or start block is less than the first block in the chain, the substreams will now start from the
first block in the chain. Previously, setting the initial block to a block before the first block in the chain would
cause the substreams to hang.

## v1.1.12

### Highlights
Expand Down
8 changes: 8 additions & 0 deletions service/tier1.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (
"context"
"errors"
"fmt"
"github.com/streamingfast/bstream"
"path/filepath"
"regexp"
"strconv"
Expand Down Expand Up @@ -284,6 +285,13 @@ func (s *Tier1Service) writePackage(ctx context.Context, request *pbsubstreamsrp
var IsValidCacheTag = regexp.MustCompile(`^[a-zA-Z0-9_-]+$`).MatchString

func (s *Tier1Service) blocks(ctx context.Context, request *pbsubstreamsrpc.Request, outputGraph *outputmodules.Graph, respFunc substreams.ResponseFunc) error {
chainFirstStreamableBlock := bstream.GetProtocolFirstStreamableBlock
if request.StartBlockNum != 0 && request.StartBlockNum < int64(chainFirstStreamableBlock) {
return stream.NewErrInvalidArg("invalid start block %d, must be >= %d (the first streamable block of the chain)", request.StartBlockNum, chainFirstStreamableBlock)
} else if request.StartBlockNum == 0 {
request.StartBlockNum = int64(chainFirstStreamableBlock)
}

logger := reqctx.Logger(ctx)

requestDetails, undoSignal, err := pipeline.BuildRequestDetails(ctx, request, s.getRecentFinalBlock, s.resolveCursor, s.getHeadBlock)
Expand Down

0 comments on commit 1ec1e77

Please sign in to comment.