-
Notifications
You must be signed in to change notification settings - Fork 176
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(oft-solana): add fallback for when getSimulationComputeUnits
fails
#1185
base: main
Are you sure you want to change the base?
Conversation
getSimulationComputeUnits
fails
Check failing due to unrelated test:
|
checks are now passing |
Great work! Is this ready for review? |
Yes! Sorry, forgot it was created as a draft. |
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.
left some big picture suggestions
SendOFT = 'SendOFT', | ||
} | ||
|
||
const TransactionCuEstimates: Record<TransactionType, number> = { |
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.
A few thoughts here:
I see we are overshooting the estimate for a lot of these Transaction Types, would we need to warn the users about the potential of overpaying ?
Another point here is that the estimates might not reflect the network CU usage overtime. In a few months time if everyone decides to use Solana, these values would need to be manually changed. Are we okay with making that manual change to keep the example upto date?
) | ||
let computeUnits | ||
|
||
try { |
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.
thoughts on trying more than once before defaulting to estimates?
potentially using exponential backoff and retry and a couple times before defaulting
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.
nit: try/catch can just be condensed to
const computeUnits = await getSimulationComputeUnits(
connection,
ixs.map((ix) => toWeb3JsInstruction(ix)),
toWeb3JsPublicKey(wallet.publicKey),
[lookupTableAccount]
).catch(e => {
console.error(`Error retrieving simulation compute units from RPC:`, e);
console.log(
`Falling back to hardcoded estimate for ${transactionType}: ${TransactionCuEstimates[transactionType]} CUs`
);
return TransactionCuEstimates[transactionType];
});
Motivation
We've found that in times of network congestion, the RPC method that supports the
getSimulationComputeUnits
function would fail, resulting in scripts being stuck as every transaction currently relies ongetSimulationComputeUnits
. This blocks the deployment of Solana OFTs.Solution
Given that as part of a Solana OFT deployment, we are executing a standard set of instructions, we can introduce a fallback by way of hardcoded CU estimates for each transaction type. The following is introduced into
examples/oft-solana/tasks/solana/index.ts
:We use the fallback in
getComputeUnitPriceAndLimit
:Notes:
createToken
as it has CPIs into the Metaplex program. More basic transactions likesetAuthority
have more stable CU count.getSimulationComputeUnits
(to estimate CU limit) is the one failing and notgetRecentPrioritizationFees
(rpc method to estimate CU price)Testing
To test, init a new repo with the following:
To simulate the
getSimulationComputeUnits
method failing in times of RPC congestion, make the following temporary edit toexamples/oft-solana/tasks/solana/index.ts
:Then, run any of the Solana scripts, such as
and observe the logs