-
Notifications
You must be signed in to change notification settings - Fork 1.4k
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
Conversation
The latest updates on your projects. Learn more about Vercel for Git ↗︎
|
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:
Post-optimizationsequenceDiagram
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:
|
There was a problem hiding this comment.
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.
There was a problem hiding this 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**. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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?
There was a problem hiding this comment.
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.
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 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
// and then perform multiple network requests to fund, simulate and submit | |
// and then perform multiple network requests to simulate, fund and submit |
There was a problem hiding this comment.
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?
request.addCoinOutput( | ||
Address.fromString(recipientAddress), | ||
1_000_000, | ||
provider.getBaseAssetId() | ||
); |
There was a problem hiding this comment.
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(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
request = await contract.functions.increment_count(1).getTransactionRequest(); | |
request = await contract.functions | |
.increment_count(1) | |
.getTransactionRequest(); |
// 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 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
// 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 |
apps/docs/src/guide/optimizing-transactions/optimistic-predicates.md
Outdated
Show resolved
Hide resolved
); | ||
// 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 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
); | |
// 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 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
// and then perform multiple network requests to fund, simulate and submit | |
// and then perform multiple network requests to simulate, fund and submit |
Co-authored-by: Peter Smith <[email protected]>
…/FuelLabs/fuels-ts into db/docs/transaction-optimisation
Coverage Report:
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 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
- 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. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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. |
Converting to draft whilst considering a change of approach |
Closing as changing approach |
Release notes
In this release, we:
Checklist