Add storage point tracking and tie in storage rewards to economics (#4824)
* Add storage point tracking and tie in storage rewards to epochs and economics * Prevent validators from updating their validations for a segment * Fix test * Retain syscall scoping for readability * Update Credits to own epoch tracking
This commit is contained in:
@@ -6,7 +6,7 @@ use crate::storage_instruction::StorageInstruction;
|
||||
use solana_sdk::account::KeyedAccount;
|
||||
use solana_sdk::instruction::InstructionError;
|
||||
use solana_sdk::pubkey::Pubkey;
|
||||
use solana_sdk::syscall::current::Current;
|
||||
use solana_sdk::syscall;
|
||||
|
||||
pub fn process_instruction(
|
||||
_program_id: &Pubkey,
|
||||
@@ -42,13 +42,13 @@ pub fn process_instruction(
|
||||
// This instruction must be signed by `me`
|
||||
Err(InstructionError::InvalidArgument)?;
|
||||
}
|
||||
let current = Current::from(&rest[0].account).unwrap();
|
||||
let current = syscall::current::from_keyed_account(&rest[0])?;
|
||||
storage_account.submit_mining_proof(
|
||||
sha_state,
|
||||
segment_index,
|
||||
signature,
|
||||
blockhash,
|
||||
current.slot,
|
||||
current,
|
||||
)
|
||||
}
|
||||
StorageInstruction::AdvertiseStorageRecentBlockhash { hash, slot } => {
|
||||
@@ -56,31 +56,47 @@ pub fn process_instruction(
|
||||
// This instruction must be signed by `me`
|
||||
Err(InstructionError::InvalidArgument)?;
|
||||
}
|
||||
let current = Current::from(&rest[0].account).unwrap();
|
||||
storage_account.advertise_storage_recent_blockhash(hash, slot, current.slot)
|
||||
let current = syscall::current::from_keyed_account(&rest[0])?;
|
||||
storage_account.advertise_storage_recent_blockhash(hash, slot, current)
|
||||
}
|
||||
StorageInstruction::ClaimStorageReward => {
|
||||
if rest.len() != 2 {
|
||||
if rest.len() != 4 {
|
||||
Err(InstructionError::InvalidArgument)?;
|
||||
}
|
||||
let (mining_pool, owner) = rest.split_at_mut(1);
|
||||
let (current, rest) = rest.split_at_mut(1);
|
||||
let (rewards, rest) = rest.split_at_mut(1);
|
||||
let (rewards_pools, owner) = rest.split_at_mut(1);
|
||||
|
||||
let rewards = syscall::rewards::from_keyed_account(&rewards[0])?;
|
||||
let current = syscall::current::from_keyed_account(¤t[0])?;
|
||||
let mut owner = StorageAccount::new(*owner[0].unsigned_key(), &mut owner[0].account);
|
||||
|
||||
storage_account.claim_storage_reward(&mut mining_pool[0], &mut owner)
|
||||
storage_account.claim_storage_reward(
|
||||
&mut rewards_pools[0],
|
||||
current,
|
||||
rewards,
|
||||
&mut owner,
|
||||
)
|
||||
}
|
||||
StorageInstruction::ProofValidation { segment, proofs } => {
|
||||
if rest.is_empty() {
|
||||
Err(InstructionError::InvalidArgument)?;
|
||||
}
|
||||
|
||||
let (current, rest) = rest.split_at_mut(1);
|
||||
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 current = syscall::current::from_keyed_account(¤t[0])?;
|
||||
let mut rest: Vec<_> = rest
|
||||
.iter_mut()
|
||||
.map(|keyed_account| {
|
||||
StorageAccount::new(*keyed_account.unsigned_key(), &mut keyed_account.account)
|
||||
})
|
||||
.collect();
|
||||
storage_account.proof_validation(&me_id, segment, proofs, &mut rest)
|
||||
storage_account.proof_validation(&me_id, current, segment, proofs, &mut rest)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user