Skip to content

Commit 9da0edd

Browse files
committed
Use TaskInfoFetcher
1 parent c07a177 commit 9da0edd

File tree

4 files changed

+66
-51
lines changed

4 files changed

+66
-51
lines changed

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

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@ use lru::LruCache;
1111
use magicblock_rpc_client::{MagicBlockRpcClientError, MagicblockRpcClient};
1212
use solana_pubkey::Pubkey;
1313

14+
use crate::tasks::account_fetcher::AccountFetcher;
15+
1416
const NUM_FETCH_RETRIES: NonZeroUsize =
1517
unsafe { NonZeroUsize::new_unchecked(5) };
1618
const MUTEX_POISONED_MSG: &str = "CacheTaskInfoFetcher mutex poisoned!";
@@ -35,6 +37,8 @@ pub trait TaskInfoFetcher: Send + Sync + 'static {
3537

3638
/// Resets cache for some or all accounts
3739
fn reset(&self, reset_type: ResetType);
40+
41+
fn new_account_fetcher(&self) -> AccountFetcher;
3842
}
3943

4044
pub enum ResetType<'a> {
@@ -262,6 +266,10 @@ impl TaskInfoFetcher for CacheTaskInfoFetcher {
262266
}
263267
}
264268
}
269+
270+
fn new_account_fetcher(&self) -> AccountFetcher {
271+
AccountFetcher::with_client(self.rpc_client.clone())
272+
}
265273
}
266274

267275
#[derive(thiserror::Error, Debug)]
Lines changed: 45 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -1,61 +1,64 @@
1+
use magicblock_rpc_client::{MagicBlockRpcClientResult, MagicblockRpcClient};
12
use solana_account::Account;
23
use solana_pubkey::Pubkey;
3-
use solana_rpc_client::nonblocking::rpc_client::RpcClient;
4-
use solana_sdk::commitment_config::CommitmentConfig;
54

65
//
76
// AccountFetcher is used by CommitTask
87
//
98
pub struct AccountFetcher {
10-
rpc_client: RpcClient,
9+
rpc_client: MagicblockRpcClient,
1110
}
1211

13-
impl Default for AccountFetcher {
14-
fn default() -> Self {
15-
Self::new()
16-
}
17-
}
12+
// impl Default for AccountFetcher {
13+
// fn default() -> Self {
14+
// Self::new()
15+
// }
16+
// }
1817

1918
impl AccountFetcher {
20-
pub fn new() -> Self {
21-
use crate::{config::ChainConfig, ComputeBudgetConfig};
22-
23-
#[cfg(feature = "dev-context-only-utils")]
24-
let chain_config =
25-
ChainConfig::local(ComputeBudgetConfig::new(1_000_000));
26-
27-
#[cfg(not(feature = "dev-context-only-utils"))]
28-
let chain_config = ChainConfig {
29-
rpc_uri: magicblock_config::MagicBlockConfig::parse_config()
30-
.config
31-
.accounts
32-
.remote
33-
.url
34-
.as_ref()
35-
.map(|url| url.to_string())
36-
.unwrap_or_else(|| {
37-
log::error!(
38-
"Remote URL not configured, falling back to mainnet"
39-
);
40-
"https://api.mainnet-beta.solana.com".to_string()
41-
}),
42-
..ChainConfig::mainnet(ComputeBudgetConfig::new(1_000_000))
43-
};
44-
45-
Self {
46-
rpc_client: RpcClient::new_with_commitment(
47-
chain_config.rpc_uri.to_string(),
48-
CommitmentConfig {
49-
commitment: chain_config.commitment,
50-
},
51-
),
52-
}
19+
// pub fn new() -> Self {
20+
// use crate::{config::ChainConfig, ComputeBudgetConfig};
21+
22+
// #[cfg(feature = "dev-context-only-utils")]
23+
// let chain_config =
24+
// ChainConfig::local(ComputeBudgetConfig::new(1_000_000));
25+
26+
// #[cfg(not(feature = "dev-context-only-utils"))]
27+
// let chain_config = ChainConfig {
28+
// rpc_uri: magicblock_config::MagicBlockConfig::parse_config()
29+
// .config
30+
// .accounts
31+
// .remote
32+
// .url
33+
// .as_ref()
34+
// .map(|url| url.to_string())
35+
// .unwrap_or_else(|| {
36+
// log::error!(
37+
// "Remote URL not configured, falling back to mainnet"
38+
// );
39+
// "https://api.mainnet-beta.solana.com".to_string()
40+
// }),
41+
// ..ChainConfig::mainnet(ComputeBudgetConfig::new(1_000_000))
42+
// };
43+
44+
// Self {
45+
// rpc_client: RpcClient::new_with_commitment(
46+
// chain_config.rpc_uri.to_string(),
47+
// CommitmentConfig {
48+
// commitment: chain_config.commitment,
49+
// },
50+
// ),
51+
// }
52+
// }
53+
54+
pub fn with_client(rpc_client: MagicblockRpcClient) -> Self {
55+
Self { rpc_client }
5356
}
5457

5558
pub async fn fetch_account(
5659
&self,
5760
pubkey: &Pubkey,
58-
) -> Result<Account, solana_rpc_client_api::client_error::Error> {
61+
) -> MagicBlockRpcClientResult<Option<Account>> {
5962
self.rpc_client.get_account(pubkey).await
6063
}
6164
}

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

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -136,7 +136,12 @@ impl CommitTask {
136136
.fetch_account(&committed_account.pubkey)
137137
.await
138138
{
139-
Ok(account) => Some(account),
139+
Ok(Some(account)) => Some(account),
140+
Ok(None) => {
141+
log::warn!("AccountNotFound for commit_diff, pubkey: {}, commit_id: {}, Falling back to commit_state.",
142+
committed_account.pubkey, commit_id);
143+
None
144+
}
140145
Err(e) => {
141146
log::warn!("Failed to fetch base account for commit diff, pubkey: {}, commit_id: {}, error: {}. Falling back to commit_state.",
142147
committed_account.pubkey, commit_id, e);

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

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@ use magicblock_program::magic_scheduled_base_intent::{
99
};
1010
use solana_pubkey::Pubkey;
1111

12-
use super::account_fetcher::AccountFetcher;
1312
use crate::{
1413
intent_executor::task_info_fetcher::{
1514
TaskInfoFetcher, TaskInfoFetcherError,
@@ -25,14 +24,14 @@ use crate::{
2524
pub trait TasksBuilder {
2625
// Creates tasks for commit stage
2726
async fn commit_tasks<C: TaskInfoFetcher, P: IntentPersister>(
28-
commit_id_fetcher: &Arc<C>,
27+
task_info_fetcher: &Arc<C>,
2928
base_intent: &ScheduledBaseIntent,
3029
persister: &Option<P>,
3130
) -> TaskBuilderResult<Vec<Box<dyn BaseTask>>>;
3231

3332
// Create tasks for finalize stage
3433
async fn finalize_tasks<C: TaskInfoFetcher>(
35-
info_fetcher: &Arc<C>,
34+
task_info_fetcher: &Arc<C>,
3635
base_intent: &ScheduledBaseIntent,
3736
) -> TaskBuilderResult<Vec<Box<dyn BaseTask>>>;
3837
}
@@ -45,7 +44,7 @@ pub struct TaskBuilderImpl;
4544
impl TasksBuilder for TaskBuilderImpl {
4645
/// Returns [`Task`]s for Commit stage
4746
async fn commit_tasks<C: TaskInfoFetcher, P: IntentPersister>(
48-
commit_id_fetcher: &Arc<C>,
47+
task_info_fetcher: &Arc<C>,
4948
base_intent: &ScheduledBaseIntent,
5049
persister: &Option<P>,
5150
) -> TaskBuilderResult<Vec<Box<dyn BaseTask>>> {
@@ -73,7 +72,7 @@ impl TasksBuilder for TaskBuilderImpl {
7372
.iter()
7473
.map(|account| account.pubkey)
7574
.collect::<Vec<_>>();
76-
let commit_ids = commit_id_fetcher
75+
let commit_ids = task_info_fetcher
7776
.fetch_next_commit_ids(&committed_pubkeys)
7877
.await
7978
.map_err(TaskBuilderError::CommitTasksBuildError)?;
@@ -95,7 +94,7 @@ impl TasksBuilder for TaskBuilderImpl {
9594
commit_id,
9695
allow_undelegation,
9796
account.clone(),
98-
AccountFetcher::new(),
97+
task_info_fetcher.new_account_fetcher(),
9998
).await);
10099

101100
Box::new(ArgsTask::new(task)) as Box<dyn BaseTask>
@@ -106,7 +105,7 @@ impl TasksBuilder for TaskBuilderImpl {
106105

107106
/// Returns [`Task`]s for Finalize stage
108107
async fn finalize_tasks<C: TaskInfoFetcher>(
109-
info_fetcher: &Arc<C>,
108+
task_info_fetcher: &Arc<C>,
110109
base_intent: &ScheduledBaseIntent,
111110
) -> TaskBuilderResult<Vec<Box<dyn BaseTask>>> {
112111
// Helper to create a finalize task
@@ -169,7 +168,7 @@ impl TasksBuilder for TaskBuilderImpl {
169168
.iter()
170169
.map(|account| account.pubkey)
171170
.collect::<Vec<_>>();
172-
let rent_reimbursements = info_fetcher
171+
let rent_reimbursements = task_info_fetcher
173172
.fetch_rent_reimbursements(&pubkeys)
174173
.await
175174
.map_err(TaskBuilderError::FinalizedTasksBuildError)?;

0 commit comments

Comments
 (0)