1- use dlp:: {
2- args:: { CallHandlerArgs , CommitDiffArgs , CommitStateArgs } ,
3- compute_diff,
4- } ;
5- use solana_account:: ReadableAccount ;
1+ use dlp:: args:: CallHandlerArgs ;
62use solana_pubkey:: Pubkey ;
7- use solana_rpc_client:: rpc_client:: RpcClient ;
8- use solana_sdk:: {
9- commitment_config:: CommitmentConfig ,
10- instruction:: { AccountMeta , Instruction } ,
11- } ;
3+ use solana_sdk:: instruction:: { AccountMeta , Instruction } ;
124
135#[ cfg( test) ]
146use crate :: tasks:: TaskStrategy ;
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 ,
7+ use crate :: tasks:: {
8+ buffer_task:: { BufferTask , BufferTaskType } ,
9+ visitor:: Visitor ,
10+ BaseActionTask , BaseTask , BaseTaskError , BaseTaskResult , CommitTask ,
11+ FinalizeTask , PreparationState , TaskType , UndelegateTask ,
2412} ;
2513
2614/// Task that will be executed on Base layer via arguments
2715#[ derive( Clone ) ]
2816pub enum ArgsTaskType {
2917 Commit ( CommitTask ) ,
30- CommitDiff ( CommitTask ) ,
3118 Finalize ( FinalizeTask ) ,
3219 Undelegate ( UndelegateTask ) , // Special action really
3320 BaseAction ( BaseActionTask ) ,
@@ -57,69 +44,7 @@ impl ArgsTask {
5744impl BaseTask for ArgsTask {
5845 fn instruction ( & self , validator : & Pubkey ) -> Instruction {
5946 match & self . task_type {
60- ArgsTaskType :: Commit ( value) => {
61- let args = CommitStateArgs {
62- nonce : value. commit_id ,
63- lamports : value. committed_account . account . lamports ,
64- data : value. committed_account . account . data . clone ( ) ,
65- allow_undelegation : value. allow_undelegation ,
66- } ;
67- dlp:: instruction_builder:: commit_state (
68- * validator,
69- value. committed_account . pubkey ,
70- value. committed_account . account . owner ,
71- args,
72- )
73- }
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, commmit_id: {} , error: {}" , value. commit_id, 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- . to_vec ( ) ,
114- allow_undelegation : value. allow_undelegation ,
115- } ;
116- dlp:: instruction_builder:: commit_diff (
117- * validator,
118- value. committed_account . pubkey ,
119- value. committed_account . account . owner ,
120- args,
121- )
122- }
47+ ArgsTaskType :: Commit ( value) => value. create_commit_ix ( validator) ,
12348 ArgsTaskType :: Finalize ( value) => {
12449 dlp:: instruction_builder:: finalize (
12550 * validator,
@@ -163,13 +88,23 @@ impl BaseTask for ArgsTask {
16388 self : Box < Self > ,
16489 ) -> Result < Box < dyn BaseTask > , Box < dyn BaseTask > > {
16590 match self . task_type {
91+ ArgsTaskType :: Commit ( mut value) if value. is_commit_diff ( ) => {
92+ // TODO (snawaz): Currently, we do not support executing CommitDiff
93+ // as BufferTask, which is why we're forcing CommitTask to use CommitState
94+ // before converting this task into BufferTask Once CommitDiff is supported
95+ // by BufferTask, we do not have to force_commit_state and we can remove
96+ // force_commit_state stuff, as it's essentially a downgrade.
97+
98+ value. force_commit_state ( ) ;
99+ Ok ( Box :: new ( BufferTask :: new_preparation_required (
100+ BufferTaskType :: Commit ( value) ,
101+ ) ) )
102+ }
166103 ArgsTaskType :: Commit ( value) => {
167104 Ok ( Box :: new ( BufferTask :: new_preparation_required (
168105 BufferTaskType :: Commit ( value) ,
169106 ) ) )
170107 }
171- // TODO (snawaz): discuss this with reviewers
172- ArgsTaskType :: CommitDiff ( _) => Err ( self ) ,
173108 ArgsTaskType :: BaseAction ( _)
174109 | ArgsTaskType :: Finalize ( _)
175110 | ArgsTaskType :: Undelegate ( _) => Err ( self ) ,
@@ -196,7 +131,6 @@ impl BaseTask for ArgsTask {
196131 fn compute_units ( & self ) -> u32 {
197132 match & self . task_type {
198133 ArgsTaskType :: Commit ( _) => 70_000 ,
199- ArgsTaskType :: CommitDiff ( _) => 65_000 ,
200134 ArgsTaskType :: BaseAction ( task) => task. action . compute_units ,
201135 ArgsTaskType :: Undelegate ( _) => 70_000 ,
202136 ArgsTaskType :: Finalize ( _) => 70_000 ,
@@ -211,9 +145,6 @@ impl BaseTask for ArgsTask {
211145 fn task_type ( & self ) -> TaskType {
212146 match & self . task_type {
213147 ArgsTaskType :: Commit ( _) => TaskType :: Commit ,
214- // TODO (snawaz): What should we use here? Commit (in the sense of "category of task"), or add a
215- // new variant "CommitDiff" to indicate a specific instruction?
216- ArgsTaskType :: CommitDiff ( _) => TaskType :: Commit ,
217148 ArgsTaskType :: BaseAction ( _) => TaskType :: Action ,
218149 ArgsTaskType :: Undelegate ( _) => TaskType :: Undelegate ,
219150 ArgsTaskType :: Finalize ( _) => TaskType :: Finalize ,
@@ -226,7 +157,6 @@ impl BaseTask for ArgsTask {
226157 }
227158
228159 fn reset_commit_id ( & mut self , commit_id : u64 ) {
229- // TODO (snawaz): handle CommitDiff as well? what is it about?
230160 let ArgsTaskType :: Commit ( commit_task) = & mut self . task_type else {
231161 return ;
232162 } ;
0 commit comments