-
Notifications
You must be signed in to change notification settings - Fork 686
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
fix: process incoming requests in order #4638
Conversation
…eleased while client is initializing
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Are all tests passing ? Should we add unhappy path cases ?
@@ -1028,6 +1029,23 @@ export class Engine extends IEngine { | |||
return formatMessage(request, iss); | |||
}; | |||
|
|||
public processRelayMessageCache: IEngine["processRelayMessageCache"] = () => { | |||
// process the relay messages cache in the next tick to allow event listeners to be registered by the implementing app | |||
setTimeout(async () => { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not sure if it's a good idea to mix setTimeout with an async operation.
Unless I misunderstood, I'd rather isolate the setTimeout
and do something along the lines of
setTimeout(async () => { | |
await sleep(50) | |
if (this.relayMessageCache.length === 0) return; | |
while (this.relayMessageCache.length > 0) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
why do we need that small timeout?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
the goal is to process the message after the finish initializing. This allows to setup listeners after the client.init()
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yes, but why 50 and not other number? Is 50 enough in a RN environment?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
it's arbitrary number. We can change it to some other value if you have suggestion
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Shouldn't we use a flag like client.initialized
then ?
}); | ||
this.client.core.relayer.on(RELAYER_EVENTS.message, (event: RelayerTypes.MessageEvent) => { | ||
// capture any messages that arrive before the client is initialized so we can process them after initialization is complete | ||
if (!this.initialized || this.relayMessageCache.length > 0) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is it a cache or a queue ? Why are we pushing the events in the cache instead of processing them?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
we put all messages received during init, and process them after init has finished. Otherwise it can lead to missed events by the implementing app
Not sure how to slow down the client and force the behaviour thus has been manually dogfooded. Will tinker @Cali93 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
@@ -1028,6 +1029,23 @@ export class Engine extends IEngine { | |||
return formatMessage(request, iss); | |||
}; | |||
|
|||
public processRelayMessageCache: IEngine["processRelayMessageCache"] = () => { | |||
// process the relay messages cache in the next tick to allow event listeners to be registered by the implementing app | |||
setTimeout(async () => { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Shouldn't we use a flag like client.initialized
then ?
….14.0 (#5765) [![Mend Renovate](https://app.renovatebot.com/images/banner.svg)](https://renovatebot.com) This PR contains the following updates: | Package | Change | Age | Adoption | Passing | Confidence | |---|---|---|---|---|---| | [@walletconnect/react-native-compat](https://github.com/walletconnect/walletconnect-monorepo) | [`^2.13.3` -> `^2.14.0`](https://renovatebot.com/diffs/npm/@walletconnect%2freact-native-compat/2.13.3/2.14.0) | [![age](https://developer.mend.io/api/mc/badges/age/npm/@walletconnect%2freact-native-compat/2.14.0?slim=true)](https://docs.renovatebot.com/merge-confidence/) | [![adoption](https://developer.mend.io/api/mc/badges/adoption/npm/@walletconnect%2freact-native-compat/2.14.0?slim=true)](https://docs.renovatebot.com/merge-confidence/) | [![passing](https://developer.mend.io/api/mc/badges/compatibility/npm/@walletconnect%2freact-native-compat/2.13.3/2.14.0?slim=true)](https://docs.renovatebot.com/merge-confidence/) | [![confidence](https://developer.mend.io/api/mc/badges/confidence/npm/@walletconnect%2freact-native-compat/2.13.3/2.14.0?slim=true)](https://docs.renovatebot.com/merge-confidence/) | --- ### Release Notes <details> <summary>walletconnect/walletconnect-monorepo (@​walletconnect/react-native-compat)</summary> ### [`v2.14.0`](https://github.com/WalletConnect/walletconnect-monorepo/releases/tag/2.14.0) [Compare Source](https://github.com/walletconnect/walletconnect-monorepo/compare/2.13.3...2.14.0) ##### What's Changed - fix: update requester and responder pairing metadata upon sessionAuthenticate approval by [@​quetool](https://github.com/quetool) in [https://github.com/WalletConnect/walletconnect-monorepo/pull/4614](https://github.com/WalletConnect/walletconnect-monorepo/pull/4614) - feat: random session identifier by [@​ganchoradkov](https://github.com/ganchoradkov) in [https://github.com/WalletConnect/walletconnect-monorepo/pull/2454](https://github.com/WalletConnect/walletconnect-monorepo/pull/2454) - fix: process incoming requests in order by [@​ganchoradkov](https://github.com/ganchoradkov) in [https://github.com/WalletConnect/walletconnect-monorepo/pull/4638](https://github.com/WalletConnect/walletconnect-monorepo/pull/4638) - chore: parsing optional fields in formatMessage function by [@​ignaciosantise](https://github.com/ignaciosantise) in [https://github.com/WalletConnect/walletconnect-monorepo/pull/5114](https://github.com/WalletConnect/walletconnect-monorepo/pull/5114) - fix: always use fallback verify server by [@​chris13524](https://github.com/chris13524) in [https://github.com/WalletConnect/walletconnect-monorepo/pull/5091](https://github.com/WalletConnect/walletconnect-monorepo/pull/5091) - refactor: `.org` relay url by [@​ganchoradkov](https://github.com/ganchoradkov) in [https://github.com/WalletConnect/walletconnect-monorepo/pull/5151](https://github.com/WalletConnect/walletconnect-monorepo/pull/5151) - feat: generic provider by [@​ganchoradkov](https://github.com/ganchoradkov) in [https://github.com/WalletConnect/walletconnect-monorepo/pull/5182](https://github.com/WalletConnect/walletconnect-monorepo/pull/5182) - feat: verify context session authenticate by [@​ganchoradkov](https://github.com/ganchoradkov) in [https://github.com/WalletConnect/walletconnect-monorepo/pull/5192](https://github.com/WalletConnect/walletconnect-monorepo/pull/5192) - refactor: reduce reconnect timeout by [@​ganchoradkov](https://github.com/ganchoradkov) in [https://github.com/WalletConnect/walletconnect-monorepo/pull/5194](https://github.com/WalletConnect/walletconnect-monorepo/pull/5194) ##### New Contributors - [@​quetool](https://github.com/quetool) made their first contribution in [https://github.com/WalletConnect/walletconnect-monorepo/pull/4614](https://github.com/WalletConnect/walletconnect-monorepo/pull/4614) **Full Changelog**: WalletConnect/walletconnect-monorepo@2.13.3...2.14.0 </details> --- ### Configuration 📅 **Schedule**: Branch creation - "after 5pm,every weekend" in timezone America/Los_Angeles, Automerge - "after 5pm,every weekend" in timezone America/Los_Angeles. 🚦 **Automerge**: Enabled. ♻ **Rebasing**: Whenever PR becomes conflicted, or you tick the rebase/retry checkbox. 🔕 **Ignore**: Close this PR and you won't be reminded about this update again. --- - [ ] <!-- rebase-check -->If you want to rebase/retry this PR, check this box --- This PR was generated by [Mend Renovate](https://www.mend.io/free-developer-tools/renovate/). View the [repository job log](https://developer.mend.io/github/valora-inc/wallet). <!--renovate-debug:eyJjcmVhdGVkSW5WZXIiOiIzOC4yMC4xIiwidXBkYXRlZEluVmVyIjoiMzguMjAuMSIsInRhcmdldEJyYW5jaCI6Im1haW4iLCJsYWJlbHMiOlsibnBtIiwicmVub3ZhdGUiXX0=--> --------- Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com> Co-authored-by: valora-bot <valorabot@valoraapp.com>
Description
Updated intake logic of incoming relay messages so they are processed by Sign Client one by one instead of all at the same time. The old approach was resulting in conflicts when messages were dependent on each other such as
session_update
adding new chain to the session andsession_event
instructing the client to switch to that new chain. In the above case, thesession_event
must be processed after thesession_update
has finished the update, else the client has no knowledge of that new chain.Additionally, implemented
relayMessageCache
that stores any messages received while the client is still initializing and the messages are processed after init has finished. This allows implementing apps to setup all event listeners and not miss eventsType of change
How has this been tested?
dogfooding
Checklist
Additional Information (Optional)
Please include any additional information that may be useful for the reviewer.