Refactor: Replaces KeyedAccount in_get_sysvar_with_account_check (#23905)

* Replaces all use sites of get_sysvar_with_account_check by get_sysvar_with_account_check2.

* Removes get_sysvar_with_account_check.

* Renames get_sysvar_with_account_check2 to get_sysvar_with_account_check.
This commit is contained in:
Alexander Meißner
2022-03-24 19:30:42 +01:00
committed by GitHub
parent 37c36ce3fa
commit 140c8dd01f
5 changed files with 50 additions and 161 deletions

View File

@@ -492,20 +492,9 @@ fn process_loader_upgradeable_instruction(
keyed_accounts,
first_instruction_account.saturating_add(3),
)?;
let rent = get_sysvar_with_account_check::rent(
keyed_account_at_index(
keyed_accounts,
first_instruction_account.saturating_add(4),
)?,
invoke_context,
)?;
let clock = get_sysvar_with_account_check::clock(
keyed_account_at_index(
keyed_accounts,
first_instruction_account.saturating_add(5),
)?,
invoke_context,
)?;
let rent = get_sysvar_with_account_check::rent(invoke_context, instruction_context, 4)?;
let clock =
get_sysvar_with_account_check::clock(invoke_context, instruction_context, 5)?;
let authority = keyed_account_at_index(
keyed_accounts,
first_instruction_account.saturating_add(7),
@@ -683,20 +672,9 @@ fn process_loader_upgradeable_instruction(
keyed_accounts,
first_instruction_account.saturating_add(2),
)?;
let rent = get_sysvar_with_account_check::rent(
keyed_account_at_index(
keyed_accounts,
first_instruction_account.saturating_add(4),
)?,
invoke_context,
)?;
let clock = get_sysvar_with_account_check::clock(
keyed_account_at_index(
keyed_accounts,
first_instruction_account.saturating_add(5),
)?,
invoke_context,
)?;
let rent = get_sysvar_with_account_check::rent(invoke_context, instruction_context, 4)?;
let clock =
get_sysvar_with_account_check::clock(invoke_context, instruction_context, 5)?;
let authority = keyed_account_at_index(
keyed_accounts,
first_instruction_account.saturating_add(6),

View File

@@ -43,10 +43,7 @@ pub fn process_instruction(
let signers = instruction_context.get_signers(transaction_context);
match limited_deserialize(data)? {
StakeInstruction::Initialize(authorized, lockup) => {
let rent = get_sysvar_with_account_check::rent(
keyed_account_at_index(keyed_accounts, first_instruction_account + 1)?,
invoke_context,
)?;
let rent = get_sysvar_with_account_check::rent(invoke_context, instruction_context, 1)?;
me.initialize(&authorized, &lockup, &rent)
}
StakeInstruction::Authorize(authorized_pubkey, stake_authorize) => {
@@ -55,10 +52,8 @@ pub fn process_instruction(
.is_active(&feature_set::require_custodian_for_locked_stake_authorize::id());
if require_custodian_for_locked_stake_authorize {
let clock = get_sysvar_with_account_check::clock(
keyed_account_at_index(keyed_accounts, first_instruction_account + 1)?,
invoke_context,
)?;
let clock =
get_sysvar_with_account_check::clock(invoke_context, instruction_context, 1)?;
let _current_authority =
keyed_account_at_index(keyed_accounts, first_instruction_account + 2)?;
let custodian =
@@ -93,10 +88,8 @@ pub fn process_instruction(
.is_active(&feature_set::require_custodian_for_locked_stake_authorize::id());
if require_custodian_for_locked_stake_authorize {
let clock = get_sysvar_with_account_check::clock(
keyed_account_at_index(keyed_accounts, first_instruction_account + 2)?,
invoke_context,
)?;
let clock =
get_sysvar_with_account_check::clock(invoke_context, instruction_context, 2)?;
let custodian =
keyed_account_at_index(keyed_accounts, first_instruction_account + 3)
.ok()
@@ -127,13 +120,12 @@ pub fn process_instruction(
}
StakeInstruction::DelegateStake => {
let vote = keyed_account_at_index(keyed_accounts, first_instruction_account + 1)?;
let clock = get_sysvar_with_account_check::clock(
keyed_account_at_index(keyed_accounts, first_instruction_account + 2)?,
invoke_context,
)?;
let clock =
get_sysvar_with_account_check::clock(invoke_context, instruction_context, 2)?;
let stake_history = get_sysvar_with_account_check::stake_history(
keyed_account_at_index(keyed_accounts, first_instruction_account + 3)?,
invoke_context,
instruction_context,
3,
)?;
let config_account =
keyed_account_at_index(keyed_accounts, first_instruction_account + 4)?;
@@ -152,13 +144,12 @@ pub fn process_instruction(
StakeInstruction::Merge => {
let source_stake =
&keyed_account_at_index(keyed_accounts, first_instruction_account + 1)?;
let clock = get_sysvar_with_account_check::clock(
keyed_account_at_index(keyed_accounts, first_instruction_account + 2)?,
invoke_context,
)?;
let clock =
get_sysvar_with_account_check::clock(invoke_context, instruction_context, 2)?;
let stake_history = get_sysvar_with_account_check::stake_history(
keyed_account_at_index(keyed_accounts, first_instruction_account + 3)?,
invoke_context,
instruction_context,
3,
)?;
me.merge(
invoke_context,
@@ -170,13 +161,12 @@ pub fn process_instruction(
}
StakeInstruction::Withdraw(lamports) => {
let to = &keyed_account_at_index(keyed_accounts, first_instruction_account + 1)?;
let clock = get_sysvar_with_account_check::clock(
keyed_account_at_index(keyed_accounts, first_instruction_account + 2)?,
invoke_context,
)?;
let clock =
get_sysvar_with_account_check::clock(invoke_context, instruction_context, 2)?;
let stake_history = get_sysvar_with_account_check::stake_history(
keyed_account_at_index(keyed_accounts, first_instruction_account + 3)?,
invoke_context,
instruction_context,
3,
)?;
me.withdraw(
lamports,
@@ -188,10 +178,8 @@ pub fn process_instruction(
)
}
StakeInstruction::Deactivate => {
let clock = get_sysvar_with_account_check::clock(
keyed_account_at_index(keyed_accounts, first_instruction_account + 1)?,
invoke_context,
)?;
let clock =
get_sysvar_with_account_check::clock(invoke_context, instruction_context, 1)?;
me.deactivate(&clock, &signers)
}
StakeInstruction::SetLockup(lockup) => {
@@ -214,10 +202,8 @@ pub fn process_instruction(
.ok_or(InstructionError::MissingRequiredSignature)?,
};
let rent = get_sysvar_with_account_check::rent(
keyed_account_at_index(keyed_accounts, first_instruction_account + 1)?,
invoke_context,
)?;
let rent =
get_sysvar_with_account_check::rent(invoke_context, instruction_context, 1)?;
me.initialize(&authorized, &Lockup::default(), &rent)
} else {
Err(InstructionError::InvalidInstructionData)
@@ -228,10 +214,8 @@ pub fn process_instruction(
.feature_set
.is_active(&feature_set::vote_stake_checked_instructions::id())
{
let clock = get_sysvar_with_account_check::clock(
keyed_account_at_index(keyed_accounts, first_instruction_account + 1)?,
invoke_context,
)?;
let clock =
get_sysvar_with_account_check::clock(invoke_context, instruction_context, 1)?;
let _current_authority =
keyed_account_at_index(keyed_accounts, first_instruction_account + 2)?;
let authorized_pubkey =
@@ -262,10 +246,8 @@ pub fn process_instruction(
{
let authority_base =
keyed_account_at_index(keyed_accounts, first_instruction_account + 1)?;
let clock = get_sysvar_with_account_check::clock(
keyed_account_at_index(keyed_accounts, first_instruction_account + 2)?,
invoke_context,
)?;
let clock =
get_sysvar_with_account_check::clock(invoke_context, instruction_context, 2)?;
let authorized_pubkey =
&keyed_account_at_index(keyed_accounts, first_instruction_account + 3)?
.signer_key()

View File

@@ -36,22 +36,15 @@ pub fn process_instruction(
let signers = instruction_context.get_signers(transaction_context);
match limited_deserialize(data)? {
VoteInstruction::InitializeAccount(vote_init) => {
let rent = get_sysvar_with_account_check::rent(
keyed_account_at_index(keyed_accounts, first_instruction_account + 1)?,
invoke_context,
)?;
let rent = get_sysvar_with_account_check::rent(invoke_context, instruction_context, 1)?;
verify_rent_exemption(me, &rent)?;
let clock = get_sysvar_with_account_check::clock(
keyed_account_at_index(keyed_accounts, first_instruction_account + 2)?,
invoke_context,
)?;
let clock =
get_sysvar_with_account_check::clock(invoke_context, instruction_context, 2)?;
vote_state::initialize_account(me, &vote_init, &signers, &clock)
}
VoteInstruction::Authorize(voter_pubkey, vote_authorize) => {
let clock = get_sysvar_with_account_check::clock(
keyed_account_at_index(keyed_accounts, first_instruction_account + 1)?,
invoke_context,
)?;
let clock =
get_sysvar_with_account_check::clock(invoke_context, instruction_context, 1)?;
vote_state::authorize(
me,
&voter_pubkey,
@@ -71,14 +64,10 @@ pub fn process_instruction(
}
VoteInstruction::Vote(vote) | VoteInstruction::VoteSwitch(vote, _) => {
inc_new_counter_info!("vote-native", 1);
let slot_hashes = get_sysvar_with_account_check::slot_hashes(
keyed_account_at_index(keyed_accounts, first_instruction_account + 1)?,
invoke_context,
)?;
let clock = get_sysvar_with_account_check::clock(
keyed_account_at_index(keyed_accounts, first_instruction_account + 2)?,
invoke_context,
)?;
let slot_hashes =
get_sysvar_with_account_check::slot_hashes(invoke_context, instruction_context, 1)?;
let clock =
get_sysvar_with_account_check::clock(invoke_context, instruction_context, 2)?;
vote_state::process_vote(
me,
&slot_hashes,
@@ -147,10 +136,8 @@ pub fn process_instruction(
&keyed_account_at_index(keyed_accounts, first_instruction_account + 3)?
.signer_key()
.ok_or(InstructionError::MissingRequiredSignature)?;
let clock = get_sysvar_with_account_check::clock(
keyed_account_at_index(keyed_accounts, first_instruction_account + 1)?,
invoke_context,
)?;
let clock =
get_sysvar_with_account_check::clock(invoke_context, instruction_context, 1)?;
vote_state::authorize(
me,
voter_pubkey,