remove syscall tick height (#4891)
This commit is contained in:
		@@ -82,7 +82,6 @@ mod bpf {
 | 
				
			|||||||
        use solana_sdk::hash;
 | 
					        use solana_sdk::hash;
 | 
				
			||||||
        use solana_sdk::instruction::{AccountMeta, Instruction};
 | 
					        use solana_sdk::instruction::{AccountMeta, Instruction};
 | 
				
			||||||
        use solana_sdk::signature::{Keypair, KeypairUtil};
 | 
					        use solana_sdk::signature::{Keypair, KeypairUtil};
 | 
				
			||||||
        use solana_sdk::syscall::tick_height;
 | 
					 | 
				
			||||||
        use std::io::Read;
 | 
					        use std::io::Read;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        #[test]
 | 
					        #[test]
 | 
				
			||||||
@@ -97,7 +96,6 @@ mod bpf {
 | 
				
			|||||||
                // ("solana_bpf_rust_many_args", true),  // Issue #3099
 | 
					                // ("solana_bpf_rust_many_args", true),  // Issue #3099
 | 
				
			||||||
                ("solana_bpf_rust_noop", true),
 | 
					                ("solana_bpf_rust_noop", true),
 | 
				
			||||||
                ("solana_bpf_rust_panic", false),
 | 
					                ("solana_bpf_rust_panic", false),
 | 
				
			||||||
                ("solana_bpf_rust_tick_height", true),
 | 
					 | 
				
			||||||
            ];
 | 
					            ];
 | 
				
			||||||
            for program in programs.iter() {
 | 
					            for program in programs.iter() {
 | 
				
			||||||
                let filename = create_bpf_path(program.0);
 | 
					                let filename = create_bpf_path(program.0);
 | 
				
			||||||
@@ -123,7 +121,6 @@ mod bpf {
 | 
				
			|||||||
                let account_metas = vec![
 | 
					                let account_metas = vec![
 | 
				
			||||||
                    AccountMeta::new(mint_keypair.pubkey(), true),
 | 
					                    AccountMeta::new(mint_keypair.pubkey(), true),
 | 
				
			||||||
                    AccountMeta::new(Keypair::new().pubkey(), false),
 | 
					                    AccountMeta::new(Keypair::new().pubkey(), false),
 | 
				
			||||||
                    AccountMeta::new(tick_height::id(), false),
 | 
					 | 
				
			||||||
                ];
 | 
					                ];
 | 
				
			||||||
                let instruction = Instruction::new(program_id, &1u8, account_metas);
 | 
					                let instruction = Instruction::new(program_id, &1u8, account_metas);
 | 
				
			||||||
                let result = bank_client.send_instruction(&mint_keypair, instruction);
 | 
					                let result = bank_client.send_instruction(&mint_keypair, instruction);
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -36,7 +36,6 @@ use solana_sdk::signature::{Keypair, Signature};
 | 
				
			|||||||
use solana_sdk::syscall::{
 | 
					use solana_sdk::syscall::{
 | 
				
			||||||
    current, fees, rewards,
 | 
					    current, fees, rewards,
 | 
				
			||||||
    slot_hashes::{self, SlotHashes},
 | 
					    slot_hashes::{self, SlotHashes},
 | 
				
			||||||
    tick_height,
 | 
					 | 
				
			||||||
};
 | 
					};
 | 
				
			||||||
use solana_sdk::system_transaction;
 | 
					use solana_sdk::system_transaction;
 | 
				
			||||||
use solana_sdk::timing::{duration_as_ns, MAX_RECENT_BLOCKHASHES};
 | 
					use solana_sdk::timing::{duration_as_ns, MAX_RECENT_BLOCKHASHES};
 | 
				
			||||||
@@ -434,13 +433,6 @@ impl Bank {
 | 
				
			|||||||
        self.store_account(&fees::id(), &fees::create_account(1, &self.fee_calculator));
 | 
					        self.store_account(&fees::id(), &fees::create_account(1, &self.fee_calculator));
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    fn update_tick_height(&self) {
 | 
					 | 
				
			||||||
        self.store_account(
 | 
					 | 
				
			||||||
            &tick_height::id(),
 | 
					 | 
				
			||||||
            &tick_height::create_account(1, self.tick_height()),
 | 
					 | 
				
			||||||
        );
 | 
					 | 
				
			||||||
    }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    // update reward for previous epoch
 | 
					    // update reward for previous epoch
 | 
				
			||||||
    fn update_rewards(&mut self, epoch: u64) {
 | 
					    fn update_rewards(&mut self, epoch: u64) {
 | 
				
			||||||
        if epoch == self.epoch() {
 | 
					        if epoch == self.epoch() {
 | 
				
			||||||
@@ -732,8 +724,6 @@ impl Bank {
 | 
				
			|||||||
        };
 | 
					        };
 | 
				
			||||||
        inc_new_counter_debug!("bank-register_tick-registered", 1);
 | 
					        inc_new_counter_debug!("bank-register_tick-registered", 1);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        self.update_tick_height();
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
        // Register a new block hash if at the last tick in the slot
 | 
					        // Register a new block hash if at the last tick in the slot
 | 
				
			||||||
        if current_tick_height % self.ticks_per_slot == self.ticks_per_slot - 1 {
 | 
					        if current_tick_height % self.ticks_per_slot == self.ticks_per_slot - 1 {
 | 
				
			||||||
            self.blockhash_queue
 | 
					            self.blockhash_queue
 | 
				
			||||||
@@ -1444,7 +1434,7 @@ 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, tick_height::TickHeight};
 | 
					    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::timing::DEFAULT_TICKS_PER_SLOT;
 | 
					    use solana_sdk::timing::DEFAULT_TICKS_PER_SLOT;
 | 
				
			||||||
@@ -2640,21 +2630,6 @@ mod tests {
 | 
				
			|||||||
        assert_eq!(fees.fee_calculator.lamports_per_signature, 12345);
 | 
					        assert_eq!(fees.fee_calculator.lamports_per_signature, 12345);
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    #[test]
 | 
					 | 
				
			||||||
    fn test_bank_tick_height_account() {
 | 
					 | 
				
			||||||
        let (genesis_block, _) = create_genesis_block(1);
 | 
					 | 
				
			||||||
        let bank = Bank::new(&genesis_block);
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
        for i in 0..10 {
 | 
					 | 
				
			||||||
            bank.register_tick(&hash::hash(format!("hashing {}", i).as_bytes()));
 | 
					 | 
				
			||||||
        }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
        let tick_account = bank.get_account(&tick_height::id()).unwrap();
 | 
					 | 
				
			||||||
        let tick_height = TickHeight::from(&tick_account).unwrap().0;
 | 
					 | 
				
			||||||
        assert_eq!(bank.tick_height(), tick_height);
 | 
					 | 
				
			||||||
        assert_eq!(tick_height, 10);
 | 
					 | 
				
			||||||
    }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    #[test]
 | 
					    #[test]
 | 
				
			||||||
    fn test_is_delta_with_no_committables() {
 | 
					    fn test_is_delta_with_no_committables() {
 | 
				
			||||||
        let (genesis_block, mint_keypair) = create_genesis_block(8000);
 | 
					        let (genesis_block, mint_keypair) = create_genesis_block(8000);
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -6,13 +6,9 @@ pub mod current;
 | 
				
			|||||||
pub mod fees;
 | 
					pub mod fees;
 | 
				
			||||||
pub mod rewards;
 | 
					pub mod rewards;
 | 
				
			||||||
pub mod slot_hashes;
 | 
					pub mod slot_hashes;
 | 
				
			||||||
pub mod tick_height;
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
pub fn is_syscall_id(id: &Pubkey) -> bool {
 | 
					pub fn is_syscall_id(id: &Pubkey) -> bool {
 | 
				
			||||||
    current::check_id(id)
 | 
					    current::check_id(id) || fees::check_id(id) || slot_hashes::check_id(id)
 | 
				
			||||||
        || fees::check_id(id)
 | 
					 | 
				
			||||||
        || slot_hashes::check_id(id)
 | 
					 | 
				
			||||||
        || tick_height::check_id(id)
 | 
					 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
/// "Sysca11111111111111111111111111111111111111"
 | 
					/// "Sysca11111111111111111111111111111111111111"
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -1,47 +0,0 @@
 | 
				
			|||||||
//! This account contains the current cluster tick height
 | 
					 | 
				
			||||||
//!
 | 
					 | 
				
			||||||
use crate::account::Account;
 | 
					 | 
				
			||||||
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,
 | 
					 | 
				
			||||||
];
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
crate::solana_name_id!(ID, "Sysca11TickHeight11111111111111111111111111");
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
#[repr(C)]
 | 
					 | 
				
			||||||
#[derive(Serialize, Deserialize, Debug, Default)]
 | 
					 | 
				
			||||||
pub struct TickHeight(pub u64);
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
impl TickHeight {
 | 
					 | 
				
			||||||
    pub fn from(account: &Account) -> Option<Self> {
 | 
					 | 
				
			||||||
        account.deserialize_data().ok()
 | 
					 | 
				
			||||||
    }
 | 
					 | 
				
			||||||
    pub fn to(&self, account: &mut Account) -> Option<()> {
 | 
					 | 
				
			||||||
        account.serialize_data(self).ok()
 | 
					 | 
				
			||||||
    }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    pub fn size_of() -> usize {
 | 
					 | 
				
			||||||
        serialized_size(&TickHeight::default()).unwrap() as usize
 | 
					 | 
				
			||||||
    }
 | 
					 | 
				
			||||||
}
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
pub fn create_account(lamports: u64, tick_height: u64) -> Account {
 | 
					 | 
				
			||||||
    Account::new_data(lamports, &TickHeight(tick_height), &syscall::id()).unwrap()
 | 
					 | 
				
			||||||
}
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
#[cfg(test)]
 | 
					 | 
				
			||||||
mod tests {
 | 
					 | 
				
			||||||
    use super::*;
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    #[test]
 | 
					 | 
				
			||||||
    fn test_tick_height_create_account() {
 | 
					 | 
				
			||||||
        let account = create_account(1, 1);
 | 
					 | 
				
			||||||
        let tick_height = TickHeight::from(&account).unwrap();
 | 
					 | 
				
			||||||
        assert_eq!(tick_height.0, 1);
 | 
					 | 
				
			||||||
    }
 | 
					 | 
				
			||||||
}
 | 
					 | 
				
			||||||
		Reference in New Issue
	
	Block a user