From 816625b518f9282962300ad4de4fd198266d9e9d Mon Sep 17 00:00:00 2001 From: Jonas Hahn Date: Mon, 18 Nov 2024 22:25:39 +0100 Subject: [PATCH] Update add-priority-fees.md --- content/cookbook/transactions/add-priority-fees.md | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/content/cookbook/transactions/add-priority-fees.md b/content/cookbook/transactions/add-priority-fees.md index 733177e49..ac6929448 100644 --- a/content/cookbook/transactions/add-priority-fees.md +++ b/content/cookbook/transactions/add-priority-fees.md @@ -111,8 +111,15 @@ async function writeMemoWithPriorityFees(message: string) { // so that you can right-size the compute budget to maximize the // chance that it will be selected for inclusion into a block. console.log("Estimating the compute consumption of the transaction"); - const estimatedComputeUnits = - await getComputeUnitEstimate(transactionMessage); + var estimatedComputeUnits = await getComputeUnitEstimate(transactionMessage); + // While these estimates are quite accurate they are not perfect. So you may want to add a + // buffer if you expect that the transaction may consume more compute units than estimated. + // You would need to invent time travel to exactly know what the transaction will consume when + // you send it in the future. You can add a buffer to the estimate to account for this. + // estimatedComputeUnits += 1000; + // estimatedComputeUnits *= 1.1; + // You can read more about the issue here: https://github.com/solana-labs/solana-web3.js/tree/master/packages/library#getcomputeunitestimatefortransactionmessagefactoryrpc + console.log( `Transaction is estimated to consume ${estimatedComputeUnits} compute units`, );