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

docs: transaction optimization #3513

Closed
wants to merge 12 commits into from

Conversation

danielbate
Copy link
Member

@danielbate danielbate commented Dec 31, 2024

Release notes

In this release, we:

  • Documented transaction optimisations and optimistic loading techniques

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)

@danielbate danielbate added the docs Requests pertinent to documentation label Dec 31, 2024
@danielbate danielbate self-assigned this Dec 31, 2024
Copy link

vercel bot commented Dec 31, 2024

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 Jan 2, 2025 10:02am
ts-docs ✅ Ready (Inspect) Visit Preview 💬 Add feedback Jan 2, 2025 10:02am
ts-docs-api ✅ Ready (Inspect) Visit Preview 💬 Add feedback Jan 2, 2025 10:02am

@petertonysmith94
Copy link
Contributor

petertonysmith94 commented Dec 31, 2024

Pre-optimization

%%{
  init: {
    'theme': 'base',
    'themeVariables': {
      'primaryColor': '#00F58C',
      'primaryTextColor': '#000000',
      'primaryBorderColor': '#00F58C',
      'lineColor': '#2B2B2B',
      'secondaryColor': '#1A1A1A',
      'tertiaryColor': '#00F58C',
      
      'mainBkg': '#000000',
      'secondaryBkg': '#1A1A1A',
      'mainContrastColor': '#FFFFFF',
      'darkTextColor': '#FFFFFF',
      'lightTextColor': '#000000',
      'textColor': '#FFFFFF',
      'altTextColor': '#FFFFFF',
      'borderColor': '#2B2B2B',
      
      'nodeBkg': '#1A1A1A',
      'nodeBorder': '#00F58C',
      'clusterBkg': '#1A1A1A',
      'clusterBorder': '#2B2B2B',
      'defaultLinkColor': '#00F58C',
      'fontFamily': 'SpaceGrotesk, -apple-system, BlinkMacSystemFont, "Segoe UI"',
      'fontSize': '14px'
    }
  }
}%%

sequenceDiagram
    User->>+DApp: Page load
    User->>+DApp: Clicks "Send Transaction"
    DApp->>+DApp: Prepare Transaction
    DApp->>+Network: Fetch dependencies
    Network->>+DApp: 
    DApp->>+DApp: Fund Transaction
    DApp->>+Network: Send transaction
    Network->>+DApp: Transaction confirmation
    DApp->>+User: 
Loading

Post-optimization

sequenceDiagram
    User->>+DApp: Page load
    DApp->>+DApp: Prepare Transaction
    DApp->>+Network: Fetch dependencies
    Network->>+DApp: 
    DApp->>+DApp: Fund Transaction
    DApp->>+DApp: Cache pre-prepared transaction 

    User->>+DApp: Clicks "Send Transaction"
    DApp->>+DApp: Use pre-prepared cached transaction
    DApp->>+Network: Send transaction
    Network->>+DApp: Transaction confirmation
    DApp->>+User: 
Loading

Copy link
Member Author

Choose a reason for hiding this comment

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

This is just some formatting that was bugging me.

Copy link
Contributor

@petertonysmith94 petertonysmith94 left a comment

Choose a reason for hiding this comment

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

Nice. Just one point from me, is the consistency of naming of simulate vs estimate. It might be worth just picking one and rolling with it.


![Pre-optimization Tx Process](../../public/tx-optimization-before.png)

This can be mitigated by optimistically building the transaction before your user submits the transaction. Pre-preparation of the transaction can improve the perceived speed of transactions by **~2x**.
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
This can be mitigated by optimistically building the transaction before your user submits the transaction. Pre-preparation of the transaction can improve the perceived speed of transactions by **~2x**.
This can be mitigated by optimistically building the transaction before your user submits the transaction. Pre-preparation of the transaction can improve the perceived speed of transactions.

Do we need to provide a figure?

Copy link
Member

Choose a reason for hiding this comment

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

Yeah, numbers can be tricky. I still think the whole message around this may have been framed incorrectly from the idea's inception. I will review this in-depth to provide better and more actionable feedback.

apps/docs/src/public/tx-optimization-after.png Outdated Show resolved Hide resolved
const sender = Wallet.fromPrivateKey(WALLET_PVT_KEY, provider);

// Calling the transfer function will create the transaction,
// and then perform multiple network requests to fund, simulate and submit
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
// and then perform multiple network requests to fund, simulate and submit
// and then perform multiple network requests to simulate, fund and submit

Copy link
Contributor

Choose a reason for hiding this comment

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

Should we rename "Fetch dependencies" to "Simulate transaction" to be synced with the examples?

Comment on lines +41 to +45
request.addCoinOutput(
Address.fromString(recipientAddress),
1_000_000,
provider.getBaseAssetId()
);
Copy link
Contributor

Choose a reason for hiding this comment

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

If the user clicks transfer without resetting the request, we could add another coin output.

const { contract } = await waitForResult();

// Get the transaction request for the increment_count function
request = await contract.functions.increment_count(1).getTransactionRequest();
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
request = await contract.functions.increment_count(1).getTransactionRequest();
request = await contract.functions
.increment_count(1)
.getTransactionRequest();

Comment on lines +34 to +35
// When the user presses the increment button, we submit the transaction
// ensuring that the dependencies are not re-estimated and making redundant calls to the network
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
// When the user presses the increment button, we submit the transaction
// ensuring that the dependencies are not re-estimated and making redundant calls to the network
// When the user presses the increment button, we submit the transaction
// ensuring that the dependencies are not re-estimated

Comment on lines +53 to +58
);
// Then we must alter any existing predicate data that may have changed
const predicateWithData = new ConfigurablePin({ provider, data: [pin] });
const requestWithData =
predicateWithData.populateTransactionPredicateData(request);
// And submit the transaction, ensuring that the dependencies are
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
);
// Then we must alter any existing predicate data that may have changed
const predicateWithData = new ConfigurablePin({ provider, data: [pin] });
const requestWithData =
predicateWithData.populateTransactionPredicateData(request);
// And submit the transaction, ensuring that the dependencies are
);
// Then we must alter any existing predicate data that may have changed
const predicateWithData = new ConfigurablePin({ provider, data: [pin] });
const requestWithData =
predicateWithData.populateTransactionPredicateData(request);
// And submit the transaction, ensuring that the dependencies are

await fundTx.waitForResult();

// Calling the transfer function will create the transaction,
// and then perform multiple network requests to fund, simulate and submit
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
// and then perform multiple network requests to fund, simulate and submit
// and then perform multiple network requests to simulate, fund and submit

Copy link
Contributor

github-actions bot commented Jan 2, 2025

Coverage Report:

Lines Branches Functions Statements
77.83%(+0%) 70.5%(+0%) 75.5%(+0%) 77.79%(+0%)
Changed Files:

Coverage values did not change👌.


- Fetching chain information to compute transaction data
- Retrieving the gas price for cost estimation
- Simulating the transaction to obtain missing or estimating transaction data
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
- Simulating the transaction to obtain missing or estimating transaction data
- Simulating the transaction to obtain missing data and estimate transaction costs

- Simulating the transaction to obtain missing or estimating transaction data
- Fetching funds for the transaction

Depending on how you are performing the transaction, all of the above may have been abstracted away underneath a single function call that is performing multiple calls to the network to retrieve necessary information. Which gives the appearance of slowness for users interacting with your application.
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
Depending on how you are performing the transaction, all of the above may have been abstracted away underneath a single function call that is performing multiple calls to the network to retrieve necessary information. Which gives the appearance of slowness for users interacting with your application.
Depending on how you are performing the transaction, all of the above may have been abstracted away underneath a single function call that is performing multiple calls to the network to retrieve necessary information, which might give the appearance of slowness for users interacting with your application.

@danielbate danielbate marked this pull request as draft January 3, 2025 10:33
@danielbate
Copy link
Member Author

Converting to draft whilst considering a change of approach

@danielbate
Copy link
Member Author

Closing as changing approach

@danielbate danielbate closed this Jan 3, 2025
@arboleya arboleya deleted the db/docs/transaction-optimisation branch January 3, 2025 12:20
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
docs Requests pertinent to documentation
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Add documentation for tx dependency optimisation technique
4 participants