chore: Remove abusive cloning (#2663)

This commit is contained in:
Jean Marchand (Exotic Markets) 2023-10-12 23:59:21 +02:00 committed by GitHub
parent 6cf200493a
commit 0fef819e4b
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
7 changed files with 158 additions and 176 deletions

View File

@ -18,7 +18,7 @@ Solana version: 1.17.0
| Program | Binary Size | +/- |
| ------- | ----------- | ------------------------ |
| bench | 764,032 | 🟢 **-389,704 (33.78%)** |
| bench | 735,800 | 🟢 **-417,936 (36.22%)** |
### Notable changes

View File

@ -22,53 +22,53 @@ Solana version: 1.17.0
| accountInfo2 | 824 | 🟢 **-651 (44.14%)** |
| accountInfo4 | 1,319 | 🟢 **-645 (32.84%)** |
| accountInfo8 | 2,531 | 🟢 **-1,310 (34.11%)** |
| accountEmptyInit1 | 5,099 | 🟢 **-718 (12.34%)** |
| accountEmptyInit1 | 4,899 | 🟢 **-918 (15.78%)** |
| accountEmpty1 | 708 | 🟢 **-441 (38.38%)** |
| accountEmptyInit2 | 9,676 | 🟢 **-726 (6.98%)** |
| accountEmptyInit2 | 9,325 | 🟢 **-1,077 (10.35%)** |
| accountEmpty2 | 1,064 | 🟢 **-690 (39.34%)** |
| accountEmptyInit4 | 18,477 | 🟢 **-1,031 (5.29%)** |
| accountEmptyInit4 | 17,821 | 🟢 **-1,687 (8.65%)** |
| accountEmpty4 | 1,766 | 🟢 **-774 (30.47%)** |
| accountEmptyInit8 | 36,113 | 🟢 **-1,152 (3.09%)** |
| accountEmptyInit8 | 34,855 | 🟢 **-2,410 (6.47%)** |
| accountEmpty8 | 3,179 | 🟢 **-1,837 (36.62%)** |
| accountSizedInit1 | 5,187 | 🟢 **-737 (12.44%)** |
| accountSizedInit1 | 4,988 | 🟢 **-936 (15.80%)** |
| accountSized1 | 732 | 🟢 **-482 (39.70%)** |
| accountSizedInit2 | 9,851 | 🟢 **-829 (7.76%)** |
| accountSizedInit2 | 9,499 | 🟢 **-1,181 (11.06%)** |
| accountSized2 | 1,106 | 🟢 **-767 (40.95%)** |
| accountSizedInit4 | 18,876 | 🟢 **-1,094 (5.48%)** |
| accountSizedInit4 | 18,219 | 🟢 **-1,751 (8.77%)** |
| accountSized4 | 1,863 | 🟢 **-899 (32.55%)** |
| accountSizedInit8 | 36,832 | 🟢 **-1,290 (3.38%)** |
| accountSizedInit8 | 35,574 | 🟢 **-2,548 (6.68%)** |
| accountSized8 | 3,374 | 🟢 **-1,979 (36.97%)** |
| accountUnsizedInit1 | 5,275 | 🟢 **-777 (12.84%)** |
| accountUnsizedInit1 | 5,075 | 🟢 **-977 (16.14%)** |
| accountUnsized1 | 759 | 🟢 **-579 (43.27%)** |
| accountUnsizedInit2 | 10,090 | 🟢 **-839 (7.68%)** |
| accountUnsizedInit2 | 9,736 | 🟢 **-1,193 (10.92%)** |
| accountUnsized2 | 1,168 | 🟢 **-610 (34.31%)** |
| accountUnsizedInit4 | 19,281 | 🟢 **-1,058 (5.20%)** |
| accountUnsizedInit4 | 18,622 | 🟢 **-1,717 (8.44%)** |
| accountUnsized4 | 2,000 | 🟢 **-1,136 (36.22%)** |
| accountUnsizedInit8 | 37,378 | 🟢 **-1,718 (4.39%)** |
| accountUnsizedInit8 | 36,119 | 🟢 **-2,977 (7.61%)** |
| accountUnsized8 | 3,667 | 🟢 **-2,285 (38.39%)** |
| boxedAccountEmptyInit1 | 5,145 | 🟢 **-889 (14.73%)** |
| boxedAccountEmptyInit1 | 4,952 | 🟢 **-1,082 (17.93%)** |
| boxedAccountEmpty1 | 745 | 🟢 **-143 (16.10%)** |
| boxedAccountEmptyInit2 | 9,769 | 🟢 **-864 (8.13%)** |
| boxedAccountEmptyInit2 | 9,426 | 🟢 **-1,207 (11.35%)** |
| boxedAccountEmpty2 | 1,136 | 🟢 **-265 (18.92%)** |
| boxedAccountEmptyInit4 | 18,661 | 🟢 **-650 (3.37%)** |
| boxedAccountEmptyInit4 | 18,020 | 🟢 **-1,291 (6.69%)** |
| boxedAccountEmpty4 | 1,913 | 🟢 **-511 (21.08%)** |
| boxedAccountEmptyInit8 | 36,488 | 🟢 **-648 (1.74%)** |
| boxedAccountEmptyInit8 | 35,248 | 🟢 **-1,888 (5.08%)** |
| boxedAccountEmpty8 | 3,500 | 🟢 **-1,159 (24.88%)** |
| boxedAccountSizedInit1 | 5,222 | 🟢 **-908 (14.81%)** |
| boxedAccountSizedInit1 | 5,027 | 🟢 **-1,103 (17.99%)** |
| boxedAccountSized1 | 767 | 🟢 **-150 (16.36%)** |
| boxedAccountSizedInit2 | 9,925 | 🟢 **-903 (8.34%)** |
| boxedAccountSizedInit2 | 9,582 | 🟢 **-1,246 (11.51%)** |
| boxedAccountSized2 | 1,183 | 🟢 **-280 (19.14%)** |
| boxedAccountSizedInit4 | 18,973 | 🟢 **-730 (3.71%)** |
| boxedAccountSizedInit4 | 18,332 | 🟢 **-1,371 (6.96%)** |
| boxedAccountSized4 | 2,002 | 🟢 **-541 (21.27%)** |
| boxedAccountSizedInit8 | 37,111 | 🟢 **-808 (2.13%)** |
| boxedAccountSizedInit8 | 35,868 | 🟢 **-2,051 (5.41%)** |
| boxedAccountSized8 | 3,682 | 🟢 **-1,216 (24.83%)** |
| boxedAccountUnsizedInit1 | 5,304 | 🟢 **-936 (15.00%)** |
| boxedAccountUnsizedInit1 | 5,109 | 🟢 **-1,131 (18.13%)** |
| boxedAccountUnsized1 | 797 | 🟢 **-175 (18.00%)** |
| boxedAccountUnsizedInit2 | 10,089 | 🟢 **-959 (8.68%)** |
| boxedAccountUnsizedInit2 | 9,746 | 🟢 **-1,302 (11.78%)** |
| boxedAccountUnsized2 | 1,246 | 🟢 **-324 (20.64%)** |
| boxedAccountUnsizedInit4 | 19,303 | 🟢 **-835 (4.15%)** |
| boxedAccountUnsizedInit4 | 18,658 | 🟢 **-1,480 (7.35%)** |
| boxedAccountUnsized4 | 2,135 | 🟢 **-633 (22.87%)** |
| boxedAccountUnsizedInit8 | 37,770 | 🟢 **-1,030 (2.65%)** |
| boxedAccountUnsizedInit8 | 36,525 | 🟢 **-2,275 (5.86%)** |
| boxedAccountUnsized8 | 3,948 | 🟢 **-1,399 (26.16%)** |
| boxedInterfaceAccountMint1 | 2,085 | 🟢 **-211 (9.19%)** |
| boxedInterfaceAccountMint2 | 3,726 | 🟢 **-403 (9.76%)** |

View File

@ -239,9 +239,10 @@ pub fn generate_constraint_close(
pub fn generate_constraint_mut(f: &Field, c: &ConstraintMut) -> proc_macro2::TokenStream {
let ident = &f.ident;
let account_ref = generate_account_ref(f);
let error = generate_custom_error(ident, &c.error, quote! { ConstraintMut }, &None);
quote! {
if !#ident.to_account_info().is_writable {
if !#account_ref.is_writable {
return #error;
}
}
@ -281,16 +282,11 @@ pub fn generate_constraint_has_one(
pub fn generate_constraint_signer(f: &Field, c: &ConstraintSigner) -> proc_macro2::TokenStream {
let ident = &f.ident;
let info = match f.ty {
Ty::AccountInfo => quote! { #ident },
Ty::Account(_) => quote! { #ident.to_account_info() },
Ty::InterfaceAccount(_) => quote! { #ident.to_account_info() },
Ty::AccountLoader(_) => quote! { #ident.to_account_info() },
_ => panic!("Invalid syntax: signer cannot be specified."),
};
let account_ref = generate_account_ref(f);
let error = generate_custom_error(ident, &c.error, quote! { ConstraintSigner }, &None);
quote! {
if !#info.is_signer {
if !#account_ref.is_signer {
return #error;
}
}
@ -403,7 +399,7 @@ fn generate_constraint_realloc(
**__field_info.lamports.borrow_mut() = __field_info.lamports().checked_sub(__lamport_amt).unwrap();
}
#field.to_account_info().realloc(#new_space, #zero)?;
__field_info.realloc(#new_space, #zero)?;
__reallocs.insert(#field.key());
}
}
@ -430,6 +426,8 @@ fn generate_constraint_init_group(
let from_account_info = f.from_account_info(Some(&c.kind), true);
let from_account_info_unchecked = f.from_account_info(Some(&c.kind), false);
let account_ref = generate_account_ref(f);
// PDA bump seeds.
let (find_pda, seeds_with_bump) = match &c.seeds {
None => (quote! {}, quote! {}),
@ -547,7 +545,7 @@ fn generate_constraint_init_group(
// Checks that all the required accounts for this operation are present.
#optional_checks
let owner_program = AsRef::<AccountInfo>::as_ref(&#field).owner;
let owner_program = #account_ref.owner;
if !#if_needed || owner_program == &anchor_lang::solana_program::system_program::ID {
#payer_optional_check
@ -618,7 +616,7 @@ fn generate_constraint_init_group(
// Checks that all the required accounts for this operation are present.
#optional_checks
let owner_program = AsRef::<AccountInfo>::as_ref(&#field).owner;
let owner_program = #account_ref.owner;
if !#if_needed || owner_program == &anchor_lang::solana_program::system_program::ID {
#payer_optional_check
@ -796,7 +794,7 @@ fn generate_constraint_init_group(
// Checks that all the required accounts for this operation are present.
#optional_checks
let actual_field = #field.to_account_info();
let actual_field = #account_ref;
let actual_owner = actual_field.owner;
// Define the account space variable.
@ -911,6 +909,7 @@ fn generate_constraint_associated_token(
) -> proc_macro2::TokenStream {
let name = &f.ident;
let name_str = name.to_string();
let account_ref = generate_account_ref(f);
let wallet_address = &c.wallet;
let spl_token_mint_address = &c.mint;
@ -928,7 +927,7 @@ fn generate_constraint_associated_token(
let token_program_optional_check = optional_check_scope.generate_check(token_program);
quote! {
#token_program_optional_check
if #name.to_account_info().owner != &#token_program.key() { return Err(anchor_lang::error::ErrorCode::ConstraintAssociatedTokenTokenProgram.into()); }
if #account_ref.owner != &#token_program.key() { return Err(anchor_lang::error::ErrorCode::ConstraintAssociatedTokenTokenProgram.into()); }
}
}
None => quote! {},
@ -967,6 +966,7 @@ fn generate_constraint_token_account(
accs: &AccountsStruct,
) -> proc_macro2::TokenStream {
let name = &f.ident;
let account_ref = generate_account_ref(f);
let mut optional_check_scope = OptionalCheckScope::new_with_field(accs, name);
let authority_check = match &c.authority {
Some(authority) => {
@ -993,7 +993,7 @@ fn generate_constraint_token_account(
let token_program_optional_check = optional_check_scope.generate_check(token_program);
quote! {
#token_program_optional_check
if #name.to_account_info().owner != &#token_program.key() { return Err(anchor_lang::error::ErrorCode::ConstraintTokenTokenProgram.into()); }
if #account_ref.owner != &#token_program.key() { return Err(anchor_lang::error::ErrorCode::ConstraintTokenTokenProgram.into()); }
}
}
None => quote! {},
@ -1013,6 +1013,7 @@ fn generate_constraint_mint(
accs: &AccountsStruct,
) -> proc_macro2::TokenStream {
let name = &f.ident;
let account_ref = generate_account_ref(f);
let decimal_check = match &c.decimals {
Some(decimals) => quote! {
@ -1053,7 +1054,7 @@ fn generate_constraint_mint(
let token_program_optional_check = optional_check_scope.generate_check(token_program);
quote! {
#token_program_optional_check
if #name.to_account_info().owner != &#token_program.key() { return Err(anchor_lang::error::ErrorCode::ConstraintMintTokenProgram.into()); }
if #account_ref.owner != &#token_program.key() { return Err(anchor_lang::error::ErrorCode::ConstraintMintTokenProgram.into()); }
}
}
None => quote! {},
@ -1192,13 +1193,13 @@ pub fn generate_constraint_executable(
f: &Field,
_c: &ConstraintExecutable,
) -> proc_macro2::TokenStream {
let name = &f.ident;
let name_str = name.to_string();
let name_str = f.ident.to_string();
let account_ref = generate_account_ref(f);
// because we are only acting on the field, we know it isnt optional at this point
// as it was unwrapped in `generate_constraint`
quote! {
if !#name.to_account_info().executable {
if !#account_ref.executable {
return Err(anchor_lang::error::Error::from(anchor_lang::error::ErrorCode::ConstraintExecutable).with_account_name(#name_str));
}
}
@ -1231,3 +1232,16 @@ fn generate_custom_error(
Err(#error)
}
}
fn generate_account_ref(field: &Field) -> proc_macro2::TokenStream {
let name = &field.ident;
match &field.ty {
Ty::AccountInfo => quote!(&#name),
Ty::Account(acc) if acc.boxed => quote!(AsRef::<AccountInfo>::as_ref(#name.as_ref())),
Ty::InterfaceAccount(acc) if acc.boxed => {
quote!(AsRef::<AccountInfo>::as_ref(#name.as_ref()))
}
_ => quote!(AsRef::<AccountInfo>::as_ref(&#name)),
}
}

View File

@ -166,7 +166,7 @@ pub fn idl_accounts_and_functions() -> proc_macro2::TokenStream {
accounts.from.clone(),
accounts.to.clone(),
accounts.base.clone(),
accounts.system_program.to_account_info().clone(),
accounts.system_program.to_account_info(),
],
&[seeds],
)?;
@ -209,15 +209,16 @@ pub fn idl_accounts_and_functions() -> proc_macro2::TokenStream {
return Err(anchor_lang::error::ErrorCode::IdlAccountNotEmpty.into());
}
let new_account_space = accounts.idl.to_account_info().data_len().checked_add(std::cmp::min(
let idl_ref = AsRef::<AccountInfo>::as_ref(&accounts.idl);
let new_account_space = idl_ref.data_len().checked_add(std::cmp::min(
data_len
.checked_sub(accounts.idl.to_account_info().data_len())
.checked_sub(idl_ref.data_len())
.expect("data_len should always be >= the current account space"),
10_000,
))
.unwrap();
if new_account_space > accounts.idl.to_account_info().data_len() {
if new_account_space > idl_ref.data_len() {
let sysvar_rent = Rent::get()?;
let new_rent_minimum = sysvar_rent.minimum_balance(new_account_space);
anchor_lang::system_program::transfer(
@ -229,10 +230,10 @@ pub fn idl_accounts_and_functions() -> proc_macro2::TokenStream {
},
),
new_rent_minimum
.checked_sub(accounts.idl.to_account_info().lamports())
.checked_sub(idl_ref.lamports())
.unwrap(),
)?;
accounts.idl.to_account_info().realloc(new_account_space, false)?;
idl_ref.realloc(new_account_space, false)?;
}
Ok(())

View File

@ -23,11 +23,7 @@ pub fn transfer<'info>(
)?;
solana_program::program::invoke_signed(
&ix,
&[
ctx.accounts.from.clone(),
ctx.accounts.to.clone(),
ctx.accounts.authority.clone(),
],
&[ctx.accounts.from, ctx.accounts.to, ctx.accounts.authority],
ctx.signer_seeds,
)
.map_err(Into::into)
@ -51,10 +47,10 @@ pub fn transfer_checked<'info>(
solana_program::program::invoke_signed(
&ix,
&[
ctx.accounts.from.clone(),
ctx.accounts.mint.clone(),
ctx.accounts.to.clone(),
ctx.accounts.authority.clone(),
ctx.accounts.from,
ctx.accounts.mint,
ctx.accounts.to,
ctx.accounts.authority,
],
ctx.signer_seeds,
)
@ -75,11 +71,7 @@ pub fn mint_to<'info>(
)?;
solana_program::program::invoke_signed(
&ix,
&[
ctx.accounts.to.clone(),
ctx.accounts.mint.clone(),
ctx.accounts.authority.clone(),
],
&[ctx.accounts.to, ctx.accounts.mint, ctx.accounts.authority],
ctx.signer_seeds,
)
.map_err(Into::into)
@ -96,11 +88,7 @@ pub fn burn<'info>(ctx: CpiContext<'_, '_, '_, 'info, Burn<'info>>, amount: u64)
)?;
solana_program::program::invoke_signed(
&ix,
&[
ctx.accounts.from.clone(),
ctx.accounts.mint.clone(),
ctx.accounts.authority.clone(),
],
&[ctx.accounts.from, ctx.accounts.mint, ctx.accounts.authority],
ctx.signer_seeds,
)
.map_err(Into::into)
@ -121,9 +109,9 @@ pub fn approve<'info>(
solana_program::program::invoke_signed(
&ix,
&[
ctx.accounts.to.clone(),
ctx.accounts.delegate.clone(),
ctx.accounts.authority.clone(),
ctx.accounts.to,
ctx.accounts.delegate,
ctx.accounts.authority,
],
ctx.signer_seeds,
)
@ -148,10 +136,10 @@ pub fn approve_checked<'info>(
solana_program::program::invoke_signed(
&ix,
&[
ctx.accounts.to.clone(),
ctx.accounts.mint.clone(),
ctx.accounts.delegate.clone(),
ctx.accounts.authority.clone(),
ctx.accounts.to,
ctx.accounts.mint,
ctx.accounts.delegate,
ctx.accounts.authority,
],
ctx.signer_seeds,
)
@ -167,7 +155,7 @@ pub fn revoke<'info>(ctx: CpiContext<'_, '_, '_, 'info, Revoke<'info>>) -> Resul
)?;
solana_program::program::invoke_signed(
&ix,
&[ctx.accounts.source.clone(), ctx.accounts.authority.clone()],
&[ctx.accounts.source, ctx.accounts.authority],
ctx.signer_seeds,
)
.map_err(Into::into)
@ -185,10 +173,10 @@ pub fn initialize_account<'info>(
solana_program::program::invoke_signed(
&ix,
&[
ctx.accounts.account.clone(),
ctx.accounts.mint.clone(),
ctx.accounts.authority.clone(),
ctx.accounts.rent.clone(),
ctx.accounts.account,
ctx.accounts.mint,
ctx.accounts.authority,
ctx.accounts.rent,
],
ctx.signer_seeds,
)
@ -206,7 +194,7 @@ pub fn initialize_account3<'info>(
)?;
solana_program::program::invoke_signed(
&ix,
&[ctx.accounts.account.clone(), ctx.accounts.mint.clone()],
&[ctx.accounts.account, ctx.accounts.mint],
ctx.signer_seeds,
)
.map_err(Into::into)
@ -223,9 +211,9 @@ pub fn close_account<'info>(ctx: CpiContext<'_, '_, '_, 'info, CloseAccount<'inf
solana_program::program::invoke_signed(
&ix,
&[
ctx.accounts.account.clone(),
ctx.accounts.destination.clone(),
ctx.accounts.authority.clone(),
ctx.accounts.account,
ctx.accounts.destination,
ctx.accounts.authority,
],
ctx.signer_seeds,
)
@ -245,9 +233,9 @@ pub fn freeze_account<'info>(
solana_program::program::invoke_signed(
&ix,
&[
ctx.accounts.account.clone(),
ctx.accounts.mint.clone(),
ctx.accounts.authority.clone(),
ctx.accounts.account,
ctx.accounts.mint,
ctx.accounts.authority,
],
ctx.signer_seeds,
)
@ -265,9 +253,9 @@ pub fn thaw_account<'info>(ctx: CpiContext<'_, '_, '_, 'info, ThawAccount<'info>
solana_program::program::invoke_signed(
&ix,
&[
ctx.accounts.account.clone(),
ctx.accounts.mint.clone(),
ctx.accounts.authority.clone(),
ctx.accounts.account,
ctx.accounts.mint,
ctx.accounts.authority,
],
ctx.signer_seeds,
)
@ -289,7 +277,7 @@ pub fn initialize_mint<'info>(
)?;
solana_program::program::invoke_signed(
&ix,
&[ctx.accounts.mint.clone(), ctx.accounts.rent.clone()],
&[ctx.accounts.mint, ctx.accounts.rent],
ctx.signer_seeds,
)
.map_err(Into::into)
@ -308,7 +296,7 @@ pub fn initialize_mint2<'info>(
freeze_authority,
decimals,
)?;
solana_program::program::invoke_signed(&ix, &[ctx.accounts.mint.clone()], ctx.signer_seeds)
solana_program::program::invoke_signed(&ix, &[ctx.accounts.mint], ctx.signer_seeds)
.map_err(Into::into)
}
@ -332,10 +320,7 @@ pub fn set_authority<'info>(
)?;
solana_program::program::invoke_signed(
&ix,
&[
ctx.accounts.account_or_mint.clone(),
ctx.accounts.current_authority.clone(),
],
&[ctx.accounts.account_or_mint, ctx.accounts.current_authority],
ctx.signer_seeds,
)
.map_err(Into::into)
@ -343,7 +328,7 @@ pub fn set_authority<'info>(
pub fn sync_native<'info>(ctx: CpiContext<'_, '_, '_, 'info, SyncNative<'info>>) -> Result<()> {
let ix = spl_token::instruction::sync_native(&spl_token::ID, ctx.accounts.account.key)?;
solana_program::program::invoke_signed(&ix, &[ctx.accounts.account.clone()], ctx.signer_seeds)
solana_program::program::invoke_signed(&ix, &[ctx.accounts.account], ctx.signer_seeds)
.map_err(Into::into)
}

View File

@ -26,11 +26,7 @@ pub fn transfer<'info>(
)?;
solana_program::program::invoke_signed(
&ix,
&[
ctx.accounts.from.clone(),
ctx.accounts.to.clone(),
ctx.accounts.authority.clone(),
],
&[ctx.accounts.from, ctx.accounts.to, ctx.accounts.authority],
ctx.signer_seeds,
)
.map_err(Into::into)
@ -54,10 +50,10 @@ pub fn transfer_checked<'info>(
solana_program::program::invoke_signed(
&ix,
&[
ctx.accounts.from.clone(),
ctx.accounts.mint.clone(),
ctx.accounts.to.clone(),
ctx.accounts.authority.clone(),
ctx.accounts.from,
ctx.accounts.mint,
ctx.accounts.to,
ctx.accounts.authority,
],
ctx.signer_seeds,
)
@ -78,11 +74,7 @@ pub fn mint_to<'info>(
)?;
solana_program::program::invoke_signed(
&ix,
&[
ctx.accounts.to.clone(),
ctx.accounts.mint.clone(),
ctx.accounts.authority.clone(),
],
&[ctx.accounts.to, ctx.accounts.mint, ctx.accounts.authority],
ctx.signer_seeds,
)
.map_err(Into::into)
@ -99,11 +91,7 @@ pub fn burn<'info>(ctx: CpiContext<'_, '_, '_, 'info, Burn<'info>>, amount: u64)
)?;
solana_program::program::invoke_signed(
&ix,
&[
ctx.accounts.from.clone(),
ctx.accounts.mint.clone(),
ctx.accounts.authority.clone(),
],
&[ctx.accounts.from, ctx.accounts.mint, ctx.accounts.authority],
ctx.signer_seeds,
)
.map_err(Into::into)
@ -124,9 +112,9 @@ pub fn approve<'info>(
solana_program::program::invoke_signed(
&ix,
&[
ctx.accounts.to.clone(),
ctx.accounts.delegate.clone(),
ctx.accounts.authority.clone(),
ctx.accounts.to,
ctx.accounts.delegate,
ctx.accounts.authority,
],
ctx.signer_seeds,
)
@ -142,7 +130,7 @@ pub fn revoke<'info>(ctx: CpiContext<'_, '_, '_, 'info, Revoke<'info>>) -> Resul
)?;
solana_program::program::invoke_signed(
&ix,
&[ctx.accounts.source.clone(), ctx.accounts.authority.clone()],
&[ctx.accounts.source, ctx.accounts.authority],
ctx.signer_seeds,
)
.map_err(Into::into)
@ -160,10 +148,10 @@ pub fn initialize_account<'info>(
solana_program::program::invoke(
&ix,
&[
ctx.accounts.account.clone(),
ctx.accounts.mint.clone(),
ctx.accounts.authority.clone(),
ctx.accounts.rent.clone(),
ctx.accounts.account,
ctx.accounts.mint,
ctx.accounts.authority,
ctx.accounts.rent,
],
)
.map_err(Into::into)
@ -178,10 +166,7 @@ pub fn initialize_account3<'info>(
ctx.accounts.mint.key,
ctx.accounts.authority.key,
)?;
solana_program::program::invoke(
&ix,
&[ctx.accounts.account.clone(), ctx.accounts.mint.clone()],
)
solana_program::program::invoke(&ix, &[ctx.accounts.account, ctx.accounts.mint])
.map_err(Into::into)
}
@ -196,9 +181,9 @@ pub fn close_account<'info>(ctx: CpiContext<'_, '_, '_, 'info, CloseAccount<'inf
solana_program::program::invoke_signed(
&ix,
&[
ctx.accounts.account.clone(),
ctx.accounts.destination.clone(),
ctx.accounts.authority.clone(),
ctx.accounts.account,
ctx.accounts.destination,
ctx.accounts.authority,
],
ctx.signer_seeds,
)
@ -218,9 +203,9 @@ pub fn freeze_account<'info>(
solana_program::program::invoke_signed(
&ix,
&[
ctx.accounts.account.clone(),
ctx.accounts.mint.clone(),
ctx.accounts.authority.clone(),
ctx.accounts.account,
ctx.accounts.mint,
ctx.accounts.authority,
],
ctx.signer_seeds,
)
@ -238,9 +223,9 @@ pub fn thaw_account<'info>(ctx: CpiContext<'_, '_, '_, 'info, ThawAccount<'info>
solana_program::program::invoke_signed(
&ix,
&[
ctx.accounts.account.clone(),
ctx.accounts.mint.clone(),
ctx.accounts.authority.clone(),
ctx.accounts.account,
ctx.accounts.mint,
ctx.accounts.authority,
],
ctx.signer_seeds,
)
@ -260,7 +245,7 @@ pub fn initialize_mint<'info>(
freeze_authority,
decimals,
)?;
solana_program::program::invoke(&ix, &[ctx.accounts.mint.clone(), ctx.accounts.rent.clone()])
solana_program::program::invoke(&ix, &[ctx.accounts.mint, ctx.accounts.rent])
.map_err(Into::into)
}
@ -277,7 +262,7 @@ pub fn initialize_mint2<'info>(
freeze_authority,
decimals,
)?;
solana_program::program::invoke(&ix, &[ctx.accounts.mint.clone()]).map_err(Into::into)
solana_program::program::invoke(&ix, &[ctx.accounts.mint]).map_err(Into::into)
}
pub fn set_authority<'info>(
@ -300,10 +285,7 @@ pub fn set_authority<'info>(
)?;
solana_program::program::invoke_signed(
&ix,
&[
ctx.accounts.account_or_mint.clone(),
ctx.accounts.current_authority.clone(),
],
&[ctx.accounts.account_or_mint, ctx.accounts.current_authority],
ctx.signer_seeds,
)
.map_err(Into::into)
@ -311,7 +293,7 @@ pub fn set_authority<'info>(
pub fn sync_native<'info>(ctx: CpiContext<'_, '_, '_, 'info, SyncNative<'info>>) -> Result<()> {
let ix = spl_token_2022::instruction::sync_native(ctx.program.key, ctx.accounts.account.key)?;
solana_program::program::invoke(&ix, &[ctx.accounts.account.clone()]).map_err(Into::into)
solana_program::program::invoke(&ix, &[ctx.accounts.account]).map_err(Into::into)
}
pub fn get_account_data_size<'info>(
@ -323,7 +305,7 @@ pub fn get_account_data_size<'info>(
ctx.accounts.mint.key,
extension_types,
)?;
solana_program::program::invoke(&ix, &[ctx.accounts.mint.clone()])?;
solana_program::program::invoke(&ix, &[ctx.accounts.mint])?;
solana_program::program::get_return_data()
.ok_or(solana_program::program_error::ProgramError::InvalidInstructionData)
.and_then(|(key, data)| {
@ -347,7 +329,7 @@ pub fn initialize_mint_close_authority<'info>(
ctx.accounts.mint.key,
close_authority,
)?;
solana_program::program::invoke(&ix, &[ctx.accounts.mint.clone()]).map_err(Into::into)
solana_program::program::invoke(&ix, &[ctx.accounts.mint]).map_err(Into::into)
}
pub fn initialize_immutable_owner<'info>(
@ -357,7 +339,7 @@ pub fn initialize_immutable_owner<'info>(
ctx.program.key,
ctx.accounts.account.key,
)?;
solana_program::program::invoke(&ix, &[ctx.accounts.account.clone()]).map_err(Into::into)
solana_program::program::invoke(&ix, &[ctx.accounts.account]).map_err(Into::into)
}
pub fn amount_to_ui_amount<'info>(
@ -369,7 +351,7 @@ pub fn amount_to_ui_amount<'info>(
ctx.accounts.account.key,
amount,
)?;
solana_program::program::invoke(&ix, &[ctx.accounts.account.clone()])?;
solana_program::program::invoke(&ix, &[ctx.accounts.account])?;
solana_program::program::get_return_data()
.ok_or(solana_program::program_error::ProgramError::InvalidInstructionData)
.and_then(|(key, data)| {
@ -393,7 +375,7 @@ pub fn ui_amount_to_amount<'info>(
ctx.accounts.account.key,
ui_amount,
)?;
solana_program::program::invoke(&ix, &[ctx.accounts.account.clone()])?;
solana_program::program::invoke(&ix, &[ctx.accounts.account])?;
solana_program::program::get_return_data()
.ok_or(solana_program::program_error::ProgramError::InvalidInstructionData)
.and_then(|(key, data)| {

View File

@ -375,60 +375,60 @@
"solanaVersion": "1.17.0",
"result": {
"binarySize": {
"bench": 764032
"bench": 735800
},
"computeUnits": {
"accountInfo1": 584,
"accountInfo2": 824,
"accountInfo4": 1319,
"accountInfo8": 2531,
"accountEmptyInit1": 5099,
"accountEmptyInit1": 4899,
"accountEmpty1": 708,
"accountEmptyInit2": 9676,
"accountEmptyInit2": 9325,
"accountEmpty2": 1064,
"accountEmptyInit4": 18477,
"accountEmptyInit4": 17821,
"accountEmpty4": 1766,
"accountEmptyInit8": 36113,
"accountEmptyInit8": 34855,
"accountEmpty8": 3179,
"accountSizedInit1": 5187,
"accountSizedInit1": 4988,
"accountSized1": 732,
"accountSizedInit2": 9851,
"accountSizedInit2": 9499,
"accountSized2": 1106,
"accountSizedInit4": 18876,
"accountSizedInit4": 18219,
"accountSized4": 1863,
"accountSizedInit8": 36832,
"accountSizedInit8": 35574,
"accountSized8": 3374,
"accountUnsizedInit1": 5275,
"accountUnsizedInit1": 5075,
"accountUnsized1": 759,
"accountUnsizedInit2": 10090,
"accountUnsizedInit2": 9736,
"accountUnsized2": 1168,
"accountUnsizedInit4": 19281,
"accountUnsizedInit4": 18622,
"accountUnsized4": 2000,
"accountUnsizedInit8": 37378,
"accountUnsizedInit8": 36119,
"accountUnsized8": 3667,
"boxedAccountEmptyInit1": 5145,
"boxedAccountEmptyInit1": 4952,
"boxedAccountEmpty1": 745,
"boxedAccountEmptyInit2": 9769,
"boxedAccountEmptyInit2": 9426,
"boxedAccountEmpty2": 1136,
"boxedAccountEmptyInit4": 18661,
"boxedAccountEmptyInit4": 18020,
"boxedAccountEmpty4": 1913,
"boxedAccountEmptyInit8": 36488,
"boxedAccountEmptyInit8": 35248,
"boxedAccountEmpty8": 3500,
"boxedAccountSizedInit1": 5222,
"boxedAccountSizedInit1": 5027,
"boxedAccountSized1": 767,
"boxedAccountSizedInit2": 9925,
"boxedAccountSizedInit2": 9582,
"boxedAccountSized2": 1183,
"boxedAccountSizedInit4": 18973,
"boxedAccountSizedInit4": 18332,
"boxedAccountSized4": 2002,
"boxedAccountSizedInit8": 37111,
"boxedAccountSizedInit8": 35868,
"boxedAccountSized8": 3682,
"boxedAccountUnsizedInit1": 5304,
"boxedAccountUnsizedInit1": 5109,
"boxedAccountUnsized1": 797,
"boxedAccountUnsizedInit2": 10089,
"boxedAccountUnsizedInit2": 9746,
"boxedAccountUnsized2": 1246,
"boxedAccountUnsizedInit4": 19303,
"boxedAccountUnsizedInit4": 18658,
"boxedAccountUnsized4": 2135,
"boxedAccountUnsizedInit8": 37770,
"boxedAccountUnsizedInit8": 36525,
"boxedAccountUnsized8": 3948,
"boxedInterfaceAccountMint1": 2085,
"boxedInterfaceAccountMint2": 3726,