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:
parent
7aecb87bce
commit
d2b6c2e0ce
|
@ -6,8 +6,8 @@ use serde_derive::{Deserialize, Serialize};
|
||||||
use solana_sdk::account::KeyedAccount;
|
use solana_sdk::account::KeyedAccount;
|
||||||
use solana_sdk::instruction::{AccountMeta, Instruction, InstructionError};
|
use solana_sdk::instruction::{AccountMeta, Instruction, InstructionError};
|
||||||
use solana_sdk::pubkey::Pubkey;
|
use solana_sdk::pubkey::Pubkey;
|
||||||
use solana_sdk::syscall;
|
|
||||||
use solana_sdk::system_instruction;
|
use solana_sdk::system_instruction;
|
||||||
|
use solana_sdk::sysvar;
|
||||||
|
|
||||||
#[derive(Serialize, Deserialize, Debug, PartialEq, Eq, Clone)]
|
#[derive(Serialize, Deserialize, Debug, PartialEq, Eq, Clone)]
|
||||||
pub enum StakeInstruction {
|
pub enum StakeInstruction {
|
||||||
|
@ -16,7 +16,7 @@ pub enum StakeInstruction {
|
||||||
/// Expects 3 Accounts:
|
/// Expects 3 Accounts:
|
||||||
/// 0 - Uninitialized StakeAccount to be delegated <= must have this signature
|
/// 0 - Uninitialized StakeAccount to be delegated <= must have this signature
|
||||||
/// 1 - VoteAccount to which this Stake will be delegated
|
/// 1 - VoteAccount to which this Stake will be delegated
|
||||||
/// 2 - Current syscall Account that carries current bank epoch
|
/// 2 - Clock sysvar Account that carries clock bank epoch
|
||||||
///
|
///
|
||||||
/// The u64 is the portion of the Stake account balance to be activated,
|
/// The u64 is the portion of the Stake account balance to be activated,
|
||||||
/// must be less than StakeAccount.lamports
|
/// must be less than StakeAccount.lamports
|
||||||
|
@ -29,7 +29,7 @@ pub enum StakeInstruction {
|
||||||
/// 0 - Delegate StakeAccount to be updated with rewards
|
/// 0 - Delegate StakeAccount to be updated with rewards
|
||||||
/// 1 - VoteAccount to which the Stake is delegated,
|
/// 1 - VoteAccount to which the Stake is delegated,
|
||||||
/// 2 - RewardsPool Stake Account from which to redeem credits
|
/// 2 - RewardsPool Stake Account from which to redeem credits
|
||||||
/// 3 - Rewards syscall Account that carries points values
|
/// 3 - Rewards sysvar Account that carries points values
|
||||||
RedeemVoteCredits,
|
RedeemVoteCredits,
|
||||||
|
|
||||||
/// Withdraw unstaked lamports from the stake account
|
/// Withdraw unstaked lamports from the stake account
|
||||||
|
@ -81,7 +81,7 @@ pub fn redeem_vote_credits(stake_pubkey: &Pubkey, vote_pubkey: &Pubkey) -> Instr
|
||||||
AccountMeta::new(*stake_pubkey, false),
|
AccountMeta::new(*stake_pubkey, false),
|
||||||
AccountMeta::new(*vote_pubkey, false),
|
AccountMeta::new(*vote_pubkey, false),
|
||||||
AccountMeta::new(crate::rewards_pools::random_id(), false),
|
AccountMeta::new(crate::rewards_pools::random_id(), false),
|
||||||
AccountMeta::new_credit_only(syscall::rewards::id(), false),
|
AccountMeta::new_credit_only(sysvar::rewards::id(), false),
|
||||||
];
|
];
|
||||||
Instruction::new(id(), &StakeInstruction::RedeemVoteCredits, account_metas)
|
Instruction::new(id(), &StakeInstruction::RedeemVoteCredits, account_metas)
|
||||||
}
|
}
|
||||||
|
@ -90,7 +90,7 @@ pub fn delegate_stake(stake_pubkey: &Pubkey, vote_pubkey: &Pubkey, stake: u64) -
|
||||||
let account_metas = vec![
|
let account_metas = vec![
|
||||||
AccountMeta::new(*stake_pubkey, true),
|
AccountMeta::new(*stake_pubkey, true),
|
||||||
AccountMeta::new(*vote_pubkey, false),
|
AccountMeta::new(*vote_pubkey, false),
|
||||||
AccountMeta::new_credit_only(syscall::current::id(), false),
|
AccountMeta::new_credit_only(sysvar::clock::id(), false),
|
||||||
];
|
];
|
||||||
Instruction::new(id(), &StakeInstruction::DelegateStake(stake), account_metas)
|
Instruction::new(id(), &StakeInstruction::DelegateStake(stake), account_metas)
|
||||||
}
|
}
|
||||||
|
@ -99,7 +99,7 @@ pub fn withdraw(stake_pubkey: &Pubkey, to_pubkey: &Pubkey, lamports: u64) -> Ins
|
||||||
let account_metas = vec![
|
let account_metas = vec![
|
||||||
AccountMeta::new(*stake_pubkey, true),
|
AccountMeta::new(*stake_pubkey, true),
|
||||||
AccountMeta::new(*to_pubkey, false),
|
AccountMeta::new(*to_pubkey, false),
|
||||||
AccountMeta::new_credit_only(syscall::current::id(), false),
|
AccountMeta::new_credit_only(sysvar::clock::id(), false),
|
||||||
];
|
];
|
||||||
Instruction::new(id(), &StakeInstruction::Withdraw(lamports), account_metas)
|
Instruction::new(id(), &StakeInstruction::Withdraw(lamports), account_metas)
|
||||||
}
|
}
|
||||||
|
@ -107,7 +107,7 @@ pub fn withdraw(stake_pubkey: &Pubkey, to_pubkey: &Pubkey, lamports: u64) -> Ins
|
||||||
pub fn deactivate_stake(stake_pubkey: &Pubkey) -> Instruction {
|
pub fn deactivate_stake(stake_pubkey: &Pubkey) -> Instruction {
|
||||||
let account_metas = vec![
|
let account_metas = vec![
|
||||||
AccountMeta::new(*stake_pubkey, true),
|
AccountMeta::new(*stake_pubkey, true),
|
||||||
AccountMeta::new_credit_only(syscall::current::id(), false),
|
AccountMeta::new_credit_only(sysvar::clock::id(), false),
|
||||||
];
|
];
|
||||||
Instruction::new(id(), &StakeInstruction::Deactivate, account_metas)
|
Instruction::new(id(), &StakeInstruction::Deactivate, account_metas)
|
||||||
}
|
}
|
||||||
|
@ -137,11 +137,7 @@ pub fn process_instruction(
|
||||||
}
|
}
|
||||||
let vote = &rest[0];
|
let vote = &rest[0];
|
||||||
|
|
||||||
me.delegate_stake(
|
me.delegate_stake(vote, stake, &sysvar::clock::from_keyed_account(&rest[1])?)
|
||||||
vote,
|
|
||||||
stake,
|
|
||||||
&syscall::current::from_keyed_account(&rest[1])?,
|
|
||||||
)
|
|
||||||
}
|
}
|
||||||
StakeInstruction::RedeemVoteCredits => {
|
StakeInstruction::RedeemVoteCredits => {
|
||||||
if rest.len() != 3 {
|
if rest.len() != 3 {
|
||||||
|
@ -155,29 +151,29 @@ pub fn process_instruction(
|
||||||
me.redeem_vote_credits(
|
me.redeem_vote_credits(
|
||||||
vote,
|
vote,
|
||||||
rewards_pool,
|
rewards_pool,
|
||||||
&syscall::rewards::from_keyed_account(&rest[0])?,
|
&sysvar::rewards::from_keyed_account(&rest[0])?,
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
StakeInstruction::Withdraw(lamports) => {
|
StakeInstruction::Withdraw(lamports) => {
|
||||||
if rest.len() != 2 {
|
if rest.len() != 2 {
|
||||||
Err(InstructionError::InvalidInstructionData)?;
|
Err(InstructionError::InvalidInstructionData)?;
|
||||||
}
|
}
|
||||||
let (to, syscall) = &mut rest.split_at_mut(1);
|
let (to, sysvar) = &mut rest.split_at_mut(1);
|
||||||
let mut to = &mut to[0];
|
let mut to = &mut to[0];
|
||||||
|
|
||||||
me.withdraw(
|
me.withdraw(
|
||||||
lamports,
|
lamports,
|
||||||
&mut to,
|
&mut to,
|
||||||
&syscall::current::from_keyed_account(&syscall[0])?,
|
&sysvar::clock::from_keyed_account(&sysvar[0])?,
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
StakeInstruction::Deactivate => {
|
StakeInstruction::Deactivate => {
|
||||||
if rest.len() != 1 {
|
if rest.len() != 1 {
|
||||||
Err(InstructionError::InvalidInstructionData)?;
|
Err(InstructionError::InvalidInstructionData)?;
|
||||||
}
|
}
|
||||||
let syscall = &rest[0];
|
let sysvar = &rest[0];
|
||||||
|
|
||||||
me.deactivate_stake(&syscall::current::from_keyed_account(&syscall)?)
|
me.deactivate_stake(&sysvar::clock::from_keyed_account(&sysvar)?)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -193,10 +189,10 @@ mod tests {
|
||||||
.accounts
|
.accounts
|
||||||
.iter()
|
.iter()
|
||||||
.map(|meta| {
|
.map(|meta| {
|
||||||
if syscall::current::check_id(&meta.pubkey) {
|
if sysvar::clock::check_id(&meta.pubkey) {
|
||||||
syscall::current::create_account(1, 0, 0, 0, 0)
|
sysvar::clock::create_account(1, 0, 0, 0, 0)
|
||||||
} else if syscall::rewards::check_id(&meta.pubkey) {
|
} else if sysvar::rewards::check_id(&meta.pubkey) {
|
||||||
syscall::rewards::create_account(1, 0.0, 0.0)
|
sysvar::rewards::create_account(1, 0.0, 0.0)
|
||||||
} else {
|
} else {
|
||||||
Account::default()
|
Account::default()
|
||||||
}
|
}
|
||||||
|
@ -286,9 +282,9 @@ mod tests {
|
||||||
KeyedAccount::new(&Pubkey::default(), true, &mut Account::default()),
|
KeyedAccount::new(&Pubkey::default(), true, &mut Account::default()),
|
||||||
KeyedAccount::new(&Pubkey::default(), false, &mut Account::default()),
|
KeyedAccount::new(&Pubkey::default(), false, &mut Account::default()),
|
||||||
KeyedAccount::new(
|
KeyedAccount::new(
|
||||||
&syscall::current::id(),
|
&sysvar::clock::id(),
|
||||||
false,
|
false,
|
||||||
&mut syscall::current::create_account(1, 0, 0, 0, 0)
|
&mut sysvar::clock::create_account(1, 0, 0, 0, 0)
|
||||||
),
|
),
|
||||||
],
|
],
|
||||||
&serialize(&StakeInstruction::DelegateStake(0)).unwrap(),
|
&serialize(&StakeInstruction::DelegateStake(0)).unwrap(),
|
||||||
|
@ -305,9 +301,9 @@ mod tests {
|
||||||
KeyedAccount::new(&Pubkey::default(), false, &mut Account::default()),
|
KeyedAccount::new(&Pubkey::default(), false, &mut Account::default()),
|
||||||
KeyedAccount::new(&Pubkey::default(), false, &mut Account::default()),
|
KeyedAccount::new(&Pubkey::default(), false, &mut Account::default()),
|
||||||
KeyedAccount::new(
|
KeyedAccount::new(
|
||||||
&syscall::rewards::id(),
|
&sysvar::rewards::id(),
|
||||||
false,
|
false,
|
||||||
&mut syscall::rewards::create_account(1, 0.0, 0.0)
|
&mut sysvar::rewards::create_account(1, 0.0, 0.0)
|
||||||
),
|
),
|
||||||
],
|
],
|
||||||
&serialize(&StakeInstruction::RedeemVoteCredits).unwrap(),
|
&serialize(&StakeInstruction::RedeemVoteCredits).unwrap(),
|
||||||
|
@ -315,7 +311,7 @@ mod tests {
|
||||||
Err(InstructionError::InvalidAccountData),
|
Err(InstructionError::InvalidAccountData),
|
||||||
);
|
);
|
||||||
|
|
||||||
// Tests 3rd keyed account is of correct type (Current instead of rewards) in withdraw
|
// Tests 3rd keyed account is of correct type (Clock instead of rewards) in withdraw
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
super::process_instruction(
|
super::process_instruction(
|
||||||
&Pubkey::default(),
|
&Pubkey::default(),
|
||||||
|
@ -323,9 +319,9 @@ mod tests {
|
||||||
KeyedAccount::new(&Pubkey::default(), false, &mut Account::default()),
|
KeyedAccount::new(&Pubkey::default(), false, &mut Account::default()),
|
||||||
KeyedAccount::new(&Pubkey::default(), false, &mut Account::default()),
|
KeyedAccount::new(&Pubkey::default(), false, &mut Account::default()),
|
||||||
KeyedAccount::new(
|
KeyedAccount::new(
|
||||||
&syscall::rewards::id(),
|
&sysvar::rewards::id(),
|
||||||
false,
|
false,
|
||||||
&mut syscall::rewards::create_account(1, 0.0, 0.0)
|
&mut sysvar::rewards::create_account(1, 0.0, 0.0)
|
||||||
),
|
),
|
||||||
],
|
],
|
||||||
&serialize(&StakeInstruction::Withdraw(42)).unwrap(),
|
&serialize(&StakeInstruction::Withdraw(42)).unwrap(),
|
||||||
|
@ -340,9 +336,9 @@ mod tests {
|
||||||
&mut [
|
&mut [
|
||||||
KeyedAccount::new(&Pubkey::default(), false, &mut Account::default()),
|
KeyedAccount::new(&Pubkey::default(), false, &mut Account::default()),
|
||||||
KeyedAccount::new(
|
KeyedAccount::new(
|
||||||
&syscall::current::id(),
|
&sysvar::clock::id(),
|
||||||
false,
|
false,
|
||||||
&mut syscall::rewards::create_account(1, 0.0, 0.0)
|
&mut sysvar::rewards::create_account(1, 0.0, 0.0)
|
||||||
),
|
),
|
||||||
],
|
],
|
||||||
&serialize(&StakeInstruction::Withdraw(42)).unwrap(),
|
&serialize(&StakeInstruction::Withdraw(42)).unwrap(),
|
||||||
|
@ -350,16 +346,16 @@ mod tests {
|
||||||
Err(InstructionError::InvalidInstructionData),
|
Err(InstructionError::InvalidInstructionData),
|
||||||
);
|
);
|
||||||
|
|
||||||
// Tests 2nd keyed account is of correct type (Current instead of rewards) in deactivate
|
// Tests 2nd keyed account is of correct type (Clock instead of rewards) in deactivate
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
super::process_instruction(
|
super::process_instruction(
|
||||||
&Pubkey::default(),
|
&Pubkey::default(),
|
||||||
&mut [
|
&mut [
|
||||||
KeyedAccount::new(&Pubkey::default(), false, &mut Account::default()),
|
KeyedAccount::new(&Pubkey::default(), false, &mut Account::default()),
|
||||||
KeyedAccount::new(
|
KeyedAccount::new(
|
||||||
&syscall::rewards::id(),
|
&sysvar::rewards::id(),
|
||||||
false,
|
false,
|
||||||
&mut syscall::rewards::create_account(1, 0.0, 0.0)
|
&mut sysvar::rewards::create_account(1, 0.0, 0.0)
|
||||||
),
|
),
|
||||||
],
|
],
|
||||||
&serialize(&StakeInstruction::Deactivate).unwrap(),
|
&serialize(&StakeInstruction::Deactivate).unwrap(),
|
||||||
|
@ -375,9 +371,9 @@ mod tests {
|
||||||
KeyedAccount::new(&Pubkey::default(), false, &mut Account::default()),
|
KeyedAccount::new(&Pubkey::default(), false, &mut Account::default()),
|
||||||
KeyedAccount::new(&Pubkey::default(), false, &mut Account::default()),
|
KeyedAccount::new(&Pubkey::default(), false, &mut Account::default()),
|
||||||
KeyedAccount::new(
|
KeyedAccount::new(
|
||||||
&syscall::current::id(),
|
&sysvar::clock::id(),
|
||||||
false,
|
false,
|
||||||
&mut syscall::rewards::create_account(1, 0.0, 0.0)
|
&mut sysvar::rewards::create_account(1, 0.0, 0.0)
|
||||||
),
|
),
|
||||||
],
|
],
|
||||||
&serialize(&StakeInstruction::Deactivate).unwrap(),
|
&serialize(&StakeInstruction::Deactivate).unwrap(),
|
||||||
|
|
|
@ -9,7 +9,7 @@ use solana_sdk::account::{Account, KeyedAccount};
|
||||||
use solana_sdk::account_utils::State;
|
use solana_sdk::account_utils::State;
|
||||||
use solana_sdk::instruction::InstructionError;
|
use solana_sdk::instruction::InstructionError;
|
||||||
use solana_sdk::pubkey::Pubkey;
|
use solana_sdk::pubkey::Pubkey;
|
||||||
use solana_sdk::syscall;
|
use solana_sdk::sysvar;
|
||||||
use solana_sdk::timing::Epoch;
|
use solana_sdk::timing::Epoch;
|
||||||
use solana_vote_api::vote_state::VoteState;
|
use solana_vote_api::vote_state::VoteState;
|
||||||
use std::cmp;
|
use std::cmp;
|
||||||
|
@ -178,23 +178,20 @@ pub trait StakeAccount {
|
||||||
&mut self,
|
&mut self,
|
||||||
vote_account: &KeyedAccount,
|
vote_account: &KeyedAccount,
|
||||||
stake: u64,
|
stake: u64,
|
||||||
current: &syscall::current::Current,
|
clock: &sysvar::clock::Clock,
|
||||||
) -> Result<(), InstructionError>;
|
|
||||||
fn deactivate_stake(
|
|
||||||
&mut self,
|
|
||||||
current: &syscall::current::Current,
|
|
||||||
) -> Result<(), InstructionError>;
|
) -> Result<(), InstructionError>;
|
||||||
|
fn deactivate_stake(&mut self, clock: &sysvar::clock::Clock) -> Result<(), InstructionError>;
|
||||||
fn redeem_vote_credits(
|
fn redeem_vote_credits(
|
||||||
&mut self,
|
&mut self,
|
||||||
vote_account: &mut KeyedAccount,
|
vote_account: &mut KeyedAccount,
|
||||||
rewards_account: &mut KeyedAccount,
|
rewards_account: &mut KeyedAccount,
|
||||||
rewards: &syscall::rewards::Rewards,
|
rewards: &sysvar::rewards::Rewards,
|
||||||
) -> Result<(), InstructionError>;
|
) -> Result<(), InstructionError>;
|
||||||
fn withdraw(
|
fn withdraw(
|
||||||
&mut self,
|
&mut self,
|
||||||
lamports: u64,
|
lamports: u64,
|
||||||
to: &mut KeyedAccount,
|
to: &mut KeyedAccount,
|
||||||
current: &syscall::current::Current,
|
clock: &sysvar::clock::Clock,
|
||||||
) -> Result<(), InstructionError>;
|
) -> Result<(), InstructionError>;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -203,7 +200,7 @@ impl<'a> StakeAccount for KeyedAccount<'a> {
|
||||||
&mut self,
|
&mut self,
|
||||||
vote_account: &KeyedAccount,
|
vote_account: &KeyedAccount,
|
||||||
new_stake: u64,
|
new_stake: u64,
|
||||||
current: &syscall::current::Current,
|
clock: &sysvar::clock::Clock,
|
||||||
) -> Result<(), InstructionError> {
|
) -> Result<(), InstructionError> {
|
||||||
if self.signer_key().is_none() {
|
if self.signer_key().is_none() {
|
||||||
return Err(InstructionError::MissingRequiredSignature);
|
return Err(InstructionError::MissingRequiredSignature);
|
||||||
|
@ -220,7 +217,7 @@ impl<'a> StakeAccount for KeyedAccount<'a> {
|
||||||
new_stake,
|
new_stake,
|
||||||
vote_account.unsigned_key(),
|
vote_account.unsigned_key(),
|
||||||
&vote_account.state()?,
|
&vote_account.state()?,
|
||||||
current.epoch,
|
clock.epoch,
|
||||||
);
|
);
|
||||||
|
|
||||||
self.set_state(&StakeState::Stake(stake))
|
self.set_state(&StakeState::Stake(stake))
|
||||||
|
@ -228,16 +225,13 @@ impl<'a> StakeAccount for KeyedAccount<'a> {
|
||||||
Err(InstructionError::InvalidAccountData)
|
Err(InstructionError::InvalidAccountData)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
fn deactivate_stake(
|
fn deactivate_stake(&mut self, clock: &sysvar::clock::Clock) -> Result<(), InstructionError> {
|
||||||
&mut self,
|
|
||||||
current: &syscall::current::Current,
|
|
||||||
) -> Result<(), InstructionError> {
|
|
||||||
if self.signer_key().is_none() {
|
if self.signer_key().is_none() {
|
||||||
return Err(InstructionError::MissingRequiredSignature);
|
return Err(InstructionError::MissingRequiredSignature);
|
||||||
}
|
}
|
||||||
|
|
||||||
if let StakeState::Stake(mut stake) = self.state()? {
|
if let StakeState::Stake(mut stake) = self.state()? {
|
||||||
stake.deactivate(current.epoch);
|
stake.deactivate(clock.epoch);
|
||||||
|
|
||||||
self.set_state(&StakeState::Stake(stake))
|
self.set_state(&StakeState::Stake(stake))
|
||||||
} else {
|
} else {
|
||||||
|
@ -248,7 +242,7 @@ impl<'a> StakeAccount for KeyedAccount<'a> {
|
||||||
&mut self,
|
&mut self,
|
||||||
vote_account: &mut KeyedAccount,
|
vote_account: &mut KeyedAccount,
|
||||||
rewards_account: &mut KeyedAccount,
|
rewards_account: &mut KeyedAccount,
|
||||||
rewards: &syscall::rewards::Rewards,
|
rewards: &sysvar::rewards::Rewards,
|
||||||
) -> Result<(), InstructionError> {
|
) -> Result<(), InstructionError> {
|
||||||
if let (StakeState::Stake(mut stake), StakeState::RewardsPool) =
|
if let (StakeState::Stake(mut stake), StakeState::RewardsPool) =
|
||||||
(self.state()?, rewards_account.state()?)
|
(self.state()?, rewards_account.state()?)
|
||||||
|
@ -285,7 +279,7 @@ impl<'a> StakeAccount for KeyedAccount<'a> {
|
||||||
&mut self,
|
&mut self,
|
||||||
lamports: u64,
|
lamports: u64,
|
||||||
to: &mut KeyedAccount,
|
to: &mut KeyedAccount,
|
||||||
current: &syscall::current::Current,
|
clock: &sysvar::clock::Clock,
|
||||||
) -> Result<(), InstructionError> {
|
) -> Result<(), InstructionError> {
|
||||||
if self.signer_key().is_none() {
|
if self.signer_key().is_none() {
|
||||||
return Err(InstructionError::MissingRequiredSignature);
|
return Err(InstructionError::MissingRequiredSignature);
|
||||||
|
@ -293,7 +287,7 @@ impl<'a> StakeAccount for KeyedAccount<'a> {
|
||||||
|
|
||||||
match self.state()? {
|
match self.state()? {
|
||||||
StakeState::Stake(mut stake) => {
|
StakeState::Stake(mut stake) => {
|
||||||
let staked = if stake.stake(current.epoch) == 0 {
|
let staked = if stake.stake(clock.epoch) == 0 {
|
||||||
0
|
0
|
||||||
} else {
|
} else {
|
||||||
// Assume full stake if the stake is under warmup/cooldown
|
// Assume full stake if the stake is under warmup/cooldown
|
||||||
|
@ -359,7 +353,7 @@ mod tests {
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn test_stake_delegate_stake() {
|
fn test_stake_delegate_stake() {
|
||||||
let current = syscall::current::Current::default();
|
let clock = sysvar::clock::Clock::default();
|
||||||
|
|
||||||
let vote_keypair = Keypair::new();
|
let vote_keypair = Keypair::new();
|
||||||
let mut vote_state = VoteState::default();
|
let mut vote_state = VoteState::default();
|
||||||
|
@ -387,14 +381,14 @@ mod tests {
|
||||||
}
|
}
|
||||||
|
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
stake_keyed_account.delegate_stake(&vote_keyed_account, 0, ¤t),
|
stake_keyed_account.delegate_stake(&vote_keyed_account, 0, &clock),
|
||||||
Err(InstructionError::MissingRequiredSignature)
|
Err(InstructionError::MissingRequiredSignature)
|
||||||
);
|
);
|
||||||
|
|
||||||
// signed keyed account
|
// signed keyed account
|
||||||
let mut stake_keyed_account = KeyedAccount::new(&stake_pubkey, true, &mut stake_account);
|
let mut stake_keyed_account = KeyedAccount::new(&stake_pubkey, true, &mut stake_account);
|
||||||
assert!(stake_keyed_account
|
assert!(stake_keyed_account
|
||||||
.delegate_stake(&vote_keyed_account, stake_lamports, ¤t)
|
.delegate_stake(&vote_keyed_account, stake_lamports, &clock)
|
||||||
.is_ok());
|
.is_ok());
|
||||||
|
|
||||||
// verify that delegate_stake() looks right, compare against hand-rolled
|
// verify that delegate_stake() looks right, compare against hand-rolled
|
||||||
|
@ -412,14 +406,14 @@ mod tests {
|
||||||
// verify that delegate_stake can't be called twice StakeState::default()
|
// verify that delegate_stake can't be called twice StakeState::default()
|
||||||
// signed keyed account
|
// signed keyed account
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
stake_keyed_account.delegate_stake(&vote_keyed_account, stake_lamports, ¤t),
|
stake_keyed_account.delegate_stake(&vote_keyed_account, stake_lamports, &clock),
|
||||||
Err(InstructionError::InvalidAccountData)
|
Err(InstructionError::InvalidAccountData)
|
||||||
);
|
);
|
||||||
|
|
||||||
// verify can only stake up to account lamports
|
// verify can only stake up to account lamports
|
||||||
let mut stake_keyed_account = KeyedAccount::new(&stake_pubkey, true, &mut stake_account);
|
let mut stake_keyed_account = KeyedAccount::new(&stake_pubkey, true, &mut stake_account);
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
stake_keyed_account.delegate_stake(&vote_keyed_account, stake_lamports + 1, ¤t),
|
stake_keyed_account.delegate_stake(&vote_keyed_account, stake_lamports + 1, &clock),
|
||||||
Err(InstructionError::InsufficientFunds)
|
Err(InstructionError::InsufficientFunds)
|
||||||
);
|
);
|
||||||
|
|
||||||
|
@ -427,7 +421,7 @@ mod tests {
|
||||||
|
|
||||||
stake_keyed_account.set_state(&stake_state).unwrap();
|
stake_keyed_account.set_state(&stake_state).unwrap();
|
||||||
assert!(stake_keyed_account
|
assert!(stake_keyed_account
|
||||||
.delegate_stake(&vote_keyed_account, 0, ¤t)
|
.delegate_stake(&vote_keyed_account, 0, &clock)
|
||||||
.is_err());
|
.is_err());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -462,19 +456,19 @@ mod tests {
|
||||||
let mut stake_account =
|
let mut stake_account =
|
||||||
Account::new(stake_lamports, std::mem::size_of::<StakeState>(), &id());
|
Account::new(stake_lamports, std::mem::size_of::<StakeState>(), &id());
|
||||||
|
|
||||||
let current = syscall::current::Current::default();
|
let clock = sysvar::clock::Clock::default();
|
||||||
|
|
||||||
// unsigned keyed account
|
// unsigned keyed account
|
||||||
let mut stake_keyed_account = KeyedAccount::new(&stake_pubkey, false, &mut stake_account);
|
let mut stake_keyed_account = KeyedAccount::new(&stake_pubkey, false, &mut stake_account);
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
stake_keyed_account.deactivate_stake(¤t),
|
stake_keyed_account.deactivate_stake(&clock),
|
||||||
Err(InstructionError::MissingRequiredSignature)
|
Err(InstructionError::MissingRequiredSignature)
|
||||||
);
|
);
|
||||||
|
|
||||||
// signed keyed account but not staked yet
|
// signed keyed account but not staked yet
|
||||||
let mut stake_keyed_account = KeyedAccount::new(&stake_pubkey, true, &mut stake_account);
|
let mut stake_keyed_account = KeyedAccount::new(&stake_pubkey, true, &mut stake_account);
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
stake_keyed_account.deactivate_stake(¤t),
|
stake_keyed_account.deactivate_stake(&clock),
|
||||||
Err(InstructionError::InvalidAccountData)
|
Err(InstructionError::InvalidAccountData)
|
||||||
);
|
);
|
||||||
|
|
||||||
|
@ -485,12 +479,12 @@ mod tests {
|
||||||
let mut vote_keyed_account = KeyedAccount::new(&vote_pubkey, false, &mut vote_account);
|
let mut vote_keyed_account = KeyedAccount::new(&vote_pubkey, false, &mut vote_account);
|
||||||
vote_keyed_account.set_state(&VoteState::default()).unwrap();
|
vote_keyed_account.set_state(&VoteState::default()).unwrap();
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
stake_keyed_account.delegate_stake(&vote_keyed_account, stake_lamports, ¤t),
|
stake_keyed_account.delegate_stake(&vote_keyed_account, stake_lamports, &clock),
|
||||||
Ok(())
|
Ok(())
|
||||||
);
|
);
|
||||||
|
|
||||||
// Deactivate after staking
|
// Deactivate after staking
|
||||||
assert_eq!(stake_keyed_account.deactivate_stake(¤t), Ok(()));
|
assert_eq!(stake_keyed_account.deactivate_stake(&clock), Ok(()));
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
|
@ -501,7 +495,7 @@ mod tests {
|
||||||
let mut stake_account =
|
let mut stake_account =
|
||||||
Account::new(total_lamports, std::mem::size_of::<StakeState>(), &id());
|
Account::new(total_lamports, std::mem::size_of::<StakeState>(), &id());
|
||||||
|
|
||||||
let current = syscall::current::Current::default();
|
let clock = sysvar::clock::Clock::default();
|
||||||
|
|
||||||
let to = Pubkey::new_rand();
|
let to = Pubkey::new_rand();
|
||||||
let mut to_account = Account::new(1, 0, &system_program::id());
|
let mut to_account = Account::new(1, 0, &system_program::id());
|
||||||
|
@ -510,7 +504,7 @@ mod tests {
|
||||||
// unsigned keyed account
|
// unsigned keyed account
|
||||||
let mut stake_keyed_account = KeyedAccount::new(&stake_pubkey, false, &mut stake_account);
|
let mut stake_keyed_account = KeyedAccount::new(&stake_pubkey, false, &mut stake_account);
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
stake_keyed_account.withdraw(total_lamports, &mut to_keyed_account, ¤t),
|
stake_keyed_account.withdraw(total_lamports, &mut to_keyed_account, &clock),
|
||||||
Err(InstructionError::MissingRequiredSignature)
|
Err(InstructionError::MissingRequiredSignature)
|
||||||
);
|
);
|
||||||
|
|
||||||
|
@ -518,14 +512,14 @@ mod tests {
|
||||||
// try withdrawing more than balance
|
// try withdrawing more than balance
|
||||||
let mut stake_keyed_account = KeyedAccount::new(&stake_pubkey, true, &mut stake_account);
|
let mut stake_keyed_account = KeyedAccount::new(&stake_pubkey, true, &mut stake_account);
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
stake_keyed_account.withdraw(total_lamports + 1, &mut to_keyed_account, ¤t),
|
stake_keyed_account.withdraw(total_lamports + 1, &mut to_keyed_account, &clock),
|
||||||
Err(InstructionError::InsufficientFunds)
|
Err(InstructionError::InsufficientFunds)
|
||||||
);
|
);
|
||||||
|
|
||||||
// try withdrawing some (enough for rest of the test to carry forward)
|
// try withdrawing some (enough for rest of the test to carry forward)
|
||||||
let mut stake_keyed_account = KeyedAccount::new(&stake_pubkey, true, &mut stake_account);
|
let mut stake_keyed_account = KeyedAccount::new(&stake_pubkey, true, &mut stake_account);
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
stake_keyed_account.withdraw(5, &mut to_keyed_account, ¤t),
|
stake_keyed_account.withdraw(5, &mut to_keyed_account, &clock),
|
||||||
Ok(())
|
Ok(())
|
||||||
);
|
);
|
||||||
total_lamports -= 5;
|
total_lamports -= 5;
|
||||||
|
@ -537,7 +531,7 @@ mod tests {
|
||||||
let mut vote_keyed_account = KeyedAccount::new(&vote_pubkey, false, &mut vote_account);
|
let mut vote_keyed_account = KeyedAccount::new(&vote_pubkey, false, &mut vote_account);
|
||||||
vote_keyed_account.set_state(&VoteState::default()).unwrap();
|
vote_keyed_account.set_state(&VoteState::default()).unwrap();
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
stake_keyed_account.delegate_stake(&vote_keyed_account, stake_lamports, ¤t),
|
stake_keyed_account.delegate_stake(&vote_keyed_account, stake_lamports, &clock),
|
||||||
Ok(())
|
Ok(())
|
||||||
);
|
);
|
||||||
|
|
||||||
|
@ -546,7 +540,7 @@ mod tests {
|
||||||
stake_keyed_account.withdraw(
|
stake_keyed_account.withdraw(
|
||||||
total_lamports - stake_lamports + 1,
|
total_lamports - stake_lamports + 1,
|
||||||
&mut to_keyed_account,
|
&mut to_keyed_account,
|
||||||
¤t
|
&clock
|
||||||
),
|
),
|
||||||
Err(InstructionError::InsufficientFunds)
|
Err(InstructionError::InsufficientFunds)
|
||||||
);
|
);
|
||||||
|
@ -556,7 +550,7 @@ mod tests {
|
||||||
stake_keyed_account.withdraw(
|
stake_keyed_account.withdraw(
|
||||||
total_lamports - stake_lamports,
|
total_lamports - stake_lamports,
|
||||||
&mut to_keyed_account,
|
&mut to_keyed_account,
|
||||||
¤t
|
&clock
|
||||||
),
|
),
|
||||||
Ok(())
|
Ok(())
|
||||||
);
|
);
|
||||||
|
@ -570,8 +564,8 @@ mod tests {
|
||||||
let mut stake_account =
|
let mut stake_account =
|
||||||
Account::new(total_lamports, std::mem::size_of::<StakeState>(), &id());
|
Account::new(total_lamports, std::mem::size_of::<StakeState>(), &id());
|
||||||
|
|
||||||
let current = syscall::current::Current::default();
|
let clock = sysvar::clock::Clock::default();
|
||||||
let mut future = syscall::current::Current::default();
|
let mut future = sysvar::clock::Clock::default();
|
||||||
future.epoch += 16;
|
future.epoch += 16;
|
||||||
|
|
||||||
let to = Pubkey::new_rand();
|
let to = Pubkey::new_rand();
|
||||||
|
@ -596,7 +590,7 @@ mod tests {
|
||||||
stake_keyed_account.withdraw(
|
stake_keyed_account.withdraw(
|
||||||
total_lamports - stake_lamports + 1,
|
total_lamports - stake_lamports + 1,
|
||||||
&mut to_keyed_account,
|
&mut to_keyed_account,
|
||||||
¤t
|
&clock
|
||||||
),
|
),
|
||||||
Ok(())
|
Ok(())
|
||||||
);
|
);
|
||||||
|
@ -609,8 +603,8 @@ mod tests {
|
||||||
let mut stake_account =
|
let mut stake_account =
|
||||||
Account::new(total_lamports, std::mem::size_of::<StakeState>(), &id());
|
Account::new(total_lamports, std::mem::size_of::<StakeState>(), &id());
|
||||||
|
|
||||||
let current = syscall::current::Current::default();
|
let clock = sysvar::clock::Clock::default();
|
||||||
let mut future = syscall::current::Current::default();
|
let mut future = sysvar::clock::Clock::default();
|
||||||
future.epoch += 16;
|
future.epoch += 16;
|
||||||
|
|
||||||
let to = Pubkey::new_rand();
|
let to = Pubkey::new_rand();
|
||||||
|
@ -622,7 +616,7 @@ mod tests {
|
||||||
stake_keyed_account.set_state(&stake_state).unwrap();
|
stake_keyed_account.set_state(&stake_state).unwrap();
|
||||||
|
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
stake_keyed_account.withdraw(total_lamports, &mut to_keyed_account, ¤t),
|
stake_keyed_account.withdraw(total_lamports, &mut to_keyed_account, &clock),
|
||||||
Err(InstructionError::InvalidAccountData)
|
Err(InstructionError::InvalidAccountData)
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
@ -704,8 +698,8 @@ mod tests {
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn test_stake_redeem_vote_credits() {
|
fn test_stake_redeem_vote_credits() {
|
||||||
let current = syscall::current::Current::default();
|
let clock = sysvar::clock::Clock::default();
|
||||||
let mut rewards = syscall::rewards::Rewards::default();
|
let mut rewards = sysvar::rewards::Rewards::default();
|
||||||
rewards.validator_point_value = 100.0;
|
rewards.validator_point_value = 100.0;
|
||||||
|
|
||||||
let rewards_pool_pubkey = Pubkey::new_rand();
|
let rewards_pool_pubkey = Pubkey::new_rand();
|
||||||
|
@ -736,7 +730,7 @@ mod tests {
|
||||||
|
|
||||||
// delegate the stake
|
// delegate the stake
|
||||||
assert!(stake_keyed_account
|
assert!(stake_keyed_account
|
||||||
.delegate_stake(&vote_keyed_account, stake_lamports, ¤t)
|
.delegate_stake(&vote_keyed_account, stake_lamports, &clock)
|
||||||
.is_ok());
|
.is_ok());
|
||||||
// no credits to claim
|
// no credits to claim
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
|
|
|
@ -7,8 +7,8 @@ use solana_sdk::client::SyncClient;
|
||||||
use solana_sdk::message::Message;
|
use solana_sdk::message::Message;
|
||||||
use solana_sdk::pubkey::Pubkey;
|
use solana_sdk::pubkey::Pubkey;
|
||||||
use solana_sdk::signature::{Keypair, KeypairUtil};
|
use solana_sdk::signature::{Keypair, KeypairUtil};
|
||||||
use solana_sdk::syscall;
|
use solana_sdk::sysvar;
|
||||||
use solana_sdk::syscall::rewards::Rewards;
|
use solana_sdk::sysvar::rewards::Rewards;
|
||||||
use solana_stake_api::id;
|
use solana_stake_api::id;
|
||||||
use solana_stake_api::stake_instruction;
|
use solana_stake_api::stake_instruction;
|
||||||
use solana_stake_api::stake_instruction::process_instruction;
|
use solana_stake_api::stake_instruction::process_instruction;
|
||||||
|
@ -145,7 +145,7 @@ fn test_stake_account_delegate() {
|
||||||
|
|
||||||
// Test that rewards are there
|
// Test that rewards are there
|
||||||
let rewards_account = bank
|
let rewards_account = bank
|
||||||
.get_account(&syscall::rewards::id())
|
.get_account(&sysvar::rewards::id())
|
||||||
.expect("account not found");
|
.expect("account not found");
|
||||||
assert_matches!(Rewards::from(&rewards_account), Some(_));
|
assert_matches!(Rewards::from(&rewards_account), Some(_));
|
||||||
|
|
||||||
|
|
|
@ -8,7 +8,7 @@ use solana_sdk::hash::Hash;
|
||||||
use solana_sdk::instruction::InstructionError;
|
use solana_sdk::instruction::InstructionError;
|
||||||
use solana_sdk::pubkey::Pubkey;
|
use solana_sdk::pubkey::Pubkey;
|
||||||
use solana_sdk::signature::Signature;
|
use solana_sdk::signature::Signature;
|
||||||
use solana_sdk::syscall;
|
use solana_sdk::sysvar;
|
||||||
use std::collections::BTreeMap;
|
use std::collections::BTreeMap;
|
||||||
|
|
||||||
// Todo Tune this for actual use cases when PoRep is feature complete
|
// Todo Tune this for actual use cases when PoRep is feature complete
|
||||||
|
@ -167,7 +167,7 @@ impl<'a> StorageAccount<'a> {
|
||||||
segment_index: u64,
|
segment_index: u64,
|
||||||
signature: Signature,
|
signature: Signature,
|
||||||
blockhash: Hash,
|
blockhash: Hash,
|
||||||
current: syscall::current::Current,
|
clock: sysvar::clock::Clock,
|
||||||
) -> Result<(), InstructionError> {
|
) -> Result<(), InstructionError> {
|
||||||
let mut storage_contract = &mut self.account.state()?;
|
let mut storage_contract = &mut self.account.state()?;
|
||||||
if let StorageContract::ReplicatorStorage {
|
if let StorageContract::ReplicatorStorage {
|
||||||
|
@ -177,7 +177,7 @@ impl<'a> StorageAccount<'a> {
|
||||||
..
|
..
|
||||||
} = &mut storage_contract
|
} = &mut storage_contract
|
||||||
{
|
{
|
||||||
let current_segment = current.segment;
|
let current_segment = clock.segment;
|
||||||
|
|
||||||
// clean up the account
|
// clean up the account
|
||||||
// TODO check for time correctness - storage seems to run at a delay of about 3
|
// 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,
|
StorageError::ProofLimitReached as u32,
|
||||||
));
|
));
|
||||||
}
|
}
|
||||||
credits.update_epoch(current.epoch);
|
credits.update_epoch(clock.epoch);
|
||||||
segment_proofs.push(proof);
|
segment_proofs.push(proof);
|
||||||
self.account.set_state(storage_contract)
|
self.account.set_state(storage_contract)
|
||||||
} else {
|
} else {
|
||||||
|
@ -242,7 +242,7 @@ impl<'a> StorageAccount<'a> {
|
||||||
&mut self,
|
&mut self,
|
||||||
hash: Hash,
|
hash: Hash,
|
||||||
segment: u64,
|
segment: u64,
|
||||||
current: syscall::current::Current,
|
clock: sysvar::clock::Clock,
|
||||||
) -> Result<(), InstructionError> {
|
) -> Result<(), InstructionError> {
|
||||||
let mut storage_contract = &mut self.account.state()?;
|
let mut storage_contract = &mut self.account.state()?;
|
||||||
if let StorageContract::ValidatorStorage {
|
if let StorageContract::ValidatorStorage {
|
||||||
|
@ -253,11 +253,8 @@ impl<'a> StorageAccount<'a> {
|
||||||
..
|
..
|
||||||
} = &mut storage_contract
|
} = &mut storage_contract
|
||||||
{
|
{
|
||||||
debug!(
|
debug!("advertise new segment: {} orig: {}", segment, clock.segment);
|
||||||
"advertise new segment: {} orig: {}",
|
if segment < *state_segment || segment > clock.segment {
|
||||||
segment, current.segment
|
|
||||||
);
|
|
||||||
if segment < *state_segment || segment > current.segment {
|
|
||||||
return Err(InstructionError::CustomError(
|
return Err(InstructionError::CustomError(
|
||||||
StorageError::InvalidSegment as u32,
|
StorageError::InvalidSegment as u32,
|
||||||
));
|
));
|
||||||
|
@ -269,7 +266,7 @@ impl<'a> StorageAccount<'a> {
|
||||||
// storage epoch updated, move the lockout_validations to credits
|
// storage epoch updated, move the lockout_validations to credits
|
||||||
let (_num_valid, total_validations) = count_valid_proofs(&lockout_validations);
|
let (_num_valid, total_validations) = count_valid_proofs(&lockout_validations);
|
||||||
lockout_validations.clear();
|
lockout_validations.clear();
|
||||||
credits.update_epoch(current.epoch);
|
credits.update_epoch(clock.epoch);
|
||||||
credits.current_epoch += total_validations;
|
credits.current_epoch += total_validations;
|
||||||
self.account.set_state(storage_contract)
|
self.account.set_state(storage_contract)
|
||||||
} else {
|
} else {
|
||||||
|
@ -280,7 +277,7 @@ impl<'a> StorageAccount<'a> {
|
||||||
pub fn proof_validation(
|
pub fn proof_validation(
|
||||||
&mut self,
|
&mut self,
|
||||||
me: &Pubkey,
|
me: &Pubkey,
|
||||||
current: syscall::current::Current,
|
clock: sysvar::clock::Clock,
|
||||||
segment_index: u64,
|
segment_index: u64,
|
||||||
proofs_per_account: Vec<Vec<ProofStatus>>,
|
proofs_per_account: Vec<Vec<ProofStatus>>,
|
||||||
replicator_accounts: &mut [StorageAccount],
|
replicator_accounts: &mut [StorageAccount],
|
||||||
|
@ -341,13 +338,7 @@ impl<'a> StorageAccount<'a> {
|
||||||
.into_iter()
|
.into_iter()
|
||||||
.zip(accounts.into_iter())
|
.zip(accounts.into_iter())
|
||||||
.filter_map(|(checked_proofs, account)| {
|
.filter_map(|(checked_proofs, account)| {
|
||||||
if store_validation_result(
|
if store_validation_result(me, &clock, account, segment_index, &checked_proofs)
|
||||||
me,
|
|
||||||
¤t,
|
|
||||||
account,
|
|
||||||
segment_index,
|
|
||||||
&checked_proofs,
|
|
||||||
)
|
|
||||||
.is_ok()
|
.is_ok()
|
||||||
{
|
{
|
||||||
Some((account.id, checked_proofs))
|
Some((account.id, checked_proofs))
|
||||||
|
@ -376,8 +367,8 @@ impl<'a> StorageAccount<'a> {
|
||||||
pub fn claim_storage_reward(
|
pub fn claim_storage_reward(
|
||||||
&mut self,
|
&mut self,
|
||||||
rewards_pool: &mut KeyedAccount,
|
rewards_pool: &mut KeyedAccount,
|
||||||
current: syscall::current::Current,
|
clock: sysvar::clock::Clock,
|
||||||
rewards: syscall::rewards::Rewards,
|
rewards: sysvar::rewards::Rewards,
|
||||||
owner: &mut StorageAccount,
|
owner: &mut StorageAccount,
|
||||||
) -> Result<(), InstructionError> {
|
) -> Result<(), InstructionError> {
|
||||||
let mut storage_contract = &mut self.account.state()?;
|
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)?;
|
check_redeemable(credits, rewards.storage_point_value, rewards_pool, owner)?;
|
||||||
|
|
||||||
self.account.set_state(storage_contract)
|
self.account.set_state(storage_contract)
|
||||||
|
@ -410,7 +401,7 @@ impl<'a> StorageAccount<'a> {
|
||||||
StorageError::InvalidOwner as u32,
|
StorageError::InvalidOwner as u32,
|
||||||
))?
|
))?
|
||||||
}
|
}
|
||||||
credits.update_epoch(current.epoch);
|
credits.update_epoch(clock.epoch);
|
||||||
let (num_validations, _total_proofs) = count_valid_proofs(&validations);
|
let (num_validations, _total_proofs) = count_valid_proofs(&validations);
|
||||||
credits.current_epoch += num_validations;
|
credits.current_epoch += num_validations;
|
||||||
validations.clear();
|
validations.clear();
|
||||||
|
@ -451,7 +442,7 @@ pub fn create_rewards_pool() -> Account {
|
||||||
/// Store the result of a proof validation into the replicator account
|
/// Store the result of a proof validation into the replicator account
|
||||||
fn store_validation_result(
|
fn store_validation_result(
|
||||||
me: &Pubkey,
|
me: &Pubkey,
|
||||||
current: &syscall::current::Current,
|
clock: &sysvar::clock::Clock,
|
||||||
storage_account: &mut StorageAccount,
|
storage_account: &mut StorageAccount,
|
||||||
segment: u64,
|
segment: u64,
|
||||||
proof_mask: &[ProofStatus],
|
proof_mask: &[ProofStatus],
|
||||||
|
@ -478,7 +469,7 @@ fn store_validation_result(
|
||||||
entry.insert(*me, proof_mask.to_vec());
|
entry.insert(*me, proof_mask.to_vec());
|
||||||
}
|
}
|
||||||
let (total_validations, _) = count_valid_proofs(&validations);
|
let (total_validations, _) = count_valid_proofs(&validations);
|
||||||
credits.update_epoch(current.epoch);
|
credits.update_epoch(clock.epoch);
|
||||||
credits.current_epoch += total_validations - recorded_validations;
|
credits.current_epoch += total_validations - recorded_validations;
|
||||||
}
|
}
|
||||||
_ => return Err(InstructionError::InvalidAccountData),
|
_ => return Err(InstructionError::InvalidAccountData),
|
||||||
|
@ -571,7 +562,7 @@ mod tests {
|
||||||
// account has no space
|
// account has no space
|
||||||
store_validation_result(
|
store_validation_result(
|
||||||
&Pubkey::default(),
|
&Pubkey::default(),
|
||||||
&syscall::current::Current::default(),
|
&sysvar::clock::Clock::default(),
|
||||||
&mut account,
|
&mut account,
|
||||||
segment_index,
|
segment_index,
|
||||||
&vec![ProofStatus::default(); 1],
|
&vec![ProofStatus::default(); 1],
|
||||||
|
@ -598,7 +589,7 @@ mod tests {
|
||||||
// proof is valid
|
// proof is valid
|
||||||
store_validation_result(
|
store_validation_result(
|
||||||
&Pubkey::default(),
|
&Pubkey::default(),
|
||||||
&syscall::current::Current::default(),
|
&sysvar::clock::Clock::default(),
|
||||||
&mut account,
|
&mut account,
|
||||||
segment_index,
|
segment_index,
|
||||||
&vec![ProofStatus::Valid],
|
&vec![ProofStatus::Valid],
|
||||||
|
@ -608,7 +599,7 @@ mod tests {
|
||||||
// proof failed verification but we should still be able to store it
|
// proof failed verification but we should still be able to store it
|
||||||
store_validation_result(
|
store_validation_result(
|
||||||
&Pubkey::default(),
|
&Pubkey::default(),
|
||||||
&syscall::current::Current::default(),
|
&sysvar::clock::Clock::default(),
|
||||||
&mut account,
|
&mut account,
|
||||||
segment_index,
|
segment_index,
|
||||||
&vec![ProofStatus::NotValid],
|
&vec![ProofStatus::NotValid],
|
||||||
|
|
|
@ -5,8 +5,8 @@ use solana_sdk::hash::Hash;
|
||||||
use solana_sdk::instruction::{AccountMeta, Instruction};
|
use solana_sdk::instruction::{AccountMeta, Instruction};
|
||||||
use solana_sdk::pubkey::Pubkey;
|
use solana_sdk::pubkey::Pubkey;
|
||||||
use solana_sdk::signature::Signature;
|
use solana_sdk::signature::Signature;
|
||||||
use solana_sdk::syscall::{current, rewards};
|
|
||||||
use solana_sdk::system_instruction;
|
use solana_sdk::system_instruction;
|
||||||
|
use solana_sdk::sysvar::{clock, rewards};
|
||||||
|
|
||||||
#[derive(Serialize, Deserialize, Debug, Clone)]
|
#[derive(Serialize, Deserialize, Debug, Clone)]
|
||||||
pub enum StorageInstruction {
|
pub enum StorageInstruction {
|
||||||
|
@ -35,7 +35,7 @@ pub enum StorageInstruction {
|
||||||
///
|
///
|
||||||
/// Expects 1 Account:
|
/// Expects 1 Account:
|
||||||
/// 0 - Storage account with credits to redeem
|
/// 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
|
/// 2 - Replicator account to credit - this account *must* be the owner
|
||||||
/// 3 - MiningPool account to redeem credits from
|
/// 3 - MiningPool account to redeem credits from
|
||||||
/// 4 - Rewards Syscall to figure out point values
|
/// 4 - Rewards Syscall to figure out point values
|
||||||
|
@ -144,7 +144,7 @@ pub fn mining_proof(
|
||||||
};
|
};
|
||||||
let account_metas = vec![
|
let account_metas = vec![
|
||||||
AccountMeta::new(*storage_pubkey, true),
|
AccountMeta::new(*storage_pubkey, true),
|
||||||
AccountMeta::new(current::id(), false),
|
AccountMeta::new(clock::id(), false),
|
||||||
];
|
];
|
||||||
Instruction::new(id(), &storage_instruction, account_metas)
|
Instruction::new(id(), &storage_instruction, account_metas)
|
||||||
}
|
}
|
||||||
|
@ -160,7 +160,7 @@ pub fn advertise_recent_blockhash(
|
||||||
};
|
};
|
||||||
let account_metas = vec![
|
let account_metas = vec![
|
||||||
AccountMeta::new(*storage_pubkey, true),
|
AccountMeta::new(*storage_pubkey, true),
|
||||||
AccountMeta::new(current::id(), false),
|
AccountMeta::new(clock::id(), false),
|
||||||
];
|
];
|
||||||
Instruction::new(id(), &storage_instruction, account_metas)
|
Instruction::new(id(), &storage_instruction, account_metas)
|
||||||
}
|
}
|
||||||
|
@ -172,7 +172,7 @@ pub fn proof_validation(
|
||||||
) -> Instruction {
|
) -> Instruction {
|
||||||
let mut account_metas = vec![
|
let mut account_metas = vec![
|
||||||
AccountMeta::new(*storage_pubkey, true),
|
AccountMeta::new(*storage_pubkey, true),
|
||||||
AccountMeta::new(current::id(), false),
|
AccountMeta::new(clock::id(), false),
|
||||||
];
|
];
|
||||||
let mut proofs = vec![];
|
let mut proofs = vec![];
|
||||||
checked_proofs.into_iter().for_each(|(id, p)| {
|
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 storage_instruction = StorageInstruction::ClaimStorageReward;
|
||||||
let account_metas = vec![
|
let account_metas = vec![
|
||||||
AccountMeta::new(*storage_pubkey, false),
|
AccountMeta::new(*storage_pubkey, false),
|
||||||
AccountMeta::new(current::id(), false),
|
AccountMeta::new(clock::id(), false),
|
||||||
AccountMeta::new(rewards::id(), false),
|
AccountMeta::new(rewards::id(), false),
|
||||||
AccountMeta::new(rewards_pools::random_id(), false),
|
AccountMeta::new(rewards_pools::random_id(), false),
|
||||||
AccountMeta::new(*owner_pubkey, false),
|
AccountMeta::new(*owner_pubkey, false),
|
||||||
|
|
|
@ -6,7 +6,7 @@ use crate::storage_instruction::StorageInstruction;
|
||||||
use solana_sdk::account::KeyedAccount;
|
use solana_sdk::account::KeyedAccount;
|
||||||
use solana_sdk::instruction::InstructionError;
|
use solana_sdk::instruction::InstructionError;
|
||||||
use solana_sdk::pubkey::Pubkey;
|
use solana_sdk::pubkey::Pubkey;
|
||||||
use solana_sdk::syscall;
|
use solana_sdk::sysvar;
|
||||||
|
|
||||||
pub fn process_instruction(
|
pub fn process_instruction(
|
||||||
_program_id: &Pubkey,
|
_program_id: &Pubkey,
|
||||||
|
@ -42,13 +42,13 @@ pub fn process_instruction(
|
||||||
// This instruction must be signed by `me`
|
// This instruction must be signed by `me`
|
||||||
Err(InstructionError::InvalidArgument)?;
|
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(
|
storage_account.submit_mining_proof(
|
||||||
sha_state,
|
sha_state,
|
||||||
segment_index,
|
segment_index,
|
||||||
signature,
|
signature,
|
||||||
blockhash,
|
blockhash,
|
||||||
current,
|
clock,
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
StorageInstruction::AdvertiseStorageRecentBlockhash { hash, segment } => {
|
StorageInstruction::AdvertiseStorageRecentBlockhash { hash, segment } => {
|
||||||
|
@ -56,47 +56,42 @@ pub fn process_instruction(
|
||||||
// This instruction must be signed by `me`
|
// This instruction must be signed by `me`
|
||||||
Err(InstructionError::InvalidArgument)?;
|
Err(InstructionError::InvalidArgument)?;
|
||||||
}
|
}
|
||||||
let current = syscall::current::from_keyed_account(&rest[0])?;
|
let clock = sysvar::clock::from_keyed_account(&rest[0])?;
|
||||||
storage_account.advertise_storage_recent_blockhash(hash, segment, current)
|
storage_account.advertise_storage_recent_blockhash(hash, segment, clock)
|
||||||
}
|
}
|
||||||
StorageInstruction::ClaimStorageReward => {
|
StorageInstruction::ClaimStorageReward => {
|
||||||
if rest.len() != 4 {
|
if rest.len() != 4 {
|
||||||
Err(InstructionError::InvalidArgument)?;
|
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, rest) = rest.split_at_mut(1);
|
||||||
let (rewards_pools, owner) = rest.split_at_mut(1);
|
let (rewards_pools, owner) = rest.split_at_mut(1);
|
||||||
|
|
||||||
let rewards = syscall::rewards::from_keyed_account(&rewards[0])?;
|
let rewards = sysvar::rewards::from_keyed_account(&rewards[0])?;
|
||||||
let current = syscall::current::from_keyed_account(¤t[0])?;
|
let clock = sysvar::clock::from_keyed_account(&clock[0])?;
|
||||||
let mut owner = StorageAccount::new(*owner[0].unsigned_key(), &mut owner[0].account);
|
let mut owner = StorageAccount::new(*owner[0].unsigned_key(), &mut owner[0].account);
|
||||||
|
|
||||||
storage_account.claim_storage_reward(
|
storage_account.claim_storage_reward(&mut rewards_pools[0], clock, rewards, &mut owner)
|
||||||
&mut rewards_pools[0],
|
|
||||||
current,
|
|
||||||
rewards,
|
|
||||||
&mut owner,
|
|
||||||
)
|
|
||||||
}
|
}
|
||||||
StorageInstruction::ProofValidation { segment, proofs } => {
|
StorageInstruction::ProofValidation { segment, proofs } => {
|
||||||
if rest.is_empty() {
|
if rest.is_empty() {
|
||||||
Err(InstructionError::InvalidArgument)?;
|
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() {
|
if me_unsigned || rest.is_empty() {
|
||||||
// This instruction must be signed by `me` and `rest` cannot be empty
|
// This instruction must be signed by `me` and `rest` cannot be empty
|
||||||
Err(InstructionError::InvalidArgument)?;
|
Err(InstructionError::InvalidArgument)?;
|
||||||
}
|
}
|
||||||
let me_id = storage_account.id;
|
let me_id = storage_account.id;
|
||||||
let current = syscall::current::from_keyed_account(¤t[0])?;
|
let clock = sysvar::clock::from_keyed_account(&clock[0])?;
|
||||||
let mut rest: Vec<_> = rest
|
let mut rest: Vec<_> = rest
|
||||||
.iter_mut()
|
.iter_mut()
|
||||||
.map(|keyed_account| {
|
.map(|keyed_account| {
|
||||||
StorageAccount::new(*keyed_account.unsigned_key(), &mut keyed_account.account)
|
StorageAccount::new(*keyed_account.unsigned_key(), &mut keyed_account.account)
|
||||||
})
|
})
|
||||||
.collect();
|
.collect();
|
||||||
storage_account.proof_validation(&me_id, current, segment, proofs, &mut rest)
|
storage_account.proof_validation(&me_id, clock, segment, proofs, &mut rest)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -12,10 +12,10 @@ use solana_sdk::instruction::{Instruction, InstructionError};
|
||||||
use solana_sdk::message::Message;
|
use solana_sdk::message::Message;
|
||||||
use solana_sdk::pubkey::Pubkey;
|
use solana_sdk::pubkey::Pubkey;
|
||||||
use solana_sdk::signature::{Keypair, KeypairUtil, Signature};
|
use solana_sdk::signature::{Keypair, KeypairUtil, Signature};
|
||||||
use solana_sdk::syscall::current::Current;
|
|
||||||
use solana_sdk::syscall::rewards::Rewards;
|
|
||||||
use solana_sdk::syscall::{current, rewards};
|
|
||||||
use solana_sdk::system_instruction;
|
use solana_sdk::system_instruction;
|
||||||
|
use solana_sdk::sysvar::clock::Clock;
|
||||||
|
use solana_sdk::sysvar::rewards::Rewards;
|
||||||
|
use solana_sdk::sysvar::{clock, rewards};
|
||||||
use solana_sdk::timing::{
|
use solana_sdk::timing::{
|
||||||
get_segment_from_slot, DEFAULT_SLOTS_PER_SEGMENT, DEFAULT_TICKS_PER_SLOT,
|
get_segment_from_slot, DEFAULT_SLOTS_PER_SEGMENT, DEFAULT_TICKS_PER_SLOT,
|
||||||
};
|
};
|
||||||
|
@ -126,21 +126,18 @@ fn test_proof_bounds() {
|
||||||
Hash::default(),
|
Hash::default(),
|
||||||
);
|
);
|
||||||
// the proof is for segment 0, need to move the slot into segment 2
|
// the proof is for segment 0, need to move the slot into segment 2
|
||||||
let mut current_account = current::create_account(1, 0, 0, 0, 0);
|
let mut clock_account = clock::create_account(1, 0, 0, 0, 0);
|
||||||
Current::to(
|
Clock::to(
|
||||||
&Current {
|
&Clock {
|
||||||
slot: DEFAULT_SLOTS_PER_SEGMENT * 2,
|
slot: DEFAULT_SLOTS_PER_SEGMENT * 2,
|
||||||
segment: 2,
|
segment: 2,
|
||||||
epoch: 0,
|
epoch: 0,
|
||||||
stakers_epoch: 0,
|
stakers_epoch: 0,
|
||||||
},
|
},
|
||||||
&mut current_account,
|
&mut clock_account,
|
||||||
);
|
);
|
||||||
|
|
||||||
assert_eq!(
|
assert_eq!(test_instruction(&ix, &mut [account, clock_account]), Ok(()));
|
||||||
test_instruction(&ix, &mut [account, current_account]),
|
|
||||||
Ok(())
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
|
@ -154,12 +151,12 @@ fn test_storage_tx() {
|
||||||
#[test]
|
#[test]
|
||||||
fn test_serialize_overflow() {
|
fn test_serialize_overflow() {
|
||||||
let pubkey = Pubkey::new_rand();
|
let pubkey = Pubkey::new_rand();
|
||||||
let current_id = current::id();
|
let clock_id = clock::id();
|
||||||
let mut keyed_accounts = Vec::new();
|
let mut keyed_accounts = Vec::new();
|
||||||
let mut user_account = Account::default();
|
let mut user_account = Account::default();
|
||||||
let mut current_account = current::create_account(1, 0, 0, 0, 0);
|
let mut clock_account = clock::create_account(1, 0, 0, 0, 0);
|
||||||
keyed_accounts.push(KeyedAccount::new(&pubkey, true, &mut user_account));
|
keyed_accounts.push(KeyedAccount::new(&pubkey, true, &mut user_account));
|
||||||
keyed_accounts.push(KeyedAccount::new(¤t_id, false, &mut current_account));
|
keyed_accounts.push(KeyedAccount::new(&clock_id, false, &mut clock_account));
|
||||||
|
|
||||||
let ix = storage_instruction::advertise_recent_blockhash(&pubkey, Hash::default(), 1);
|
let ix = storage_instruction::advertise_recent_blockhash(&pubkey, Hash::default(), 1);
|
||||||
|
|
||||||
|
@ -182,20 +179,20 @@ fn test_invalid_accounts_len() {
|
||||||
Hash::default(),
|
Hash::default(),
|
||||||
);
|
);
|
||||||
// move tick height into segment 1
|
// move tick height into segment 1
|
||||||
let mut current_account = current::create_account(1, 0, 0, 0, 0);
|
let mut clock_account = clock::create_account(1, 0, 0, 0, 0);
|
||||||
Current::to(
|
Clock::to(
|
||||||
&Current {
|
&Clock {
|
||||||
slot: 16,
|
slot: 16,
|
||||||
segment: 1,
|
segment: 1,
|
||||||
epoch: 0,
|
epoch: 0,
|
||||||
stakers_epoch: 0,
|
stakers_epoch: 0,
|
||||||
},
|
},
|
||||||
&mut current_account,
|
&mut clock_account,
|
||||||
);
|
);
|
||||||
|
|
||||||
assert!(test_instruction(&ix, &mut accounts).is_err());
|
assert!(test_instruction(&ix, &mut accounts).is_err());
|
||||||
|
|
||||||
let mut accounts = [Account::default(), current_account, Account::default()];
|
let mut accounts = [Account::default(), clock_account, Account::default()];
|
||||||
|
|
||||||
assert!(test_instruction(&ix, &mut accounts).is_err());
|
assert!(test_instruction(&ix, &mut accounts).is_err());
|
||||||
}
|
}
|
||||||
|
@ -242,21 +239,18 @@ fn test_submit_mining_ok() {
|
||||||
Hash::default(),
|
Hash::default(),
|
||||||
);
|
);
|
||||||
// move slot into segment 1
|
// move slot into segment 1
|
||||||
let mut current_account = current::create_account(1, 0, 0, 0, 0);
|
let mut clock_account = clock::create_account(1, 0, 0, 0, 0);
|
||||||
Current::to(
|
Clock::to(
|
||||||
&Current {
|
&Clock {
|
||||||
slot: DEFAULT_SLOTS_PER_SEGMENT,
|
slot: DEFAULT_SLOTS_PER_SEGMENT,
|
||||||
segment: 1,
|
segment: 1,
|
||||||
epoch: 0,
|
epoch: 0,
|
||||||
stakers_epoch: 0,
|
stakers_epoch: 0,
|
||||||
},
|
},
|
||||||
&mut current_account,
|
&mut clock_account,
|
||||||
);
|
);
|
||||||
|
|
||||||
assert_matches!(
|
assert_matches!(test_instruction(&ix, &mut [account, clock_account]), Ok(_));
|
||||||
test_instruction(&ix, &mut [account, current_account]),
|
|
||||||
Ok(_)
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
|
|
|
@ -10,8 +10,8 @@ use solana_metrics::datapoint_warn;
|
||||||
use solana_sdk::account::KeyedAccount;
|
use solana_sdk::account::KeyedAccount;
|
||||||
use solana_sdk::instruction::{AccountMeta, Instruction, InstructionError};
|
use solana_sdk::instruction::{AccountMeta, Instruction, InstructionError};
|
||||||
use solana_sdk::pubkey::Pubkey;
|
use solana_sdk::pubkey::Pubkey;
|
||||||
use solana_sdk::syscall;
|
|
||||||
use solana_sdk::system_instruction;
|
use solana_sdk::system_instruction;
|
||||||
|
use solana_sdk::sysvar;
|
||||||
|
|
||||||
#[derive(Serialize, Deserialize, Debug, PartialEq, Eq, Clone)]
|
#[derive(Serialize, Deserialize, Debug, PartialEq, Eq, Clone)]
|
||||||
pub enum VoteInstruction {
|
pub enum VoteInstruction {
|
||||||
|
@ -94,10 +94,10 @@ pub fn vote(
|
||||||
vote_pubkey,
|
vote_pubkey,
|
||||||
authorized_voter_pubkey,
|
authorized_voter_pubkey,
|
||||||
&[
|
&[
|
||||||
// request slot_hashes syscall account after vote_pubkey
|
// request slot_hashes sysvar account after vote_pubkey
|
||||||
AccountMeta::new_credit_only(syscall::slot_hashes::id(), false),
|
AccountMeta::new_credit_only(sysvar::slot_hashes::id(), false),
|
||||||
// request current syscall account after that
|
// request clock sysvar account after that
|
||||||
AccountMeta::new_credit_only(syscall::current::id(), false),
|
AccountMeta::new_credit_only(sysvar::clock::id(), false),
|
||||||
],
|
],
|
||||||
);
|
);
|
||||||
|
|
||||||
|
@ -135,12 +135,12 @@ pub fn process_instruction(
|
||||||
if rest.len() < 2 {
|
if rest.len() < 2 {
|
||||||
Err(InstructionError::InvalidInstructionData)?;
|
Err(InstructionError::InvalidInstructionData)?;
|
||||||
}
|
}
|
||||||
let (slot_hashes_and_current, other_signers) = rest.split_at_mut(2);
|
let (slot_hashes_and_clock, other_signers) = rest.split_at_mut(2);
|
||||||
|
|
||||||
vote_state::process_votes(
|
vote_state::process_votes(
|
||||||
me,
|
me,
|
||||||
&syscall::slot_hashes::from_keyed_account(&slot_hashes_and_current[0])?,
|
&sysvar::slot_hashes::from_keyed_account(&slot_hashes_and_clock[0])?,
|
||||||
&syscall::current::from_keyed_account(&slot_hashes_and_current[1])?,
|
&sysvar::clock::from_keyed_account(&slot_hashes_and_clock[1])?,
|
||||||
other_signers,
|
other_signers,
|
||||||
&votes,
|
&votes,
|
||||||
)
|
)
|
||||||
|
@ -167,10 +167,10 @@ mod tests {
|
||||||
.accounts
|
.accounts
|
||||||
.iter()
|
.iter()
|
||||||
.map(|meta| {
|
.map(|meta| {
|
||||||
if syscall::current::check_id(&meta.pubkey) {
|
if sysvar::clock::check_id(&meta.pubkey) {
|
||||||
syscall::current::create_account(1, 0, 0, 0, 0)
|
sysvar::clock::create_account(1, 0, 0, 0, 0)
|
||||||
} else if syscall::slot_hashes::check_id(&meta.pubkey) {
|
} else if sysvar::slot_hashes::check_id(&meta.pubkey) {
|
||||||
syscall::slot_hashes::create_account(1, &[])
|
sysvar::slot_hashes::create_account(1, &[])
|
||||||
} else {
|
} else {
|
||||||
Account::default()
|
Account::default()
|
||||||
}
|
}
|
||||||
|
|
|
@ -9,7 +9,7 @@ use solana_sdk::account_utils::State;
|
||||||
use solana_sdk::hash::Hash;
|
use solana_sdk::hash::Hash;
|
||||||
use solana_sdk::instruction::InstructionError;
|
use solana_sdk::instruction::InstructionError;
|
||||||
use solana_sdk::pubkey::Pubkey;
|
use solana_sdk::pubkey::Pubkey;
|
||||||
use solana_sdk::syscall::current::Current;
|
use solana_sdk::sysvar::clock::Clock;
|
||||||
pub use solana_sdk::timing::{Epoch, Slot};
|
pub use solana_sdk::timing::{Epoch, Slot};
|
||||||
use std::collections::VecDeque;
|
use std::collections::VecDeque;
|
||||||
|
|
||||||
|
@ -74,9 +74,9 @@ pub struct VoteState {
|
||||||
pub commission: u8,
|
pub commission: u8,
|
||||||
pub root_slot: Option<u64>,
|
pub root_slot: Option<u64>,
|
||||||
|
|
||||||
/// current epoch
|
/// clock epoch
|
||||||
epoch: Epoch,
|
epoch: Epoch,
|
||||||
/// current credits earned, monotonically increasing
|
/// clock credits earned, monotonically increasing
|
||||||
credits: u64,
|
credits: u64,
|
||||||
|
|
||||||
/// credits as of previous epoch
|
/// credits as of previous epoch
|
||||||
|
@ -286,7 +286,7 @@ pub fn authorize_voter(
|
||||||
) -> Result<(), InstructionError> {
|
) -> Result<(), InstructionError> {
|
||||||
let mut vote_state: VoteState = vote_account.state()?;
|
let mut vote_state: VoteState = vote_account.state()?;
|
||||||
|
|
||||||
// current authorized signer must say "yay"
|
// clock authorized signer must say "yay"
|
||||||
let authorized = Some(&vote_state.authorized_voter_pubkey);
|
let authorized = Some(&vote_state.authorized_voter_pubkey);
|
||||||
if vote_account.signer_key() != authorized
|
if vote_account.signer_key() != authorized
|
||||||
&& other_signers
|
&& other_signers
|
||||||
|
@ -323,7 +323,7 @@ pub fn initialize_account(
|
||||||
pub fn process_votes(
|
pub fn process_votes(
|
||||||
vote_account: &mut KeyedAccount,
|
vote_account: &mut KeyedAccount,
|
||||||
slot_hashes: &[(Slot, Hash)],
|
slot_hashes: &[(Slot, Hash)],
|
||||||
current: &Current,
|
clock: &Clock,
|
||||||
other_signers: &[KeyedAccount],
|
other_signers: &[KeyedAccount],
|
||||||
votes: &[Vote],
|
votes: &[Vote],
|
||||||
) -> Result<(), InstructionError> {
|
) -> Result<(), InstructionError> {
|
||||||
|
@ -343,7 +343,7 @@ pub fn process_votes(
|
||||||
return Err(InstructionError::MissingRequiredSignature);
|
return Err(InstructionError::MissingRequiredSignature);
|
||||||
}
|
}
|
||||||
|
|
||||||
vote_state.process_votes(&votes, slot_hashes, current.epoch);
|
vote_state.process_votes(&votes, slot_hashes, clock.epoch);
|
||||||
vote_account.set_state(&vote_state)
|
vote_account.set_state(&vote_state)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -427,9 +427,9 @@ mod tests {
|
||||||
process_votes(
|
process_votes(
|
||||||
&mut KeyedAccount::new(vote_pubkey, true, vote_account),
|
&mut KeyedAccount::new(vote_pubkey, true, vote_account),
|
||||||
slot_hashes,
|
slot_hashes,
|
||||||
&Current {
|
&Clock {
|
||||||
epoch,
|
epoch,
|
||||||
..Current::default()
|
..Clock::default()
|
||||||
},
|
},
|
||||||
&[],
|
&[],
|
||||||
&[vote.clone()],
|
&[vote.clone()],
|
||||||
|
@ -533,7 +533,7 @@ mod tests {
|
||||||
let res = process_votes(
|
let res = process_votes(
|
||||||
&mut KeyedAccount::new(&vote_pubkey, false, &mut vote_account),
|
&mut KeyedAccount::new(&vote_pubkey, false, &mut vote_account),
|
||||||
&[(vote.slot, vote.hash)],
|
&[(vote.slot, vote.hash)],
|
||||||
&Current::default(),
|
&Clock::default(),
|
||||||
&[],
|
&[],
|
||||||
&[vote],
|
&[vote],
|
||||||
);
|
);
|
||||||
|
@ -543,7 +543,7 @@ mod tests {
|
||||||
let res = process_votes(
|
let res = process_votes(
|
||||||
&mut KeyedAccount::new(&vote_pubkey, true, &mut vote_account),
|
&mut KeyedAccount::new(&vote_pubkey, true, &mut vote_account),
|
||||||
&[(vote.slot, vote.hash)],
|
&[(vote.slot, vote.hash)],
|
||||||
&Current::default(),
|
&Clock::default(),
|
||||||
&[],
|
&[],
|
||||||
&[vote],
|
&[vote],
|
||||||
);
|
);
|
||||||
|
@ -581,7 +581,7 @@ mod tests {
|
||||||
let res = process_votes(
|
let res = process_votes(
|
||||||
&mut KeyedAccount::new(&vote_pubkey, true, &mut vote_account),
|
&mut KeyedAccount::new(&vote_pubkey, true, &mut vote_account),
|
||||||
&[(vote.slot, vote.hash)],
|
&[(vote.slot, vote.hash)],
|
||||||
&Current::default(),
|
&Clock::default(),
|
||||||
&[],
|
&[],
|
||||||
&[vote],
|
&[vote],
|
||||||
);
|
);
|
||||||
|
@ -592,7 +592,7 @@ mod tests {
|
||||||
let res = process_votes(
|
let res = process_votes(
|
||||||
&mut KeyedAccount::new(&vote_pubkey, false, &mut vote_account),
|
&mut KeyedAccount::new(&vote_pubkey, false, &mut vote_account),
|
||||||
&[(vote.slot, vote.hash)],
|
&[(vote.slot, vote.hash)],
|
||||||
&Current::default(),
|
&Clock::default(),
|
||||||
&[KeyedAccount::new(
|
&[KeyedAccount::new(
|
||||||
&authorized_voter_pubkey,
|
&authorized_voter_pubkey,
|
||||||
true,
|
true,
|
||||||
|
|
|
@ -15,8 +15,8 @@ use solana_sdk::message::Message;
|
||||||
use solana_sdk::native_loader;
|
use solana_sdk::native_loader;
|
||||||
use solana_sdk::pubkey::Pubkey;
|
use solana_sdk::pubkey::Pubkey;
|
||||||
use solana_sdk::signature::{Keypair, KeypairUtil};
|
use solana_sdk::signature::{Keypair, KeypairUtil};
|
||||||
use solana_sdk::syscall;
|
|
||||||
use solana_sdk::system_program;
|
use solana_sdk::system_program;
|
||||||
|
use solana_sdk::sysvar;
|
||||||
use solana_sdk::transaction::Result;
|
use solana_sdk::transaction::Result;
|
||||||
use solana_sdk::transaction::{Transaction, TransactionError};
|
use solana_sdk::transaction::{Transaction, TransactionError};
|
||||||
use std::collections::{HashMap, HashSet};
|
use std::collections::{HashMap, HashSet};
|
||||||
|
@ -494,7 +494,7 @@ impl Accounts {
|
||||||
|
|
||||||
pub fn hash_internal_state(&self, fork_id: Fork) -> Option<Hash> {
|
pub fn hash_internal_state(&self, fork_id: Fork) -> Option<Hash> {
|
||||||
let account_hashes = self.scan_fork(fork_id, |stored_account| {
|
let account_hashes = self.scan_fork(fork_id, |stored_account| {
|
||||||
if !syscall::check_id(&stored_account.balance.owner) {
|
if !sysvar::check_id(&stored_account.balance.owner) {
|
||||||
Some(Self::hash_account(stored_account))
|
Some(Self::hash_account(stored_account))
|
||||||
} else {
|
} else {
|
||||||
None
|
None
|
||||||
|
@ -695,7 +695,7 @@ mod tests {
|
||||||
use solana_sdk::hash::Hash;
|
use solana_sdk::hash::Hash;
|
||||||
use solana_sdk::instruction::CompiledInstruction;
|
use solana_sdk::instruction::CompiledInstruction;
|
||||||
use solana_sdk::signature::{Keypair, KeypairUtil};
|
use solana_sdk::signature::{Keypair, KeypairUtil};
|
||||||
use solana_sdk::syscall;
|
use solana_sdk::sysvar;
|
||||||
use solana_sdk::transaction::Transaction;
|
use solana_sdk::transaction::Transaction;
|
||||||
use std::io::Cursor;
|
use std::io::Cursor;
|
||||||
use std::sync::atomic::AtomicBool;
|
use std::sync::atomic::AtomicBool;
|
||||||
|
@ -1183,7 +1183,7 @@ mod tests {
|
||||||
fn test_accounts_empty_hash_internal_state() {
|
fn test_accounts_empty_hash_internal_state() {
|
||||||
let accounts = Accounts::new(None);
|
let accounts = Accounts::new(None);
|
||||||
assert_eq!(accounts.hash_internal_state(0), None);
|
assert_eq!(accounts.hash_internal_state(0), None);
|
||||||
accounts.store_slow(0, &Pubkey::default(), &Account::new(1, 0, &syscall::id()));
|
accounts.store_slow(0, &Pubkey::default(), &Account::new(1, 0, &sysvar::id()));
|
||||||
assert_eq!(accounts.hash_internal_state(0), None);
|
assert_eq!(accounts.hash_internal_state(0), None);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -33,11 +33,11 @@ use solana_sdk::inflation::Inflation;
|
||||||
use solana_sdk::native_loader;
|
use solana_sdk::native_loader;
|
||||||
use solana_sdk::pubkey::Pubkey;
|
use solana_sdk::pubkey::Pubkey;
|
||||||
use solana_sdk::signature::{Keypair, Signature};
|
use solana_sdk::signature::{Keypair, Signature};
|
||||||
use solana_sdk::syscall::{
|
use solana_sdk::system_transaction;
|
||||||
current, fees, rewards,
|
use solana_sdk::sysvar::{
|
||||||
|
clock, fees, rewards,
|
||||||
slot_hashes::{self, SlotHashes},
|
slot_hashes::{self, SlotHashes},
|
||||||
};
|
};
|
||||||
use solana_sdk::system_transaction;
|
|
||||||
use solana_sdk::timing::{duration_as_ns, get_segment_from_slot, MAX_RECENT_BLOCKHASHES};
|
use solana_sdk::timing::{duration_as_ns, get_segment_from_slot, MAX_RECENT_BLOCKHASHES};
|
||||||
use solana_sdk::transaction::{Result, Transaction, TransactionError};
|
use solana_sdk::transaction::{Result, Transaction, TransactionError};
|
||||||
use std::cmp;
|
use std::cmp;
|
||||||
|
@ -289,7 +289,7 @@ impl Bank {
|
||||||
bank.epoch_stakes.insert(i, stakes.clone());
|
bank.epoch_stakes.insert(i, stakes.clone());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
bank.update_current();
|
bank.update_clock();
|
||||||
bank
|
bank
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -366,7 +366,7 @@ impl Bank {
|
||||||
});
|
});
|
||||||
|
|
||||||
self.update_rewards(parent.epoch());
|
self.update_rewards(parent.epoch());
|
||||||
self.update_current();
|
self.update_clock();
|
||||||
self.update_fees();
|
self.update_fees();
|
||||||
self
|
self
|
||||||
}
|
}
|
||||||
|
@ -408,10 +408,10 @@ impl Bank {
|
||||||
*self.hash.read().unwrap() != Hash::default()
|
*self.hash.read().unwrap() != Hash::default()
|
||||||
}
|
}
|
||||||
|
|
||||||
fn update_current(&self) {
|
fn update_clock(&self) {
|
||||||
self.store_account(
|
self.store_account(
|
||||||
¤t::id(),
|
&clock::id(),
|
||||||
¤t::create_account(
|
&clock::create_account(
|
||||||
1,
|
1,
|
||||||
self.slot,
|
self.slot,
|
||||||
get_segment_from_slot(self.slot, self.slots_per_segment),
|
get_segment_from_slot(self.slot, self.slots_per_segment),
|
||||||
|
@ -1461,9 +1461,9 @@ mod tests {
|
||||||
use solana_sdk::instruction::InstructionError;
|
use solana_sdk::instruction::InstructionError;
|
||||||
use solana_sdk::poh_config::PohConfig;
|
use solana_sdk::poh_config::PohConfig;
|
||||||
use solana_sdk::signature::{Keypair, KeypairUtil};
|
use solana_sdk::signature::{Keypair, KeypairUtil};
|
||||||
use solana_sdk::syscall::{fees::Fees, rewards::Rewards};
|
|
||||||
use solana_sdk::system_instruction;
|
use solana_sdk::system_instruction;
|
||||||
use solana_sdk::system_transaction;
|
use solana_sdk::system_transaction;
|
||||||
|
use solana_sdk::sysvar::{fees::Fees, rewards::Rewards};
|
||||||
use solana_sdk::timing::DEFAULT_TICKS_PER_SLOT;
|
use solana_sdk::timing::DEFAULT_TICKS_PER_SLOT;
|
||||||
use solana_vote_api::vote_instruction;
|
use solana_vote_api::vote_instruction;
|
||||||
use solana_vote_api::vote_state::{VoteState, MAX_LOCKOUT_HISTORY};
|
use solana_vote_api::vote_state::{VoteState, MAX_LOCKOUT_HISTORY};
|
||||||
|
@ -2252,7 +2252,7 @@ mod tests {
|
||||||
let bank0 = Arc::new(Bank::new(&create_genesis_block(10).0));
|
let bank0 = Arc::new(Bank::new(&create_genesis_block(10).0));
|
||||||
let hash0 = bank0.hash_internal_state();
|
let hash0 = bank0.hash_internal_state();
|
||||||
// save hash0 because new_from_parent
|
// save hash0 because new_from_parent
|
||||||
// updates syscall entries
|
// updates sysvar entries
|
||||||
|
|
||||||
let bank1 = Bank::new_from_parent(&bank0, &collector_id, 1);
|
let bank1 = Bank::new_from_parent(&bank0, &collector_id, 1);
|
||||||
|
|
||||||
|
|
|
@ -2,9 +2,9 @@ use log::*;
|
||||||
use solana_sdk::account::KeyedAccount;
|
use solana_sdk::account::KeyedAccount;
|
||||||
use solana_sdk::instruction::InstructionError;
|
use solana_sdk::instruction::InstructionError;
|
||||||
use solana_sdk::pubkey::Pubkey;
|
use solana_sdk::pubkey::Pubkey;
|
||||||
use solana_sdk::syscall;
|
|
||||||
use solana_sdk::system_instruction::{SystemError, SystemInstruction};
|
use solana_sdk::system_instruction::{SystemError, SystemInstruction};
|
||||||
use solana_sdk::system_program;
|
use solana_sdk::system_program;
|
||||||
|
use solana_sdk::sysvar;
|
||||||
|
|
||||||
const FROM_ACCOUNT_INDEX: usize = 0;
|
const FROM_ACCOUNT_INDEX: usize = 0;
|
||||||
const TO_ACCOUNT_INDEX: usize = 1;
|
const TO_ACCOUNT_INDEX: usize = 1;
|
||||||
|
@ -33,7 +33,7 @@ fn create_system_account(
|
||||||
Err(SystemError::AccountAlreadyInUse)?;
|
Err(SystemError::AccountAlreadyInUse)?;
|
||||||
}
|
}
|
||||||
|
|
||||||
if syscall::check_id(&program_id) {
|
if sysvar::check_id(&program_id) {
|
||||||
debug!(
|
debug!(
|
||||||
"CreateAccount: invalid argument; program id {} invalid",
|
"CreateAccount: invalid argument; program id {} invalid",
|
||||||
program_id
|
program_id
|
||||||
|
@ -41,7 +41,7 @@ fn create_system_account(
|
||||||
Err(SystemError::InvalidProgramId)?;
|
Err(SystemError::InvalidProgramId)?;
|
||||||
}
|
}
|
||||||
|
|
||||||
if syscall::is_syscall_id(&keyed_accounts[TO_ACCOUNT_INDEX].unsigned_key()) {
|
if sysvar::is_sysvar_id(&keyed_accounts[TO_ACCOUNT_INDEX].unsigned_key()) {
|
||||||
debug!(
|
debug!(
|
||||||
"CreateAccount: invalid argument; account id {} invalid",
|
"CreateAccount: invalid argument; account id {} invalid",
|
||||||
program_id
|
program_id
|
||||||
|
@ -207,7 +207,7 @@ mod tests {
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn test_create_syscall_invalid_id() {
|
fn test_create_sysvar_invalid_id() {
|
||||||
// Attempt to create system account in account already owned by another program
|
// Attempt to create system account in account already owned by another program
|
||||||
let from = Pubkey::new_rand();
|
let from = Pubkey::new_rand();
|
||||||
let mut from_account = Account::new(100, 0, &system_program::id());
|
let mut from_account = Account::new(100, 0, &system_program::id());
|
||||||
|
@ -219,18 +219,18 @@ mod tests {
|
||||||
KeyedAccount::new(&from, true, &mut from_account),
|
KeyedAccount::new(&from, true, &mut from_account),
|
||||||
KeyedAccount::new(&to, false, &mut to_account),
|
KeyedAccount::new(&to, false, &mut to_account),
|
||||||
];
|
];
|
||||||
// fail to create a syscall::id() owned account
|
// fail to create a sysvar::id() owned account
|
||||||
let result = create_system_account(&mut keyed_accounts, 50, 2, &syscall::id());
|
let result = create_system_account(&mut keyed_accounts, 50, 2, &sysvar::id());
|
||||||
assert_eq!(result, Err(SystemError::InvalidProgramId));
|
assert_eq!(result, Err(SystemError::InvalidProgramId));
|
||||||
|
|
||||||
let to = syscall::fees::id();
|
let to = sysvar::fees::id();
|
||||||
let mut to_account = Account::default();
|
let mut to_account = Account::default();
|
||||||
|
|
||||||
let mut keyed_accounts = [
|
let mut keyed_accounts = [
|
||||||
KeyedAccount::new(&from, true, &mut from_account),
|
KeyedAccount::new(&from, true, &mut from_account),
|
||||||
KeyedAccount::new(&to, false, &mut to_account),
|
KeyedAccount::new(&to, false, &mut to_account),
|
||||||
];
|
];
|
||||||
// fail to create an account with a syscall id
|
// fail to create an account with a sysvar id
|
||||||
let result = create_system_account(&mut keyed_accounts, 50, 2, &system_program::id());
|
let result = create_system_account(&mut keyed_accounts, 50, 2, &system_program::id());
|
||||||
assert_eq!(result, Err(SystemError::InvalidAccountId));
|
assert_eq!(result, Err(SystemError::InvalidAccountId));
|
||||||
|
|
||||||
|
|
|
@ -17,10 +17,10 @@ pub mod pubkey;
|
||||||
pub mod rpc_port;
|
pub mod rpc_port;
|
||||||
pub mod short_vec;
|
pub mod short_vec;
|
||||||
pub mod signature;
|
pub mod signature;
|
||||||
pub mod syscall;
|
|
||||||
pub mod system_instruction;
|
pub mod system_instruction;
|
||||||
pub mod system_program;
|
pub mod system_program;
|
||||||
pub mod system_transaction;
|
pub mod system_transaction;
|
||||||
|
pub mod sysvar;
|
||||||
pub mod timing;
|
pub mod timing;
|
||||||
pub mod transaction;
|
pub mod transaction;
|
||||||
pub mod transport;
|
pub mod transport;
|
||||||
|
|
|
@ -1,24 +0,0 @@
|
||||||
//! named accounts for synthesized data accounts for bank state, etc.
|
|
||||||
//!
|
|
||||||
use crate::pubkey::Pubkey;
|
|
||||||
|
|
||||||
pub mod current;
|
|
||||||
pub mod fees;
|
|
||||||
pub mod rewards;
|
|
||||||
pub mod slot_hashes;
|
|
||||||
|
|
||||||
pub fn is_syscall_id(id: &Pubkey) -> bool {
|
|
||||||
current::check_id(id)
|
|
||||||
|| fees::check_id(id)
|
|
||||||
|| rewards::check_id(id)
|
|
||||||
|| slot_hashes::check_id(id)
|
|
||||||
}
|
|
||||||
|
|
||||||
/// "Sysca11111111111111111111111111111111111111"
|
|
||||||
/// owner pubkey for syscall accounts
|
|
||||||
const ID: [u8; 32] = [
|
|
||||||
6, 167, 211, 138, 69, 216, 137, 185, 198, 189, 33, 204, 111, 12, 217, 220, 229, 201, 34, 52,
|
|
||||||
253, 202, 87, 144, 232, 16, 195, 192, 0, 0, 0, 0,
|
|
||||||
];
|
|
||||||
|
|
||||||
crate::solana_name_id!(ID, "Sysca11111111111111111111111111111111111111");
|
|
|
@ -1,28 +1,28 @@
|
||||||
//! This account contains the current slot, epoch, and stakers_epoch
|
//! This account contains the clock slot, epoch, and stakers_epoch
|
||||||
//!
|
//!
|
||||||
use crate::account::Account;
|
use crate::account::Account;
|
||||||
use crate::syscall;
|
use crate::sysvar;
|
||||||
use bincode::serialized_size;
|
use bincode::serialized_size;
|
||||||
|
|
||||||
pub use crate::timing::{Epoch, Slot};
|
pub use crate::timing::{Epoch, Slot};
|
||||||
|
|
||||||
crate::solana_name_id!(ID, "Sysca11Current11111111111111111111111111111");
|
|
||||||
|
|
||||||
const ID: [u8; 32] = [
|
const ID: [u8; 32] = [
|
||||||
6, 167, 211, 138, 69, 218, 14, 184, 34, 50, 188, 33, 201, 49, 63, 13, 15, 193, 33, 132, 208,
|
6, 167, 213, 23, 24, 199, 116, 201, 40, 86, 99, 152, 105, 29, 94, 182, 139, 94, 184, 163, 155,
|
||||||
238, 129, 224, 101, 67, 14, 11, 160, 0, 0, 0,
|
75, 109, 92, 115, 85, 91, 33, 0, 0, 0, 0,
|
||||||
];
|
];
|
||||||
|
|
||||||
|
crate::solana_name_id!(ID, "SysvarC1ock11111111111111111111111111111111");
|
||||||
|
|
||||||
#[repr(C)]
|
#[repr(C)]
|
||||||
#[derive(Serialize, Deserialize, Debug, Default, PartialEq)]
|
#[derive(Serialize, Deserialize, Debug, Default, PartialEq)]
|
||||||
pub struct Current {
|
pub struct Clock {
|
||||||
pub slot: Slot,
|
pub slot: Slot,
|
||||||
pub segment: Segment,
|
pub segment: Segment,
|
||||||
pub epoch: Epoch,
|
pub epoch: Epoch,
|
||||||
pub stakers_epoch: Epoch,
|
pub stakers_epoch: Epoch,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Current {
|
impl Clock {
|
||||||
pub fn from(account: &Account) -> Option<Self> {
|
pub fn from(account: &Account) -> Option<Self> {
|
||||||
account.deserialize_data().ok()
|
account.deserialize_data().ok()
|
||||||
}
|
}
|
||||||
|
@ -44,13 +44,13 @@ pub fn create_account(
|
||||||
) -> Account {
|
) -> Account {
|
||||||
Account::new_data(
|
Account::new_data(
|
||||||
lamports,
|
lamports,
|
||||||
&Current {
|
&Clock {
|
||||||
slot,
|
slot,
|
||||||
segment,
|
segment,
|
||||||
epoch,
|
epoch,
|
||||||
stakers_epoch,
|
stakers_epoch,
|
||||||
},
|
},
|
||||||
&syscall::id(),
|
&sysvar::id(),
|
||||||
)
|
)
|
||||||
.unwrap()
|
.unwrap()
|
||||||
}
|
}
|
||||||
|
@ -59,11 +59,11 @@ use crate::account::KeyedAccount;
|
||||||
use crate::instruction::InstructionError;
|
use crate::instruction::InstructionError;
|
||||||
use crate::timing::Segment;
|
use crate::timing::Segment;
|
||||||
|
|
||||||
pub fn from_keyed_account(account: &KeyedAccount) -> Result<Current, InstructionError> {
|
pub fn from_keyed_account(account: &KeyedAccount) -> Result<Clock, InstructionError> {
|
||||||
if !check_id(account.unsigned_key()) {
|
if !check_id(account.unsigned_key()) {
|
||||||
return Err(InstructionError::InvalidArgument);
|
return Err(InstructionError::InvalidArgument);
|
||||||
}
|
}
|
||||||
Current::from(account.account).ok_or(InstructionError::InvalidArgument)
|
Clock::from(account.account).ok_or(InstructionError::InvalidArgument)
|
||||||
}
|
}
|
||||||
|
|
||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
|
@ -73,7 +73,7 @@ mod tests {
|
||||||
#[test]
|
#[test]
|
||||||
fn test_create_account() {
|
fn test_create_account() {
|
||||||
let account = create_account(1, 0, 0, 0, 0);
|
let account = create_account(1, 0, 0, 0, 0);
|
||||||
let current = Current::from(&account).unwrap();
|
let clock = Clock::from(&account).unwrap();
|
||||||
assert_eq!(current, Current::default());
|
assert_eq!(clock, Clock::default());
|
||||||
}
|
}
|
||||||
}
|
}
|
|
@ -2,16 +2,16 @@
|
||||||
//!
|
//!
|
||||||
use crate::account::Account;
|
use crate::account::Account;
|
||||||
use crate::fee_calculator::FeeCalculator;
|
use crate::fee_calculator::FeeCalculator;
|
||||||
use crate::syscall;
|
use crate::sysvar;
|
||||||
use bincode::serialized_size;
|
use bincode::serialized_size;
|
||||||
|
|
||||||
/// fees account pubkey
|
/// fees account pubkey
|
||||||
const ID: [u8; 32] = [
|
const ID: [u8; 32] = [
|
||||||
6, 167, 211, 138, 69, 218, 104, 33, 3, 92, 89, 173, 16, 89, 109, 253, 49, 97, 98, 165, 87, 222,
|
6, 167, 213, 23, 24, 226, 90, 141, 131, 80, 60, 37, 26, 122, 240, 113, 38, 253, 114, 0, 223,
|
||||||
119, 112, 253, 90, 76, 184, 0, 0, 0, 0,
|
111, 196, 237, 82, 106, 156, 144, 0, 0, 0, 0,
|
||||||
];
|
];
|
||||||
|
|
||||||
crate::solana_name_id!(ID, "Sysca11Fees11111111111111111111111111111111");
|
crate::solana_name_id!(ID, "SysvarFees111111111111111111111111111111111");
|
||||||
|
|
||||||
#[repr(C)]
|
#[repr(C)]
|
||||||
#[derive(Serialize, Deserialize, Debug, Default)]
|
#[derive(Serialize, Deserialize, Debug, Default)]
|
||||||
|
@ -38,7 +38,7 @@ pub fn create_account(lamports: u64, fee_calculator: &FeeCalculator) -> Account
|
||||||
&Fees {
|
&Fees {
|
||||||
fee_calculator: fee_calculator.clone(),
|
fee_calculator: fee_calculator.clone(),
|
||||||
},
|
},
|
||||||
&syscall::id(),
|
&sysvar::id(),
|
||||||
)
|
)
|
||||||
.unwrap()
|
.unwrap()
|
||||||
}
|
}
|
|
@ -0,0 +1,21 @@
|
||||||
|
//! named accounts for synthesized data accounts for bank state, etc.
|
||||||
|
//!
|
||||||
|
use crate::pubkey::Pubkey;
|
||||||
|
|
||||||
|
pub mod clock;
|
||||||
|
pub mod fees;
|
||||||
|
pub mod rewards;
|
||||||
|
pub mod slot_hashes;
|
||||||
|
|
||||||
|
pub fn is_sysvar_id(id: &Pubkey) -> bool {
|
||||||
|
clock::check_id(id) || fees::check_id(id) || rewards::check_id(id) || slot_hashes::check_id(id)
|
||||||
|
}
|
||||||
|
|
||||||
|
/// "Sysvar1111111111111111111111111111111111111"
|
||||||
|
/// owner pubkey for sysvar accounts
|
||||||
|
const ID: [u8; 32] = [
|
||||||
|
6, 167, 213, 23, 24, 117, 247, 41, 199, 61, 147, 64, 143, 33, 97, 32, 6, 126, 216, 140, 118,
|
||||||
|
224, 140, 40, 127, 193, 148, 96, 0, 0, 0, 0,
|
||||||
|
];
|
||||||
|
|
||||||
|
crate::solana_name_id!(ID, "Sysvar1111111111111111111111111111111111111");
|
|
@ -1,16 +1,16 @@
|
||||||
//! This account contains the current cluster rewards point values
|
//! This account contains the current cluster rewards point values
|
||||||
//!
|
//!
|
||||||
use crate::account::Account;
|
use crate::account::Account;
|
||||||
use crate::syscall;
|
use crate::sysvar;
|
||||||
use bincode::serialized_size;
|
use bincode::serialized_size;
|
||||||
|
|
||||||
/// account pubkey
|
/// account pubkey
|
||||||
const ID: [u8; 32] = [
|
const ID: [u8; 32] = [
|
||||||
6, 167, 211, 138, 69, 219, 174, 221, 84, 28, 161, 202, 169, 28, 9, 210, 255, 70, 57, 99, 48,
|
6, 167, 213, 23, 25, 44, 97, 55, 206, 224, 146, 217, 182, 146, 62, 225, 204, 214, 25, 3, 250,
|
||||||
156, 150, 32, 59, 104, 53, 117, 192, 0, 0, 0,
|
130, 184, 161, 97, 145, 87, 141, 128, 0, 0, 0,
|
||||||
];
|
];
|
||||||
|
|
||||||
crate::solana_name_id!(ID, "Sysca11Rewards11111111111111111111111111111");
|
crate::solana_name_id!(ID, "SysvarRewards111111111111111111111111111111");
|
||||||
|
|
||||||
#[repr(C)]
|
#[repr(C)]
|
||||||
#[derive(Serialize, Deserialize, Debug, Default, PartialEq)]
|
#[derive(Serialize, Deserialize, Debug, Default, PartialEq)]
|
||||||
|
@ -42,7 +42,7 @@ pub fn create_account(
|
||||||
validator_point_value,
|
validator_point_value,
|
||||||
storage_point_value,
|
storage_point_value,
|
||||||
},
|
},
|
||||||
&syscall::id(),
|
&sysvar::id(),
|
||||||
)
|
)
|
||||||
.unwrap()
|
.unwrap()
|
||||||
}
|
}
|
|
@ -4,27 +4,18 @@
|
||||||
//!
|
//!
|
||||||
use crate::account::Account;
|
use crate::account::Account;
|
||||||
use crate::hash::Hash;
|
use crate::hash::Hash;
|
||||||
use crate::pubkey::Pubkey;
|
use crate::sysvar;
|
||||||
use crate::syscall;
|
|
||||||
use bincode::serialized_size;
|
use bincode::serialized_size;
|
||||||
use std::ops::Deref;
|
use std::ops::Deref;
|
||||||
|
|
||||||
pub use crate::timing::Slot;
|
pub use crate::timing::Slot;
|
||||||
|
|
||||||
/// "Sysca11SlotHashes11111111111111111111111111"
|
|
||||||
/// slot hashes account pubkey
|
|
||||||
const ID: [u8; 32] = [
|
const ID: [u8; 32] = [
|
||||||
6, 167, 211, 138, 69, 219, 186, 157, 48, 170, 46, 66, 2, 146, 193, 59, 39, 59, 245, 188, 30,
|
6, 167, 213, 23, 25, 44, 97, 55, 206, 224, 146, 217, 182, 146, 62, 225, 204, 214, 25, 3, 250,
|
||||||
60, 130, 78, 86, 27, 113, 191, 208, 0, 0, 0,
|
130, 184, 161, 97, 145, 87, 141, 128, 0, 0, 0,
|
||||||
];
|
];
|
||||||
|
|
||||||
pub fn id() -> Pubkey {
|
crate::solana_name_id!(ID, "SysvarRewards111111111111111111111111111111");
|
||||||
Pubkey::new(&ID)
|
|
||||||
}
|
|
||||||
|
|
||||||
pub fn check_id(pubkey: &Pubkey) -> bool {
|
|
||||||
pubkey.as_ref() == ID
|
|
||||||
}
|
|
||||||
|
|
||||||
pub const MAX_SLOT_HASHES: usize = 512; // 512 slots to get your vote in
|
pub const MAX_SLOT_HASHES: usize = 512; // 512 slots to get your vote in
|
||||||
|
|
||||||
|
@ -67,7 +58,7 @@ impl Deref for SlotHashes {
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn create_account(lamports: u64, slot_hashes: &[(Slot, Hash)]) -> Account {
|
pub fn create_account(lamports: u64, slot_hashes: &[(Slot, Hash)]) -> Account {
|
||||||
let mut account = Account::new(lamports, SlotHashes::size_of(), &syscall::id());
|
let mut account = Account::new(lamports, SlotHashes::size_of(), &sysvar::id());
|
||||||
SlotHashes::new(slot_hashes).to(&mut account).unwrap();
|
SlotHashes::new(slot_hashes).to(&mut account).unwrap();
|
||||||
account
|
account
|
||||||
}
|
}
|
Loading…
Reference in New Issue