Skip to content

Commit

Permalink
nit
Browse files Browse the repository at this point in the history
  • Loading branch information
ebatsell committed Dec 13, 2024
1 parent e1c9a18 commit ee2e516
Show file tree
Hide file tree
Showing 3 changed files with 1 addition and 68 deletions.
56 changes: 1 addition & 55 deletions core/src/utils.rs
Original file line number Diff line number Diff line change
@@ -1,11 +1,4 @@
use solana_program::{
account_info::AccountInfo,
entrypoint::ProgramResult,
program::{invoke, invoke_signed},
program_error::ProgramError,
rent::Rent,
system_instruction,
};
use solana_program::program_error::ProgramError;

use crate::constants::MAX_REALLOC_BYTES;

Expand All @@ -17,50 +10,3 @@ pub fn get_new_size(current_size: usize, target_size: usize) -> Result<usize, Pr
.ok_or(ProgramError::ArithmeticOverflow)?
.min(target_size))
}

pub fn realloc_account<'a, 'info>(
account: &'a AccountInfo<'info>,
payer: &'a AccountInfo<'info>,
system_program: &'a AccountInfo<'info>,
rent: &Rent,
target_size: u64,
seeds: &[Vec<u8>],
) -> ProgramResult {
let current_size = account.data_len();

// If account is already over target size, don't try to shrink
if current_size >= target_size as usize {
return Ok(());
}

// Calculate new size, capped at target_size
let new_size = current_size
.checked_add(MAX_REALLOC_BYTES as usize)
.ok_or(ProgramError::ArithmeticOverflow)?
.min(target_size as usize);

// Calculate required lamports for new size
let new_minimum_balance = rent.minimum_balance(new_size);
let lamports_diff = new_minimum_balance.saturating_sub(account.lamports());

// Transfer lamports if needed
if lamports_diff > 0 {
invoke(
&system_instruction::transfer(payer.key, account.key, lamports_diff),
&[payer.clone(), account.clone(), system_program.clone()],
)?;
}

// Reallocate space
invoke_signed(
&system_instruction::allocate(account.key, new_size as u64),
&[account.clone(), system_program.clone()],
&[seeds
.iter()
.map(|seed| seed.as_slice())
.collect::<Vec<&[u8]>>()
.as_slice()],
)?;

Ok(())
}
7 changes: 0 additions & 7 deletions integration_tests/tests/fixtures/restaking_client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -89,13 +89,6 @@ impl RestakingProgramClient {
Ok(*Config::try_from_slice_unchecked(account.data.as_slice())?)
}

pub async fn get_ncn_epoch(&mut self, slot: u64) -> TestResult<u64> {
let restaking_config_address =
Config::find_program_address(&jito_restaking_program::id()).0;
let config = self.get_config(&restaking_config_address).await.unwrap();
Ok(config.get_epoch_from_slot(slot).unwrap())
}

#[allow(dead_code)]
pub async fn get_ncn_vault_ticket(
&mut self,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,12 +21,6 @@ mod tests {
.do_full_initialize_weight_table(test_ncn.ncn_root.ncn_pubkey, epoch)
.await?;

let weight_table_pda = WeightTable::find_program_address(
&jito_tip_router_program::id(),
&test_ncn.ncn_root.ncn_pubkey,
epoch,
)
.0;
let ncn = test_ncn.ncn_root.ncn_pubkey;

let vault_root = test_ncn.vaults[0].clone();
Expand Down

0 comments on commit ee2e516

Please sign in to comment.