ChorusOne / solido

Lido for Solana is a Lido-DAO governed liquid staking protocol for the Solana blockchain.
https://chorusone.github.io/solido/
GNU General Public License v3.0
101 stars 43 forks source link

Fix stack overflow in `Anker::SendRewards` #566

Closed ruuda closed 2 years ago

ruuda commented 2 years ago

Problem

Currently, our maintainer is failing to call SendRewards on mainnet:

Error while performing maintenance.
Solana RPC client returned an error:

  Request:    Some(SendTransaction)
  Kind:       RPC response error
  Error code: -32002
  Message:    Transaction simulation failed: Error processing Instruction 0: Program failed to complete
  Reason:     Transaction preflight failure
  Error:     

    Raw:      InstructionError(0, ProgramFailedToComplete)
    Display:  Error processing Instruction 0: Program failed to complete

  Logs:      

    Program BNVB8pd4coHpY7MVcrtiHLCLst7fyDGzMtPmfJqFAhwj invoke [1]
    Program TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA invoke [2]
    Program log: Instruction: Approve
    Program TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA consumed 2026 of 153383 compute units
    Program TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA success
    Program BNVB8pd4coHpY7MVcrtiHLCLst7fyDGzMtPmfJqFAhwj consumed 52383 of 200000 compute units
    Program failed to complete: Access violation in stack frame 3 at address 0x200003fe8 of size 8 by instruction #19763
    Program BNVB8pd4coHpY7MVcrtiHLCLst7fyDGzMtPmfJqFAhwj failed: Program failed to complete

We saw this access violation before, it is caused by a stack overflow. We ran into this in SendRewards previously and we already optimized it to reduce stack usage, but I suspect the late addition of some metrics increased the size of the Anker struct which pushed it over the edge again.

Changes