Skip to content

Commit 38a818a

Browse files
committed
Add CommitDiff to ArgsTaskType
1 parent 110e113 commit 38a818a

File tree

6 files changed

+118
-33
lines changed

6 files changed

+118
-33
lines changed

Cargo.lock

Lines changed: 28 additions & 6 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

magicblock-committor-service/src/tasks/args_task.rs

Lines changed: 54 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
use dlp::args::{CallHandlerArgs, CommitStateArgs};
1+
use dlp::args::{CallHandlerArgs, CommitDiffArgs, CommitStateArgs};
22
use solana_pubkey::Pubkey;
33
use solana_sdk::instruction::{AccountMeta, Instruction};
44

@@ -15,6 +15,7 @@ use crate::tasks::{
1515
#[derive(Clone)]
1616
pub enum ArgsTaskType {
1717
Commit(CommitTask),
18+
CommitDiff(CommitTask),
1819
Finalize(FinalizeTask),
1920
Undelegate(UndelegateTask), // Special action really
2021
BaseAction(BaseActionTask),
@@ -51,21 +52,51 @@ impl BaseTask for ArgsTask {
5152
data: value.committed_account.account.data.clone(),
5253
allow_undelegation: value.allow_undelegation,
5354
};
54-
if value.commit_diff {
55-
dlp::instruction_builder::commit_diff(
56-
*validator,
57-
value.committed_account.pubkey,
58-
value.committed_account.account.owner,
59-
args,
60-
)
61-
} else {
62-
dlp::instruction_builder::commit_state(
63-
*validator,
64-
value.committed_account.pubkey,
65-
value.committed_account.account.owner,
66-
args,
67-
)
68-
}
55+
dlp::instruction_builder::commit_state(
56+
*validator,
57+
value.committed_account.pubkey,
58+
value.committed_account.account.owner,
59+
args,
60+
)
61+
}
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+
//
87+
ArgsTaskType::CommitDiff(value) => {
88+
let args = CommitDiffArgs {
89+
nonce: value.commit_id,
90+
lamports: value.committed_account.account.lamports,
91+
diff: vec![], // compute diff for this field
92+
allow_undelegation: value.allow_undelegation,
93+
};
94+
dlp::instruction_builder::commit_diff(
95+
*validator,
96+
value.committed_account.pubkey,
97+
value.committed_account.account.owner,
98+
args,
99+
)
69100
}
70101
ArgsTaskType::Finalize(value) => {
71102
dlp::instruction_builder::finalize(
@@ -116,7 +147,8 @@ impl BaseTask for ArgsTask {
116147
BufferTaskType::Commit(value),
117148
)))
118149
}
119-
ArgsTaskType::BaseAction(_)
150+
ArgsTaskType::CommitDiff(_)
151+
| ArgsTaskType::BaseAction(_)
120152
| ArgsTaskType::Finalize(_)
121153
| ArgsTaskType::Undelegate(_) => Err(self),
122154
}
@@ -142,6 +174,7 @@ impl BaseTask for ArgsTask {
142174
fn compute_units(&self) -> u32 {
143175
match &self.task_type {
144176
ArgsTaskType::Commit(_) => 65_000,
177+
ArgsTaskType::CommitDiff(_) => 40_000,
145178
ArgsTaskType::BaseAction(task) => task.action.compute_units,
146179
ArgsTaskType::Undelegate(_) => 70_000,
147180
ArgsTaskType::Finalize(_) => 40_000,
@@ -156,6 +189,9 @@ impl BaseTask for ArgsTask {
156189
fn task_type(&self) -> TaskType {
157190
match &self.task_type {
158191
ArgsTaskType::Commit(_) => TaskType::Commit,
192+
// TODO (snawaz): What should we use here? Commit (in the sense of "category of task"), or add a
193+
// new variant "CommitDiff" to indicate a specific instruction?
194+
ArgsTaskType::CommitDiff(_) => TaskType::Commit,
159195
ArgsTaskType::BaseAction(_) => TaskType::Action,
160196
ArgsTaskType::Undelegate(_) => TaskType::Undelegate,
161197
ArgsTaskType::Finalize(_) => TaskType::Finalize,
@@ -168,6 +204,7 @@ impl BaseTask for ArgsTask {
168204
}
169205

170206
fn reset_commit_id(&mut self, commit_id: u64) {
207+
// TODO (snawaz): handle CommitDiff as well?
171208
let ArgsTaskType::Commit(commit_task) = &mut self.task_type else {
172209
return;
173210
};

magicblock-committor-service/src/tasks/mod.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,6 @@ dyn_clone::clone_trait_object!(BaseTask);
102102
pub struct CommitTask {
103103
pub commit_id: u64,
104104
pub allow_undelegation: bool,
105-
pub commit_diff: bool,
106105
pub committed_account: CommittedAccount,
107106
}
108107

magicblock-committor-service/src/tasks/task_builder.rs

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -97,12 +97,16 @@ impl TasksBuilder for TaskBuilderImpl {
9797
.iter()
9898
.map(|account| {
9999
let commit_id = *commit_ids.get(&account.pubkey).expect("CommitIdFetcher provide commit ids for all listed pubkeys, or errors!");
100-
let task = ArgsTaskType::Commit(CommitTask {
100+
let task = CommitTask {
101101
commit_id,
102102
allow_undelegation,
103-
commit_diff,
104103
committed_account: account.clone(),
105-
});
104+
};
105+
let task = if commit_diff {
106+
ArgsTaskType::CommitDiff(task)
107+
} else {
108+
ArgsTaskType::Commit(task)
109+
};
106110

107111
Box::new(ArgsTask::new(task)) as Box<dyn BaseTask>
108112
})

programs/magicblock/src/magic_scheduled_base_intent.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -298,6 +298,7 @@ impl BaseAction {
298298
}
299299

300300
type CommittedAccountRef<'a> = (Pubkey, &'a RefCell<AccountSharedData>);
301+
301302
#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
302303
pub struct CommittedAccount {
303304
pub pubkey: Pubkey,

test-integration/Cargo.lock

Lines changed: 28 additions & 6 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)