@@ -19,15 +19,10 @@ use magicblock_program::magic_scheduled_base_intent::{
1919} ;
2020use solana_account:: { Account , ReadableAccount } ;
2121use solana_pubkey:: Pubkey ;
22- use solana_rpc_client:: rpc_client:: RpcClient ;
23- use solana_sdk:: {
24- commitment_config:: CommitmentConfig , instruction:: Instruction ,
25- } ;
22+ use solana_sdk:: instruction:: Instruction ;
2623use thiserror:: Error ;
2724
28- use crate :: {
29- config:: ChainConfig , tasks:: visitor:: Visitor , ComputeBudgetConfig ,
30- } ;
25+ use crate :: tasks:: visitor:: Visitor ;
3126
3227pub mod args_task;
3328pub mod buffer_task;
@@ -114,7 +109,7 @@ pub struct CommitTask {
114109 pub commit_id : u64 ,
115110 pub allow_undelegation : bool ,
116111 pub committed_account : CommittedAccount ,
117- fetched_account : Option < Account > ,
112+ base_account : Option < Account > ,
118113}
119114
120115impl CommitTask {
@@ -125,43 +120,49 @@ impl CommitTask {
125120 allow_undelegation : bool ,
126121 committed_account : CommittedAccount ,
127122 ) -> Self {
128- let chain_config =
129- ChainConfig :: local ( ComputeBudgetConfig :: new ( 1_000_000 ) ) ;
130-
131- let rpc_client = RpcClient :: new_with_commitment (
132- chain_config. rpc_uri . to_string ( ) ,
133- CommitmentConfig {
134- commitment : chain_config. commitment ,
135- } ,
136- ) ;
137-
138123 let fetched_account = if committed_account. account . data . len ( )
139124 > CommitTask :: COMMIT_STATE_SIZE_THRESHOLD
140125 {
126+ // TODO (snawaz): it is the most ugliest piece of code as it is making network call,
127+ // and I'll soon fix it in a separate PR that will use caching of base-accounts.
128+ use solana_rpc_client:: rpc_client:: RpcClient ;
129+ use solana_sdk:: commitment_config:: CommitmentConfig ;
130+
131+ use crate :: { config:: ChainConfig , ComputeBudgetConfig } ;
132+
133+ let chain_config =
134+ ChainConfig :: local ( ComputeBudgetConfig :: new ( 1_000_000 ) ) ;
135+
136+ let rpc_client = RpcClient :: new_with_commitment (
137+ chain_config. rpc_uri . to_string ( ) ,
138+ CommitmentConfig {
139+ commitment : chain_config. commitment ,
140+ } ,
141+ ) ;
142+
141143 rpc_client. get_account ( & committed_account. pubkey ) . ok ( )
142144 } else {
143145 None
144146 } ;
145147
148+ println ! ( "fetched_account: {:#?}" , fetched_account) ;
149+
146150 Self {
147151 commit_id,
148152 allow_undelegation,
149153 committed_account,
150- fetched_account,
154+ base_account : fetched_account,
151155 }
152156 }
153157
154- // TODO (snawaz): it is infinitely bad implementation
155- // as it's making a network call, but we'll fix it soon once
156- // we start using caching and fetched accounts.
157158 pub fn is_commit_diff ( & self ) -> bool {
158159 self . committed_account . account . data . len ( )
159160 > CommitTask :: COMMIT_STATE_SIZE_THRESHOLD
160- && self . fetched_account . is_some ( )
161+ && self . base_account . is_some ( )
161162 }
162163
163164 pub fn create_commit_ix ( & self , validator : & Pubkey ) -> Instruction {
164- if let Some ( fetched_account) = self . fetched_account . as_ref ( ) {
165+ if let Some ( fetched_account) = self . base_account . as_ref ( ) {
165166 self . create_commit_diff_ix ( validator, fetched_account)
166167 } else {
167168 self . create_commit_state_ix ( validator)
0 commit comments