Skip to content

Commit 00b3b98

Browse files
committed
Address @taco-paco's feedback
1 parent 7a23d4b commit 00b3b98

File tree

13 files changed

+211
-79
lines changed

13 files changed

+211
-79
lines changed

Cargo.lock

Lines changed: 0 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

magicblock-committor-service/Cargo.toml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,6 @@ magicblock-metrics = { workspace = true }
2929
magicblock-program = { workspace = true }
3030
magicblock-rpc-client = { workspace = true }
3131
magicblock-table-mania = { workspace = true }
32-
magicblock-config = { workspace = true }
3332
rusqlite = { workspace = true }
3433
solana-account = { workspace = true }
3534
solana-address-lookup-table-interface = { workspace = true }

magicblock-committor-service/src/intent_execution_manager/intent_execution_engine.rs

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -371,6 +371,8 @@ mod tests {
371371

372372
use async_trait::async_trait;
373373
use magicblock_program::magic_scheduled_base_intent::ScheduledBaseIntent;
374+
use magicblock_rpc_client::MagicBlockRpcClientResult;
375+
use solana_account::Account;
374376
use solana_pubkey::{pubkey, Pubkey};
375377
use solana_signature::Signature;
376378
use solana_signer::SignerError;
@@ -821,5 +823,25 @@ mod tests {
821823
async fn cleanup(self) -> Result<(), BufferExecutionError> {
822824
Ok(())
823825
}
826+
827+
async fn fetch_rent_reimbursements(
828+
&self,
829+
pubkeys: &[Pubkey],
830+
) -> TaskInfoFetcherResult<Vec<Pubkey>> {
831+
Ok(pubkeys.iter().map(|_| Pubkey::new_unique()).collect())
832+
}
833+
834+
fn peek_commit_id(&self, _pubkey: &Pubkey) -> Option<u64> {
835+
None
836+
}
837+
838+
fn reset(&self, _: ResetType) {}
839+
840+
async fn get_base_account(
841+
&self,
842+
_pubkey: &Pubkey,
843+
) -> MagicBlockRpcClientResult<Option<Account>> {
844+
Ok(None) // AccountNotFound
845+
}
824846
}
825847
}

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

Lines changed: 93 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,9 @@ pub mod two_stage_executor;
66

77
use std::{mem, ops::ControlFlow, sync::Arc, time::Duration};
88

9+
#[cfg(any(test, feature = "dev-context-only-utils"))]
10+
mod null_task_info_fetcher;
11+
912
use async_trait::async_trait;
1013
use futures_util::future::{join, try_join_all};
1114
use log::{trace, warn};
@@ -22,8 +25,13 @@ use magicblock_rpc_client::{
2225
MagicBlockRpcClientError, MagicBlockSendTransactionConfig,
2326
MagicBlockSendTransactionOutcome, MagicblockRpcClient,
2427
};
28+
2529
use solana_keypair::Keypair;
2630
use solana_message::VersionedMessage;
31+
32+
#[cfg(any(test, feature = "dev-context-only-utils"))]
33+
pub use null_task_info_fetcher::*;
34+
2735
use solana_pubkey::Pubkey;
2836
use solana_rpc_client_api::config::RpcTransactionConfig;
2937
use solana_signature::Signature;
@@ -807,3 +815,88 @@ where
807815
try_join_all(cleanup_futs).await.map(|_| ())
808816
}
809817
}
818+
819+
#[cfg(test)]
820+
mod tests {
821+
use std::{collections::HashMap, sync::Arc};
822+
823+
use magicblock_rpc_client::MagicBlockRpcClientResult;
824+
use solana_account::Account;
825+
use solana_pubkey::Pubkey;
826+
827+
use crate::{
828+
intent_execution_manager::intent_scheduler::create_test_intent,
829+
intent_executor::{
830+
task_info_fetcher::{
831+
ResetType, TaskInfoFetcher, TaskInfoFetcherResult,
832+
},
833+
IntentExecutorImpl,
834+
},
835+
persist::IntentPersisterImpl,
836+
tasks::task_builder::{TaskBuilderImpl, TasksBuilder},
837+
transaction_preparator::TransactionPreparatorImpl,
838+
};
839+
840+
struct MockInfoFetcher;
841+
#[async_trait::async_trait]
842+
impl TaskInfoFetcher for MockInfoFetcher {
843+
async fn fetch_next_commit_ids(
844+
&self,
845+
pubkeys: &[Pubkey],
846+
) -> TaskInfoFetcherResult<HashMap<Pubkey, u64>> {
847+
Ok(pubkeys.iter().map(|pubkey| (*pubkey, 0)).collect())
848+
}
849+
850+
async fn fetch_rent_reimbursements(
851+
&self,
852+
pubkeys: &[Pubkey],
853+
) -> TaskInfoFetcherResult<Vec<Pubkey>> {
854+
Ok(pubkeys.iter().map(|_| Pubkey::new_unique()).collect())
855+
}
856+
857+
fn peek_commit_id(&self, _pubkey: &Pubkey) -> Option<u64> {
858+
Some(0)
859+
}
860+
861+
fn reset(&self, _: ResetType) {}
862+
863+
async fn get_base_account(
864+
&self,
865+
_pubkey: &Pubkey,
866+
) -> MagicBlockRpcClientResult<Option<Account>> {
867+
Ok(None) // AccountNotFound
868+
}
869+
}
870+
871+
#[tokio::test]
872+
async fn test_try_unite() {
873+
let pubkey = [Pubkey::new_unique()];
874+
let intent = create_test_intent(0, &pubkey);
875+
876+
let info_fetcher = Arc::new(MockInfoFetcher);
877+
let commit_task = TaskBuilderImpl::commit_tasks(
878+
&info_fetcher,
879+
&intent,
880+
&None::<IntentPersisterImpl>,
881+
)
882+
.await
883+
.unwrap();
884+
let finalize_task =
885+
TaskBuilderImpl::finalize_tasks(&info_fetcher, &intent)
886+
.await
887+
.unwrap();
888+
889+
let result = IntentExecutorImpl::<
890+
TransactionPreparatorImpl,
891+
MockInfoFetcher,
892+
>::try_unite_tasks(
893+
&commit_task,
894+
&finalize_task,
895+
&Pubkey::new_unique(),
896+
&None::<IntentPersisterImpl>,
897+
);
898+
899+
let strategy = result.unwrap().unwrap();
900+
assert!(strategy.lookup_tables_keys.is_empty());
901+
}
902+
}
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
use std::collections::HashMap;
2+
3+
use async_trait::async_trait;
4+
use magicblock_rpc_client::MagicBlockRpcClientResult;
5+
use solana_account::Account;
6+
use solana_pubkey::Pubkey;
7+
8+
use super::task_info_fetcher::{
9+
ResetType, TaskInfoFetcher, TaskInfoFetcherResult,
10+
};
11+
12+
pub struct NullTaskInfoFetcher;
13+
14+
#[async_trait]
15+
impl TaskInfoFetcher for NullTaskInfoFetcher {
16+
async fn fetch_next_commit_ids(
17+
&self,
18+
_pubkeys: &[Pubkey],
19+
) -> TaskInfoFetcherResult<HashMap<Pubkey, u64>> {
20+
Ok(Default::default())
21+
}
22+
23+
async fn fetch_rent_reimbursements(
24+
&self,
25+
_pubkeys: &[Pubkey],
26+
) -> TaskInfoFetcherResult<Vec<Pubkey>> {
27+
Ok(Default::default())
28+
}
29+
30+
fn peek_commit_id(&self, _pubkey: &Pubkey) -> Option<u64> {
31+
None
32+
}
33+
34+
fn reset(&self, _: ResetType) {}
35+
36+
async fn get_base_account(
37+
&self,
38+
_pubkey: &Pubkey,
39+
) -> MagicBlockRpcClientResult<Option<Account>> {
40+
Ok(None) // AccountNotFound
41+
}
42+
}

magicblock-committor-service/src/intent_executor/task_info_fetcher.rs

Lines changed: 1 addition & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -43,9 +43,7 @@ pub trait TaskInfoFetcher: Send + Sync + 'static {
4343
async fn get_base_account(
4444
&self,
4545
_pubkey: &Pubkey,
46-
) -> MagicBlockRpcClientResult<Option<Account>> {
47-
Ok(None) // AccountNotFound
48-
}
46+
) -> MagicBlockRpcClientResult<Option<Account>>;
4947
}
5048

5149
pub enum ResetType<'a> {
@@ -309,37 +307,3 @@ impl TaskInfoFetcherError {
309307
}
310308

311309
pub type TaskInfoFetcherResult<T, E = TaskInfoFetcherError> = Result<T, E>;
312-
313-
#[cfg(any(test, feature = "dev-context-only-utils"))]
314-
pub struct NullTaskInfoFetcher;
315-
316-
#[cfg(any(test, feature = "dev-context-only-utils"))]
317-
#[async_trait]
318-
impl TaskInfoFetcher for NullTaskInfoFetcher {
319-
async fn fetch_next_commit_ids(
320-
&self,
321-
_pubkeys: &[Pubkey],
322-
) -> TaskInfoFetcherResult<HashMap<Pubkey, u64>> {
323-
Ok(Default::default())
324-
}
325-
326-
async fn fetch_rent_reimbursements(
327-
&self,
328-
_pubkeys: &[Pubkey],
329-
) -> TaskInfoFetcherResult<Vec<Pubkey>> {
330-
Ok(Default::default())
331-
}
332-
333-
fn peek_commit_id(&self, _pubkey: &Pubkey) -> Option<u64> {
334-
None
335-
}
336-
337-
fn reset(&self, _: ResetType) {}
338-
339-
async fn get_base_account(
340-
&self,
341-
_pubkey: &Pubkey,
342-
) -> MagicBlockRpcClientResult<Option<Account>> {
343-
Ok(None) // AccountNotFound
344-
}
345-
}

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

Lines changed: 22 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -110,30 +110,23 @@ pub trait BaseTask: Send + Sync + DynClone + LabelValue {
110110

111111
dyn_clone::clone_trait_object!(BaseTask);
112112

113-
#[derive(Clone)]
114-
pub struct CommitTask {
115-
pub commit_id: u64,
116-
pub allow_undelegation: bool,
117-
pub committed_account: CommittedAccount,
118-
base_account: Option<Account>,
119-
force_commit_state: bool,
120-
}
113+
pub struct CommitTaskBuilder;
121114

122-
impl CommitTask {
115+
impl CommitTaskBuilder {
123116
// Accounts larger than COMMIT_STATE_SIZE_THRESHOLD, use CommitDiff to
124117
// reduce instruction size. Below this, commit is sent as CommitState.
125118
// Chose 256 as thresold seems good enough as it could hold 8 u32 fields
126119
// or 4 u64 fields.
127120
const COMMIT_STATE_SIZE_THRESHOLD: usize = 256;
128121

129-
pub async fn new<C: TaskInfoFetcher>(
122+
pub async fn create_commit_task<C: TaskInfoFetcher>(
130123
commit_id: u64,
131124
allow_undelegation: bool,
132125
committed_account: CommittedAccount,
133126
task_info_fetcher: &Arc<C>,
134-
) -> Self {
127+
) -> CommitTask {
135128
let base_account = if committed_account.account.data.len()
136-
> CommitTask::COMMIT_STATE_SIZE_THRESHOLD
129+
> CommitTaskBuilder::COMMIT_STATE_SIZE_THRESHOLD
137130
{
138131
match task_info_fetcher
139132
.get_base_account(&committed_account.pubkey)
@@ -155,19 +148,30 @@ impl CommitTask {
155148
None
156149
};
157150

158-
Self {
151+
CommitTask {
159152
commit_id,
160153
allow_undelegation,
161154
committed_account,
162155
base_account,
163156
force_commit_state: false,
164157
}
165158
}
159+
}
166160

161+
#[derive(Clone)]
162+
pub struct CommitTask {
163+
pub commit_id: u64,
164+
pub allow_undelegation: bool,
165+
pub committed_account: CommittedAccount,
166+
base_account: Option<Account>,
167+
force_commit_state: bool,
168+
}
169+
170+
impl CommitTask {
167171
pub fn is_commit_diff(&self) -> bool {
168172
!self.force_commit_state
169173
&& self.committed_account.account.data.len()
170-
> CommitTask::COMMIT_STATE_SIZE_THRESHOLD
174+
> CommitTaskBuilder::COMMIT_STATE_SIZE_THRESHOLD
171175
&& self.base_account.is_some()
172176
}
173177

@@ -420,7 +424,7 @@ mod serialization_safety_test {
420424
use solana_account::Account;
421425

422426
use crate::{
423-
intent_executor::task_info_fetcher::NullTaskInfoFetcher,
427+
intent_executor::NullTaskInfoFetcher,
424428
tasks::{
425429
args_task::{ArgsTask, ArgsTaskType},
426430
buffer_task::{BufferTask, BufferTaskType},
@@ -435,7 +439,7 @@ mod serialization_safety_test {
435439

436440
// Test Commit variant
437441
let commit_task: ArgsTask = ArgsTaskType::Commit(
438-
CommitTask::new(
442+
CommitTaskBuilder::create_commit_task(
439443
123,
440444
true,
441445
CommittedAccount {
@@ -499,7 +503,7 @@ mod serialization_safety_test {
499503

500504
let buffer_task =
501505
BufferTask::new_preparation_required(BufferTaskType::Commit(
502-
CommitTask::new(
506+
CommitTaskBuilder::create_commit_task(
503507
456,
504508
false,
505509
CommittedAccount {
@@ -527,7 +531,7 @@ mod serialization_safety_test {
527531
// Test BufferTask preparation
528532
let buffer_task =
529533
BufferTask::new_preparation_required(BufferTaskType::Commit(
530-
CommitTask::new(
534+
CommitTaskBuilder::create_commit_task(
531535
789,
532536
true,
533537
CommittedAccount {

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

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,8 @@ use crate::{
1717
persist::IntentPersister,
1818
tasks::{
1919
args_task::{ArgsTask, ArgsTaskType},
20-
BaseActionTask, BaseTask, CommitTask, FinalizeTask, UndelegateTask,
20+
BaseActionTask, BaseTask, CommitTaskBuilder, FinalizeTask,
21+
UndelegateTask,
2122
},
2223
};
2324

@@ -91,7 +92,7 @@ impl TasksBuilder for TaskBuilderImpl {
9192
.iter()
9293
.map(|account| async {
9394
let commit_id = *commit_ids.get(&account.pubkey).expect("CommitIdFetcher provide commit ids for all listed pubkeys, or errors!");
94-
let task = ArgsTaskType::Commit(CommitTask::new(
95+
let task = ArgsTaskType::Commit(CommitTaskBuilder::create_commit_task(
9596
commit_id,
9697
allow_undelegation,
9798
account.clone(),

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

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -387,6 +387,8 @@ mod tests {
387387
},
388388
persist::IntentPersisterImpl,
389389
tasks::{
390+
intent_executor::NullTaskInfoFetcher,
391+
persist::IntentPersisterImpl,
390392
task_builder::{TaskBuilderImpl, TasksBuilder},
391393
BaseActionTask, CommitTask, TaskStrategy, UndelegateTask,
392394
},
@@ -422,7 +424,7 @@ mod tests {
422424
data_size: usize,
423425
) -> ArgsTask {
424426
ArgsTask::new(ArgsTaskType::Commit(
425-
CommitTask::new(
427+
CommitTaskBuilder::create_commit_task(
426428
commit_id,
427429
false,
428430
CommittedAccount {

0 commit comments

Comments
 (0)