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

[Fix/stacks] Optimistic operation disappears for long running transactions #6793

Open
wants to merge 3 commits into
base: develop
Choose a base branch
from

Conversation

lawRathod
Copy link
Contributor

@lawRathod lawRathod commented May 1, 2024

βœ… Checklist

  • npx changeset was attached.
  • Covered by automatic tests.
  • Impact of the changes:
    • ...

πŸ“ Description

The optimistics transaction disappears when transactions on stacks network takes long time. The pending operations are now added to accounts object during sync to fix the problem.

❓ Context


🧐 Checklist for the PR Reviewers

  • The code aligns with the requirements described in the linked JIRA or GitHub issue.
  • The PR description clearly documents the changes made and explains any technical trade-offs or design decisions.
  • There are no undocumented trade-offs, technical debt, or maintainability issues.
  • The PR has been tested thoroughly, and any potential edge cases have been considered and handled.
  • Any new dependencies have been justified and documented.
  • Performance considerations have been taken into account. (changes have been profiled or benchmarked if necessary)

@lawRathod lawRathod requested a review from a team as a code owner May 1, 2024 10:09
Copy link

vercel bot commented May 1, 2024

The latest updates on your projects. Learn more about Vercel for Git β†—οΈŽ

Name Status Preview Comments Updated (UTC)
web-tools βœ… Ready (Inspect) Visit Preview πŸ’¬ Add feedback May 28, 2024 3:27pm
3 Ignored Deployments
Name Status Preview Comments Updated (UTC)
ledger-live-docs ⬜️ Ignored (Inspect) Visit Preview May 28, 2024 3:27pm
native-ui-storybook ⬜️ Ignored (Inspect) Visit Preview May 28, 2024 3:27pm
react-ui-storybook ⬜️ Ignored (Inspect) Visit Preview May 28, 2024 3:27pm

Copy link

vercel bot commented May 1, 2024

@lawRathod is attempting to deploy a commit to the LedgerHQ Team on Vercel.

A member of the Team first needs to authorize it.

@live-github-bot live-github-bot bot added common Has changes in live-common fork Pull request base branch comes from a fork. labels May 1, 2024
@lawRathod lawRathod changed the title Fix/stacks pending [Fix/stacks] Optimistic operation disappears for long running transactions May 1, 2024
Copy link

There as been no activity on this PR for the last 14 days. Please consider closing this PR.

Copy link
Contributor

@hzheng-ledger hzheng-ledger left a comment

Choose a reason for hiding this comment

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

Please see my comments

@hzheng-ledger hzheng-ledger self-requested a review May 27, 2024 14:40
Copy link
Contributor

@hzheng-ledger hzheng-ledger left a comment

Choose a reason for hiding this comment

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

it looks good to me.
I've some questions,
I don't know whether the balance return from /extended/v1/address/${addr}/stx includes the pending transactions(mempool transactions)

I see this piece of code

  for (const tx of mempoolTxs) {
    spendableBalance = spendableBalance
      .minus(new BigNumber(tx.fee_rate))
      .minus(new BigNumber(tx.token_transfer.amount));
  }

Does the mempoolTxs includes both incoming and outgoing (send and receive) transactions?
because the "fee_rate" is not paid by the current account for receive transactions.
should we give the "tx.token_transfer.amount" a positive or negative value according to send/receive transaction?

@lawRathod
Copy link
Contributor Author

@hzheng-ledger Thanks for the review.

whether the balance return from /extended/v1/address/${addr}/stx includes the pending transactions(mempool transactions)

Only sent transactions are part of the mempool txns object https://github.com/Zondax/ledger-live/blob/develop/libs/ledger-live-common/src/families/stacks/bridge/utils/api.ts#L142-L147 so we substract the fee and amount from the balance.

@github-actions github-actions bot removed the Stale label May 28, 2024
Copy link
Contributor

@hzheng-ledger hzheng-ledger left a comment

Choose a reason for hiding this comment

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

it looks good to me. thanks

@hzheng-ledger hzheng-ledger self-requested a review May 28, 2024 09:06
@@ -206,6 +263,7 @@ export const getAccountShape: GetAccountShape = async info => {
balance,
spendableBalance,
operations: flatMap(rawTxs, mapTxToOps(accountId)),
pendingOperations: flatMap(mempoolTxs, mapPendingTxToOps(accountId, address)),
Copy link
Contributor

Choose a reason for hiding this comment

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

we shouldn't add pendingOperations here.
This pendingOperations is used for new broadcasted transaction from our UI. (not even necessarily in mempool, but we want to display them to users in our Ledger live) It is for different usage.

what we should do here is to merge flatMap(rawTxs, mapTxToOps(accountId)) and flatMap(mempoolTxs, mapPendingTxToOps(accountId, address))
in the above "operations" field. for confirmed transaction, we set "blockHeight" and "blockHash" field correctly and for pending transaction in mempool, we set "blockHeight" and "blockHash" field as null. So that we can see these pending transactions in our Ledger live

the "pendingOperations" is normally not used in "getAccountShape" method

@lawRathod

Copy link
Contributor Author

Choose a reason for hiding this comment

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

thanks for the explanation, there was definitely some confusion around this but everything is much clear now. I have merged both as you suggest, please have another look πŸ™πŸ»

Copy link
Contributor

@hzheng-ledger hzheng-ledger left a comment

Choose a reason for hiding this comment

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

Please see my another comment. Thanks a lot

Copy link
Contributor

@hzheng-ledger hzheng-ledger left a comment

Choose a reason for hiding this comment

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

looks good to me

@hzheng-ledger
Copy link
Contributor

Thanks a lot. I've approved the PR

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
common Has changes in live-common fork Pull request base branch comes from a fork.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants