Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[WIP] Cache bumps in a generated struct instead of a BTreeMap #2065

Closed
wants to merge 14 commits into from
6 changes: 3 additions & 3 deletions lang/src/accounts/account.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ use solana_program::account_info::AccountInfo;
use solana_program::instruction::AccountMeta;
use solana_program::pubkey::Pubkey;
use solana_program::system_program;
use std::collections::{BTreeMap, BTreeSet};
use std::collections::BTreeSet;
use std::fmt;
use std::ops::{Deref, DerefMut};

Expand Down Expand Up @@ -310,7 +310,7 @@ impl<'a, T: AccountSerialize + AccountDeserialize + crate::Owner + Clone> Accoun
}
}

impl<'info, T: AccountSerialize + AccountDeserialize + Owner + Clone> Accounts<'info>
impl<'info, B, T: AccountSerialize + AccountDeserialize + Owner + Clone> Accounts<'info, B>
for Account<'info, T>
where
T: AccountSerialize + AccountDeserialize + Owner + Clone,
Expand All @@ -320,7 +320,7 @@ where
_program_id: &Pubkey,
accounts: &mut &[AccountInfo<'info>],
_ix_data: &[u8],
_bumps: &mut BTreeMap<String, u8>,
_bumps: &mut B,
_reallocs: &mut BTreeSet<Pubkey>,
) -> Result<Self> {
if accounts.is_empty() {
Expand Down
6 changes: 3 additions & 3 deletions lang/src/accounts/account_info.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,14 @@ use crate::{Accounts, AccountsExit, Key, Result, ToAccountInfos, ToAccountMetas}
use solana_program::account_info::AccountInfo;
use solana_program::instruction::AccountMeta;
use solana_program::pubkey::Pubkey;
use std::collections::{BTreeMap, BTreeSet};
use std::collections::BTreeSet;

impl<'info> Accounts<'info> for AccountInfo<'info> {
impl<'info, B> Accounts<'info, B> for AccountInfo<'info> {
fn try_accounts(
_program_id: &Pubkey,
accounts: &mut &[AccountInfo<'info>],
_ix_data: &[u8],
_bumps: &mut BTreeMap<String, u8>,
_bumps: &mut B,
_reallocs: &mut BTreeSet<Pubkey>,
) -> Result<Self> {
if accounts.is_empty() {
Expand Down
6 changes: 3 additions & 3 deletions lang/src/accounts/account_loader.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ use solana_program::account_info::AccountInfo;
use solana_program::instruction::AccountMeta;
use solana_program::pubkey::Pubkey;
use std::cell::{Ref, RefMut};
use std::collections::{BTreeMap, BTreeSet};
use std::collections::BTreeSet;
use std::fmt;
use std::io::Write;
use std::marker::PhantomData;
Expand Down Expand Up @@ -214,13 +214,13 @@ impl<'info, T: ZeroCopy + Owner> AccountLoader<'info, T> {
}
}

impl<'info, T: ZeroCopy + Owner> Accounts<'info> for AccountLoader<'info, T> {
impl<'info, B, T: ZeroCopy + Owner> Accounts<'info, B> for AccountLoader<'info, T> {
#[inline(never)]
fn try_accounts(
_program_id: &Pubkey,
accounts: &mut &[AccountInfo<'info>],
_ix_data: &[u8],
_bumps: &mut BTreeMap<String, u8>,
_bumps: &mut B,
_reallocs: &mut BTreeSet<Pubkey>,
) -> Result<Self> {
if accounts.is_empty() {
Expand Down
6 changes: 3 additions & 3 deletions lang/src/accounts/boxed.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,15 +17,15 @@ use crate::{Accounts, AccountsClose, AccountsExit, Result, ToAccountInfos, ToAcc
use solana_program::account_info::AccountInfo;
use solana_program::instruction::AccountMeta;
use solana_program::pubkey::Pubkey;
use std::collections::{BTreeMap, BTreeSet};
use std::collections::BTreeSet;
use std::ops::Deref;

impl<'info, T: Accounts<'info>> Accounts<'info> for Box<T> {
impl<'info, B, T: Accounts<'info, B>> Accounts<'info, B> for Box<T> {
fn try_accounts(
program_id: &Pubkey,
accounts: &mut &[AccountInfo<'info>],
ix_data: &[u8],
bumps: &mut BTreeMap<String, u8>,
bumps: &mut B,
reallocs: &mut BTreeSet<Pubkey>,
) -> Result<Self> {
T::try_accounts(program_id, accounts, ix_data, bumps, reallocs).map(Box::new)
Expand Down
5 changes: 2 additions & 3 deletions lang/src/accounts/cpi_account.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ use crate::{error::ErrorCode, prelude::Account};
use solana_program::account_info::AccountInfo;
use solana_program::instruction::AccountMeta;
use solana_program::pubkey::Pubkey;
use std::collections::BTreeMap;
use std::ops::{Deref, DerefMut};

/// Container for any account *not* owned by the current program.
Expand Down Expand Up @@ -43,7 +42,7 @@ impl<'a, T: AccountDeserialize + Clone> CpiAccount<'a, T> {
}

#[allow(deprecated)]
impl<'info, T> Accounts<'info> for CpiAccount<'info, T>
impl<'info, B, T> Accounts<'info, B> for CpiAccount<'info, T>
where
T: AccountDeserialize + Clone,
{
Expand All @@ -52,7 +51,7 @@ where
_program_id: &Pubkey,
accounts: &mut &[AccountInfo<'info>],
_ix_data: &[u8],
_bumps: &mut BTreeMap<String, u8>,
_bumps: &mut B,
_reallocs: &mut BTreeSet<Pubkey>,
) -> Result<Self> {
if accounts.is_empty() {
Expand Down
10 changes: 5 additions & 5 deletions lang/src/accounts/cpi_state.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ use crate::{
use solana_program::account_info::AccountInfo;
use solana_program::instruction::AccountMeta;
use solana_program::pubkey::Pubkey;
use std::collections::{BTreeMap, BTreeSet};
use std::collections::BTreeSet;
use std::ops::{Deref, DerefMut};

/// Boxed container for the program state singleton, used when the state
Expand Down Expand Up @@ -52,17 +52,17 @@ impl<'info, T: AccountSerialize + AccountDeserialize + Clone> CpiState<'info, T>
}

/// Convenience api for creating a `CpiStateContext`.
pub fn context<'a, 'b, 'c, A: Accounts<'info>>(
pub fn context<'a, 'b, 'c, B, A: Accounts<'info, B>>(
&self,
program: AccountInfo<'info>,
accounts: A,
) -> CpiStateContext<'a, 'b, 'c, 'info, A> {
) -> CpiStateContext<'a, 'b, 'c, 'info, B, A> {
CpiStateContext::new(program, self.inner.info.clone(), accounts)
}
}

#[allow(deprecated)]
impl<'info, T> Accounts<'info> for CpiState<'info, T>
impl<'info, B, T> Accounts<'info, B> for CpiState<'info, T>
where
T: AccountSerialize + AccountDeserialize + Clone,
{
Expand All @@ -71,7 +71,7 @@ where
_program_id: &Pubkey,
accounts: &mut &[AccountInfo<'info>],
_ix_data: &[u8],
_bumps: &mut BTreeMap<String, u8>,
_bumps: &mut B,
_reallocs: &mut BTreeSet<Pubkey>,
) -> Result<Self> {
if accounts.is_empty() {
Expand Down
6 changes: 3 additions & 3 deletions lang/src/accounts/loader.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ use solana_program::account_info::AccountInfo;
use solana_program::instruction::AccountMeta;
use solana_program::pubkey::Pubkey;
use std::cell::{Ref, RefMut};
use std::collections::{BTreeMap, BTreeSet};
use std::collections::BTreeSet;
use std::fmt;
use std::io::Write;
use std::marker::PhantomData;
Expand Down Expand Up @@ -156,13 +156,13 @@ impl<'info, T: ZeroCopy> Loader<'info, T> {
}

#[allow(deprecated)]
impl<'info, T: ZeroCopy> Accounts<'info> for Loader<'info, T> {
impl<'info, B, T: ZeroCopy> Accounts<'info, B> for Loader<'info, T> {
#[inline(never)]
fn try_accounts(
program_id: &Pubkey,
accounts: &mut &[AccountInfo<'info>],
_ix_data: &[u8],
_bumps: &mut BTreeMap<String, u8>,
_bumps: &mut B,
_reallocs: &mut BTreeSet<Pubkey>,
) -> Result<Self> {
if accounts.is_empty() {
Expand Down
6 changes: 3 additions & 3 deletions lang/src/accounts/program.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ use solana_program::account_info::AccountInfo;
use solana_program::bpf_loader_upgradeable::{self, UpgradeableLoaderState};
use solana_program::instruction::AccountMeta;
use solana_program::pubkey::Pubkey;
use std::collections::{BTreeMap, BTreeSet};
use std::collections::BTreeSet;
use std::fmt;
use std::marker::PhantomData;
use std::ops::Deref;
Expand Down Expand Up @@ -137,7 +137,7 @@ impl<'a, T: Id + Clone> Program<'a, T> {
}
}

impl<'info, T> Accounts<'info> for Program<'info, T>
impl<'info, B, T> Accounts<'info, B> for Program<'info, T>
where
T: Id + Clone,
{
Expand All @@ -146,7 +146,7 @@ where
_program_id: &Pubkey,
accounts: &mut &[AccountInfo<'info>],
_ix_data: &[u8],
_bumps: &mut BTreeMap<String, u8>,
_bumps: &mut B,
_reallocs: &mut BTreeSet<Pubkey>,
) -> Result<Self> {
if accounts.is_empty() {
Expand Down
6 changes: 3 additions & 3 deletions lang/src/accounts/program_account.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ use crate::{
use solana_program::account_info::AccountInfo;
use solana_program::instruction::AccountMeta;
use solana_program::pubkey::Pubkey;
use std::collections::{BTreeMap, BTreeSet};
use std::collections::BTreeSet;
use std::ops::{Deref, DerefMut};

/// Boxed container for a deserialized `account`. Use this to reference any
Expand Down Expand Up @@ -73,7 +73,7 @@ impl<'a, T: AccountSerialize + AccountDeserialize + Clone> ProgramAccount<'a, T>
}

#[allow(deprecated)]
impl<'info, T> Accounts<'info> for ProgramAccount<'info, T>
impl<'info, B, T> Accounts<'info, B> for ProgramAccount<'info, T>
where
T: AccountSerialize + AccountDeserialize + Clone,
{
Expand All @@ -82,7 +82,7 @@ where
program_id: &Pubkey,
accounts: &mut &[AccountInfo<'info>],
_ix_data: &[u8],
_bumps: &mut BTreeMap<String, u8>,
_bumps: &mut B,
_reallocs: &mut BTreeSet<Pubkey>,
) -> Result<Self> {
if accounts.is_empty() {
Expand Down
6 changes: 3 additions & 3 deletions lang/src/accounts/signer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ use crate::{Accounts, AccountsExit, Key, Result, ToAccountInfos, ToAccountMetas}
use solana_program::account_info::AccountInfo;
use solana_program::instruction::AccountMeta;
use solana_program::pubkey::Pubkey;
use std::collections::{BTreeMap, BTreeSet};
use std::collections::BTreeSet;
use std::ops::Deref;

/// Type validating that the account signed the transaction. No other ownership
Expand Down Expand Up @@ -54,13 +54,13 @@ impl<'info> Signer<'info> {
}
}

impl<'info> Accounts<'info> for Signer<'info> {
impl<'info, B> Accounts<'info, B> for Signer<'info> {
#[inline(never)]
fn try_accounts(
_program_id: &Pubkey,
accounts: &mut &[AccountInfo<'info>],
_ix_data: &[u8],
_bumps: &mut BTreeMap<String, u8>,
_bumps: &mut B,
_reallocs: &mut BTreeSet<Pubkey>,
) -> Result<Self> {
if accounts.is_empty() {
Expand Down
6 changes: 3 additions & 3 deletions lang/src/accounts/state.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ use crate::{
use solana_program::account_info::AccountInfo;
use solana_program::instruction::AccountMeta;
use solana_program::pubkey::Pubkey;
use std::collections::{BTreeMap, BTreeSet};
use std::collections::BTreeSet;
use std::ops::{Deref, DerefMut};

pub const PROGRAM_STATE_SEED: &str = "unversioned";
Expand Down Expand Up @@ -64,7 +64,7 @@ impl<'a, T: AccountSerialize + AccountDeserialize + Clone> ProgramState<'a, T> {
}

#[allow(deprecated)]
impl<'info, T> Accounts<'info> for ProgramState<'info, T>
impl<'info, B, T> Accounts<'info, B> for ProgramState<'info, T>
where
T: AccountSerialize + AccountDeserialize + Clone,
{
Expand All @@ -73,7 +73,7 @@ where
program_id: &Pubkey,
accounts: &mut &[AccountInfo<'info>],
_ix_data: &[u8],
_bumps: &mut BTreeMap<String, u8>,
_bumps: &mut B,
_reallocs: &mut BTreeSet<Pubkey>,
) -> Result<Self> {
if accounts.is_empty() {
Expand Down
6 changes: 3 additions & 3 deletions lang/src/accounts/system_account.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ use solana_program::account_info::AccountInfo;
use solana_program::instruction::AccountMeta;
use solana_program::pubkey::Pubkey;
use solana_program::system_program;
use std::collections::{BTreeMap, BTreeSet};
use std::collections::BTreeSet;
use std::ops::Deref;

/// Type validating that the account is owned by the system program
Expand All @@ -33,13 +33,13 @@ impl<'info> SystemAccount<'info> {
}
}

impl<'info> Accounts<'info> for SystemAccount<'info> {
impl<'info, B> Accounts<'info, B> for SystemAccount<'info> {
#[inline(never)]
fn try_accounts(
_program_id: &Pubkey,
accounts: &mut &[AccountInfo<'info>],
_ix_data: &[u8],
_bumps: &mut BTreeMap<String, u8>,
_bumps: &mut B,
_reallocs: &mut BTreeSet<Pubkey>,
) -> Result<Self> {
if accounts.is_empty() {
Expand Down
6 changes: 3 additions & 3 deletions lang/src/accounts/sysvar.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ use crate::{Accounts, AccountsExit, Key, Result, ToAccountInfos, ToAccountMetas}
use solana_program::account_info::AccountInfo;
use solana_program::instruction::AccountMeta;
use solana_program::pubkey::Pubkey;
use std::collections::{BTreeMap, BTreeSet};
use std::collections::BTreeSet;
use std::fmt;
use std::ops::{Deref, DerefMut};

Expand Down Expand Up @@ -65,12 +65,12 @@ impl<'info, T: solana_program::sysvar::Sysvar> Clone for Sysvar<'info, T> {
}
}

impl<'info, T: solana_program::sysvar::Sysvar> Accounts<'info> for Sysvar<'info, T> {
impl<'info, B, T: solana_program::sysvar::Sysvar> Accounts<'info, B> for Sysvar<'info, T> {
fn try_accounts(
_program_id: &Pubkey,
accounts: &mut &[AccountInfo<'info>],
_ix_data: &[u8],
_bumps: &mut BTreeMap<String, u8>,
_bumps: &mut B,
_reallocs: &mut BTreeSet<Pubkey>,
) -> Result<Self> {
if accounts.is_empty() {
Expand Down
6 changes: 3 additions & 3 deletions lang/src/accounts/unchecked_account.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ use crate::{Accounts, AccountsExit, Key, Result, ToAccountInfos, ToAccountMetas}
use solana_program::account_info::AccountInfo;
use solana_program::instruction::AccountMeta;
use solana_program::pubkey::Pubkey;
use std::collections::{BTreeMap, BTreeSet};
use std::collections::BTreeSet;
use std::ops::Deref;

/// Explicit wrapper for AccountInfo types to emphasize
Expand All @@ -20,12 +20,12 @@ impl<'info> UncheckedAccount<'info> {
}
}

impl<'info> Accounts<'info> for UncheckedAccount<'info> {
impl<'info, B> Accounts<'info, B> for UncheckedAccount<'info> {
fn try_accounts(
_program_id: &Pubkey,
accounts: &mut &[AccountInfo<'info>],
_ix_data: &[u8],
_bumps: &mut BTreeMap<String, u8>,
_bumps: &mut B,
_reallocs: &mut BTreeSet<Pubkey>,
) -> Result<Self> {
if accounts.is_empty() {
Expand Down
Loading