Skip to content

Commit fb096a7

Browse files
committed
Add force_commit_state
1 parent 9ed65ad commit fb096a7

File tree

3 files changed

+31
-11
lines changed

3 files changed

+31
-11
lines changed

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

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -88,9 +88,15 @@ impl BaseTask for ArgsTask {
8888
self: Box<Self>,
8989
) -> Result<Box<dyn BaseTask>, Box<dyn BaseTask>> {
9090
match self.task_type {
91-
ArgsTaskType::Commit(ref value) if value.is_commit_diff() => {
92-
// We do not currently support executing CommitDiff as BufferTask
93-
Err(self)
91+
ArgsTaskType::Commit(mut value) if value.is_commit_diff() => {
92+
//TODO (snawaz): We do not currently support executing CommitDiff as BufferTask, which is why we're forcing CommitTask to use CommitState before converting this task into BufferTask
93+
// Once CommitDiff is supported by BufferTask, we do not have to
94+
// force_commit_state.
95+
96+
value.force_commit_state();
97+
Ok(Box::new(BufferTask::new_preparation_required(
98+
BufferTaskType::Commit(value),
99+
)))
94100
}
95101
ArgsTaskType::Commit(value) => {
96102
Ok(Box::new(BufferTask::new_preparation_required(

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

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -110,6 +110,7 @@ pub struct CommitTask {
110110
pub allow_undelegation: bool,
111111
pub committed_account: CommittedAccount,
112112
base_account: Option<Account>,
113+
force_commit_state: bool,
113114
}
114115

115116
impl CommitTask {
@@ -152,15 +153,21 @@ impl CommitTask {
152153
allow_undelegation,
153154
committed_account,
154155
base_account: fetched_account,
156+
force_commit_state: false,
155157
}
156158
}
157159

158160
pub fn is_commit_diff(&self) -> bool {
159-
self.committed_account.account.data.len()
160-
> CommitTask::COMMIT_STATE_SIZE_THRESHOLD
161+
!self.force_commit_state
162+
&& self.committed_account.account.data.len()
163+
> CommitTask::COMMIT_STATE_SIZE_THRESHOLD
161164
&& self.base_account.is_some()
162165
}
163166

167+
pub fn force_commit_state(&mut self) {
168+
self.force_commit_state = true;
169+
}
170+
164171
pub fn create_commit_ix(&self, validator: &Pubkey) -> Instruction {
165172
if let Some(fetched_account) = self.base_account.as_ref() {
166173
self.create_commit_diff_ix(validator, fetched_account)
@@ -190,6 +197,13 @@ impl CommitTask {
190197
validator: &Pubkey,
191198
fetched_account: &Account,
192199
) -> Instruction {
200+
if self.force_commit_state {
201+
println!(
202+
"force_commit_state is true, so call create_commit_state_ix"
203+
);
204+
return self.create_commit_state_ix(validator);
205+
}
206+
193207
let args = CommitDiffArgs {
194208
nonce: self.commit_id,
195209
lamports: self.committed_account.account.lamports,

test-integration/test-committor-service/tests/test_ix_commit_local.rs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -80,28 +80,28 @@ async fn test_ix_commit_single_account_100_bytes_and_undelegate() {
8080
// # see the PR #575 for more context.
8181
#[tokio::test(flavor = "multi_thread", worker_threads = 2)]
8282
async fn test_ix_commit_single_account_800_bytes() {
83-
commit_single_account(800, CommitStrategy::Args, false).await;
83+
commit_single_account(800, CommitStrategy::FromBuffer, false).await;
8484
}
8585

8686
// TODO (snawaz): use #[tokio::test] once CommitTask::new() stops using blocking RpcClient
8787
// # see the PR #575 for more context.
8888
#[tokio::test(flavor = "multi_thread", worker_threads = 2)]
8989
async fn test_ix_commit_single_account_800_bytes_and_undelegate() {
90-
commit_single_account(800, CommitStrategy::Args, true).await;
90+
commit_single_account(800, CommitStrategy::FromBuffer, true).await;
9191
}
9292

9393
// TODO (snawaz): use #[tokio::test] once CommitTask::new() stops using blocking RpcClient
9494
// # see the PR #575 for more context.
9595
#[tokio::test(flavor = "multi_thread", worker_threads = 2)]
9696
async fn test_ix_commit_single_account_one_kb() {
97-
commit_single_account(1024, CommitStrategy::Args, false).await;
97+
commit_single_account(1024, CommitStrategy::FromBuffer, false).await;
9898
}
9999

100100
// TODO (snawaz): use #[tokio::test] once CommitTask::new() stops using blocking RpcClient
101101
// # see the PR #575 for more context.
102102
#[tokio::test(flavor = "multi_thread", worker_threads = 2)]
103103
async fn test_ix_commit_single_account_ten_kb() {
104-
commit_single_account(10 * 1024, CommitStrategy::Args, false).await;
104+
commit_single_account(10 * 1024, CommitStrategy::FromBuffer, false).await;
105105
}
106106

107107
async fn commit_single_account(
@@ -265,7 +265,7 @@ async fn test_commit_5_accounts_1kb_bundle_size_3_undelegate_all() {
265265
3,
266266
expect_strategies(&[
267267
// Intent fits in 1 TX only with ALT, see IntentExecutorImpl::try_unite_tasks
268-
(CommitStrategy::ArgsWithLookupTable, 3),
268+
(CommitStrategy::FromBufferWithLookupTable, 3),
269269
(CommitStrategy::Args, 2),
270270
]),
271271
true,
@@ -309,7 +309,7 @@ async fn test_commit_5_accounts_1kb_bundle_size_4_undelegate_all() {
309309
async fn test_commit_5_accounts_1kb_bundle_size_5_undelegate_all() {
310310
commit_5_accounts_1kb(
311311
5,
312-
expect_strategies(&[(CommitStrategy::ArgsWithLookupTable, 5)]),
312+
expect_strategies(&[(CommitStrategy::FromBufferWithLookupTable, 5)]),
313313
true,
314314
)
315315
.await;

0 commit comments

Comments
 (0)