Support inverted observations for gRPC - #5302
Open
denis-chernov-smartcontract wants to merge 1 commit into
Open
Conversation
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Closes #DS-3867
Description
Fixes a high-severity bug in the streams-adapter Go runtime: gRPC subscribers to an inverse pair (e.g. a client requesting
TRY/USDagainst a provider that only publishesUSD/TRY) received the un-inverted, reciprocal price — off by a factor matching the pair's magnitude (measured ~2,156x in one case) — delivered under the correct request's payload hash, with no error, flag, or other signal that the denomination was reversed.The HTTP transport already handled this correctly:
respondWithObservationreads each cache item'sRequiresInverseflag and inverts before responding. The gRPC fan-out path inredcon.go'shandleEval, however, published the raw provider observation to every subscriber of a transformed key regardless of that flag, so a client polling over HTTP and a client streaming the same request over gRPC would see different — reciprocal — values for the same underlying cache state.Changes
redcon/redcon.go: thehandleEvalpublish loop now looks up each subscriber's ownRequiresInverseflag (per raw key, since a single provider feed can serve both a direct and an inverse subscriber) before publishing, inverting the observation for inverse subscribers. If inversion fails, that subscriber's update is skipped rather than falling back to publishing the raw (wrong) value.helpers/inversion.go(new):InvertObservationand its private helpers, moved out ofserverso the HTTP and gRPC transports share a single implementation instead of duplicating (and risking diverging on) the reciprocal logic.server/server.go: updated to callhelpers.InvertObservation.