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

program: adjust account load ordering to match builtin #44

Merged
merged 2 commits into from
Nov 13, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 26 additions & 0 deletions program/benches/compute_units.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,29 @@
#### Compute Units: 2024-11-13 09:15:26.655388 UTC

| Name | CUs | Delta |
|------|------|-------|
| create_lookup_table | 10756 | -3 |
| freeze_lookup_table | 1518 | -- |
| extend_lookup_table_from_0_to_1 | 6227 | +1 |
| extend_lookup_table_from_0_to_10 | 8846 | +1 |
| extend_lookup_table_from_0_to_38 | 17082 | +1 |
| extend_lookup_table_from_1_to_2 | 6227 | +1 |
| extend_lookup_table_from_1_to_10 | 8552 | +1 |
| extend_lookup_table_from_1_to_39 | 17082 | +1 |
| extend_lookup_table_from_5_to_6 | 6227 | +1 |
| extend_lookup_table_from_5_to_15 | 8847 | +1 |
| extend_lookup_table_from_5_to_43 | 17082 | +1 |
| extend_lookup_table_from_25_to_26 | 6230 | +1 |
| extend_lookup_table_from_25_to_35 | 8849 | +1 |
| extend_lookup_table_from_25_to_63 | 17085 | +1 |
| extend_lookup_table_from_50_to_88 | 17088 | +1 |
| extend_lookup_table_from_100_to_138 | 17094 | +1 |
| extend_lookup_table_from_150_to_188 | 17101 | +1 |
| extend_lookup_table_from_200_to_238 | 17107 | +1 |
| extend_lookup_table_from_255_to_256 | 6259 | +1 |
| deactivate_lookup_table | 3152 | -- |
| close_lookup_table | 2228 | +1 |

#### Compute Units: 2024-11-08 13:17:54.004441 UTC

| Name | CUs | Delta |
Expand Down
21 changes: 14 additions & 7 deletions program/src/processor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,6 @@ fn process_create_lookup_table(
let lookup_table_info = next_account_info(accounts_iter)?;
let authority_info = next_account_info(accounts_iter)?;
let payer_info = next_account_info(accounts_iter)?;
let _system_program_info = next_account_info(accounts_iter)?;

if !payer_info.is_signer {
msg!("Payer account must be a signer");
Expand Down Expand Up @@ -191,6 +190,8 @@ fn process_create_lookup_table(
)?;
}

let _system_program_info = next_account_info(accounts_iter)?;

invoke_signed(
&system_instruction::allocate(lookup_table_info.key, lookup_table_data_len as u64),
&[lookup_table_info.clone()],
Expand All @@ -215,13 +216,14 @@ fn process_freeze_lookup_table(program_id: &Pubkey, accounts: &[AccountInfo]) ->
let accounts_iter = &mut accounts.iter();

let lookup_table_info = next_account_info(accounts_iter)?;
let authority_info = next_account_info(accounts_iter)?;

if lookup_table_info.owner != program_id {
msg!("Lookup table owner should be the Address Lookup Table program");
return Err(ProgramError::InvalidAccountOwner);
}

let authority_info = next_account_info(accounts_iter)?;

if !authority_info.is_signer {
msg!("Authority account must be a signer");
return Err(ProgramError::MissingRequiredSignature);
Expand Down Expand Up @@ -268,13 +270,14 @@ fn process_extend_lookup_table(
let accounts_iter = &mut accounts.iter();

let lookup_table_info = next_account_info(accounts_iter)?;
let authority_info = next_account_info(accounts_iter)?;

if lookup_table_info.owner != program_id {
msg!("Lookup table owner should be the Address Lookup Table program");
return Err(ProgramError::InvalidAccountOwner);
}

let authority_info = next_account_info(accounts_iter)?;

if !authority_info.is_signer {
msg!("Authority account must be a signer");
return Err(ProgramError::MissingRequiredSignature);
Expand Down Expand Up @@ -398,13 +401,14 @@ fn process_extend_lookup_table(

if required_lamports > 0 {
let payer_info = next_account_info(accounts_iter)?;
let _system_program_info = next_account_info(accounts_iter)?;

if !payer_info.is_signer {
msg!("Payer account must be a signer");
return Err(ProgramError::MissingRequiredSignature);
}

let _system_program_info = next_account_info(accounts_iter)?;

invoke(
&system_instruction::transfer(payer_info.key, lookup_table_info.key, required_lamports),
&[payer_info.clone(), lookup_table_info.clone()],
Expand All @@ -418,13 +422,14 @@ fn process_deactivate_lookup_table(program_id: &Pubkey, accounts: &[AccountInfo]
let accounts_iter = &mut accounts.iter();

let lookup_table_info = next_account_info(accounts_iter)?;
let authority_info = next_account_info(accounts_iter)?;

if lookup_table_info.owner != program_id {
msg!("Lookup table owner should be the Address Lookup Table program");
return Err(ProgramError::InvalidAccountOwner);
}

let authority_info = next_account_info(accounts_iter)?;

if !authority_info.is_signer {
msg!("Authority account must be a signer");
return Err(ProgramError::MissingRequiredSignature);
Expand Down Expand Up @@ -466,19 +471,21 @@ fn process_close_lookup_table(program_id: &Pubkey, accounts: &[AccountInfo]) ->
let accounts_iter = &mut accounts.iter();

let lookup_table_info = next_account_info(accounts_iter)?;
let authority_info = next_account_info(accounts_iter)?;
let recipient_info = next_account_info(accounts_iter)?;

if lookup_table_info.owner != program_id {
msg!("Lookup table owner should be the Address Lookup Table program");
return Err(ProgramError::InvalidAccountOwner);
}

let authority_info = next_account_info(accounts_iter)?;

if !authority_info.is_signer {
msg!("Authority account must be a signer");
return Err(ProgramError::MissingRequiredSignature);
}

let recipient_info = next_account_info(accounts_iter)?;

// [Core BPF]: Here the legacy built-in version of ALT fallibly checks to
// ensure the number of instruction accounts is 3.
// It also checks that the recipient account is not the same as the lookup
Expand Down