1

我的 Anchor 程序有一个如下所示的指令结构:

#[derive(Accounts)]
pub struct MyInstruction<'info> {
  pub my_account: Account<'info, MyAccount>,

  // ...
}

#[account]
pub struct MyAccount {
  // ... Many different fields
}

当我尝试运行使用该结构的指令时,我得到一个奇怪的堆栈错误,如下所示:

Program failed to complete: Access violation in stack frame 3 at address 0x200003fe0 of size 8 by instruction #28386

是什么赋予了?

4

1 回答 1

2

Anchor 默认将您的帐户放入堆栈。但是,很可能,因为您的帐户非常大,或者您有很多帐户,您的堆栈空间正在耗尽。

如果您在日志中查看上面的内容,您可能会遇到如下所示的错误:

Stack offset of -4128 exceeded max offset of -4096 by 32 bytes, please minimize large stack variables

要解决此问题,您可以尝试使用Box您的帐户结构,将它们移动到堆中:

#[derive(Accounts)]
pub struct MyInstruction<'info> {
  // Note the Box<>! 
  pub my_account: Box<Account<'info, MyAccount>>,
}
于 2022-01-17T21:27:58.460 回答