Skip to content
This repository was archived by the owner on Mar 11, 2025. It is now read-only.

Commit be4f527

Browse files
committed
remove lamport transfer logic
1 parent d3ec732 commit be4f527

File tree

3 files changed

+57
-69
lines changed

3 files changed

+57
-69
lines changed

record/program/src/instruction.rs

Lines changed: 2 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@ use {
66
instruction::{AccountMeta, Instruction},
77
program_error::ProgramError,
88
pubkey::Pubkey,
9-
system_program,
109
},
1110
std::mem::size_of,
1211
};
@@ -62,9 +61,7 @@ pub enum RecordInstruction<'a> {
6261
/// Accounts expected by this instruction:
6362
///
6463
/// 0. `[writable]` The record account to reallocate
65-
/// 1. `[signer, writable]` The payer account to fund reallocation
66-
/// 2. `[]` System program for reallocation funding
67-
/// 3. `[signer]` The account's owner
64+
/// 1. `[signer]` The account's owner
6865
Reallocate {
6966
/// The length of the data to hold in the record account excluding meta
7067
/// data
@@ -193,18 +190,11 @@ pub fn close_account(record_account: &Pubkey, signer: &Pubkey, receiver: &Pubkey
193190
}
194191

195192
/// Create a `RecordInstruction::Reallocate` instruction
196-
pub fn reallocate(
197-
record_account: &Pubkey,
198-
payer: &Pubkey,
199-
signer: &Pubkey,
200-
data_length: u64,
201-
) -> Instruction {
193+
pub fn reallocate(record_account: &Pubkey, signer: &Pubkey, data_length: u64) -> Instruction {
202194
Instruction {
203195
program_id: id(),
204196
accounts: vec![
205197
AccountMeta::new(*record_account, false),
206-
AccountMeta::new(*payer, true),
207-
AccountMeta::new_readonly(system_program::id(), false),
208198
AccountMeta::new_readonly(*signer, true),
209199
],
210200
data: RecordInstruction::Reallocate { data_length }.pack(),

record/program/src/processor.rs

Lines changed: 0 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,9 @@ use {
66
account_info::{next_account_info, AccountInfo},
77
entrypoint::ProgramResult,
88
msg,
9-
program::invoke,
109
program_error::ProgramError,
1110
program_pack::IsInitialized,
1211
pubkey::Pubkey,
13-
system_instruction,
14-
sysvar::{rent::Rent, Sysvar},
1512
},
1613
spl_pod::bytemuck::{pod_from_bytes, pod_from_bytes_mut, pod_get_packed_len},
1714
};
@@ -139,8 +136,6 @@ pub fn process_instruction(
139136
RecordInstruction::Reallocate { data_length } => {
140137
msg!("RecordInstruction::Reallocate");
141138
let data_info = next_account_info(account_info_iter)?;
142-
let payer_info = next_account_info(account_info_iter)?;
143-
let system_program_info = next_account_info(account_info_iter)?;
144139
let authority_info = next_account_info(account_info_iter)?;
145140

146141
{
@@ -178,24 +173,6 @@ pub fn process_instruction(
178173
.unwrap(),
179174
);
180175
data_info.realloc(needed_account_length, false)?;
181-
182-
// if additional lamports needed to remain rent-exempt, transfer them
183-
let current_lamport_reserve = data_info.lamports();
184-
let rent = Rent::get()?;
185-
let new_rent_exempt_reserve = rent.minimum_balance(needed_account_length);
186-
187-
let lamports_diff = new_rent_exempt_reserve.saturating_sub(current_lamport_reserve);
188-
if lamports_diff > 0 {
189-
invoke(
190-
&system_instruction::transfer(payer_info.key, data_info.key, lamports_diff),
191-
&[
192-
payer_info.clone(),
193-
data_info.clone(),
194-
system_program_info.clone(),
195-
],
196-
)?;
197-
}
198-
199176
Ok(())
200177
}
201178
}

record/program/tests/functional.rs

Lines changed: 55 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ use {
55
instruction::{AccountMeta, Instruction, InstructionError},
66
pubkey::Pubkey,
77
rent::Rent,
8-
system_instruction, system_program,
8+
system_instruction,
99
},
1010
solana_program_test::*,
1111
solana_sdk::{
@@ -533,13 +533,19 @@ async fn reallocate_success() {
533533
.checked_add(new_data_length as usize)
534534
.unwrap();
535535

536+
let delta_account_data_length = new_data_length.saturating_sub(data.len() as u64);
537+
let additional_lamports_needed =
538+
Rent::default().minimum_balance(delta_account_data_length as usize);
539+
536540
let transaction = Transaction::new_signed_with_payer(
537-
&[instruction::reallocate(
538-
&account.pubkey(),
539-
&context.payer.pubkey(),
540-
&authority.pubkey(),
541-
new_data_length,
542-
)],
541+
&[
542+
instruction::reallocate(&account.pubkey(), &authority.pubkey(), new_data_length),
543+
system_instruction::transfer(
544+
&context.payer.pubkey(),
545+
&account.pubkey(),
546+
additional_lamports_needed,
547+
),
548+
],
543549
Some(&context.payer.pubkey()),
544550
&[&context.payer, &authority],
545551
context.last_blockhash,
@@ -564,7 +570,6 @@ async fn reallocate_success() {
564570
let transaction = Transaction::new_signed_with_payer(
565571
&[instruction::reallocate(
566572
&account.pubkey(),
567-
&context.payer.pubkey(),
568573
&authority.pubkey(),
569574
old_data_length,
570575
)],
@@ -598,22 +603,30 @@ async fn reallocate_fail_wrong_authority() {
598603
initialize_storage_account(&mut context, &authority, &account, data).await;
599604

600605
let new_data_length = 16u64;
606+
let delta_account_data_length = new_data_length.saturating_sub(data.len() as u64);
607+
let additional_lamports_needed =
608+
Rent::default().minimum_balance(delta_account_data_length as usize);
601609

602610
let wrong_authority = Keypair::new();
603611
let transaction = Transaction::new_signed_with_payer(
604-
&[Instruction {
605-
program_id: id(),
606-
accounts: vec![
607-
AccountMeta::new(account.pubkey(), false),
608-
AccountMeta::new(context.payer.pubkey(), true),
609-
AccountMeta::new_readonly(system_program::id(), false),
610-
AccountMeta::new(wrong_authority.pubkey(), true),
611-
],
612-
data: instruction::RecordInstruction::Reallocate {
613-
data_length: new_data_length,
614-
}
615-
.pack(),
616-
}],
612+
&[
613+
Instruction {
614+
program_id: id(),
615+
accounts: vec![
616+
AccountMeta::new(account.pubkey(), false),
617+
AccountMeta::new(wrong_authority.pubkey(), true),
618+
],
619+
data: instruction::RecordInstruction::Reallocate {
620+
data_length: new_data_length,
621+
}
622+
.pack(),
623+
},
624+
system_instruction::transfer(
625+
&context.payer.pubkey(),
626+
&account.pubkey(),
627+
additional_lamports_needed,
628+
),
629+
],
617630
Some(&context.payer.pubkey()),
618631
&[&context.payer, &wrong_authority],
619632
context.last_blockhash,
@@ -643,21 +656,29 @@ async fn reallocate_fail_unsigned() {
643656
initialize_storage_account(&mut context, &authority, &account, data).await;
644657

645658
let new_data_length = 16u64;
659+
let delta_account_data_length = new_data_length.saturating_sub(data.len() as u64);
660+
let additional_lamports_needed =
661+
Rent::default().minimum_balance(delta_account_data_length as usize);
646662

647663
let transaction = Transaction::new_signed_with_payer(
648-
&[Instruction {
649-
program_id: id(),
650-
accounts: vec![
651-
AccountMeta::new(account.pubkey(), false),
652-
AccountMeta::new(context.payer.pubkey(), true),
653-
AccountMeta::new_readonly(system_program::id(), false),
654-
AccountMeta::new(authority.pubkey(), false),
655-
],
656-
data: instruction::RecordInstruction::Reallocate {
657-
data_length: new_data_length,
658-
}
659-
.pack(),
660-
}],
664+
&[
665+
Instruction {
666+
program_id: id(),
667+
accounts: vec![
668+
AccountMeta::new(account.pubkey(), false),
669+
AccountMeta::new(authority.pubkey(), false),
670+
],
671+
data: instruction::RecordInstruction::Reallocate {
672+
data_length: new_data_length,
673+
}
674+
.pack(),
675+
},
676+
system_instruction::transfer(
677+
&context.payer.pubkey(),
678+
&account.pubkey(),
679+
additional_lamports_needed,
680+
),
681+
],
661682
Some(&context.payer.pubkey()),
662683
&[&context.payer],
663684
context.last_blockhash,

0 commit comments

Comments
 (0)