Skip to content

Commit 1e4a115

Browse files
committed
feat: Make TaskStrategy more granular
1 parent 5e96ff9 commit 1e4a115

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
@@ -585,14 +585,14 @@ mod tests {
585585
persister.set_commit_id(1, &pubkey, 100).unwrap();
586586

587587
persister
588-
.set_commit_strategy(100, &pubkey, CommitStrategy::Args)
588+
.set_commit_strategy(100, &pubkey, CommitStrategy::StateArgs)
589589
.unwrap();
590590

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

598598
#[test]

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -772,7 +772,7 @@ mod tests {
772772
commit_type: CommitType::DataAccount,
773773
created_at: 1000,
774774
commit_status: CommitStatus::Pending,
775-
commit_strategy: CommitStrategy::Args,
775+
commit_strategy: CommitStrategy::StateArgs,
776776
last_retried_at: 1000,
777777
retries_count: 0,
778778
}
@@ -907,7 +907,7 @@ mod tests {
907907
db.insert_commit_status_rows(std::slice::from_ref(&row))
908908
.unwrap();
909909

910-
let new_strategy = CommitStrategy::FromBuffer;
910+
let new_strategy = CommitStrategy::StateBuffer;
911911
db.set_commit_strategy(100, &row.pubkey, new_strategy)
912912
.unwrap();
913913

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,32 +66,32 @@ fn expect_strategies(
6666

6767
#[tokio::test]
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
#[tokio::test]
7373
async fn test_ix_commit_single_account_100_bytes_and_undelegate() {
74-
commit_single_account(100, CommitStrategy::Args, true).await;
74+
commit_single_account(100, CommitStrategy::StateArgs, true).await;
7575
}
7676

7777
#[tokio::test]
7878
async fn test_ix_commit_single_account_800_bytes() {
79-
commit_single_account(800, CommitStrategy::FromBuffer, false).await;
79+
commit_single_account(800, CommitStrategy::StateBuffer, false).await;
8080
}
8181

8282
#[tokio::test]
8383
async fn test_ix_commit_single_account_800_bytes_and_undelegate() {
84-
commit_single_account(800, CommitStrategy::FromBuffer, true).await;
84+
commit_single_account(800, CommitStrategy::StateBuffer, true).await;
8585
}
8686

8787
#[tokio::test]
8888
async fn test_ix_commit_single_account_one_kb() {
89-
commit_single_account(1024, CommitStrategy::FromBuffer, false).await;
89+
commit_single_account(1024, CommitStrategy::StateBuffer, false).await;
9090
}
9191

9292
#[tokio::test]
9393
async fn test_ix_commit_single_account_ten_kb() {
94-
commit_single_account(10 * 1024, CommitStrategy::FromBuffer, false).await;
94+
commit_single_account(10 * 1024, CommitStrategy::StateBuffer, false).await;
9595
}
9696

9797
async fn commit_single_account(
@@ -173,7 +173,7 @@ async fn test_ix_commit_two_accounts_1kb_2kb() {
173173
&[1024, 2048],
174174
1,
175175
false,
176-
expect_strategies(&[(CommitStrategy::Args, 2)]),
176+
expect_strategies(&[(CommitStrategy::StateArgs, 2)]),
177177
)
178178
.await;
179179
}
@@ -185,7 +185,7 @@ async fn test_ix_commit_two_accounts_512kb() {
185185
&[512, 512],
186186
1,
187187
false,
188-
expect_strategies(&[(CommitStrategy::Args, 2)]),
188+
expect_strategies(&[(CommitStrategy::StateArgs, 2)]),
189189
)
190190
.await;
191191
}
@@ -197,7 +197,7 @@ async fn test_ix_commit_three_accounts_512kb() {
197197
&[512, 512, 512],
198198
1,
199199
false,
200-
expect_strategies(&[(CommitStrategy::Args, 3)]),
200+
expect_strategies(&[(CommitStrategy::StateArgs, 3)]),
201201
)
202202
.await;
203203
}
@@ -209,7 +209,7 @@ async fn test_ix_commit_six_accounts_512kb() {
209209
&[512, 512, 512, 512, 512, 512],
210210
1,
211211
false,
212-
expect_strategies(&[(CommitStrategy::Args, 6)]),
212+
expect_strategies(&[(CommitStrategy::StateArgs, 6)]),
213213
)
214214
.await;
215215
}
@@ -221,22 +221,25 @@ async fn test_ix_commit_four_accounts_1kb_2kb_5kb_10kb_single_bundle() {
221221
&[1024, 2 * 1024, 5 * 1024, 10 * 1024],
222222
1,
223223
false,
224-
expect_strategies(&[(CommitStrategy::Args, 4)]),
224+
expect_strategies(&[(CommitStrategy::StateArgs, 4)]),
225225
)
226226
.await;
227227
}
228228

229229
#[tokio::test]
230230
async fn test_commit_20_accounts_1kb_bundle_size_2() {
231-
commit_20_accounts_1kb(2, expect_strategies(&[(CommitStrategy::Args, 20)]))
232-
.await;
231+
commit_20_accounts_1kb(
232+
2,
233+
expect_strategies(&[(CommitStrategy::StateArgs, 20)]),
234+
)
235+
.await;
233236
}
234237

235238
#[tokio::test]
236239
async fn test_commit_5_accounts_1kb_bundle_size_3() {
237240
commit_5_accounts_1kb(
238241
3,
239-
expect_strategies(&[(CommitStrategy::Args, 5)]),
242+
expect_strategies(&[(CommitStrategy::StateArgs, 5)]),
240243
false,
241244
)
242245
.await;
@@ -248,8 +251,8 @@ async fn test_commit_5_accounts_1kb_bundle_size_3_undelegate_all() {
248251
3,
249252
expect_strategies(&[
250253
// Intent fits in 1 TX only with ALT, see IntentExecutorImpl::try_unite_tasks
251-
(CommitStrategy::FromBufferWithLookupTable, 3),
252-
(CommitStrategy::Args, 2),
254+
(CommitStrategy::StateBufferWithLookupTable, 3),
255+
(CommitStrategy::StateArgs, 2),
253256
]),
254257
true,
255258
)
@@ -261,8 +264,8 @@ async fn test_commit_5_accounts_1kb_bundle_size_4() {
261264
commit_5_accounts_1kb(
262265
4,
263266
expect_strategies(&[
264-
(CommitStrategy::Args, 1),
265-
(CommitStrategy::FromBufferWithLookupTable, 4),
267+
(CommitStrategy::StateArgs, 1),
268+
(CommitStrategy::StateBufferWithLookupTable, 4),
266269
]),
267270
false,
268271
)
@@ -274,8 +277,8 @@ async fn test_commit_5_accounts_1kb_bundle_size_4_undelegate_all() {
274277
commit_5_accounts_1kb(
275278
4,
276279
expect_strategies(&[
277-
(CommitStrategy::Args, 1),
278-
(CommitStrategy::FromBufferWithLookupTable, 4),
280+
(CommitStrategy::StateArgs, 1),
281+
(CommitStrategy::StateBufferWithLookupTable, 4),
279282
]),
280283
true,
281284
)
@@ -286,23 +289,26 @@ async fn test_commit_5_accounts_1kb_bundle_size_4_undelegate_all() {
286289
async fn test_commit_5_accounts_1kb_bundle_size_5_undelegate_all() {
287290
commit_5_accounts_1kb(
288291
5,
289-
expect_strategies(&[(CommitStrategy::FromBufferWithLookupTable, 5)]),
292+
expect_strategies(&[(CommitStrategy::StateBufferWithLookupTable, 5)]),
290293
true,
291294
)
292295
.await;
293296
}
294297

295298
#[tokio::test]
296299
async fn test_commit_20_accounts_1kb_bundle_size_3() {
297-
commit_20_accounts_1kb(3, expect_strategies(&[(CommitStrategy::Args, 20)]))
298-
.await;
300+
commit_20_accounts_1kb(
301+
3,
302+
expect_strategies(&[(CommitStrategy::StateArgs, 20)]),
303+
)
304+
.await;
299305
}
300306

301307
#[tokio::test]
302308
async fn test_commit_20_accounts_1kb_bundle_size_4() {
303309
commit_20_accounts_1kb(
304310
4,
305-
expect_strategies(&[(CommitStrategy::FromBufferWithLookupTable, 20)]),
311+
expect_strategies(&[(CommitStrategy::StateBufferWithLookupTable, 20)]),
306312
)
307313
.await;
308314
}
@@ -312,9 +318,9 @@ async fn test_commit_20_accounts_1kb_bundle_size_6() {
312318
commit_20_accounts_1kb(
313319
6,
314320
expect_strategies(&[
315-
(CommitStrategy::FromBufferWithLookupTable, 18),
321+
(CommitStrategy::StateBufferWithLookupTable, 18),
316322
// Two accounts don't make it into the bundles of size 6
317-
(CommitStrategy::Args, 2),
323+
(CommitStrategy::StateArgs, 2),
318324
]),
319325
)
320326
.await;
@@ -324,7 +330,7 @@ async fn test_commit_20_accounts_1kb_bundle_size_6() {
324330
async fn test_commit_20_accounts_1kb_bundle_size_20() {
325331
commit_20_accounts_1kb(
326332
20,
327-
expect_strategies(&[(CommitStrategy::FromBufferWithLookupTable, 20)]),
333+
expect_strategies(&[(CommitStrategy::StateBufferWithLookupTable, 20)]),
328334
)
329335
.await;
330336
}
@@ -336,7 +342,7 @@ async fn test_commit_8_accounts_1kb_bundle_size_8() {
336342
expect_strategies(&[
337343
// Four accounts don't make it into the bundles of size 8, but
338344
// that bundle also needs lookup tables
339-
(CommitStrategy::FromBufferWithLookupTable, 8),
345+
(CommitStrategy::StateBufferWithLookupTable, 8),
340346
]),
341347
)
342348
.await;
@@ -349,7 +355,7 @@ async fn test_commit_20_accounts_1kb_bundle_size_8() {
349355
expect_strategies(&[
350356
// Four accounts don't make it into the bundles of size 8, but
351357
// that bundle also needs lookup tables
352-
(CommitStrategy::FromBufferWithLookupTable, 20),
358+
(CommitStrategy::StateBufferWithLookupTable, 20),
353359
]),
354360
)
355361
.await;

0 commit comments

Comments
 (0)