Fix storage program space issues and limit storage transaction data (#4677)
This commit is contained in:
@@ -17,7 +17,7 @@ pub fn process_instruction(
|
||||
|
||||
let (me, rest) = keyed_accounts.split_at_mut(1);
|
||||
let me_unsigned = me[0].signer_key().is_none();
|
||||
let mut storage_account = StorageAccount::new(&mut me[0].account);
|
||||
let mut storage_account = StorageAccount::new(*me[0].unsigned_key(), &mut me[0].account);
|
||||
|
||||
match bincode::deserialize(data).map_err(|_| InstructionError::InvalidInstructionData)? {
|
||||
StorageInstruction::InitializeMiningPool => {
|
||||
@@ -42,13 +42,20 @@ pub fn process_instruction(
|
||||
sha_state,
|
||||
segment_index,
|
||||
signature,
|
||||
blockhash,
|
||||
} => {
|
||||
if me_unsigned || rest.len() != 1 {
|
||||
// This instruction must be signed by `me`
|
||||
Err(InstructionError::InvalidArgument)?;
|
||||
}
|
||||
let current = Current::from(&rest[0].account).unwrap();
|
||||
storage_account.submit_mining_proof(sha_state, segment_index, signature, current.slot)
|
||||
storage_account.submit_mining_proof(
|
||||
sha_state,
|
||||
segment_index,
|
||||
signature,
|
||||
blockhash,
|
||||
current.slot,
|
||||
)
|
||||
}
|
||||
StorageInstruction::AdvertiseStorageRecentBlockhash { hash, slot } => {
|
||||
if me_unsigned || rest.len() != 1 {
|
||||
@@ -59,21 +66,27 @@ pub fn process_instruction(
|
||||
storage_account.advertise_storage_recent_blockhash(hash, slot, current.slot)
|
||||
}
|
||||
StorageInstruction::ClaimStorageReward => {
|
||||
if rest.len() != 1 {
|
||||
if rest.len() != 2 {
|
||||
Err(InstructionError::InvalidArgument)?;
|
||||
}
|
||||
storage_account.claim_storage_reward(&mut rest[0])
|
||||
let (mining_pool, owner) = rest.split_at_mut(1);
|
||||
let mut owner = StorageAccount::new(*owner[0].unsigned_key(), &mut owner[0].account);
|
||||
|
||||
storage_account.claim_storage_reward(&mut mining_pool[0], &mut owner)
|
||||
}
|
||||
StorageInstruction::ProofValidation { segment, proofs } => {
|
||||
if me_unsigned || rest.is_empty() {
|
||||
// This instruction must be signed by `me` and `rest` cannot be empty
|
||||
Err(InstructionError::InvalidArgument)?;
|
||||
}
|
||||
let me_id = storage_account.id;
|
||||
let mut rest: Vec<_> = rest
|
||||
.iter_mut()
|
||||
.map(|keyed_account| StorageAccount::new(&mut keyed_account.account))
|
||||
.map(|keyed_account| {
|
||||
StorageAccount::new(*keyed_account.unsigned_key(), &mut keyed_account.account)
|
||||
})
|
||||
.collect();
|
||||
storage_account.proof_validation(segment, proofs, &mut rest)
|
||||
storage_account.proof_validation(&me_id, segment, proofs, &mut rest)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user