11use dlp:: args:: { CallHandlerArgs , CommitDiffArgs , CommitStateArgs } ;
2+ use solana_account:: ReadableAccount ;
23use solana_pubkey:: Pubkey ;
3- use solana_sdk:: instruction:: { AccountMeta , Instruction } ;
4+ use solana_rpc_client:: rpc_client:: RpcClient ;
5+ use solana_sdk:: {
6+ commitment_config:: CommitmentConfig ,
7+ instruction:: { AccountMeta , Instruction } ,
8+ } ;
49
510#[ cfg( test) ]
611use crate :: tasks:: TaskStrategy ;
7- use crate :: tasks:: {
8- buffer_task:: { BufferTask , BufferTaskType } ,
9- visitor:: Visitor ,
10- BaseActionTask , BaseTask , BaseTaskError , BaseTaskResult , CommitTask ,
11- FinalizeTask , PreparationState , TaskType , UndelegateTask ,
12+ use crate :: {
13+ config:: ChainConfig ,
14+ diff:: compute_diff,
15+ tasks:: {
16+ buffer_task:: { BufferTask , BufferTaskType } ,
17+ visitor:: Visitor ,
18+ BaseActionTask , BaseTask , BaseTaskError , BaseTaskResult , CommitTask ,
19+ FinalizeTask , PreparationState , TaskType , UndelegateTask ,
20+ } ,
21+ ComputeBudgetConfig ,
1222} ;
1323
1424/// Task that will be executed on Base layer via arguments
@@ -59,44 +69,63 @@ impl BaseTask for ArgsTask {
5969 args,
6070 )
6171 }
62- // algo:
63- // - delegated_account, prev
64- // - changed delegated_account
65- // - diff = prev - delegated_account
66- // - commit
67- // - prev = delegated_account
68- // - update cache with prev
69- //
70- // relevant files/modules/crates:
71- // -
72- // - https://docs.rs/scc/latest/scc/#hashcache
73- //
74- // diff:
75- // - [offset1][offset2]data
76- //
77- // 100
78- //
79- // 11..15
80- //
81- // 31...40
82- //
83- // - complete: [2] [5][11] [10][31] [11..15 31 ..40]
84- //
85- // - [3][8][11..15 31 ..40]
86- //
8772 ArgsTaskType :: CommitDiff ( value) => {
73+ let chain_config =
74+ ChainConfig :: local ( ComputeBudgetConfig :: new ( 1_000_000 ) ) ;
75+
76+ log:: info!(
77+ "Fetch account from the main chain: {}" ,
78+ value. committed_account. pubkey
79+ ) ;
80+ let rpc_client = RpcClient :: new_with_commitment (
81+ chain_config. rpc_uri . to_string ( ) ,
82+ CommitmentConfig {
83+ commitment : chain_config. commitment ,
84+ } ,
85+ ) ;
86+
87+ let account = match rpc_client
88+ . get_account ( & value. committed_account . pubkey )
89+ {
90+ Ok ( account) => {
91+ log:: info!( "Account Found: {:?}" , account) ;
92+ account
93+ }
94+ Err ( e) => {
95+ log:: error!( "error while receiving account: {}" , e) ;
96+ let args = CommitStateArgs {
97+ nonce : value. commit_id ,
98+ lamports : value. committed_account . account . lamports ,
99+ data : value. committed_account . account . data . clone ( ) ,
100+ allow_undelegation : value. allow_undelegation ,
101+ } ;
102+ return dlp:: instruction_builder:: commit_state (
103+ * validator,
104+ value. committed_account . pubkey ,
105+ value. committed_account . account . owner ,
106+ args,
107+ ) ;
108+ }
109+ } ;
88110 let args = CommitDiffArgs {
89111 nonce : value. commit_id ,
90112 lamports : value. committed_account . account . lamports ,
91- diff : vec ! [ ] , // compute diff for this field
113+ diff : compute_diff (
114+ //&vec![0; value.committed_account.account.data().len()],
115+ account. data ( ) ,
116+ value. committed_account . account . data ( ) ,
117+ ) ,
92118 allow_undelegation : value. allow_undelegation ,
93119 } ;
94- dlp:: instruction_builder:: commit_diff (
120+ log:: info!( "commit_diff: create instruction" ) ;
121+ let ix = dlp:: instruction_builder:: commit_diff (
95122 * validator,
96123 value. committed_account . pubkey ,
97124 value. committed_account . account . owner ,
98125 args,
99- )
126+ ) ;
127+ log:: info!( "commit_diff: created instruction" ) ;
128+ ix
100129 }
101130 ArgsTaskType :: Finalize ( value) => {
102131 dlp:: instruction_builder:: finalize (
@@ -147,8 +176,10 @@ impl BaseTask for ArgsTask {
147176 BufferTaskType :: Commit ( value) ,
148177 ) ) )
149178 }
150- ArgsTaskType :: CommitDiff ( _)
151- | ArgsTaskType :: BaseAction ( _)
179+ ArgsTaskType :: CommitDiff ( _) => {
180+ panic ! ( "ArgsTaskType::CommitDiff not handled" )
181+ }
182+ ArgsTaskType :: BaseAction ( _)
152183 | ArgsTaskType :: Finalize ( _)
153184 | ArgsTaskType :: Undelegate ( _) => Err ( self ) ,
154185 }
@@ -174,7 +205,7 @@ impl BaseTask for ArgsTask {
174205 fn compute_units ( & self ) -> u32 {
175206 match & self . task_type {
176207 ArgsTaskType :: Commit ( _) => 65_000 ,
177- ArgsTaskType :: CommitDiff ( _) => 40_000 ,
208+ ArgsTaskType :: CommitDiff ( _) => 65_000 ,
178209 ArgsTaskType :: BaseAction ( task) => task. action . compute_units ,
179210 ArgsTaskType :: Undelegate ( _) => 70_000 ,
180211 ArgsTaskType :: Finalize ( _) => 40_000 ,
@@ -191,7 +222,7 @@ impl BaseTask for ArgsTask {
191222 ArgsTaskType :: Commit ( _) => TaskType :: Commit ,
192223 // TODO (snawaz): What should we use here? Commit (in the sense of "category of task"), or add a
193224 // new variant "CommitDiff" to indicate a specific instruction?
194- ArgsTaskType :: CommitDiff ( _) => TaskType :: Commit ,
225+ ArgsTaskType :: CommitDiff ( _) => unimplemented ! ( "task_type" ) , // TaskType::Commit,
195226 ArgsTaskType :: BaseAction ( _) => TaskType :: Action ,
196227 ArgsTaskType :: Undelegate ( _) => TaskType :: Undelegate ,
197228 ArgsTaskType :: Finalize ( _) => TaskType :: Finalize ,
@@ -206,6 +237,7 @@ impl BaseTask for ArgsTask {
206237 fn reset_commit_id ( & mut self , commit_id : u64 ) {
207238 // TODO (snawaz): handle CommitDiff as well?
208239 let ArgsTaskType :: Commit ( commit_task) = & mut self . task_type else {
240+ log:: error!( "reset_commit_id" ) ;
209241 return ;
210242 } ;
211243
0 commit comments