split out match branches to get around stack limit
This commit is contained in:
parent
89d4d6fbd3
commit
9c6199e270
|
@ -38,8 +38,7 @@ pub enum Instruction {
|
||||||
},
|
},
|
||||||
|
|
||||||
Withdraw {
|
Withdraw {
|
||||||
// FIXME: why 32 bytes seed? could be a vec?
|
faucet_owner_seed: Vec<u8>,
|
||||||
faucet_owner_seed: [u8; 32],
|
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -2,21 +2,31 @@
|
||||||
|
|
||||||
use crate::{
|
use crate::{
|
||||||
error::Error,
|
error::Error,
|
||||||
instruction::Instruction,
|
instruction::{self, Instruction},
|
||||||
state::{Aggregator, AggregatorConfig, Authority, Oracle, Round, Submissions},
|
state::{Aggregator, AggregatorConfig, Authority, Oracle, Round, Submissions},
|
||||||
};
|
};
|
||||||
|
|
||||||
// use spl_token::state;
|
// use spl_token::state;
|
||||||
use solana_program::{account_info::AccountInfo, clock::Clock, entrypoint::ProgramResult, msg, program::invoke_signed, program_error::ProgramError, program_pack::{IsInitialized, Pack}, pubkey::Pubkey, sysvar::{rent::Rent, Sysvar}};
|
use solana_program::{
|
||||||
|
account_info::AccountInfo,
|
||||||
|
clock::Clock,
|
||||||
|
entrypoint::ProgramResult,
|
||||||
|
msg,
|
||||||
|
program::invoke_signed,
|
||||||
|
program_error::ProgramError,
|
||||||
|
program_pack::{IsInitialized, Pack},
|
||||||
|
pubkey::Pubkey,
|
||||||
|
sysvar::{rent::Rent, Sysvar},
|
||||||
|
};
|
||||||
|
|
||||||
use crate::borsh_state::{BorshState, InitBorshState};
|
use crate::borsh_state::{BorshState, InitBorshState};
|
||||||
|
|
||||||
use borsh::BorshDeserialize;
|
use borsh::BorshDeserialize;
|
||||||
|
|
||||||
struct Accounts<'a, 'b>(&'a [AccountInfo<'b>]);
|
struct Accounts<'a>(&'a [AccountInfo<'a>]);
|
||||||
|
|
||||||
impl<'a, 'b> Accounts<'a, 'b> {
|
impl<'a> Accounts<'a> {
|
||||||
fn get(&self, i: usize) -> Result<&'a AccountInfo<'b>, ProgramError> {
|
fn get(&self, i: usize) -> Result<&'a AccountInfo<'a>, ProgramError> {
|
||||||
// fn get(&self, i: usize) -> Result<&AccountInfo, ProgramError> {
|
// fn get(&self, i: usize) -> Result<&AccountInfo, ProgramError> {
|
||||||
// &accounts[input.token.account as usize]
|
// &accounts[input.token.account as usize]
|
||||||
self.0.get(i).ok_or(ProgramError::NotEnoughAccountKeys)
|
self.0.get(i).ok_or(ProgramError::NotEnoughAccountKeys)
|
||||||
|
@ -249,7 +259,6 @@ impl<'a> SubmitContext<'a> {
|
||||||
answer.created_at = now;
|
answer.created_at = now;
|
||||||
answer.updated_at = now;
|
answer.updated_at = now;
|
||||||
answer_submissions.data = round_submissions.data;
|
answer_submissions.data = round_submissions.data;
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
answer.updated_at = now;
|
answer.updated_at = now;
|
||||||
answer_submissions.data[i] = new_submission;
|
answer_submissions.data[i] = new_submission;
|
||||||
|
@ -308,8 +317,12 @@ impl<'a, 'b> WithdrawContext<'a, 'b> {
|
||||||
oracle.authorize(&self.oracle_owner)?;
|
oracle.authorize(&self.oracle_owner)?;
|
||||||
oracle.check_aggregator(self.aggregator)?;
|
oracle.check_aggregator(self.aggregator)?;
|
||||||
|
|
||||||
if !aggregator.config.reward_token_account.is_account(self.faucet) {
|
if !aggregator
|
||||||
return Err(Error::InvalidFaucet)?
|
.config
|
||||||
|
.reward_token_account
|
||||||
|
.is_account(self.faucet)
|
||||||
|
{
|
||||||
|
return Err(Error::InvalidFaucet)?;
|
||||||
}
|
}
|
||||||
|
|
||||||
if oracle.withdrawable == 0 {
|
if oracle.withdrawable == 0 {
|
||||||
|
@ -359,6 +372,41 @@ impl Processor {
|
||||||
let instruction =
|
let instruction =
|
||||||
Instruction::try_from_slice(input).map_err(|_| ProgramError::InvalidInstructionData)?;
|
Instruction::try_from_slice(input).map_err(|_| ProgramError::InvalidInstructionData)?;
|
||||||
|
|
||||||
|
// match branches would increase stack frame, and hit the hard 4096
|
||||||
|
// frame limit. break the other branches into another function call, and
|
||||||
|
// mark it as never inline.
|
||||||
|
match instruction {
|
||||||
|
Instruction::Submit { round_id, value } => SubmitContext {
|
||||||
|
clock: accounts.get_clock(0)?,
|
||||||
|
aggregator: accounts.get(1)?,
|
||||||
|
round_submissions: accounts.get(2)?,
|
||||||
|
answer_submissions: accounts.get(3)?,
|
||||||
|
oracle: accounts.get(4)?,
|
||||||
|
oracle_owner: accounts.get(5)?,
|
||||||
|
round_id,
|
||||||
|
value,
|
||||||
|
}
|
||||||
|
.process(),
|
||||||
|
|
||||||
|
Instruction::Withdraw { faucet_owner_seed } => WithdrawContext {
|
||||||
|
token_program: accounts.get(0)?,
|
||||||
|
aggregator: accounts.get(1)?,
|
||||||
|
faucet: accounts.get(2)?, // write
|
||||||
|
faucet_owner: accounts.get(3)?, // program signed
|
||||||
|
oracle: accounts.get(4)?, // write
|
||||||
|
oracle_owner: accounts.get(5)?, // signed
|
||||||
|
receiver: accounts.get(6)?, // write
|
||||||
|
|
||||||
|
faucet_owner_seed: &faucet_owner_seed[..],
|
||||||
|
}
|
||||||
|
.process(),
|
||||||
|
instruction => process2(instruction, accounts),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
#[inline(never)]
|
||||||
|
fn process2(instruction: Instruction, accounts: Accounts) -> ProgramResult {
|
||||||
match instruction {
|
match instruction {
|
||||||
Instruction::Initialize { config } => InitializeContext {
|
Instruction::Initialize { config } => InitializeContext {
|
||||||
rent: accounts.get_rent(0)?,
|
rent: accounts.get_rent(0)?,
|
||||||
|
@ -391,32 +439,7 @@ impl Processor {
|
||||||
oracle: accounts.get(2)?,
|
oracle: accounts.get(2)?,
|
||||||
}
|
}
|
||||||
.process(),
|
.process(),
|
||||||
Instruction::Submit { round_id, value } => SubmitContext {
|
_ => Err(ProgramError::InvalidInstructionData),
|
||||||
clock: accounts.get_clock(0)?,
|
|
||||||
aggregator: accounts.get(1)?,
|
|
||||||
round_submissions: accounts.get(2)?,
|
|
||||||
answer_submissions: accounts.get(3)?,
|
|
||||||
oracle: accounts.get(4)?,
|
|
||||||
oracle_owner: accounts.get(5)?,
|
|
||||||
|
|
||||||
round_id,
|
|
||||||
value,
|
|
||||||
}
|
|
||||||
.process(),
|
|
||||||
// _ => Err(ProgramError::InvalidInstructionData),
|
|
||||||
Instruction::Withdraw { faucet_owner_seed } => WithdrawContext {
|
|
||||||
token_program: accounts.get(0)?,
|
|
||||||
aggregator: accounts.get(1)?,
|
|
||||||
faucet: accounts.get(2)?,
|
|
||||||
faucet_owner: accounts.get(3)?,
|
|
||||||
oracle: accounts.get(4)?,
|
|
||||||
oracle_owner: accounts.get(5)?,
|
|
||||||
receiver: accounts.get(6)?,
|
|
||||||
|
|
||||||
faucet_owner_seed: &faucet_owner_seed[..],
|
|
||||||
}
|
|
||||||
.process(),
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue