1- use dlp:: args:: CallHandlerArgs ;
1+ use dlp:: {
2+ args:: { CallHandlerArgs , CommitDiffArgs , CommitStateArgs } ,
3+ compute_diff,
4+ } ;
25use magicblock_metrics:: metrics:: LabelValue ;
6+ use solana_account:: ReadableAccount ;
37use solana_instruction:: { AccountMeta , Instruction } ;
48use solana_pubkey:: Pubkey ;
59
@@ -8,14 +12,15 @@ use crate::tasks::TaskStrategy;
812use crate :: tasks:: {
913 buffer_task:: { BufferTask , BufferTaskType } ,
1014 visitor:: Visitor ,
11- BaseActionTask , BaseTask , BaseTaskError , BaseTaskResult , CommitTask ,
12- FinalizeTask , PreparationState , TaskType , UndelegateTask ,
15+ BaseActionTask , BaseTask , BaseTaskError , BaseTaskResult , CommitDiffTask ,
16+ CommitTask , FinalizeTask , PreparationState , TaskType , UndelegateTask ,
1317} ;
1418
1519/// Task that will be executed on Base layer via arguments
1620#[ derive( Clone ) ]
1721pub enum ArgsTaskType {
1822 Commit ( CommitTask ) ,
23+ CommitDiff ( CommitDiffTask ) ,
1924 Finalize ( FinalizeTask ) ,
2025 Undelegate ( UndelegateTask ) , // Special action really
2126 BaseAction ( BaseActionTask ) ,
@@ -45,7 +50,39 @@ impl ArgsTask {
4550impl BaseTask for ArgsTask {
4651 fn instruction ( & self , validator : & Pubkey ) -> Instruction {
4752 match & self . task_type {
48- ArgsTaskType :: Commit ( value) => value. create_commit_ix ( validator) ,
53+ ArgsTaskType :: Commit ( value) => {
54+ let args = CommitStateArgs {
55+ nonce : value. commit_id ,
56+ lamports : value. committed_account . account . lamports ,
57+ data : value. committed_account . account . data . clone ( ) ,
58+ allow_undelegation : value. allow_undelegation ,
59+ } ;
60+ dlp:: instruction_builder:: commit_state (
61+ * validator,
62+ value. committed_account . pubkey ,
63+ value. committed_account . account . owner ,
64+ args,
65+ )
66+ }
67+ ArgsTaskType :: CommitDiff ( value) => {
68+ let args = CommitDiffArgs {
69+ nonce : value. commit_id ,
70+ lamports : value. committed_account . account . lamports ,
71+ diff : compute_diff (
72+ value. base_account . data ( ) ,
73+ value. committed_account . account . data ( ) ,
74+ )
75+ . to_vec ( ) ,
76+ allow_undelegation : value. allow_undelegation ,
77+ } ;
78+
79+ dlp:: instruction_builder:: commit_diff (
80+ * validator,
81+ value. committed_account . pubkey ,
82+ value. committed_account . account . owner ,
83+ args,
84+ )
85+ }
4986 ArgsTaskType :: Finalize ( value) => {
5087 dlp:: instruction_builder:: finalize (
5188 * validator,
@@ -89,21 +126,22 @@ impl BaseTask for ArgsTask {
89126 self : Box < Self > ,
90127 ) -> Result < Box < dyn BaseTask > , Box < dyn BaseTask > > {
91128 match self . task_type {
92- ArgsTaskType :: Commit ( mut value) if value. is_commit_diff ( ) => {
93- // TODO (snawaz): Currently, we do not support executing CommitDiff
94- // as BufferTask, which is why we're forcing CommitTask to use CommitState
95- // before converting this task into BufferTask. Once CommitDiff is supported
96- // by BufferTask, we do not have to force_commit_state and we can remove
97- // force_commit_state stuff, as it's essentially a downgrade.
98-
99- value. force_commit_state ( ) ;
129+ ArgsTaskType :: Commit ( value) => {
100130 Ok ( Box :: new ( BufferTask :: new_preparation_required (
101131 BufferTaskType :: Commit ( value) ,
102132 ) ) )
103133 }
104- ArgsTaskType :: Commit ( value) => {
134+ ArgsTaskType :: CommitDiff ( value) => {
135+ // TODO (snawaz): Currently, we do not support executing CommitDiff
136+ // as BufferTask, which is why we're forcing CommitDiffTask to become CommitTask
137+ // before converting this task into BufferTask. Once CommitDiff is supported
138+ // by BufferTask, we do not have to do this, as it's essentially a downgrade.
105139 Ok ( Box :: new ( BufferTask :: new_preparation_required (
106- BufferTaskType :: Commit ( value) ,
140+ BufferTaskType :: Commit ( CommitTask {
141+ commit_id : value. commit_id ,
142+ allow_undelegation : value. allow_undelegation ,
143+ committed_account : value. committed_account ,
144+ } ) ,
107145 ) ) )
108146 }
109147 ArgsTaskType :: BaseAction ( _)
@@ -132,6 +170,7 @@ impl BaseTask for ArgsTask {
132170 fn compute_units ( & self ) -> u32 {
133171 match & self . task_type {
134172 ArgsTaskType :: Commit ( _) => 70_000 ,
173+ ArgsTaskType :: CommitDiff ( _) => 70_000 ,
135174 ArgsTaskType :: BaseAction ( task) => task. action . compute_units ,
136175 ArgsTaskType :: Undelegate ( _) => 70_000 ,
137176 ArgsTaskType :: Finalize ( _) => 70_000 ,
@@ -146,6 +185,7 @@ impl BaseTask for ArgsTask {
146185 fn task_type ( & self ) -> TaskType {
147186 match & self . task_type {
148187 ArgsTaskType :: Commit ( _) => TaskType :: Commit ,
188+ ArgsTaskType :: CommitDiff ( _) => TaskType :: Commit ,
149189 ArgsTaskType :: BaseAction ( _) => TaskType :: Action ,
150190 ArgsTaskType :: Undelegate ( _) => TaskType :: Undelegate ,
151191 ArgsTaskType :: Finalize ( _) => TaskType :: Finalize ,
@@ -170,6 +210,7 @@ impl LabelValue for ArgsTask {
170210 fn value ( & self ) -> & str {
171211 match self . task_type {
172212 ArgsTaskType :: Commit ( _) => "args_commit" ,
213+ ArgsTaskType :: CommitDiff ( _) => "args_commit_diff" ,
173214 ArgsTaskType :: BaseAction ( _) => "args_action" ,
174215 ArgsTaskType :: Finalize ( _) => "args_finalize" ,
175216 ArgsTaskType :: Undelegate ( _) => "args_undelegate" ,
0 commit comments