1- use dlp:: args:: { CallHandlerArgs , CommitStateArgs } ;
1+ use dlp:: {
2+ args:: { CallHandlerArgs , CommitDiffArgs , CommitStateArgs } ,
3+ compute_diff,
4+ } ;
5+ use solana_account:: ReadableAccount ;
26use solana_pubkey:: Pubkey ;
3- use solana_sdk:: instruction:: { AccountMeta , Instruction } ;
7+ use solana_rpc_client:: rpc_client:: RpcClient ;
8+ use solana_sdk:: {
9+ commitment_config:: CommitmentConfig ,
10+ instruction:: { AccountMeta , Instruction } ,
11+ } ;
412
513#[ cfg( test) ]
614use 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 ,
15+ use crate :: {
16+ config:: ChainConfig ,
17+ tasks:: {
18+ buffer_task:: { BufferTask , BufferTaskType } ,
19+ visitor:: Visitor ,
20+ BaseActionTask , BaseTask , BaseTaskError , BaseTaskResult , CommitTask ,
21+ FinalizeTask , PreparationState , TaskType , UndelegateTask ,
22+ } ,
23+ ComputeBudgetConfig ,
1224} ;
1325
1426/// Task that will be executed on Base layer via arguments
1527#[ derive( Clone ) ]
1628pub enum ArgsTaskType {
1729 Commit ( CommitTask ) ,
30+ CommitDiff ( CommitTask ) ,
1831 Finalize ( FinalizeTask ) ,
1932 Undelegate ( UndelegateTask ) , // Special action really
2033 BaseAction ( BaseActionTask ) ,
@@ -58,6 +71,55 @@ impl BaseTask for ArgsTask {
5871 args,
5972 )
6073 }
74+ ArgsTaskType :: CommitDiff ( value) => {
75+ let chain_config =
76+ ChainConfig :: local ( ComputeBudgetConfig :: new ( 1_000_000 ) ) ;
77+
78+ let rpc_client = RpcClient :: new_with_commitment (
79+ chain_config. rpc_uri . to_string ( ) ,
80+ CommitmentConfig {
81+ commitment : chain_config. commitment ,
82+ } ,
83+ ) ;
84+
85+ let account = match rpc_client
86+ . get_account ( & value. committed_account . pubkey )
87+ {
88+ Ok ( account) => account,
89+ Err ( e) => {
90+ log:: warn!( "Fallback to commit_state and send full-bytes, as rpc failed to fetch the delegated-account from base chain: {}" , e) ;
91+ let args = CommitStateArgs {
92+ nonce : value. commit_id ,
93+ lamports : value. committed_account . account . lamports ,
94+ data : value. committed_account . account . data . clone ( ) ,
95+ allow_undelegation : value. allow_undelegation ,
96+ } ;
97+ return dlp:: instruction_builder:: commit_state (
98+ * validator,
99+ value. committed_account . pubkey ,
100+ value. committed_account . account . owner ,
101+ args,
102+ ) ;
103+ }
104+ } ;
105+
106+ let args = CommitDiffArgs {
107+ nonce : value. commit_id ,
108+ lamports : value. committed_account . account . lamports ,
109+ diff : compute_diff (
110+ account. data ( ) ,
111+ value. committed_account . account . data ( ) ,
112+ ) ,
113+ allow_undelegation : value. allow_undelegation ,
114+ } ;
115+ log:: warn!( "DIFF computed: {:?}" , args. diff) ;
116+ dlp:: instruction_builder:: commit_diff (
117+ * validator,
118+ value. committed_account . pubkey ,
119+ value. committed_account . account . owner ,
120+ args,
121+ )
122+ }
61123 ArgsTaskType :: Finalize ( value) => {
62124 dlp:: instruction_builder:: finalize (
63125 * validator,
@@ -106,6 +168,9 @@ impl BaseTask for ArgsTask {
106168 BufferTaskType :: Commit ( value) ,
107169 ) ) )
108170 }
171+ ArgsTaskType :: CommitDiff ( _) => {
172+ panic ! ( "ArgsTaskType::CommitDiff not handled" )
173+ }
109174 ArgsTaskType :: BaseAction ( _)
110175 | ArgsTaskType :: Finalize ( _)
111176 | ArgsTaskType :: Undelegate ( _) => Err ( self ) ,
@@ -132,6 +197,7 @@ impl BaseTask for ArgsTask {
132197 fn compute_units ( & self ) -> u32 {
133198 match & self . task_type {
134199 ArgsTaskType :: Commit ( _) => 65_000 ,
200+ ArgsTaskType :: CommitDiff ( _) => 65_000 ,
135201 ArgsTaskType :: BaseAction ( task) => task. action . compute_units ,
136202 ArgsTaskType :: Undelegate ( _) => 70_000 ,
137203 ArgsTaskType :: Finalize ( _) => 40_000 ,
@@ -146,6 +212,9 @@ impl BaseTask for ArgsTask {
146212 fn task_type ( & self ) -> TaskType {
147213 match & self . task_type {
148214 ArgsTaskType :: Commit ( _) => TaskType :: Commit ,
215+ // TODO (snawaz): What should we use here? Commit (in the sense of "category of task"), or add a
216+ // new variant "CommitDiff" to indicate a specific instruction?
217+ ArgsTaskType :: CommitDiff ( _) => TaskType :: Commit ,
149218 ArgsTaskType :: BaseAction ( _) => TaskType :: Action ,
150219 ArgsTaskType :: Undelegate ( _) => TaskType :: Undelegate ,
151220 ArgsTaskType :: Finalize ( _) => TaskType :: Finalize ,
@@ -158,7 +227,9 @@ impl BaseTask for ArgsTask {
158227 }
159228
160229 fn reset_commit_id ( & mut self , commit_id : u64 ) {
230+ // TODO (snawaz): handle CommitDiff as well?
161231 let ArgsTaskType :: Commit ( commit_task) = & mut self . task_type else {
232+ log:: error!( "reset_commit_id" ) ;
162233 return ;
163234 } ;
164235
0 commit comments