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

@ -17,10 +17,10 @@ pub mod pubkey;
pub mod rpc_port;
pub mod short_vec;
pub mod signature;
pub mod syscall;
pub mod system_instruction;
pub mod system_program;
pub mod system_transaction;
pub mod sysvar;
pub mod timing;
pub mod transaction;
pub mod transport;

View File

@ -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");

View File

@ -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::syscall;
use crate::sysvar;
use bincode::serialized_size;
pub use crate::timing::{Epoch, Slot};
crate::solana_name_id!(ID, "Sysca11Current11111111111111111111111111111");
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,
238, 129, 224, 101, 67, 14, 11, 160, 0, 0, 0,
6, 167, 213, 23, 24, 199, 116, 201, 40, 86, 99, 152, 105, 29, 94, 182, 139, 94, 184, 163, 155,
75, 109, 92, 115, 85, 91, 33, 0, 0, 0, 0,
];
crate::solana_name_id!(ID, "SysvarC1ock11111111111111111111111111111111");
#[repr(C)]
#[derive(Serialize, Deserialize, Debug, Default, PartialEq)]
pub struct Current {
pub struct Clock {
pub slot: Slot,
pub segment: Segment,
pub epoch: Epoch,
pub stakers_epoch: Epoch,
}
impl Current {
impl Clock {
pub fn from(account: &Account) -> Option<Self> {
account.deserialize_data().ok()
}
@ -44,13 +44,13 @@ pub fn create_account(
) -> Account {
Account::new_data(
lamports,
&Current {
&Clock {
slot,
segment,
epoch,
stakers_epoch,
},
&syscall::id(),
&sysvar::id(),
)
.unwrap()
}
@ -59,11 +59,11 @@ use crate::account::KeyedAccount;
use crate::instruction::InstructionError;
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()) {
return Err(InstructionError::InvalidArgument);
}
Current::from(account.account).ok_or(InstructionError::InvalidArgument)
Clock::from(account.account).ok_or(InstructionError::InvalidArgument)
}
#[cfg(test)]
@ -73,7 +73,7 @@ mod tests {
#[test]
fn test_create_account() {
let account = create_account(1, 0, 0, 0, 0);
let current = Current::from(&account).unwrap();
assert_eq!(current, Current::default());
let clock = Clock::from(&account).unwrap();
assert_eq!(clock, Clock::default());
}
}

View File

@ -2,16 +2,16 @@
//!
use crate::account::Account;
use crate::fee_calculator::FeeCalculator;
use crate::syscall;
use crate::sysvar;
use bincode::serialized_size;
/// fees account pubkey
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,
119, 112, 253, 90, 76, 184, 0, 0, 0, 0,
6, 167, 213, 23, 24, 226, 90, 141, 131, 80, 60, 37, 26, 122, 240, 113, 38, 253, 114, 0, 223,
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)]
#[derive(Serialize, Deserialize, Debug, Default)]
@ -38,7 +38,7 @@ pub fn create_account(lamports: u64, fee_calculator: &FeeCalculator) -> Account
&Fees {
fee_calculator: fee_calculator.clone(),
},
&syscall::id(),
&sysvar::id(),
)
.unwrap()
}

21
sdk/src/sysvar/mod.rs Normal file
View File

@ -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");

View File

@ -1,16 +1,16 @@
//! This account contains the current cluster rewards point values
//!
use crate::account::Account;
use crate::syscall;
use crate::sysvar;
use bincode::serialized_size;
/// account pubkey
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,
156, 150, 32, 59, 104, 53, 117, 192, 0, 0, 0,
6, 167, 213, 23, 25, 44, 97, 55, 206, 224, 146, 217, 182, 146, 62, 225, 204, 214, 25, 3, 250,
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)]
#[derive(Serialize, Deserialize, Debug, Default, PartialEq)]
@ -42,7 +42,7 @@ pub fn create_account(
validator_point_value,
storage_point_value,
},
&syscall::id(),
&sysvar::id(),
)
.unwrap()
}

View File

@ -4,27 +4,18 @@
//!
use crate::account::Account;
use crate::hash::Hash;
use crate::pubkey::Pubkey;
use crate::syscall;
use crate::sysvar;
use bincode::serialized_size;
use std::ops::Deref;
pub use crate::timing::Slot;
/// "Sysca11SlotHashes11111111111111111111111111"
/// slot hashes account pubkey
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,
60, 130, 78, 86, 27, 113, 191, 208, 0, 0, 0,
6, 167, 213, 23, 25, 44, 97, 55, 206, 224, 146, 217, 182, 146, 62, 225, 204, 214, 25, 3, 250,
130, 184, 161, 97, 145, 87, 141, 128, 0, 0, 0,
];
pub fn id() -> Pubkey {
Pubkey::new(&ID)
}
pub fn check_id(pubkey: &Pubkey) -> bool {
pubkey.as_ref() == ID
}
crate::solana_name_id!(ID, "SysvarRewards111111111111111111111111111111");
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 {
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();
account
}