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

feat: status flags for the transaction request #3709

Draft
wants to merge 5 commits into
base: master
Choose a base branch
from

Conversation

petertonysmith94
Copy link
Contributor

@petertonysmith94 petertonysmith94 commented Feb 14, 2025

Summary

  • Introduction of flags to the transaction request which get calculated at strategic steps:

    • isEstimated
    • isFunded
    • isSigned (leverages the existing skipCustomFee parameter)
  • This will enable connectors to skip certain steps based upon these flags to reduce HTTP requests.

Checklist

  • All changes are covered by tests (or not applicable)
  • All changes are documented (or not applicable)
  • I reviewed the entire PR myself (preferably, on GH UI)
  • I described all Breaking Changes (or there's none)

@petertonysmith94 petertonysmith94 added the feat Issue is a feature label Feb 14, 2025
@petertonysmith94 petertonysmith94 self-assigned this Feb 14, 2025
Copy link

vercel bot commented Feb 14, 2025

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Comments Updated (UTC)
fuels-template ✅ Ready (Inspect) Visit Preview 💬 Add feedback Feb 17, 2025 0:18am
ts-docs ✅ Ready (Inspect) Visit Preview 💬 Add feedback Feb 17, 2025 0:18am
ts-docs-api ✅ Ready (Inspect) Visit Preview 💬 Add feedback Feb 17, 2025 0:18am

@petertonysmith94 petertonysmith94 changed the title feat: implement flags for the transaction request feat: status flags for the transaction request Feb 17, 2025
Copy link
Contributor

Coverage Report:

Lines Branches Functions Statements
77.15%(+0%) 70.75%(+0.06%) 75.3%(+0%) 77.15%(+0%)
Changed Files:
Ok File (✨=New File) Lines Branches Functions Statements
🔴 ✨ packages/abi-coder/src/utils/scriptData.ts 0%
(+0%)
0%
(+0%)
0%
(+0%)
0%
(+0%)
🔴 packages/account/src/account.ts 80.23%
(-0.35%)
70.66%
(-0.57%)
82.5%
(+0%)
80%
(-0.34%)
🔴 packages/account/src/providers/provider.ts 67.53%
(+0.58%)
59.8%
(+2.73%)
68.04%
(+0%)
67.29%
(+0.56%)
🔴 packages/account/src/providers/transaction-request/script-transaction-request.ts 51.11%
(+1.11%)
64.28%
(+0%)
42.1%
(+0%)
50%
(+1.12%)
🔴 packages/account/src/providers/transaction-request/transaction-request.ts 89.4%
(+0.83%)
76.62%
(-1.46%)
84.61%
(+0.61%)
89.61%
(+0.8%)
🔴 packages/errors/src/test-utils/expect-to-throw-fuel-error.ts 91.66%
(-0.34%)
88.88%
(+0%)
100%
(+0%)
91.66%
(-0.34%)

@@ -87,6 +87,8 @@ export class ScriptTransactionRequest extends BaseTransactionRequest {

await account.fund(this, txCost);

this.updateFlags({ isEstimated: true, isFunded: true });
Copy link
Member

Choose a reason for hiding this comment

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

Is there a case where these two can exist in isolation, and if not, should we merge them into a single flag?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

My initial solution was to have the isEstimate triggered using an estimate method, then the isFunded on the fund method.

@danielbate suggested that we only update in the estimateAndFund method for now as this is the primary suggested entry point for estimate + funding.

Given that users can estimate and fund with other avenues, I believe keeping these flags separate gives us more flexibility to enhance this feature later without external changes.

Copy link
Member

Choose a reason for hiding this comment

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

How do we expect the Wallet to behave in these two scenarios?

// 1
this.updateFlags({ isEstimated: true, isFunded: false });

// 2
this.updateFlags({ isEstimated: false, isFunded: true });

Copy link
Member

Choose a reason for hiding this comment

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

{ isEstimated: true, isFunded: false} - wallet does not dry-run the transaction on page load. It also expects the gasLimit and maxFee to be set correctly. Based on this, the wallet will fetch resources and add them to the request.

{ isEstimated: false, isFunded: true } - wallet increases gasLimit by 20% and dry-runs the transaction. It assumes funding is correct but IF the prior change has increased the maxFee, we would need to re-fund.

As @nedsalk suggested in sync, I'm wondering whether a status enum would be more flexible. This would make it more resistant to any changes to dry-run that could allow it to also introduce funding.

Copy link
Member

Choose a reason for hiding this comment

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

Asking from another angle: how could a transaction be funded and not estimated?

Copy link
Contributor

Choose a reason for hiding this comment

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

I'm missing something here as well. Why is the gasLimit increased by 20% for a dry run when it was never accurately estimated in the first place?

I'm trying to understand if this is meant to address a specific corner case.

Copy link
Member

Choose a reason for hiding this comment

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

The wallet makes an assumption that the gasLimit is not set high enough: https://github.com/FuelLabs/fuels-wallet/blob/d5721074c139a5a257cfc95e7ec67f29b4d24e16/packages/app/src/systems/Transaction/services/transaction.tsx#L233

I think we need to make the spec clearer so it is obvious for people what is happening and when, and we will run this by the front-end team.

Copy link
Member

Choose a reason for hiding this comment

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

I apologize for repeating myself, but just to be sure my question haven't gone unnoticed:

  • How could a transaction be funded and not estimated?

Copy link
Member

Choose a reason for hiding this comment

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

Apologies I wanted to think about this a little more - a transaction could not be funded and not estimated. We're going to rethink approach a little and will be making some changes to the spec.

* @param flags - The flags to update.
*/
public updateFlags(flags: Partial<{ [keys in keyof TransactionStatusFlags]: boolean }>) {
const CHAIN_ID = 0;
Copy link
Member

Choose a reason for hiding this comment

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

Is this supposed to be hardcoded?

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, these flags will only serve as a checksum hash to ensure the transaction body hasn't changed between steps.

By hardcoding the CHAIN_ID, we avoid having to either pass through a chain ID or making the async.

Copy link
Member

Choose a reason for hiding this comment

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

I may be missing the point or how a corner case like this could happen, but this seems like it could lead to future problems. Was this agreed upon with @FuelLabs/frontend?

Copy link
Contributor

Choose a reason for hiding this comment

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

I agree with @arboleya. Maybe I'm missing something, but since all methods calling updateFlags are async, what’s the benefit of making this method synchronous?

Also, provider.getChain() will usually resolve immediately since it relies on cached data.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

By storing the hash, it enables the detection of changes like the following:

const request = new ScriptTransactionRequest({ });
request.estimateAndFund(wallet);

// Sub-sequential changes to the request wo/ estimating or funding can be detected
request.addResources(...)

The consumer of these flags (the wallet), can choose whether they use these flags or not:

// Simple if statement
if (!request.flags.isEstimated)

// Or checking the request hash
const requestHash = request.getTransactionId(0);
if (request.flags.isEstimated !== requestHash)

Happy to change these flags to simple boolean values, but I believe having a means of detecting changes post estimate and fund would benefit this process.

There was no agreement with the @FuelLabs/frontend team, but it is in the proposed solution.

Copy link
Member

@danielbate danielbate Feb 20, 2025

Choose a reason for hiding this comment

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

I can appreciate the confusion with using a different chain ID, I think it makes sense to use the actual value.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feat Issue is a feature
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants