Skip to content

Commit d0c8497

Browse files
add new tests for subscribe execution data endpoints
1 parent f455328 commit d0c8497

File tree

4 files changed

+505
-12
lines changed

4 files changed

+505
-12
lines changed

engine/access/state_stream/backend/backend.go

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@ import (
1010
"google.golang.org/grpc/status"
1111

1212
"github.com/onflow/flow-go/engine/access/index"
13-
"github.com/onflow/flow-go/engine/access/rpc/backend/common"
1413
"github.com/onflow/flow-go/engine/access/state_stream"
1514
"github.com/onflow/flow-go/engine/access/subscription"
1615
"github.com/onflow/flow-go/engine/access/subscription/tracker"
@@ -169,7 +168,7 @@ func (b *StateStreamBackend) GetRegisterValues(
169168

170169
execResultInfo, err := b.executionResultProvider.ExecutionResultInfo(header.ID(), criteria)
171170
if err != nil {
172-
if errors.Is(err, storage.ErrNotFound) || common.IsInsufficientExecutionReceipts(err) {
171+
if errors.Is(err, storage.ErrNotFound) || errors.Is(err, optimistic_sync.ErrNotEnoughAgreeingExecutors) {
173172
return nil, nil, status.Errorf(codes.NotFound, "failed to get execution result info for block")
174173
}
175174
return nil, nil, err

engine/access/state_stream/backend/backend_executiondata.go

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -182,9 +182,8 @@ func (b *ExecutionDataBackend) SubscribeExecutionDataFromStartBlockHeight(
182182
startBlockHeight uint64,
183183
criteria optimistic_sync.Criteria,
184184
) subscription.Subscription {
185-
// can use headers, though i need a check that startBlockHeight is not greater than the highest indexed height,
185+
// TODO: can use headers, though i need a check that startBlockHeight is not greater than the highest indexed height,
186186
// i can pass this value to backend without having executionDataTracker
187-
188187
nextHeight, err := b.executionDataTracker.GetStartHeightFromHeight(startBlockHeight)
189188
if err != nil {
190189
return subscription.NewFailedSubscription(err, "could not get start block height")
@@ -217,6 +216,11 @@ func (b *ExecutionDataBackend) createResponseHandler(criteria optimistic_sync.Cr
217216
nextCriteria := criteria
218217

219218
return func(ctx context.Context, height uint64) (interface{}, error) {
219+
// TODO: there was a check like if height > highestHeight { return err }
220+
// highest height were produced by the execution data downloader in the access_node_builder.go
221+
// it was passed as an argument to the execution data tracker.
222+
// should i add back this check here?
223+
220224
// the spork root block will never have execution data available. If requested, return an empty result.
221225
if height == b.state.Params().SporkRootBlockHeight() {
222226
return &ExecutionDataResponse{
@@ -229,26 +233,26 @@ func (b *ExecutionDataBackend) createResponseHandler(criteria optimistic_sync.Cr
229233

230234
blockID, err := b.headers.BlockIDByHeight(height)
231235
if err != nil {
236+
// TODO: potentially, node could start indexing from the block past given height,
237+
// and we would run into the infinite loop here. Maybe it is safer to return an exception?
232238
err = errors.Join(err, subscription.ErrBlockNotReady)
233239
return nil, fmt.Errorf("could not get block ID for height %d: %w", height, err)
234240
}
235241

236-
execResultInfo, err := b.executionResultProvider.ExecutionResultInfo(blockID, criteria)
242+
execResultInfo, err := b.executionResultProvider.ExecutionResultInfo(blockID, nextCriteria)
237243
if err != nil {
238244
switch {
239245
case errors.Is(err, optimistic_sync.ErrRequiredExecutorNotFound) ||
240246
errors.Is(err, optimistic_sync.ErrNotEnoughAgreeingExecutors):
241247
return nil,
242248
fmt.Errorf("block %d is not available yet: %w", height, subscription.ErrBlockNotReady)
243249

244-
case errors.Is(err, optimistic_sync.ErrBlockNotFound):
250+
case errors.Is(err, optimistic_sync.ErrBlockNotFound) ||
251+
errors.Is(err, optimistic_sync.ErrForkAbandoned):
245252
return nil, err
246253

247-
case errors.Is(err, optimistic_sync.ErrForkAbandoned):
248-
return nil, fmt.Errorf("execution fork for the current block has been abandoned")
249-
250254
default:
251-
return nil, fmt.Errorf("failed to get events: %w", err)
255+
return nil, fmt.Errorf("unexpected error: %w", err)
252256
}
253257
}
254258

0 commit comments

Comments
 (0)