Add tick height syscall (#4497)
* Remove tick_height from entrypoint signature * Impl tick_height syscall and use in storage program * Properly remove tick height from bpf handling
This commit is contained in:
@ -11,7 +11,6 @@ pub type Entrypoint = unsafe extern "C" fn(
|
||||
program_id: &Pubkey,
|
||||
keyed_accounts: &mut [KeyedAccount],
|
||||
data: &[u8],
|
||||
tick_height: u64,
|
||||
) -> Result<(), InstructionError>;
|
||||
|
||||
// Convenience macro to define the native program entrypoint. Supply a fn to this macro that
|
||||
@ -24,9 +23,8 @@ macro_rules! solana_entrypoint(
|
||||
program_id: &solana_sdk::pubkey::Pubkey,
|
||||
keyed_accounts: &mut [solana_sdk::account::KeyedAccount],
|
||||
data: &[u8],
|
||||
tick_height: u64
|
||||
) -> Result<(), solana_sdk::instruction::InstructionError> {
|
||||
$entrypoint(program_id, keyed_accounts, data, tick_height)
|
||||
$entrypoint(program_id, keyed_accounts, data)
|
||||
}
|
||||
)
|
||||
);
|
||||
|
@ -4,6 +4,7 @@ use crate::pubkey::Pubkey;
|
||||
|
||||
pub mod fees;
|
||||
pub mod slot_hashes;
|
||||
pub mod tick_height;
|
||||
|
||||
/// "Sysca11111111111111111111111111111111111111"
|
||||
/// owner pubkey for syscall accounts
|
||||
|
64
sdk/src/syscall/tick_height.rs
Normal file
64
sdk/src/syscall/tick_height.rs
Normal file
@ -0,0 +1,64 @@
|
||||
//! This account contains the current cluster tick height
|
||||
//!
|
||||
use crate::account::Account;
|
||||
use crate::account_utils::State;
|
||||
use crate::pubkey::Pubkey;
|
||||
use crate::syscall;
|
||||
use bincode::serialized_size;
|
||||
|
||||
/// "Sysca11TickHeight11111111111111111111111111"
|
||||
/// tick_height account pubkey
|
||||
const ID: [u8; 32] = [
|
||||
6, 167, 211, 138, 69, 219, 242, 63, 162, 206, 168, 232, 212, 90, 152, 107, 220, 251, 113, 215,
|
||||
208, 229, 34, 163, 11, 168, 45, 109, 60, 0, 0, 0,
|
||||
];
|
||||
|
||||
pub fn id() -> Pubkey {
|
||||
Pubkey::new(&ID)
|
||||
}
|
||||
|
||||
pub fn check_id(pubkey: &Pubkey) -> bool {
|
||||
pubkey.as_ref() == ID
|
||||
}
|
||||
|
||||
#[repr(C)]
|
||||
#[derive(Serialize, Deserialize, Debug, Default)]
|
||||
pub struct TickHeight(u64);
|
||||
|
||||
impl TickHeight {
|
||||
pub fn from(account: &Account) -> Option<u64> {
|
||||
account.state().ok().map(|res: Self| res.0)
|
||||
}
|
||||
pub fn to(tick_height: u64, account: &mut Account) -> Option<()> {
|
||||
account.set_state(&TickHeight(tick_height)).ok()
|
||||
}
|
||||
|
||||
pub fn size_of() -> usize {
|
||||
serialized_size(&TickHeight::default()).unwrap() as usize
|
||||
}
|
||||
}
|
||||
|
||||
pub fn create_account(lamports: u64) -> Account {
|
||||
Account::new(lamports, TickHeight::size_of(), &syscall::id())
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use super::*;
|
||||
|
||||
#[test]
|
||||
fn test_tick_height_id() {
|
||||
let name = "Sysca11TickHeight11111111111111111111111111";
|
||||
// To get the bytes above:
|
||||
// dbg!((name, bs58::decode(name).into_vec().unwrap()));
|
||||
assert_eq!(name, id().to_string());
|
||||
assert!(check_id(&id()));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_tick_height_create_account() {
|
||||
let account = create_account(1);
|
||||
let tick_height = TickHeight::from(&account).unwrap();
|
||||
assert_eq!(tick_height, 0);
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user