Skip to content

Commit b27c505

Browse files
committed
cleanup
1 parent 77e383c commit b27c505

File tree

4 files changed

+36
-15
lines changed

4 files changed

+36
-15
lines changed

programs/system/src/context.rs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -261,7 +261,6 @@ where
261261
}
262262

263263
pub fn with_transaction_hash(&self) -> bool {
264-
// TODO: if any cpi context invocation requires transaction hash it should be set.
265264
self.instruction_data.with_transaction_hash()
266265
}
267266

@@ -293,7 +292,6 @@ where
293292
}
294293
}
295294

296-
// TODO: add read only cpi context accounts
297295
impl<'a, T: InstructionData<'a>> WrappedInstructionData<'a, T> {
298296
pub fn owner(&self) -> light_compressed_account::pubkey::Pubkey {
299297
self.instruction_data.owner()

programs/system/src/cpi_context/process_cpi_context.rs

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,6 @@ pub fn process_cpi_context<'a, 'info, T: InstructionData<'a>>(
5656
msg!("cpi context account is some but cpi context is none");
5757
return Err(SystemProgramError::CpiContextMissing.into());
5858
}
59-
6059
if let Some(cpi_context) = cpi_context {
6160
let cpi_context_account_info = match cpi_context_account_info {
6261
Some(cpi_context_account_info) => cpi_context_account_info,
@@ -68,18 +67,18 @@ pub fn process_cpi_context<'a, 'info, T: InstructionData<'a>>(
6867
return Ok(None);
6968
} else {
7069
let cpi_context_account = deserialize_cpi_context_account(cpi_context_account_info)?;
70+
validate_cpi_context_associated_with_merkle_tree(
71+
&instruction_data,
72+
&cpi_context_account,
73+
remaining_accounts,
74+
)?;
7175
if cpi_context_account.is_empty() {
7276
return Err(SystemProgramError::CpiContextEmpty.into());
7377
}
7478
if (*cpi_context_account.fee_payer).to_bytes() != fee_payer {
7579
msg!(format!(" {:?} != {:?}", fee_payer, cpi_context_account.fee_payer).as_str());
7680
return Err(SystemProgramError::CpiContextFeePayerMismatch.into());
7781
}
78-
validate_cpi_context_associated_with_merkle_tree(
79-
&instruction_data,
80-
&cpi_context_account,
81-
remaining_accounts,
82-
)?;
8382

8483
instruction_data.set_cpi_context(cpi_context_account)?;
8584
return Ok(Some((1, instruction_data)));
@@ -120,10 +119,16 @@ pub fn set_cpi_context<'a, 'info, T: InstructionData<'a>>(
120119
} else {
121120
let mut cpi_context_account = deserialize_cpi_context_account(cpi_context_account_info)?;
122121

123-
if *cpi_context_account.fee_payer == fee_payer {
122+
if *cpi_context_account.fee_payer == fee_payer && !cpi_context_account.is_empty() {
124123
cpi_context_account.store_data(&instruction_data)?;
125124
} else {
126-
msg!(format!(" {:?} != {:?}", fee_payer, cpi_context_account.fee_payer).as_str());
125+
msg!(format!(
126+
" {:?} != {:?} or cpi context account empty {}",
127+
fee_payer,
128+
cpi_context_account.fee_payer,
129+
cpi_context_account.is_empty()
130+
)
131+
.as_str());
127132
return Err(SystemProgramError::CpiContextFeePayerMismatch.into());
128133
}
129134
}

programs/system/src/cpi_context/state.rs

Lines changed: 20 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,8 @@ use light_compressed_account::{
1313
};
1414
use light_program_profiler::profile;
1515
use light_zero_copy::{errors::ZeroCopyError, slice_mut::ZeroCopySliceMut, vec::ZeroCopyVecU8};
16-
use pinocchio::{account_info::AccountInfo, msg, program_error::ProgramError, pubkey::Pubkey};
16+
use pinocchio::{account_info::AccountInfo, program_error::ProgramError, pubkey::Pubkey};
17+
use solana_msg::msg;
1718
use zerocopy::{little_endian::U16, Ref};
1819

1920
use crate::{
@@ -175,19 +176,33 @@ impl<'a> ZCpiContextAccount2<'a> {
175176
};
176177
self.in_accounts.push(in_account)?;
177178
}
179+
// Note: if any cpi context invocation requires transaction hash it should be set.
180+
// Currently only the executing cpi can enforce the transaction hash
181+
if instruction_data.with_transaction_hash() {
182+
msg!("with_transaction_hash is not supported when writing into cpi context account");
183+
return Err(SystemProgramError::Unimplemented)?;
184+
}
178185

179186
// Store read-only addresses if any
180187
if let Some(readonly_addresses) = instruction_data.read_only_addresses() {
181-
for readonly_address in readonly_addresses {
182-
self.readonly_addresses.push(*readonly_address)?;
188+
if !readonly_addresses.is_empty() {
189+
msg!("readonly_addresses are not supported when writing into cpi context account");
190+
return Err(SystemProgramError::Unimplemented)?;
183191
}
192+
// for readonly_address in readonly_addresses {
193+
// self.readonly_addresses.push(*readonly_address)?;
194+
//}
184195
}
185196

186197
// Store read-only accounts if any
187198
if let Some(readonly_accounts) = instruction_data.read_only_accounts() {
188-
for readonly_account in readonly_accounts {
189-
self.readonly_accounts.push(*readonly_account)?;
199+
if !readonly_accounts.is_empty() {
200+
msg!("read_only_accounts are not supported when writing into cpi context account");
201+
return Err(SystemProgramError::Unimplemented)?;
190202
}
203+
// for readonly_account in readonly_accounts {
204+
// self.readonly_accounts.push(*readonly_account)?;
205+
// }
191206
}
192207
// Store output accounts
193208
for output in instruction_data.output_accounts() {

programs/system/src/errors.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -134,6 +134,8 @@ pub enum SystemProgramError {
134134
OutputMerkleTreeIndexOutOfBounds,
135135
#[error("Packed Account index out of bounds index.")]
136136
PackedAccountIndexOutOfBounds,
137+
#[error("Unimplemented.")]
138+
Unimplemented,
137139
#[error("Batched Merkle tree error {0}")]
138140
BatchedMerkleTreeError(#[from] BatchedMerkleTreeError),
139141
#[error("Concurrent Merkle tree error {0}")]
@@ -214,6 +216,7 @@ impl From<SystemProgramError> for u32 {
214216
SystemProgramError::AddressAssignedAccountIndexOutOfBounds => 6060,
215217
SystemProgramError::OutputMerkleTreeIndexOutOfBounds => 6061,
216218
SystemProgramError::PackedAccountIndexOutOfBounds => 6062,
219+
SystemProgramError::Unimplemented => 6063,
217220
SystemProgramError::BatchedMerkleTreeError(e) => e.into(),
218221
SystemProgramError::IndexedMerkleTreeError(e) => e.into(),
219222
SystemProgramError::ConcurrentMerkleTreeError(e) => e.into(),

0 commit comments

Comments
 (0)