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

Add ResponseListener.listenForResponseFromTransaction() #36

Merged
merged 4 commits into from
Oct 24, 2023
Merged

Conversation

bolekk
Copy link
Contributor

@bolekk bolekk commented Oct 19, 2023

No description provided.

Copy link
Collaborator

@chudilka1 chudilka1 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@bolekk, would you be so kind as to address Sonar's issues? They fall under critical "code smells." If you believe they are irrelevant, please let me know, and we will provide a corresponding resolution for those...

@bolekk
Copy link
Contributor Author

bolekk commented Oct 19, 2023

The PR is still in draft, I'll address everything once it's ready.

@bolekk bolekk force-pushed the txwait branch 5 times, most recently from 7dbfc33 to 2880bdf Compare October 19, 2023 22:15
@bolekk bolekk marked this pull request as ready for review October 19, 2023 22:21
@bolekk
Copy link
Contributor Author

bolekk commented Oct 19, 2023

@chudilka1 I fixed most issues except two:

  1. Sonar tells me that "checkTimeout" should be const but it can't be const.
  2. Prettier wants to add one semicolon and eslint wants to remove it so I can't satisfy lint.

What should I do?

@justinkaseman
Copy link
Contributor

2. Prettier wants to add one semicolon and eslint wants to remove it so I can't satisfy lint.

What should I do?

It looks like this repo is missing a prettier <> eslint integration, which is how you make them play nicely together.
Docs here: https://prettier.io/docs/en/integrating-with-linters.html
Let me know if you want me to iron this out.

Copy link
Collaborator

@KuphJr KuphJr left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should add a README entry for this method. Also, maybe we should probably update our README, docs & tutorials to make this the preferred method for listening for Functions responses given that listening based on requestId can break during reorgs.

): Promise<FunctionsResponse> {
return new Promise<FunctionsResponse>((resolve, reject) => {
(async () => {
let requestID: string = ''
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: you shouldn't need to specify a type here. Typescript can infer the type based on the initial empty string value.

return new Promise<FunctionsResponse>((resolve, reject) => {
(async () => {
let requestID: string = ''
// eslint-disable-next-line
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What is being disabled here? Usually eslint-disble statementments disable a single warning:
example: // eslint-disable-next-line no-implicit-any (usually Copilot helps me do this automatically)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Lint claims this can be const but it can't, right? (I'm using it before setting)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Adding "@typescript-eslint/prefer-as-const" doesn't work

reject('Response not received within timeout period')
}, timeout)

const check = async () => {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Might this method lead to a potential race condition if the check interval is much higher than the block time?

  1. User sends Functions request & calls listenForReponseFromTransaction which extracts the current requestId and listens for the response.
  2. A reorg occurs and the reorged request is fulfilled before a check is called again.
  3. Now we are listening for a response after the response has already occurred, meaning we won't ever actually hear it and this function hangs forever.

I think the logic is fine here as this only occurs with high checkInvervals, but maybe something to note in the README entry.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes. The old method has a similar problem - when we start listening after the response is emitted, we will miss it. It seems to be inherent to a functionsRouter.on() call. I'll add a note to README.

@KuphJr
Copy link
Collaborator

KuphJr commented Oct 23, 2023

prettier.io/docs/en/integrating-with-linters.html

Thanks @justinkaseman! I'll take care of this now since I am the one who set up esLint to begin with.

@chudilka1
Copy link
Collaborator

chudilka1 commented Oct 24, 2023

@chudilka1 I fixed most issues except two:

  1. Sonar tells me that "checkTimeout" should be const but it can't be const.
  2. Prettier wants to add one semicolon and eslint wants to remove it so I can't satisfy lint.

@bolekk

  1. Is addressed from within Sonar (as won't fix with your comment)
  2. Rebase your branch from main, prettier <> lint setup has been addressed by @KuphJr in this commit

@cl-sonarqube-production
Copy link

@KuphJr KuphJr merged commit 97e8dde into main Oct 24, 2023
6 checks passed
@KuphJr KuphJr deleted the txwait branch October 24, 2023 22:08
zeuslawyer added a commit that referenced this pull request Aug 9, 2024
Makes changes to code introduced in #36.

Things to note:
1. 2 confirmations is a sensible default but have made 1 to reduce friction for devs so it works out of the box with local functions testnet.
2. Alternative could be to check inside `listenForResponseFromTransaction()` for ChainID 1337 (local funcs testnet) and then change the default confirmations to 1.
3. DevX Improvement: . README updates and added inline docs to the function so that it shows on however in the IDE
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants