diff --git a/magicblock-magic-program-api/src/instruction.rs b/magicblock-magic-program-api/src/instruction.rs index a137815b8..b12830f6b 100644 --- a/magicblock-magic-program-api/src/instruction.rs +++ b/magicblock-magic-program-api/src/instruction.rs @@ -100,6 +100,9 @@ pub enum MagicBlockInstruction { /// # Account references /// - **0.** `[SIGNER]` Validator authority EnableExecutableCheck, + + /// Noop instruction + Noop(u64), } impl MagicBlockInstruction { diff --git a/magicblock-task-scheduler/src/service.rs b/magicblock-task-scheduler/src/service.rs index a0fb3c5ad..75068426b 100644 --- a/magicblock-task-scheduler/src/service.rs +++ b/magicblock-task-scheduler/src/service.rs @@ -13,11 +13,12 @@ use magicblock_core::link::transactions::{ use magicblock_ledger::LatestBlock; use magicblock_program::{ args::{CancelTaskRequest, TaskRequest}, + instruction_utils::InstructionUtils, validator::{validator_authority, validator_authority_id}, }; use solana_sdk::{ - instruction::Instruction, message::Message, pubkey::Pubkey, - signature::Signature, transaction::Transaction, + instruction::Instruction, message::Message, signature::Signature, + transaction::Transaction, }; use tokio::{select, task::JoinHandle, time::Duration}; use tokio_util::{ @@ -30,9 +31,6 @@ use crate::{ errors::{TaskSchedulerError, TaskSchedulerResult}, }; -const NOOP_PROGRAM_ID: Pubkey = - Pubkey::from_str_const("noopb9bkMVfRPU8AsbpTUg8AQkHtKwMYZiFUjNRtMmV"); - pub struct TaskSchedulerService { /// Database for persisting tasks db: SchedulerDatabase, @@ -308,13 +306,8 @@ impl TaskSchedulerService { let blockhash = self.block.load().blockhash; // Execute unsigned transactions // We prepend a noop instruction to make each transaction unique. - let noop_instruction = Instruction::new_with_bytes( - NOOP_PROGRAM_ID, - &self - .tx_counter - .fetch_add(1, Ordering::Relaxed) - .to_le_bytes(), - vec![], + let noop_instruction = InstructionUtils::noop_instruction( + self.tx_counter.fetch_add(1, Ordering::Relaxed), ); let tx = Transaction::new( &[validator_authority()], diff --git a/magicblock-task-scheduler/tests/service.rs b/magicblock-task-scheduler/tests/service.rs index 347498f08..601f8274b 100644 --- a/magicblock-task-scheduler/tests/service.rs +++ b/magicblock-task-scheduler/tests/service.rs @@ -181,6 +181,9 @@ pub async fn test_cancel_task() -> TaskSchedulerResult<()> { result ); + // Wait for the cancel to be processed + tokio::time::sleep(Duration::from_millis(interval as u64)).await; + let value_at_cancel = env .get_account(account.pubkey()) .data() diff --git a/programs/magicblock/src/magicblock_processor.rs b/programs/magicblock/src/magicblock_processor.rs index 433e3a6cf..1025c4447 100644 --- a/programs/magicblock/src/magicblock_processor.rs +++ b/programs/magicblock/src/magicblock_processor.rs @@ -77,6 +77,7 @@ declare_process_instruction!( EnableExecutableCheck => { process_toggle_executable_check(signers, invoke_context, true) } + Noop(_) => Ok(()), } } ); diff --git a/programs/magicblock/src/schedule_task/process_schedule_task.rs b/programs/magicblock/src/schedule_task/process_schedule_task.rs index 11f11b90c..840544184 100644 --- a/programs/magicblock/src/schedule_task/process_schedule_task.rs +++ b/programs/magicblock/src/schedule_task/process_schedule_task.rs @@ -154,15 +154,13 @@ mod test { use super::*; use crate::{ - test_utils::{ - process_instruction, COUNTER_PROGRAM_ID, NOOP_PROGRAM_ID, - }, + test_utils::{process_instruction, COUNTER_PROGRAM_ID}, utils::instruction_utils::InstructionUtils, validator::generate_validator_authority_if_needed, }; fn create_simple_ix() -> Instruction { - Instruction::new_with_borsh(NOOP_PROGRAM_ID, b"test noop", vec![]) + InstructionUtils::noop_instruction(0) } fn create_complex_ix( diff --git a/programs/magicblock/src/test_utils/mod.rs b/programs/magicblock/src/test_utils/mod.rs index 2f4ae5035..3586ecdf4 100644 --- a/programs/magicblock/src/test_utils/mod.rs +++ b/programs/magicblock/src/test_utils/mod.rs @@ -23,8 +23,6 @@ use super::*; use crate::validator; pub const AUTHORITY_BALANCE: u64 = u64::MAX / 2; -pub const NOOP_PROGRAM_ID: Pubkey = - Pubkey::from_str_const("noopb9bkMVfRPU8AsbpTUg8AQkHtKwMYZiFUjNRtMmV"); pub const COUNTER_PROGRAM_ID: Pubkey = Pubkey::from_str_const("2jQZbSfAfqT5nZHGrLpDG2vXuEGtTgZYnNy7AZEjMCYz"); diff --git a/programs/magicblock/src/utils/instruction_utils.rs b/programs/magicblock/src/utils/instruction_utils.rs index ebdeb5d6d..1dd46d876 100644 --- a/programs/magicblock/src/utils/instruction_utils.rs +++ b/programs/magicblock/src/utils/instruction_utils.rs @@ -278,6 +278,17 @@ impl InstructionUtils { ) } + // ----------------- + // Noop + // ----------------- + pub fn noop_instruction(data: u64) -> Instruction { + Instruction::new_with_bincode( + crate::id(), + &MagicBlockInstruction::Noop(data), + vec![], + ) + } + // ----------------- // Utils // ----------------- diff --git a/test-integration/configs/schedule-task.devnet.toml b/test-integration/configs/schedule-task.devnet.toml index a4c3239fa..4f8085e01 100644 --- a/test-integration/configs/schedule-task.devnet.toml +++ b/test-integration/configs/schedule-task.devnet.toml @@ -18,9 +18,5 @@ path = "../schedulecommit/elfs/dlp.so" id = "DmnRGfyyftzacFb1XadYhWF6vWqXwtQk5tbr6XgR3BA1" path = "../schedulecommit/elfs/mdp.so" -[[programs]] -id = "noopb9bkMVfRPU8AsbpTUg8AQkHtKwMYZiFUjNRtMmV" -path = "../programs/noop/noop.so" - [metrics] address = "0.0.0.0:9000" diff --git a/test-integration/programs/noop/noop.so b/test-integration/programs/noop/noop.so deleted file mode 100644 index e250fa092..000000000 Binary files a/test-integration/programs/noop/noop.so and /dev/null differ diff --git a/test-integration/test-task-scheduler/src/lib.rs b/test-integration/test-task-scheduler/src/lib.rs index feeeabfaf..8674de7dc 100644 --- a/test-integration/test-task-scheduler/src/lib.rs +++ b/test-integration/test-task-scheduler/src/lib.rs @@ -26,14 +26,10 @@ use program_flexi_counter::instruction::{ create_delegate_ix_with_commit_frequency_ms, create_init_ix, }; use solana_sdk::{ - hash::Hash, instruction::Instruction, pubkey::Pubkey, signature::Keypair, - signer::Signer, transaction::Transaction, + signature::Keypair, signer::Signer, transaction::Transaction, }; use tempfile::TempDir; -pub const NOOP_PROGRAM_ID: Pubkey = - Pubkey::from_str_const("noopb9bkMVfRPU8AsbpTUg8AQkHtKwMYZiFUjNRtMmV"); - pub const TASK_SCHEDULER_TICK_MILLIS: u64 = 50; pub fn setup_validator() -> (TempDir, Child, IntegrationTestContext) { @@ -126,36 +122,3 @@ pub fn create_delegated_counter( // Wait for account to be delegated expect!(ctx.wait_for_delta_slot_ephem(10), validator); } - -pub fn send_noop_tx( - ctx: &IntegrationTestContext, - payer: &Keypair, - validator: &mut Child, -) -> Hash { - // Noop tx to make sure the noop program is cloned - let ephem_blockhash = expect!( - ctx.try_ephem_client().and_then(|client| client - .get_latest_blockhash() - .map_err(|e| anyhow::anyhow!( - "Failed to get latest blockhash: {}", - e - ))), - validator - ); - let noop_instruction = - Instruction::new_with_bytes(NOOP_PROGRAM_ID, &[0], vec![]); - expect!( - ctx.send_transaction_ephem( - &mut Transaction::new_signed_with_payer( - &[noop_instruction], - Some(&payer.pubkey()), - &[&payer], - ephem_blockhash, - ), - &[payer] - ), - validator - ); - - ephem_blockhash -} diff --git a/test-integration/test-task-scheduler/tests/test_cancel_ongoing_task.rs b/test-integration/test-task-scheduler/tests/test_cancel_ongoing_task.rs index 5b109426b..951f98239 100644 --- a/test-integration/test-task-scheduler/tests/test_cancel_ongoing_task.rs +++ b/test-integration/test-task-scheduler/tests/test_cancel_ongoing_task.rs @@ -9,9 +9,7 @@ use solana_sdk::{ native_token::LAMPORTS_PER_SOL, signature::Keypair, signer::Signer, transaction::Transaction, }; -use test_task_scheduler::{ - create_delegated_counter, send_noop_tx, setup_validator, -}; +use test_task_scheduler::{create_delegated_counter, setup_validator}; use tokio::runtime::Runtime; #[test] @@ -29,8 +27,8 @@ fn test_cancel_ongoing_task() { create_delegated_counter(&ctx, &payer, &mut validator, 0); - // Noop tx to make sure the noop program is cloned - let ephem_blockhash = send_noop_tx(&ctx, &payer, &mut validator); + let ephem_blockhash = + expect!(ctx.try_get_latest_blockhash_ephem(), validator); // Schedule a task let task_id = 3; diff --git a/test-integration/test-task-scheduler/tests/test_reschedule_task.rs b/test-integration/test-task-scheduler/tests/test_reschedule_task.rs index 3b21ee189..37eb346db 100644 --- a/test-integration/test-task-scheduler/tests/test_reschedule_task.rs +++ b/test-integration/test-task-scheduler/tests/test_reschedule_task.rs @@ -9,9 +9,7 @@ use solana_sdk::{ native_token::LAMPORTS_PER_SOL, signature::Keypair, signer::Signer, transaction::Transaction, }; -use test_task_scheduler::{ - create_delegated_counter, send_noop_tx, setup_validator, -}; +use test_task_scheduler::{create_delegated_counter, setup_validator}; use tokio::runtime::Runtime; #[test] @@ -29,8 +27,8 @@ fn test_reschedule_task() { create_delegated_counter(&ctx, &payer, &mut validator, 0); - // Noop tx to make sure the noop program is cloned - let ephem_blockhash = send_noop_tx(&ctx, &payer, &mut validator); + let ephem_blockhash = + expect!(ctx.try_get_latest_blockhash_ephem(), validator); // Schedule a task let task_id = 1; diff --git a/test-integration/test-task-scheduler/tests/test_schedule_error.rs b/test-integration/test-task-scheduler/tests/test_schedule_error.rs index 45e3d5b7f..bca4b34b7 100644 --- a/test-integration/test-task-scheduler/tests/test_schedule_error.rs +++ b/test-integration/test-task-scheduler/tests/test_schedule_error.rs @@ -9,9 +9,7 @@ use solana_sdk::{ native_token::LAMPORTS_PER_SOL, signature::Keypair, signer::Signer, transaction::Transaction, }; -use test_task_scheduler::{ - create_delegated_counter, send_noop_tx, setup_validator, -}; +use test_task_scheduler::{create_delegated_counter, setup_validator}; use tokio::runtime::Runtime; // Test that a task with an error is unscheduled @@ -30,8 +28,8 @@ fn test_schedule_error() { create_delegated_counter(&ctx, &payer, &mut validator, 0); - // Noop tx to make sure the noop program is cloned - let ephem_blockhash = send_noop_tx(&ctx, &payer, &mut validator); + let ephem_blockhash = + expect!(ctx.try_get_latest_blockhash_ephem(), validator); // Schedule a task let task_id = 2; diff --git a/test-integration/test-task-scheduler/tests/test_schedule_task.rs b/test-integration/test-task-scheduler/tests/test_schedule_task.rs index 72d72e830..32d3c514e 100644 --- a/test-integration/test-task-scheduler/tests/test_schedule_task.rs +++ b/test-integration/test-task-scheduler/tests/test_schedule_task.rs @@ -9,9 +9,7 @@ use solana_sdk::{ native_token::LAMPORTS_PER_SOL, signature::Keypair, signer::Signer, transaction::Transaction, }; -use test_task_scheduler::{ - create_delegated_counter, send_noop_tx, setup_validator, -}; +use test_task_scheduler::{create_delegated_counter, setup_validator}; use tokio::runtime::Runtime; #[test] @@ -29,8 +27,8 @@ fn test_schedule_task() { create_delegated_counter(&ctx, &payer, &mut validator, 0); - // Noop tx to make sure the noop program is cloned - let ephem_blockhash = send_noop_tx(&ctx, &payer, &mut validator); + let ephem_blockhash = + expect!(ctx.try_get_latest_blockhash_ephem(), validator); // Schedule a task let task_id = 1; diff --git a/test-integration/test-task-scheduler/tests/test_schedule_task_signed.rs b/test-integration/test-task-scheduler/tests/test_schedule_task_signed.rs index 0626aba42..9765f3728 100644 --- a/test-integration/test-task-scheduler/tests/test_schedule_task_signed.rs +++ b/test-integration/test-task-scheduler/tests/test_schedule_task_signed.rs @@ -7,9 +7,7 @@ use solana_sdk::{ signer::Signer, transaction::{Transaction, TransactionError}, }; -use test_task_scheduler::{ - create_delegated_counter, send_noop_tx, setup_validator, -}; +use test_task_scheduler::{create_delegated_counter, setup_validator}; /// Test that a task can be scheduled and executed when it has multiple signers #[test] @@ -24,8 +22,8 @@ fn test_schedule_task_signed() { create_delegated_counter(&ctx, &payer, &mut validator, 0); - // Noop tx to make sure the noop program is cloned - let ephem_blockhash = send_noop_tx(&ctx, &payer, &mut validator); + let ephem_blockhash = + expect!(ctx.try_get_latest_blockhash_ephem(), validator); // Schedule a task let task_id = 4; diff --git a/test-integration/test-task-scheduler/tests/test_scheduled_commits.rs b/test-integration/test-task-scheduler/tests/test_scheduled_commits.rs index 3007e76c3..0aa9ab565 100644 --- a/test-integration/test-task-scheduler/tests/test_scheduled_commits.rs +++ b/test-integration/test-task-scheduler/tests/test_scheduled_commits.rs @@ -7,9 +7,7 @@ use solana_sdk::{ native_token::LAMPORTS_PER_SOL, signature::Keypair, signer::Signer, transaction::Transaction, }; -use test_task_scheduler::{ - create_delegated_counter, send_noop_tx, setup_validator, -}; +use test_task_scheduler::{create_delegated_counter, setup_validator}; #[test] fn test_scheduled_commits() { @@ -23,8 +21,8 @@ fn test_scheduled_commits() { validator ); - // Noop tx to make sure the noop program is cloned - let ephem_blockhash = send_noop_tx(&ctx, &payer, &mut validator); + let ephem_blockhash = + expect!(ctx.try_get_latest_blockhash_ephem(), validator); let commit_frequency_ms = 400; create_delegated_counter(&ctx, &payer, &mut validator, commit_frequency_ms); diff --git a/test-integration/test-task-scheduler/tests/test_unauthorized_reschedule.rs b/test-integration/test-task-scheduler/tests/test_unauthorized_reschedule.rs index d1cf96241..5e859f7a0 100644 --- a/test-integration/test-task-scheduler/tests/test_unauthorized_reschedule.rs +++ b/test-integration/test-task-scheduler/tests/test_unauthorized_reschedule.rs @@ -8,9 +8,7 @@ use solana_sdk::{ native_token::LAMPORTS_PER_SOL, signature::Keypair, signer::Signer, transaction::Transaction, }; -use test_task_scheduler::{ - create_delegated_counter, send_noop_tx, setup_validator, -}; +use test_task_scheduler::{create_delegated_counter, setup_validator}; use tokio::runtime::Runtime; #[test] @@ -34,8 +32,8 @@ fn test_unauthorized_reschedule() { create_delegated_counter(&ctx, &payer, &mut validator, 0); create_delegated_counter(&ctx, &different_payer, &mut validator, 0); - // Noop tx to make sure the noop program is cloned - let ephem_blockhash = send_noop_tx(&ctx, &payer, &mut validator); + let ephem_blockhash = + expect!(ctx.try_get_latest_blockhash_ephem(), validator); // Schedule a task let task_id = 1; diff --git a/test-kit/src/lib.rs b/test-kit/src/lib.rs index c0d992a5c..66faea2c2 100644 --- a/test-kit/src/lib.rs +++ b/test-kit/src/lib.rs @@ -37,9 +37,6 @@ use solana_transaction::Transaction; use solana_transaction_status_client_types::TransactionStatusMeta; use tempfile::TempDir; -const NOOP_PROGRAM_ID: Pubkey = - Pubkey::from_str_const("noopb9bkMVfRPU8AsbpTUg8AQkHtKwMYZiFUjNRtMmV"); - /// A simulated validator backend for integration tests. /// /// This struct encapsulates all the core components of a validator, including @@ -136,12 +133,6 @@ impl ExecutionTestEnv { "../programs/elfs/guinea.so".into(), )]) .expect("failed to load test programs into test env"); - scheduler_state - .load_upgradeable_programs(&[( - NOOP_PROGRAM_ID, - "../test-integration/programs/noop/noop.so".into(), - )]) - .expect("failed to load test programs into test env"); // Start the transaction processing backend. TransactionScheduler::new(1, scheduler_state).spawn();