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

.awaitRequiredOperationStatus cannot await on both speculative status #472

Open
sydhds opened this issue Sep 13, 2023 · 6 comments
Open

Comments

@sydhds
Copy link
Contributor

sydhds commented Sep 13, 2023

Cannot await on both:

  • EOperationStatus.SPECULATIVE_SUCCESS
  • EOperationStatus.SPECULATIVE_ERROR
@Ben-Rey
Copy link
Collaborator

Ben-Rey commented Sep 14, 2023

@gregLibert We can start the discussion here.

@damip
Copy link
Member

damip commented Sep 14, 2023

From what I understand, this is heavily impairing the developer experience and should be solved asap.

@Ben-Rey
Copy link
Collaborator

Ben-Rey commented Sep 14, 2023

One quick solution would be to accept an array of status and return if one of them is reached.

@gregLibert
Copy link
Contributor

Let's focus on building something robust.
IMHO we should go to something like event manager.
We could also wrap the event management using the observable design pattern for a specific operation.

@damip we should also discuss about the priority, ASAP is misleading I think.

@damip
Copy link
Member

damip commented Sep 15, 2023

Here is a preliminary specification on how to make things cleanly:

After emitting an operation:

  • wait for the operation to be executed as speculative, notify of the result (notification can happen 0, 1 or multiple times if the blockclique changes)
  • wait for the operation to be executed as final, notify of the result (can happen 0 or 1 times)
    • in that case, stop waiting, we are done
  • if the final execution cursor becomes superior or equal to the operation's expiry period:
    • check the status of the operation just in case it executed at the last slot before finality => emit the right notification (speculative/final) if necessary
    • if it was not executed, return that the execution did not happen
    • stop waiting, we are done
  • if we fail to interrogate the execution status for more than 2 minutes (downtime), return an error notifying that we might never know if the operation executed or not

@Ben-Rey
Copy link
Collaborator

Ben-Rey commented Sep 19, 2023

Cannot await on both:

  • EOperationStatus.SPECULATIVE_SUCCESS
  • EOperationStatus.SPECULATIVE_ERROR

Just for information. We can do that

    try {
      const specSuccess = client
        .smartContracts()
        .awaitRequiredOperationStatus(opId, EOperationStatus.SPECULATIVE_SUCCESS);

      const specError = client
        .smartContracts()
        .awaitRequiredOperationStatus(opId, EOperationStatus.SPECULATIVE_ERROR);

      const finalSuccess = client
        .smartContracts()
        .awaitRequiredOperationStatus(opId, EOperationStatus.FINAL_SUCCESS);

      const finalError = client
        .smartContracts()
        .awaitRequiredOperationStatus(opId, EOperationStatus.FINAL_ERROR);

      const specResult = await Promise.race([specSuccess, specError]);
      console.log(EOperationStatus[specResult]);

      const finalResult = await Promise.race([finalSuccess, finalError]);
      console.log(EOperationStatus[finalResult]);
    } catch (error) {
      console.error("An error occurred:", error);
    }

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

No branches or pull requests

4 participants