Reed
Reed

Reputation: 529

Is it possible to continue a computation in a Solana smart-contract beyond the compute budget?

I've been trying to figure out if it's at all possible to create a smart contract in Solana that will run a long-ish calculation (e.g. many sha256 iterations, or a KDF), maybe in parts, even though the calculation as a whole is obviously longer than the maximum compute budget for a transaction.

A CPI will not cut it since, as the docs say, the budget is transferred to the other program.

Any help on this issue would be appreciated. Thanks!

Upvotes: 0

Views: 776

Answers (2)

Setmax
Setmax

Reputation: 1034

If you want to use CU for more than 200k(maximum is 1.4m) you can use this trick:

    const additionalComputeBudgetInstruction =
    ComputeBudgetProgram.requestUnits({
      units: 400000,
      additionalFee: 0,
    });

use the code above before calling your instruction inside ts test, then use it inside your instruction call like this:

     await program.methods
    .test()
    .accounts({
      //accounts
    })
    .signers()
    .preInstructions([additionalComputeBudgetInstruction])
    .rpc();

hope it helps.

Upvotes: 1

Frank C.
Frank C.

Reputation: 8098

Well, that would mean structuring the programs instruction set to be a bit more orchestration.

You can then submit multiple transactions thereby 'chunking' up the CU consumption.

We did something similar to handle both data chunking and distributing the CU to process (validate proofs, etc.).

Upvotes: 2

Related Questions