Skip to content

Commit 59b7935

Browse files
committed
Make CI happy again
1 parent 256ab3f commit 59b7935

File tree

2 files changed

+92
-74
lines changed

2 files changed

+92
-74
lines changed

magicblock-committor-service/src/tasks/mod.rs

Lines changed: 22 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -119,7 +119,9 @@ pub struct CommitTask {
119119
impl CommitTask {
120120
// Accounts larger than COMMIT_STATE_SIZE_THRESHOLD, use CommitDiff to
121121
// reduce instruction size. Below this, commit is sent as CommitState.
122-
const COMMIT_STATE_SIZE_THRESHOLD: usize = 200;
122+
// Chose 256 as thresold seems good enough as it could hold 8 u32 fields
123+
// or 4 u64 fields.
124+
const COMMIT_STATE_SIZE_THRESHOLD: usize = 256;
123125

124126
pub async fn new(
125127
commit_id: u64,
@@ -416,25 +418,29 @@ mod serialization_safety_test {
416418
};
417419

418420
// Test all ArgsTask variants
419-
#[test]
420-
fn test_args_task_instruction_serialization() {
421+
#[tokio::test]
422+
async fn test_args_task_instruction_serialization() {
421423
let validator = Pubkey::new_unique();
422424

423425
// Test Commit variant
424-
let commit_task: ArgsTask = ArgsTaskType::Commit(CommitTask::new(
425-
123,
426-
true,
427-
CommittedAccount {
428-
pubkey: Pubkey::new_unique(),
429-
account: Account {
430-
lamports: 1000,
431-
data: vec![1, 2, 3],
432-
owner: Pubkey::new_unique(),
433-
executable: false,
434-
rent_epoch: 0,
426+
let commit_task: ArgsTask = ArgsTaskType::Commit(
427+
CommitTask::new(
428+
123,
429+
true,
430+
CommittedAccount {
431+
pubkey: Pubkey::new_unique(),
432+
account: Account {
433+
lamports: 1000,
434+
data: vec![1, 2, 3],
435+
owner: Pubkey::new_unique(),
436+
executable: false,
437+
rent_epoch: 0,
438+
},
435439
},
436-
},
437-
))
440+
AccountFetcher::new(),
441+
)
442+
.await,
443+
)
438444
.into();
439445
assert_serializable(&commit_task.instruction(&validator));
440446

magicblock-committor-service/src/tasks/task_strategist.rs

Lines changed: 70 additions & 58 deletions
Original file line numberDiff line numberDiff line change
@@ -250,6 +250,7 @@ pub type TaskStrategistResult<T, E = TaskStrategistError> = Result<T, E>;
250250

251251
#[cfg(test)]
252252
mod tests {
253+
use futures_util::future::join_all;
253254
use magicblock_program::magic_scheduled_base_intent::{
254255
BaseAction, CommittedAccount, ProgramArgs,
255256
};
@@ -259,25 +260,35 @@ mod tests {
259260
use super::*;
260261
use crate::{
261262
persist::IntentPersisterImpl,
262-
tasks::{BaseActionTask, CommitTask, TaskStrategy, UndelegateTask},
263+
tasks::{
264+
AccountFetcher, BaseActionTask, CommitTask, TaskStrategy,
265+
UndelegateTask,
266+
},
263267
};
264268

265269
// Helper to create a simple commit task
266-
fn create_test_commit_task(commit_id: u64, data_size: usize) -> ArgsTask {
267-
ArgsTask::new(ArgsTaskType::Commit(CommitTask::new(
268-
commit_id,
269-
false,
270-
CommittedAccount {
271-
pubkey: Pubkey::new_unique(),
272-
account: Account {
273-
lamports: 1000,
274-
data: vec![1; data_size],
275-
owner: system_program::id(),
276-
executable: false,
277-
rent_epoch: 0,
270+
async fn create_test_commit_task(
271+
commit_id: u64,
272+
data_size: usize,
273+
) -> ArgsTask {
274+
ArgsTask::new(ArgsTaskType::Commit(
275+
CommitTask::new(
276+
commit_id,
277+
false,
278+
CommittedAccount {
279+
pubkey: Pubkey::new_unique(),
280+
account: Account {
281+
lamports: 1000,
282+
data: vec![1; data_size],
283+
owner: system_program::id(),
284+
executable: false,
285+
rent_epoch: 0,
286+
},
278287
},
279-
},
280-
)))
288+
AccountFetcher::new(),
289+
)
290+
.await,
291+
))
281292
}
282293

283294
// Helper to create a Base action task
@@ -312,10 +323,10 @@ mod tests {
312323
}))
313324
}
314325

315-
#[test]
316-
fn test_build_strategy_with_single_small_task() {
326+
#[tokio::test]
327+
async fn test_build_strategy_with_single_small_task() {
317328
let validator = Pubkey::new_unique();
318-
let task = create_test_commit_task(1, 100);
329+
let task = create_test_commit_task(1, 100).await;
319330
let tasks = vec![Box::new(task) as Box<dyn BaseTask>];
320331

321332
let strategy = TaskStrategist::build_strategy(
@@ -329,11 +340,11 @@ mod tests {
329340
assert!(strategy.lookup_tables_keys.is_empty());
330341
}
331342

332-
#[test]
333-
fn test_build_strategy_optimizes_to_buffer_when_needed() {
343+
#[tokio::test]
344+
async fn test_build_strategy_optimizes_to_buffer_when_needed() {
334345
let validator = Pubkey::new_unique();
335346

336-
let task = create_test_commit_task(1, 1000); // Large task
347+
let task = create_test_commit_task(1, 1000).await; // Large task
337348
let tasks = vec![Box::new(task) as Box<dyn BaseTask>];
338349

339350
let strategy = TaskStrategist::build_strategy(
@@ -350,11 +361,11 @@ mod tests {
350361
));
351362
}
352363

353-
#[test]
354-
fn test_build_strategy_optimizes_to_buffer_u16_exceeded() {
364+
#[tokio::test]
365+
async fn test_build_strategy_optimizes_to_buffer_u16_exceeded() {
355366
let validator = Pubkey::new_unique();
356367

357-
let task = create_test_commit_task(1, 66_000); // Large task
368+
let task = create_test_commit_task(1, 66_000).await; // Large task
358369
let tasks = vec![Box::new(task) as Box<dyn BaseTask>];
359370

360371
let strategy = TaskStrategist::build_strategy(
@@ -371,19 +382,18 @@ mod tests {
371382
));
372383
}
373384

374-
#[test]
375-
fn test_build_strategy_creates_multiple_buffers() {
385+
#[tokio::test]
386+
async fn test_build_strategy_creates_multiple_buffers() {
376387
// TODO: ALSO MAX NUM WITH PURE BUFFER commits, no alts
377388
const NUM_COMMITS: u64 = 3;
378389

379390
let validator = Pubkey::new_unique();
380391

381-
let tasks = (0..NUM_COMMITS)
382-
.map(|i| {
383-
let task = create_test_commit_task(i, 500); // Large task
384-
Box::new(task) as Box<dyn BaseTask>
385-
})
386-
.collect();
392+
let tasks = join_all((0..NUM_COMMITS).map(|i| async move {
393+
let task = create_test_commit_task(i, 500).await; // Large task
394+
Box::new(task) as Box<dyn BaseTask>
395+
}))
396+
.await;
387397

388398
let strategy = TaskStrategist::build_strategy(
389399
tasks,
@@ -398,20 +408,19 @@ mod tests {
398408
assert!(strategy.lookup_tables_keys.is_empty());
399409
}
400410

401-
#[test]
402-
fn test_build_strategy_with_lookup_tables_when_needed() {
411+
#[tokio::test]
412+
async fn test_build_strategy_with_lookup_tables_when_needed() {
403413
// Also max number of committed accounts fit with ALTs!
404414
const NUM_COMMITS: u64 = 22;
405415

406416
let validator = Pubkey::new_unique();
407417

408-
let tasks = (0..NUM_COMMITS)
409-
.map(|i| {
410-
// Large task
411-
let task = create_test_commit_task(i, 10000);
412-
Box::new(task) as Box<dyn BaseTask>
413-
})
414-
.collect();
418+
let tasks = join_all((0..NUM_COMMITS).map(|i| async move {
419+
// Large task
420+
let task = create_test_commit_task(i, 10000).await;
421+
Box::new(task) as Box<dyn BaseTask>
422+
}))
423+
.await;
415424

416425
let strategy = TaskStrategist::build_strategy(
417426
tasks,
@@ -426,19 +435,18 @@ mod tests {
426435
assert!(!strategy.lookup_tables_keys.is_empty());
427436
}
428437

429-
#[test]
430-
fn test_build_strategy_fails_when_cant_fit() {
438+
#[tokio::test]
439+
async fn test_build_strategy_fails_when_cant_fit() {
431440
const NUM_COMMITS: u64 = 23;
432441

433442
let validator = Pubkey::new_unique();
434443

435-
let tasks = (0..NUM_COMMITS)
436-
.map(|i| {
437-
// Large task
438-
let task = create_test_commit_task(i, 1000);
439-
Box::new(task) as Box<dyn BaseTask>
440-
})
441-
.collect();
444+
let tasks = join_all((0..NUM_COMMITS).map(|i| async move {
445+
// Large task
446+
let task = create_test_commit_task(i, 1000).await;
447+
Box::new(task) as Box<dyn BaseTask>
448+
}))
449+
.await;
442450

443451
let result = TaskStrategist::build_strategy(
444452
tasks,
@@ -448,12 +456,15 @@ mod tests {
448456
assert!(matches!(result, Err(TaskStrategistError::FailedToFitError)));
449457
}
450458

451-
#[test]
452-
fn test_optimize_strategy_prioritizes_largest_tasks() {
459+
#[tokio::test]
460+
async fn test_optimize_strategy_prioritizes_largest_tasks() {
453461
let mut tasks = [
454-
Box::new(create_test_commit_task(1, 100)) as Box<dyn BaseTask>,
455-
Box::new(create_test_commit_task(2, 1000)) as Box<dyn BaseTask>, // Larger task
456-
Box::new(create_test_commit_task(3, 1000)) as Box<dyn BaseTask>, // Larger task
462+
Box::new(create_test_commit_task(1, 100).await)
463+
as Box<dyn BaseTask>,
464+
Box::new(create_test_commit_task(2, 1000).await)
465+
as Box<dyn BaseTask>, // Larger task
466+
Box::new(create_test_commit_task(3, 1000).await)
467+
as Box<dyn BaseTask>, // Larger task
457468
];
458469

459470
let _ = TaskStrategist::optimize_strategy(&mut tasks);
@@ -462,11 +473,12 @@ mod tests {
462473
assert!(matches!(tasks[1].strategy(), TaskStrategy::Buffer));
463474
}
464475

465-
#[test]
466-
fn test_mixed_task_types_with_optimization() {
476+
#[tokio::test]
477+
async fn test_mixed_task_types_with_optimization() {
467478
let validator = Pubkey::new_unique();
468479
let tasks = vec![
469-
Box::new(create_test_commit_task(1, 1000)) as Box<dyn BaseTask>,
480+
Box::new(create_test_commit_task(1, 1000).await)
481+
as Box<dyn BaseTask>,
470482
Box::new(create_test_finalize_task()) as Box<dyn BaseTask>,
471483
Box::new(create_test_base_action_task(500)) as Box<dyn BaseTask>,
472484
Box::new(create_test_undelegate_task()) as Box<dyn BaseTask>,

0 commit comments

Comments
 (0)