SOLANA:ComputeBudget在打字稿SDK中

发布于 2025-01-21 19:15:44 字数 538 浏览 0 评论 0原文

我目前正在尝试增加我在DEVNET上的Solana程序上的计算预算。我正在使用Solana版本1.9.9。

我已经检查了锚点,并发现此实现要求更大的计算预算。但是,当我运行此代码 - 尼珀时,

    const data = Buffer.from(
        Uint8Array.of(0, ...new BN(256000).toArray("le", 4))
    );

    const additionalComputeIx: TransactionInstruction = new TransactionInstruction({
        keys: [],
        programId: new PublicKey("ComputeBudget111111111111111111111111111111"),
        data,
    });
    ...

我会得到无效的指令数据。知道为什么这可能是吗?

在将此指令添加到交易中之前,我会得到计算预算超过

I am currently trying to increase the Compute-Budget on my Solana Program on devnet. I am using solana version 1.9.9.

I have checked the anchor discord, and found this implementation to request a larger compute-budget. however, when I run this code-snippet

    const data = Buffer.from(
        Uint8Array.of(0, ...new BN(256000).toArray("le", 4))
    );

    const additionalComputeIx: TransactionInstruction = new TransactionInstruction({
        keys: [],
        programId: new PublicKey("ComputeBudget111111111111111111111111111111"),
        data,
    });
    ...

I get invalid instruction data. any idea why this could be?

I was getting Compute Budget Exceeded before adding this instruction to the transaction.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

oО清风挽发oО 2025-01-28 19:15:44

你很近!请求从计算预算计划增加的指令定义包含单位的小U32,但随后还包含一个小的u32,以添加额外费用,即使是0

const data = Buffer.from(
        Uint8Array.of(0, ...new BN(256000).toArray("le", 4), ...new BN(0).toArray("le", 4))
    );

。 /compute_budget.rs#L10" rel="nofollow noreferrer">https://github.com/solana-labs/solana/blob/a6742b5838ffe6f37afcb24ab32ad2287a1514cf/sdk/src/compute_budget.rs#L10

You're very close! The instruction definition for requesting an increase from the compute budget program contains a little-endian u32 for the units, but then also a little-endian u32 for the additional fee to add, which you must include, even if it's 0. So instead, you should try:

const data = Buffer.from(
        Uint8Array.of(0, ...new BN(256000).toArray("le", 4), ...new BN(0).toArray("le", 4))
    );

More information about the instruction at https://github.com/solana-labs/solana/blob/a6742b5838ffe6f37afcb24ab32ad2287a1514cf/sdk/src/compute_budget.rs#L10

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文