Skip to content

Commit 9dfa9a2

Browse files
committed
feat: Make TaskStrategy more granular
1 parent ec0d2f5 commit 9dfa9a2

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
@@ -64,32 +64,32 @@ fn expect_strategies(
6464

6565
#[tokio::test]
6666
async fn test_ix_commit_single_account_100_bytes() {
67-
commit_single_account(100, CommitStrategy::Args, false).await;
67+
commit_single_account(100, CommitStrategy::StateArgs, false).await;
6868
}
6969

7070
#[tokio::test]
7171
async fn test_ix_commit_single_account_100_bytes_and_undelegate() {
72-
commit_single_account(100, CommitStrategy::Args, true).await;
72+
commit_single_account(100, CommitStrategy::StateArgs, true).await;
7373
}
7474

7575
#[tokio::test]
7676
async fn test_ix_commit_single_account_800_bytes() {
77-
commit_single_account(800, CommitStrategy::FromBuffer, false).await;
77+
commit_single_account(800, CommitStrategy::StateBuffer, false).await;
7878
}
7979

8080
#[tokio::test]
8181
async fn test_ix_commit_single_account_800_bytes_and_undelegate() {
82-
commit_single_account(800, CommitStrategy::FromBuffer, true).await;
82+
commit_single_account(800, CommitStrategy::StateBuffer, true).await;
8383
}
8484

8585
#[tokio::test]
8686
async fn test_ix_commit_single_account_one_kb() {
87-
commit_single_account(1024, CommitStrategy::FromBuffer, false).await;
87+
commit_single_account(1024, CommitStrategy::StateBuffer, false).await;
8888
}
8989

9090
#[tokio::test]
9191
async fn test_ix_commit_single_account_ten_kb() {
92-
commit_single_account(10 * 1024, CommitStrategy::FromBuffer, false).await;
92+
commit_single_account(10 * 1024, CommitStrategy::StateBuffer, false).await;
9393
}
9494

9595
async fn commit_single_account(
@@ -162,7 +162,7 @@ async fn test_ix_commit_two_accounts_1kb_2kb() {
162162
&[1024, 2048],
163163
1,
164164
false,
165-
expect_strategies(&[(CommitStrategy::Args, 2)]),
165+
expect_strategies(&[(CommitStrategy::StateArgs, 2)]),
166166
)
167167
.await;
168168
}
@@ -174,7 +174,7 @@ async fn test_ix_commit_two_accounts_512kb() {
174174
&[512, 512],
175175
1,
176176
false,
177-
expect_strategies(&[(CommitStrategy::Args, 2)]),
177+
expect_strategies(&[(CommitStrategy::StateArgs, 2)]),
178178
)
179179
.await;
180180
}
@@ -186,7 +186,7 @@ async fn test_ix_commit_three_accounts_512kb() {
186186
&[512, 512, 512],
187187
1,
188188
false,
189-
expect_strategies(&[(CommitStrategy::Args, 3)]),
189+
expect_strategies(&[(CommitStrategy::StateArgs, 3)]),
190190
)
191191
.await;
192192
}
@@ -198,7 +198,7 @@ async fn test_ix_commit_six_accounts_512kb() {
198198
&[512, 512, 512, 512, 512, 512],
199199
1,
200200
false,
201-
expect_strategies(&[(CommitStrategy::Args, 6)]),
201+
expect_strategies(&[(CommitStrategy::StateArgs, 6)]),
202202
)
203203
.await;
204204
}
@@ -210,22 +210,25 @@ async fn test_ix_commit_four_accounts_1kb_2kb_5kb_10kb_single_bundle() {
210210
&[1024, 2 * 1024, 5 * 1024, 10 * 1024],
211211
1,
212212
false,
213-
expect_strategies(&[(CommitStrategy::Args, 4)]),
213+
expect_strategies(&[(CommitStrategy::StateArgs, 4)]),
214214
)
215215
.await;
216216
}
217217

218218
#[tokio::test]
219219
async fn test_commit_20_accounts_1kb_bundle_size_2() {
220-
commit_20_accounts_1kb(2, expect_strategies(&[(CommitStrategy::Args, 20)]))
221-
.await;
220+
commit_20_accounts_1kb(
221+
2,
222+
expect_strategies(&[(CommitStrategy::StateArgs, 20)]),
223+
)
224+
.await;
222225
}
223226

224227
#[tokio::test]
225228
async fn test_commit_5_accounts_1kb_bundle_size_3() {
226229
commit_5_accounts_1kb(
227230
3,
228-
expect_strategies(&[(CommitStrategy::Args, 5)]),
231+
expect_strategies(&[(CommitStrategy::StateArgs, 5)]),
229232
false,
230233
)
231234
.await;
@@ -237,8 +240,8 @@ async fn test_commit_5_accounts_1kb_bundle_size_3_undelegate_all() {
237240
3,
238241
expect_strategies(&[
239242
// Intent fits in 1 TX only with ALT, see IntentExecutorImpl::try_unite_tasks
240-
(CommitStrategy::FromBufferWithLookupTable, 3),
241-
(CommitStrategy::Args, 2),
243+
(CommitStrategy::StateBufferWithLookupTable, 3),
244+
(CommitStrategy::StateArgs, 2),
242245
]),
243246
true,
244247
)
@@ -250,8 +253,8 @@ async fn test_commit_5_accounts_1kb_bundle_size_4() {
250253
commit_5_accounts_1kb(
251254
4,
252255
expect_strategies(&[
253-
(CommitStrategy::Args, 1),
254-
(CommitStrategy::FromBufferWithLookupTable, 4),
256+
(CommitStrategy::StateArgs, 1),
257+
(CommitStrategy::StateBufferWithLookupTable, 4),
255258
]),
256259
false,
257260
)
@@ -263,8 +266,8 @@ async fn test_commit_5_accounts_1kb_bundle_size_4_undelegate_all() {
263266
commit_5_accounts_1kb(
264267
4,
265268
expect_strategies(&[
266-
(CommitStrategy::Args, 1),
267-
(CommitStrategy::FromBufferWithLookupTable, 4),
269+
(CommitStrategy::StateArgs, 1),
270+
(CommitStrategy::StateBufferWithLookupTable, 4),
268271
]),
269272
true,
270273
)
@@ -275,23 +278,26 @@ async fn test_commit_5_accounts_1kb_bundle_size_4_undelegate_all() {
275278
async fn test_commit_5_accounts_1kb_bundle_size_5_undelegate_all() {
276279
commit_5_accounts_1kb(
277280
5,
278-
expect_strategies(&[(CommitStrategy::FromBufferWithLookupTable, 5)]),
281+
expect_strategies(&[(CommitStrategy::StateBufferWithLookupTable, 5)]),
279282
true,
280283
)
281284
.await;
282285
}
283286

284287
#[tokio::test]
285288
async fn test_commit_20_accounts_1kb_bundle_size_3() {
286-
commit_20_accounts_1kb(3, expect_strategies(&[(CommitStrategy::Args, 20)]))
287-
.await;
289+
commit_20_accounts_1kb(
290+
3,
291+
expect_strategies(&[(CommitStrategy::StateArgs, 20)]),
292+
)
293+
.await;
288294
}
289295

290296
#[tokio::test]
291297
async fn test_commit_20_accounts_1kb_bundle_size_4() {
292298
commit_20_accounts_1kb(
293299
4,
294-
expect_strategies(&[(CommitStrategy::FromBufferWithLookupTable, 20)]),
300+
expect_strategies(&[(CommitStrategy::StateBufferWithLookupTable, 20)]),
295301
)
296302
.await;
297303
}
@@ -301,9 +307,9 @@ async fn test_commit_20_accounts_1kb_bundle_size_6() {
301307
commit_20_accounts_1kb(
302308
6,
303309
expect_strategies(&[
304-
(CommitStrategy::FromBufferWithLookupTable, 18),
310+
(CommitStrategy::StateBufferWithLookupTable, 18),
305311
// Two accounts don't make it into the bundles of size 6
306-
(CommitStrategy::Args, 2),
312+
(CommitStrategy::StateArgs, 2),
307313
]),
308314
)
309315
.await;
@@ -313,7 +319,7 @@ async fn test_commit_20_accounts_1kb_bundle_size_6() {
313319
async fn test_commit_20_accounts_1kb_bundle_size_20() {
314320
commit_20_accounts_1kb(
315321
20,
316-
expect_strategies(&[(CommitStrategy::FromBufferWithLookupTable, 20)]),
322+
expect_strategies(&[(CommitStrategy::StateBufferWithLookupTable, 20)]),
317323
)
318324
.await;
319325
}
@@ -325,7 +331,7 @@ async fn test_commit_8_accounts_1kb_bundle_size_8() {
325331
expect_strategies(&[
326332
// Four accounts don't make it into the bundles of size 8, but
327333
// that bundle also needs lookup tables
328-
(CommitStrategy::FromBufferWithLookupTable, 8),
334+
(CommitStrategy::StateBufferWithLookupTable, 8),
329335
]),
330336
)
331337
.await;
@@ -338,7 +344,7 @@ async fn test_commit_20_accounts_1kb_bundle_size_8() {
338344
expect_strategies(&[
339345
// Four accounts don't make it into the bundles of size 8, but
340346
// that bundle also needs lookup tables
341-
(CommitStrategy::FromBufferWithLookupTable, 20),
347+
(CommitStrategy::StateBufferWithLookupTable, 20),
342348
]),
343349
)
344350
.await;

0 commit comments

Comments
 (0)