Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Access] Change SendAndSubscribe endpoint's MessageIndex to start at 0 #6598

8 changes: 6 additions & 2 deletions access/handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -1435,15 +1435,19 @@ func (h *Handler) SendAndSubscribeTransactionStatuses(
messageIndex := counters.NewMonotonousCounter(0)
return subscription.HandleSubscription(sub, func(txResults []*TransactionResult) error {
for i := range txResults {
value := messageIndex.Increment()
index := messageIndex.Value()
AndriiDiachuk marked this conversation as resolved.
Show resolved Hide resolved

err = stream.Send(&access.SendAndSubscribeTransactionStatusesResponse{
TransactionResults: TransactionResultToMessage(txResults[i]),
MessageIndex: value,
MessageIndex: index,
})
if err != nil {
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
12 changes: 10 additions & 2 deletions engine/access/state_stream/backend/handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -381,7 +381,7 @@ func (h *Handler) handleEventsResponse(send sendSubscribeEventsResponseFunc, hea
return status.Errorf(codes.Internal, "could not convert events to entity: %v", err)
}

index := messageIndex.Increment()
index := messageIndex.Value()
AndriiDiachuk marked this conversation as resolved.
Show resolved Hide resolved

err = send(&executiondata.SubscribeEventsResponse{
BlockHeight: resp.Height,
Expand All @@ -394,6 +394,10 @@ 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 @@ -495,7 +499,7 @@ func (h *Handler) handleAccountStatusesResponse(
return err
}

index := messageIndex.Increment()
index := messageIndex.Value()
AndriiDiachuk marked this conversation as resolved.
Show resolved Hide resolved

err = send(&executiondata.SubscribeAccountStatusesResponse{
BlockId: convert.IdentifierToMessage(resp.BlockID),
Expand All @@ -507,6 +511,10 @@ 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
Loading