forked from jito-foundation/jito-solana
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Simd 47 syscall sysvar last restart slot (#31957)
* add sysvar and logic for last restart slot * cleanup * add test for getting last restart slot from account * format code * add some basic rustdoc * copy+paste error * feature flag for last_restart_slot * add to sysvars.md * updated wording in sysvars.md * rename sol_get_last_restart_slot_sysvar > sol_get_last_restart_slot * create sbf C header for sol_get_last_restart_slot * cleanup imports * reverted hardened_unpack workaround * cleanup imports * cleanup logs + blank lines * Implementing ui changes for last restart slot, nit * Some more nit change and implementing the UI for sysvar * fixing the CI * Minor clippy fix * format changes * changes suggested by mvines and lichtso * increase timeout in local_cluster test * fix code format * use keypair for feature flag from mvines * delete test.json file * Revert "increase timeout in local_cluster test" This reverts commit a67465ae225186be5ebaa46badfe44ecac6d76a8. * last restart slot should be always less than or equal to current slot * fixing bug * changes after steviez comments * format issue fixed * fixing the comment on premature application of future hardfork * nit change in test Co-authored-by: steviez <[email protected]> * reverting sysvar_cache.rs because change was not necessary --------- Co-authored-by: steve-gg <[email protected]> Co-authored-by: steviez <[email protected]>
- Loading branch information
1 parent
987e8ee
commit 2ceabd9
Showing
17 changed files
with
393 additions
and
9 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,104 @@ | ||
use { | ||
solana_program_test::{processor, ProgramTest, ProgramTestContext}, | ||
solana_sdk::{ | ||
account_info::AccountInfo, | ||
clock::Slot, | ||
entrypoint::ProgramResult, | ||
instruction::{AccountMeta, Instruction}, | ||
msg, | ||
pubkey::Pubkey, | ||
signature::Signer, | ||
sysvar::{last_restart_slot, last_restart_slot::LastRestartSlot, Sysvar}, | ||
transaction::Transaction, | ||
}, | ||
}; | ||
|
||
// program to check both syscall and sysvar | ||
fn sysvar_last_restart_slot_process_instruction( | ||
_program_id: &Pubkey, | ||
accounts: &[AccountInfo], | ||
input: &[u8], | ||
) -> ProgramResult { | ||
msg!("sysvar_last_restart_slot"); | ||
assert_eq!(input.len(), 8); | ||
let expected_last_hardfork_slot = u64::from_le_bytes(input[0..8].try_into().unwrap()); | ||
|
||
let last_restart_slot = LastRestartSlot::get(); | ||
msg!("last restart slot: {:?}", last_restart_slot); | ||
assert_eq!( | ||
last_restart_slot, | ||
Ok(LastRestartSlot { | ||
last_restart_slot: expected_last_hardfork_slot | ||
}) | ||
); | ||
|
||
let last_restart_slot_account = &accounts[0]; | ||
let slot_via_account = LastRestartSlot::from_account_info(last_restart_slot_account)?; | ||
msg!("slot via account: {:?}", slot_via_account); | ||
|
||
assert_eq!( | ||
slot_via_account, | ||
LastRestartSlot { | ||
last_restart_slot: expected_last_hardfork_slot | ||
} | ||
); | ||
|
||
Ok(()) | ||
} | ||
|
||
async fn check_with_program( | ||
context: &mut ProgramTestContext, | ||
program_id: Pubkey, | ||
expected_last_restart_slot: u64, | ||
) { | ||
let instructions = vec![Instruction::new_with_bincode( | ||
program_id, | ||
&expected_last_restart_slot.to_le_bytes(), | ||
vec![AccountMeta::new(last_restart_slot::id(), false)], | ||
)]; | ||
|
||
let transaction = Transaction::new_signed_with_payer( | ||
&instructions, | ||
Some(&context.payer.pubkey()), | ||
&[&context.payer], | ||
context.last_blockhash, | ||
); | ||
|
||
context | ||
.banks_client | ||
.process_transaction(transaction) | ||
.await | ||
.unwrap(); | ||
} | ||
|
||
#[tokio::test] | ||
async fn get_sysvar_last_restart_slot() { | ||
let program_id = Pubkey::new_unique(); | ||
let program_test = ProgramTest::new( | ||
"sysvar_last_restart_slot_process", | ||
program_id, | ||
processor!(sysvar_last_restart_slot_process_instruction), | ||
); | ||
|
||
let mut context = program_test.start_with_context().await; | ||
|
||
check_with_program(&mut context, program_id, 0).await; | ||
context.warp_to_slot(40).unwrap(); | ||
context.register_hard_fork(41 as Slot); | ||
check_with_program(&mut context, program_id, 0).await; | ||
context.warp_to_slot(41).unwrap(); | ||
check_with_program(&mut context, program_id, 41).await; | ||
// check for value lower than previous hardfork | ||
context.register_hard_fork(40 as Slot); | ||
context.warp_to_slot(45).unwrap(); | ||
check_with_program(&mut context, program_id, 41).await; | ||
context.register_hard_fork(43 as Slot); | ||
context.register_hard_fork(47 as Slot); | ||
context.warp_to_slot(46).unwrap(); | ||
check_with_program(&mut context, program_id, 43).await; | ||
context.register_hard_fork(50 as Slot); | ||
context.warp_to_slot(48).unwrap(); | ||
check_with_program(&mut context, program_id, 47).await; | ||
context.warp_to_slot(50).unwrap(); | ||
check_with_program(&mut context, program_id, 50).await; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.