syscall work, rename syscall to sysvar, rename current to clock (#5074)

* syscall work, rename syscall to sysvar, rename current to clock

* missed one

* nit
This commit is contained in:
Rob Walker
2019-07-12 16:38:15 -07:00
committed by GitHub
parent 7aecb87bce
commit d2b6c2e0ce
19 changed files with 229 additions and 271 deletions

View File

@@ -8,7 +8,7 @@ use solana_sdk::hash::Hash;
use solana_sdk::instruction::InstructionError;
use solana_sdk::pubkey::Pubkey;
use solana_sdk::signature::Signature;
use solana_sdk::syscall;
use solana_sdk::sysvar;
use std::collections::BTreeMap;
// Todo Tune this for actual use cases when PoRep is feature complete
@@ -167,7 +167,7 @@ impl<'a> StorageAccount<'a> {
segment_index: u64,
signature: Signature,
blockhash: Hash,
current: syscall::current::Current,
clock: sysvar::clock::Clock,
) -> Result<(), InstructionError> {
let mut storage_contract = &mut self.account.state()?;
if let StorageContract::ReplicatorStorage {
@@ -177,7 +177,7 @@ impl<'a> StorageAccount<'a> {
..
} = &mut storage_contract
{
let current_segment = current.segment;
let current_segment = clock.segment;
// clean up the account
// TODO check for time correctness - storage seems to run at a delay of about 3
@@ -230,7 +230,7 @@ impl<'a> StorageAccount<'a> {
StorageError::ProofLimitReached as u32,
));
}
credits.update_epoch(current.epoch);
credits.update_epoch(clock.epoch);
segment_proofs.push(proof);
self.account.set_state(storage_contract)
} else {
@@ -242,7 +242,7 @@ impl<'a> StorageAccount<'a> {
&mut self,
hash: Hash,
segment: u64,
current: syscall::current::Current,
clock: sysvar::clock::Clock,
) -> Result<(), InstructionError> {
let mut storage_contract = &mut self.account.state()?;
if let StorageContract::ValidatorStorage {
@@ -253,11 +253,8 @@ impl<'a> StorageAccount<'a> {
..
} = &mut storage_contract
{
debug!(
"advertise new segment: {} orig: {}",
segment, current.segment
);
if segment < *state_segment || segment > current.segment {
debug!("advertise new segment: {} orig: {}", segment, clock.segment);
if segment < *state_segment || segment > clock.segment {
return Err(InstructionError::CustomError(
StorageError::InvalidSegment as u32,
));
@@ -269,7 +266,7 @@ impl<'a> StorageAccount<'a> {
// storage epoch updated, move the lockout_validations to credits
let (_num_valid, total_validations) = count_valid_proofs(&lockout_validations);
lockout_validations.clear();
credits.update_epoch(current.epoch);
credits.update_epoch(clock.epoch);
credits.current_epoch += total_validations;
self.account.set_state(storage_contract)
} else {
@@ -280,7 +277,7 @@ impl<'a> StorageAccount<'a> {
pub fn proof_validation(
&mut self,
me: &Pubkey,
current: syscall::current::Current,
clock: sysvar::clock::Clock,
segment_index: u64,
proofs_per_account: Vec<Vec<ProofStatus>>,
replicator_accounts: &mut [StorageAccount],
@@ -341,14 +338,8 @@ impl<'a> StorageAccount<'a> {
.into_iter()
.zip(accounts.into_iter())
.filter_map(|(checked_proofs, account)| {
if store_validation_result(
me,
&current,
account,
segment_index,
&checked_proofs,
)
.is_ok()
if store_validation_result(me, &clock, account, segment_index, &checked_proofs)
.is_ok()
{
Some((account.id, checked_proofs))
} else {
@@ -376,8 +367,8 @@ impl<'a> StorageAccount<'a> {
pub fn claim_storage_reward(
&mut self,
rewards_pool: &mut KeyedAccount,
current: syscall::current::Current,
rewards: syscall::rewards::Rewards,
clock: sysvar::clock::Clock,
rewards: sysvar::rewards::Rewards,
owner: &mut StorageAccount,
) -> Result<(), InstructionError> {
let mut storage_contract = &mut self.account.state()?;
@@ -394,7 +385,7 @@ impl<'a> StorageAccount<'a> {
))?
}
credits.update_epoch(current.epoch);
credits.update_epoch(clock.epoch);
check_redeemable(credits, rewards.storage_point_value, rewards_pool, owner)?;
self.account.set_state(storage_contract)
@@ -410,7 +401,7 @@ impl<'a> StorageAccount<'a> {
StorageError::InvalidOwner as u32,
))?
}
credits.update_epoch(current.epoch);
credits.update_epoch(clock.epoch);
let (num_validations, _total_proofs) = count_valid_proofs(&validations);
credits.current_epoch += num_validations;
validations.clear();
@@ -451,7 +442,7 @@ pub fn create_rewards_pool() -> Account {
/// Store the result of a proof validation into the replicator account
fn store_validation_result(
me: &Pubkey,
current: &syscall::current::Current,
clock: &sysvar::clock::Clock,
storage_account: &mut StorageAccount,
segment: u64,
proof_mask: &[ProofStatus],
@@ -478,7 +469,7 @@ fn store_validation_result(
entry.insert(*me, proof_mask.to_vec());
}
let (total_validations, _) = count_valid_proofs(&validations);
credits.update_epoch(current.epoch);
credits.update_epoch(clock.epoch);
credits.current_epoch += total_validations - recorded_validations;
}
_ => return Err(InstructionError::InvalidAccountData),
@@ -571,7 +562,7 @@ mod tests {
// account has no space
store_validation_result(
&Pubkey::default(),
&syscall::current::Current::default(),
&sysvar::clock::Clock::default(),
&mut account,
segment_index,
&vec![ProofStatus::default(); 1],
@@ -598,7 +589,7 @@ mod tests {
// proof is valid
store_validation_result(
&Pubkey::default(),
&syscall::current::Current::default(),
&sysvar::clock::Clock::default(),
&mut account,
segment_index,
&vec![ProofStatus::Valid],
@@ -608,7 +599,7 @@ mod tests {
// proof failed verification but we should still be able to store it
store_validation_result(
&Pubkey::default(),
&syscall::current::Current::default(),
&sysvar::clock::Clock::default(),
&mut account,
segment_index,
&vec![ProofStatus::NotValid],

View File

@@ -5,8 +5,8 @@ use solana_sdk::hash::Hash;
use solana_sdk::instruction::{AccountMeta, Instruction};
use solana_sdk::pubkey::Pubkey;
use solana_sdk::signature::Signature;
use solana_sdk::syscall::{current, rewards};
use solana_sdk::system_instruction;
use solana_sdk::sysvar::{clock, rewards};
#[derive(Serialize, Deserialize, Debug, Clone)]
pub enum StorageInstruction {
@@ -35,7 +35,7 @@ pub enum StorageInstruction {
///
/// Expects 1 Account:
/// 0 - Storage account with credits to redeem
/// 1 - Current Syscall to figure out the current epoch
/// 1 - Clock Syscall to figure out the clock epoch
/// 2 - Replicator account to credit - this account *must* be the owner
/// 3 - MiningPool account to redeem credits from
/// 4 - Rewards Syscall to figure out point values
@@ -144,7 +144,7 @@ pub fn mining_proof(
};
let account_metas = vec![
AccountMeta::new(*storage_pubkey, true),
AccountMeta::new(current::id(), false),
AccountMeta::new(clock::id(), false),
];
Instruction::new(id(), &storage_instruction, account_metas)
}
@@ -160,7 +160,7 @@ pub fn advertise_recent_blockhash(
};
let account_metas = vec![
AccountMeta::new(*storage_pubkey, true),
AccountMeta::new(current::id(), false),
AccountMeta::new(clock::id(), false),
];
Instruction::new(id(), &storage_instruction, account_metas)
}
@@ -172,7 +172,7 @@ pub fn proof_validation(
) -> Instruction {
let mut account_metas = vec![
AccountMeta::new(*storage_pubkey, true),
AccountMeta::new(current::id(), false),
AccountMeta::new(clock::id(), false),
];
let mut proofs = vec![];
checked_proofs.into_iter().for_each(|(id, p)| {
@@ -187,7 +187,7 @@ pub fn claim_reward(owner_pubkey: &Pubkey, storage_pubkey: &Pubkey) -> Instructi
let storage_instruction = StorageInstruction::ClaimStorageReward;
let account_metas = vec![
AccountMeta::new(*storage_pubkey, false),
AccountMeta::new(current::id(), false),
AccountMeta::new(clock::id(), false),
AccountMeta::new(rewards::id(), false),
AccountMeta::new(rewards_pools::random_id(), false),
AccountMeta::new(*owner_pubkey, false),

View File

@@ -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;
use solana_sdk::sysvar;
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 = syscall::current::from_keyed_account(&rest[0])?;
let clock = sysvar::clock::from_keyed_account(&rest[0])?;
storage_account.submit_mining_proof(
sha_state,
segment_index,
signature,
blockhash,
current,
clock,
)
}
StorageInstruction::AdvertiseStorageRecentBlockhash { hash, segment } => {
@@ -56,47 +56,42 @@ pub fn process_instruction(
// This instruction must be signed by `me`
Err(InstructionError::InvalidArgument)?;
}
let current = syscall::current::from_keyed_account(&rest[0])?;
storage_account.advertise_storage_recent_blockhash(hash, segment, current)
let clock = sysvar::clock::from_keyed_account(&rest[0])?;
storage_account.advertise_storage_recent_blockhash(hash, segment, clock)
}
StorageInstruction::ClaimStorageReward => {
if rest.len() != 4 {
Err(InstructionError::InvalidArgument)?;
}
let (current, rest) = rest.split_at_mut(1);
let (clock, 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(&current[0])?;
let rewards = sysvar::rewards::from_keyed_account(&rewards[0])?;
let clock = sysvar::clock::from_keyed_account(&clock[0])?;
let mut owner = StorageAccount::new(*owner[0].unsigned_key(), &mut owner[0].account);
storage_account.claim_storage_reward(
&mut rewards_pools[0],
current,
rewards,
&mut owner,
)
storage_account.claim_storage_reward(&mut rewards_pools[0], clock, rewards, &mut owner)
}
StorageInstruction::ProofValidation { segment, proofs } => {
if rest.is_empty() {
Err(InstructionError::InvalidArgument)?;
}
let (current, rest) = rest.split_at_mut(1);
let (clock, 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(&current[0])?;
let clock = sysvar::clock::from_keyed_account(&clock[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, current, segment, proofs, &mut rest)
storage_account.proof_validation(&me_id, clock, segment, proofs, &mut rest)
}
}
}