Skip to content

Commit 70ad890

Browse files
committed
feat: Make TaskStrategy more granular
1 parent b72b7e3 commit 70ad890

File tree

5 files changed

+61
-53
lines changed

5 files changed

+61
-53
lines changed

magicblock-committor-service/src/persist/commit_persister.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -584,14 +584,14 @@ mod tests {
584584
persister.set_commit_id(1, &pubkey, 100).unwrap();
585585

586586
persister
587-
.set_commit_strategy(100, &pubkey, CommitStrategy::Args)
587+
.set_commit_strategy(100, &pubkey, CommitStrategy::StateArgs)
588588
.unwrap();
589589

590590
let updated = persister
591591
.get_commit_status_by_message(1, &pubkey)
592592
.unwrap()
593593
.unwrap();
594-
assert_eq!(updated.commit_strategy, CommitStrategy::Args);
594+
assert_eq!(updated.commit_strategy, CommitStrategy::StateArgs);
595595
}
596596

597597
#[test]

magicblock-committor-service/src/persist/db.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -769,7 +769,7 @@ mod tests {
769769
commit_type: CommitType::DataAccount,
770770
created_at: 1000,
771771
commit_status: CommitStatus::Pending,
772-
commit_strategy: CommitStrategy::Args,
772+
commit_strategy: CommitStrategy::StateArgs,
773773
last_retried_at: 1000,
774774
retries_count: 0,
775775
}
@@ -900,7 +900,7 @@ mod tests {
900900
let row = create_test_row(1, 100);
901901
db.insert_commit_status_rows(&[row.clone()]).unwrap();
902902

903-
let new_strategy = CommitStrategy::FromBuffer;
903+
let new_strategy = CommitStrategy::StateBuffer;
904904
db.set_commit_strategy(100, &row.pubkey, new_strategy)
905905
.unwrap();
906906

magicblock-committor-service/src/persist/types/commit_strategy.rs

Lines changed: 18 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -4,39 +4,39 @@ use crate::persist::error::CommitPersistError;
44
pub enum CommitStrategy {
55
/// Args without the use of a lookup table
66
#[default]
7-
Args,
7+
StateArgs,
88
/// Args with the use of a lookup table
9-
ArgsWithLookupTable,
9+
StateArgsWithLookupTable,
1010
/// Buffer and chunks which has the most overhead
11-
FromBuffer,
11+
StateBuffer,
1212
/// Buffer and chunks with the use of a lookup table
13-
FromBufferWithLookupTable,
13+
StateBufferWithLookupTable,
1414
}
1515

1616
impl CommitStrategy {
1717
pub fn args(use_lookup: bool) -> Self {
1818
if use_lookup {
19-
Self::ArgsWithLookupTable
19+
Self::StateArgsWithLookupTable
2020
} else {
21-
Self::Args
21+
Self::StateArgs
2222
}
2323
}
2424

2525
pub fn as_str(&self) -> &str {
2626
use CommitStrategy::*;
2727
match self {
28-
Args => "Args",
29-
ArgsWithLookupTable => "ArgsWithLookupTable",
30-
FromBuffer => "FromBuffer",
31-
FromBufferWithLookupTable => "FromBufferWithLookupTable",
28+
StateArgs => "StateArgs",
29+
StateArgsWithLookupTable => "StageArgsWithLookupTable",
30+
StateBuffer => "StageBuffer",
31+
StateBufferWithLookupTable => "StageBufferWithLookupTable",
3232
}
3333
}
3434

3535
pub fn uses_lookup(&self) -> bool {
3636
matches!(
3737
self,
38-
CommitStrategy::ArgsWithLookupTable
39-
| CommitStrategy::FromBufferWithLookupTable
38+
CommitStrategy::StateArgsWithLookupTable
39+
| CommitStrategy::StateBufferWithLookupTable
4040
)
4141
}
4242
}
@@ -45,10 +45,12 @@ impl TryFrom<&str> for CommitStrategy {
4545
type Error = CommitPersistError;
4646
fn try_from(value: &str) -> Result<Self, CommitPersistError> {
4747
match value {
48-
"Args" => Ok(Self::Args),
49-
"ArgsWithLookupTable" => Ok(Self::ArgsWithLookupTable),
50-
"FromBuffer" => Ok(Self::FromBuffer),
51-
"FromBufferWithLookupTable" => Ok(Self::FromBufferWithLookupTable),
48+
"StateArgs" => Ok(Self::StateArgs),
49+
"StateArgsWithLookupTable" => Ok(Self::StateArgsWithLookupTable),
50+
"StageBuffer" => Ok(Self::StateBuffer),
51+
"StageBufferWithLookupTable" => {
52+
Ok(Self::StateBufferWithLookupTable)
53+
}
5254
_ => Err(CommitPersistError::InvalidCommitStrategy(
5355
value.to_string(),
5456
)),

magicblock-committor-service/src/tasks/task_visitors/persistor_visitor.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -32,9 +32,9 @@ where
3232
};
3333

3434
let commit_strategy = if uses_lookup_tables {
35-
CommitStrategy::ArgsWithLookupTable
35+
CommitStrategy::StateArgsWithLookupTable
3636
} else {
37-
CommitStrategy::Args
37+
CommitStrategy::StateArgs
3838
};
3939

4040
if let Err(err) = self.persistor.set_commit_strategy(
@@ -57,9 +57,9 @@ where
5757
PersistorContext::PersistStrategy { uses_lookup_tables } => {
5858
let BufferTaskType::Commit(ref commit_task) = task.task_type;
5959
let commit_strategy = if uses_lookup_tables {
60-
CommitStrategy::FromBufferWithLookupTable
60+
CommitStrategy::StateBufferWithLookupTable
6161
} else {
62-
CommitStrategy::FromBuffer
62+
CommitStrategy::StateBuffer
6363
};
6464

6565
if let Err(err) = self.persistor.set_commit_strategy(

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

Lines changed: 35 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -66,42 +66,42 @@ fn expect_strategies(
6666
// # see the PR #575 for more context.
6767
#[tokio::test(flavor = "multi_thread", worker_threads = 2)]
6868
async fn test_ix_commit_single_account_100_bytes() {
69-
commit_single_account(100, CommitStrategy::Args, false).await;
69+
commit_single_account(100, CommitStrategy::StateArgs, false).await;
7070
}
7171

7272
// TODO (snawaz): use #[tokio::test] once CommitTask::new() stops using blocking RpcClient
7373
// # see the PR #575 for more context.
7474
#[tokio::test(flavor = "multi_thread", worker_threads = 2)]
7575
async fn test_ix_commit_single_account_100_bytes_and_undelegate() {
76-
commit_single_account(100, CommitStrategy::Args, true).await;
76+
commit_single_account(100, CommitStrategy::StateArgs, true).await;
7777
}
7878

7979
// TODO (snawaz): use #[tokio::test] once CommitTask::new() stops using blocking RpcClient
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::FromBuffer, false).await;
83+
commit_single_account(800, CommitStrategy::StateBuffer, 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::FromBuffer, true).await;
90+
commit_single_account(800, CommitStrategy::StateBuffer, 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::FromBuffer, false).await;
97+
commit_single_account(1024, CommitStrategy::StateBuffer, 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::FromBuffer, false).await;
104+
commit_single_account(10 * 1024, CommitStrategy::StateBuffer, false).await;
105105
}
106106

107107
async fn commit_single_account(
@@ -176,7 +176,7 @@ async fn test_ix_commit_two_accounts_1kb_2kb() {
176176
&[1024, 2048],
177177
1,
178178
false,
179-
expect_strategies(&[(CommitStrategy::Args, 2)]),
179+
expect_strategies(&[(CommitStrategy::StateArgs, 2)]),
180180
)
181181
.await;
182182
}
@@ -190,7 +190,7 @@ async fn test_ix_commit_two_accounts_512kb() {
190190
&[512, 512],
191191
1,
192192
false,
193-
expect_strategies(&[(CommitStrategy::Args, 2)]),
193+
expect_strategies(&[(CommitStrategy::StateArgs, 2)]),
194194
)
195195
.await;
196196
}
@@ -204,7 +204,7 @@ async fn test_ix_commit_three_accounts_512kb() {
204204
&[512, 512, 512],
205205
1,
206206
false,
207-
expect_strategies(&[(CommitStrategy::Args, 3)]),
207+
expect_strategies(&[(CommitStrategy::StateArgs, 3)]),
208208
)
209209
.await;
210210
}
@@ -218,7 +218,7 @@ async fn test_ix_commit_six_accounts_512kb() {
218218
&[512, 512, 512, 512, 512, 512],
219219
1,
220220
false,
221-
expect_strategies(&[(CommitStrategy::Args, 6)]),
221+
expect_strategies(&[(CommitStrategy::StateArgs, 6)]),
222222
)
223223
.await;
224224
}
@@ -232,7 +232,7 @@ async fn test_ix_commit_four_accounts_1kb_2kb_5kb_10kb_single_bundle() {
232232
&[1024, 2 * 1024, 5 * 1024, 10 * 1024],
233233
1,
234234
false,
235-
expect_strategies(&[(CommitStrategy::Args, 4)]),
235+
expect_strategies(&[(CommitStrategy::StateArgs, 4)]),
236236
)
237237
.await;
238238
}
@@ -241,8 +241,11 @@ async fn test_ix_commit_four_accounts_1kb_2kb_5kb_10kb_single_bundle() {
241241
// # see the PR #575 for more context.
242242
#[tokio::test(flavor = "multi_thread", worker_threads = 2)]
243243
async fn test_commit_20_accounts_1kb_bundle_size_2() {
244-
commit_20_accounts_1kb(2, expect_strategies(&[(CommitStrategy::Args, 20)]))
245-
.await;
244+
commit_20_accounts_1kb(
245+
2,
246+
expect_strategies(&[(CommitStrategy::StateArgs, 20)]),
247+
)
248+
.await;
246249
}
247250

248251
// TODO (snawaz): use #[tokio::test] once CommitTask::new() stops using blocking RpcClient
@@ -251,7 +254,7 @@ async fn test_commit_20_accounts_1kb_bundle_size_2() {
251254
async fn test_commit_5_accounts_1kb_bundle_size_3() {
252255
commit_5_accounts_1kb(
253256
3,
254-
expect_strategies(&[(CommitStrategy::Args, 5)]),
257+
expect_strategies(&[(CommitStrategy::StateArgs, 5)]),
255258
false,
256259
)
257260
.await;
@@ -265,8 +268,8 @@ async fn test_commit_5_accounts_1kb_bundle_size_3_undelegate_all() {
265268
3,
266269
expect_strategies(&[
267270
// Intent fits in 1 TX only with ALT, see IntentExecutorImpl::try_unite_tasks
268-
(CommitStrategy::FromBufferWithLookupTable, 3),
269-
(CommitStrategy::Args, 2),
271+
(CommitStrategy::StateBufferWithLookupTable, 3),
272+
(CommitStrategy::StateArgs, 2),
270273
]),
271274
true,
272275
)
@@ -280,8 +283,8 @@ async fn test_commit_5_accounts_1kb_bundle_size_4() {
280283
commit_5_accounts_1kb(
281284
4,
282285
expect_strategies(&[
283-
(CommitStrategy::Args, 1),
284-
(CommitStrategy::FromBufferWithLookupTable, 4),
286+
(CommitStrategy::StateArgs, 1),
287+
(CommitStrategy::StateBufferWithLookupTable, 4),
285288
]),
286289
false,
287290
)
@@ -295,8 +298,8 @@ async fn test_commit_5_accounts_1kb_bundle_size_4_undelegate_all() {
295298
commit_5_accounts_1kb(
296299
4,
297300
expect_strategies(&[
298-
(CommitStrategy::Args, 1),
299-
(CommitStrategy::FromBufferWithLookupTable, 4),
301+
(CommitStrategy::StateArgs, 1),
302+
(CommitStrategy::StateBufferWithLookupTable, 4),
300303
]),
301304
true,
302305
)
@@ -309,7 +312,7 @@ async fn test_commit_5_accounts_1kb_bundle_size_4_undelegate_all() {
309312
async fn test_commit_5_accounts_1kb_bundle_size_5_undelegate_all() {
310313
commit_5_accounts_1kb(
311314
5,
312-
expect_strategies(&[(CommitStrategy::FromBufferWithLookupTable, 5)]),
315+
expect_strategies(&[(CommitStrategy::StateBufferWithLookupTable, 5)]),
313316
true,
314317
)
315318
.await;
@@ -319,8 +322,11 @@ async fn test_commit_5_accounts_1kb_bundle_size_5_undelegate_all() {
319322
// # see the PR #575 for more context.
320323
#[tokio::test(flavor = "multi_thread", worker_threads = 2)]
321324
async fn test_commit_20_accounts_1kb_bundle_size_3() {
322-
commit_20_accounts_1kb(3, expect_strategies(&[(CommitStrategy::Args, 20)]))
323-
.await;
325+
commit_20_accounts_1kb(
326+
3,
327+
expect_strategies(&[(CommitStrategy::StateArgs, 20)]),
328+
)
329+
.await;
324330
}
325331

326332
// TODO (snawaz): use #[tokio::test] once CommitTask::new() stops using blocking RpcClient
@@ -329,7 +335,7 @@ async fn test_commit_20_accounts_1kb_bundle_size_3() {
329335
async fn test_commit_20_accounts_1kb_bundle_size_4() {
330336
commit_20_accounts_1kb(
331337
4,
332-
expect_strategies(&[(CommitStrategy::FromBufferWithLookupTable, 20)]),
338+
expect_strategies(&[(CommitStrategy::StateBufferWithLookupTable, 20)]),
333339
)
334340
.await;
335341
}
@@ -341,9 +347,9 @@ async fn test_commit_20_accounts_1kb_bundle_size_6() {
341347
commit_20_accounts_1kb(
342348
6,
343349
expect_strategies(&[
344-
(CommitStrategy::FromBufferWithLookupTable, 18),
350+
(CommitStrategy::StateBufferWithLookupTable, 18),
345351
// Two accounts don't make it into the bundles of size 6
346-
(CommitStrategy::Args, 2),
352+
(CommitStrategy::StateArgs, 2),
347353
]),
348354
)
349355
.await;
@@ -355,7 +361,7 @@ async fn test_commit_20_accounts_1kb_bundle_size_6() {
355361
async fn test_commit_20_accounts_1kb_bundle_size_20() {
356362
commit_20_accounts_1kb(
357363
20,
358-
expect_strategies(&[(CommitStrategy::FromBufferWithLookupTable, 20)]),
364+
expect_strategies(&[(CommitStrategy::StateBufferWithLookupTable, 20)]),
359365
)
360366
.await;
361367
}
@@ -369,7 +375,7 @@ async fn test_commit_8_accounts_1kb_bundle_size_8() {
369375
expect_strategies(&[
370376
// Four accounts don't make it into the bundles of size 8, but
371377
// that bundle also needs lookup tables
372-
(CommitStrategy::FromBufferWithLookupTable, 8),
378+
(CommitStrategy::StateBufferWithLookupTable, 8),
373379
]),
374380
)
375381
.await;
@@ -384,7 +390,7 @@ async fn test_commit_20_accounts_1kb_bundle_size_8() {
384390
expect_strategies(&[
385391
// Four accounts don't make it into the bundles of size 8, but
386392
// that bundle also needs lookup tables
387-
(CommitStrategy::FromBufferWithLookupTable, 20),
393+
(CommitStrategy::StateBufferWithLookupTable, 20),
388394
]),
389395
)
390396
.await;

0 commit comments

Comments
 (0)