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

refactor: optimize some checks on upd_price #403

Merged
merged 2 commits into from
May 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
16 changes: 1 addition & 15 deletions program/rust/src/tests/test_add_publisher.rs
Original file line number Diff line number Diff line change
Expand Up @@ -58,21 +58,7 @@ fn test_add_publisher() {
permissions_account_data.security_authority = *funding_account.key;
}

// Expect the instruction to fail, because the price account isn't rent exempt
assert_eq!(
process_instruction(
&program_id,
&[
funding_account.clone(),
price_account.clone(),
permissions_account.clone(),
],
instruction_data
),
Err(OracleError::InvalidWritableAccount.into())
);

// Now give the price account enough lamports to be rent exempt
// Give the price account enough lamports to be rent exempt
**price_account.try_borrow_mut_lamports().unwrap() =
Rent::minimum_balance(&Rent::default(), PriceAccount::MINIMUM_SIZE);

Expand Down
15 changes: 3 additions & 12 deletions program/rust/src/utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -115,9 +115,7 @@ fn valid_writable_account(
program_id: &Pubkey,
account: &AccountInfo,
) -> Result<bool, ProgramError> {
Ok(account.is_writable
&& account.owner == program_id
&& get_rent()?.is_exempt(account.lamports(), account.data_len()))
Ok(account.is_writable && account.owner == program_id)
}

pub fn check_valid_writable_account(
Expand All @@ -134,10 +132,7 @@ fn valid_readable_account(
program_id: &Pubkey,
account: &AccountInfo,
) -> Result<bool, ProgramError> {
Ok(
account.owner == program_id
&& get_rent()?.is_exempt(account.lamports(), account.data_len()),
)
Ok(account.owner == program_id)
}

pub fn check_valid_readable_account(
Expand Down Expand Up @@ -180,11 +175,7 @@ pub fn get_status_for_conf_price_ratio(
confidence: u64,
status: u32,
) -> Result<u32, OracleError> {
let mut threshold_conf = price / MAX_CI_DIVISOR;

if threshold_conf < 0 {
threshold_conf = -threshold_conf;
}
let threshold_conf = price.abs() / MAX_CI_DIVISOR;

if confidence > try_convert::<_, u64>(threshold_conf)? {
Ok(PC_STATUS_IGNORED)
Expand Down
Loading