Skip to content

Commit

Permalink
Moved check for index to return error instantly
Browse files Browse the repository at this point in the history
  • Loading branch information
AndriiDiachuk committed Nov 5, 2024
1 parent 948a053 commit 299829d
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 11 deletions.
6 changes: 3 additions & 3 deletions access/handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -1436,6 +1436,9 @@ func (h *Handler) SendAndSubscribeTransactionStatuses(
return subscription.HandleSubscription(sub, func(txResults []*TransactionResult) error {
for i := range txResults {
index := messageIndex.Value()
if ok := messageIndex.Set(index + 1); !ok {
return status.Errorf(codes.Internal, "message index already incremented to %d", messageIndex.Value())
}

err = stream.Send(&access.SendAndSubscribeTransactionStatusesResponse{
TransactionResults: TransactionResultToMessage(txResults[i]),
Expand All @@ -1445,9 +1448,6 @@ func (h *Handler) SendAndSubscribeTransactionStatuses(
return rpc.ConvertError(err, "could not send response", codes.Internal)
}

if ok := messageIndex.Set(index + 1); !ok {
return status.Errorf(codes.Internal, "message index already incremented to %d", messageIndex.Value())
}
}

return nil
Expand Down
14 changes: 6 additions & 8 deletions engine/access/state_stream/backend/handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -382,6 +382,9 @@ func (h *Handler) handleEventsResponse(send sendSubscribeEventsResponseFunc, hea
}

index := messageIndex.Value()
if ok := messageIndex.Set(index + 1); !ok {
return status.Errorf(codes.Internal, "message index already incremented to %d", messageIndex.Value())
}

err = send(&executiondata.SubscribeEventsResponse{
BlockHeight: resp.Height,
Expand All @@ -394,10 +397,6 @@ func (h *Handler) handleEventsResponse(send sendSubscribeEventsResponseFunc, hea
return rpc.ConvertError(err, "could not send response", codes.Internal)
}

if ok := messageIndex.Set(index + 1); !ok {
return status.Errorf(codes.Internal, "message index already incremented to %d", messageIndex.Value())
}

return nil
}
}
Expand Down Expand Up @@ -500,6 +499,9 @@ func (h *Handler) handleAccountStatusesResponse(
}

index := messageIndex.Value()
if ok := messageIndex.Set(index + 1); !ok {
return status.Errorf(codes.Internal, "message index already incremented to %d", messageIndex.Value())
}

err = send(&executiondata.SubscribeAccountStatusesResponse{
BlockId: convert.IdentifierToMessage(resp.BlockID),
Expand All @@ -511,10 +513,6 @@ func (h *Handler) handleAccountStatusesResponse(
return rpc.ConvertError(err, "could not send response", codes.Internal)
}

if ok := messageIndex.Set(index + 1); !ok {
return status.Errorf(codes.Internal, "message index already incremented to %d", messageIndex.Value())
}

return nil
}
}
Expand Down

0 comments on commit 299829d

Please sign in to comment.