Skip to content

Commit 8cd5955

Browse files
committed
Add more members to CommitStrategy
1 parent 3b36e08 commit 8cd5955

3 files changed

Lines changed: 138 additions & 98 deletions

File tree

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

Lines changed: 19 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -11,24 +11,29 @@ pub enum CommitStrategy {
1111
StateBuffer,
1212
/// Buffer and chunks with the use of a lookup table
1313
StateBufferWithLookupTable,
14+
15+
/// Args without the use of a lookup table
16+
DiffArgs,
17+
/// Args with the use of a lookup table
18+
DiffArgsWithLookupTable,
19+
/// Buffer and chunks which has the most overhead
20+
DiffBuffer,
21+
/// Buffer and chunks with the use of a lookup table
22+
DiffBufferWithLookupTable,
1423
}
1524

1625
impl CommitStrategy {
17-
pub fn args(use_lookup: bool) -> Self {
18-
if use_lookup {
19-
Self::StateArgsWithLookupTable
20-
} else {
21-
Self::StateArgs
22-
}
23-
}
24-
2526
pub fn as_str(&self) -> &str {
2627
use CommitStrategy::*;
2728
match self {
2829
StateArgs => "StateArgs",
2930
StateArgsWithLookupTable => "StateArgsWithLookupTable",
3031
StateBuffer => "StateBuffer",
3132
StateBufferWithLookupTable => "StateBufferWithLookupTable",
33+
DiffArgs => "DiffArgs",
34+
DiffArgsWithLookupTable => "DiffArgsWithLookupTable",
35+
DiffBuffer => "DiffBuffer",
36+
DiffBufferWithLookupTable => "DiffBufferWithLookupTable",
3237
}
3338
}
3439

@@ -37,6 +42,8 @@ impl CommitStrategy {
3742
self,
3843
CommitStrategy::StateArgsWithLookupTable
3944
| CommitStrategy::StateBufferWithLookupTable
45+
| CommitStrategy::DiffArgsWithLookupTable
46+
| CommitStrategy::DiffBufferWithLookupTable
4047
)
4148
}
4249
}
@@ -53,6 +60,10 @@ impl TryFrom<&str> for CommitStrategy {
5360
"FromBufferWithLookupTable" | "StateBufferWithLookupTable" => {
5461
Ok(Self::StateBufferWithLookupTable)
5562
}
63+
"DiffArgs" => Ok(Self::DiffArgs),
64+
"DiffArgsWithLookupTable" => Ok(Self::DiffArgsWithLookupTable),
65+
"DiffBuffer" => Ok(Self::DiffBuffer),
66+
"DiffBufferWithLookupTable" => Ok(Self::DiffBufferWithLookupTable),
5667
_ => Err(CommitPersistError::InvalidCommitStrategy(
5768
value.to_string(),
5869
)),

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

Lines changed: 73 additions & 63 deletions
Original file line numberDiff line numberDiff line change
@@ -26,40 +26,45 @@ where
2626
fn visit_args_task(&mut self, task: &ArgsTask) {
2727
match self.context {
2828
PersistorContext::PersistStrategy { uses_lookup_tables } => {
29-
let commit_strategy = if uses_lookup_tables {
30-
CommitStrategy::StateArgsWithLookupTable
31-
} else {
32-
CommitStrategy::StateArgs
33-
};
34-
35-
match &task.task_type {
36-
ArgsTaskType::Commit(task) => {
37-
if let Err(err) = self.persistor.set_commit_strategy(
38-
task.commit_id,
39-
&task.committed_account.pubkey,
40-
commit_strategy,
41-
) {
42-
error!(
43-
"Failed to persist commit strategy {}: {}",
44-
commit_strategy.as_str(),
45-
err
46-
);
47-
}
48-
}
49-
ArgsTaskType::CommitDiff(task) => {
50-
if let Err(err) = self.persistor.set_commit_strategy(
51-
task.commit_id,
52-
&task.committed_account.pubkey,
53-
commit_strategy,
54-
) {
55-
error!(
56-
"Failed to persist commit strategy {}: {}",
57-
commit_strategy.as_str(),
58-
err
59-
);
29+
let commit_strategy = |is_diff: bool| {
30+
if is_diff {
31+
if uses_lookup_tables {
32+
CommitStrategy::DiffArgsWithLookupTable
33+
} else {
34+
CommitStrategy::DiffArgs
6035
}
36+
} else if uses_lookup_tables {
37+
CommitStrategy::StateArgsWithLookupTable
38+
} else {
39+
CommitStrategy::StateArgs
6140
}
62-
_ => {}
41+
};
42+
43+
let (commit_id, pubkey, commit_strategy) = match &task.task_type
44+
{
45+
ArgsTaskType::Commit(task) => (
46+
task.commit_id,
47+
&task.committed_account.pubkey,
48+
commit_strategy(false),
49+
),
50+
ArgsTaskType::CommitDiff(task) => (
51+
task.commit_id,
52+
&task.committed_account.pubkey,
53+
commit_strategy(true),
54+
),
55+
_ => return,
56+
};
57+
58+
if let Err(err) = self.persistor.set_commit_strategy(
59+
commit_id,
60+
pubkey,
61+
commit_strategy,
62+
) {
63+
error!(
64+
"Failed to persist commit strategy {}: {}",
65+
commit_strategy.as_str(),
66+
err
67+
);
6368
}
6469
}
6570
}
@@ -68,39 +73,44 @@ where
6873
fn visit_buffer_task(&mut self, task: &BufferTask) {
6974
match self.context {
7075
PersistorContext::PersistStrategy { uses_lookup_tables } => {
71-
let commit_strategy = if uses_lookup_tables {
72-
CommitStrategy::StateBufferWithLookupTable
73-
} else {
74-
CommitStrategy::StateBuffer
75-
};
76-
77-
match &task.task_type {
78-
BufferTaskType::Commit(task) => {
79-
if let Err(err) = self.persistor.set_commit_strategy(
80-
task.commit_id,
81-
&task.committed_account.pubkey,
82-
commit_strategy,
83-
) {
84-
error!(
85-
"Failed to persist commit strategy {}: {}",
86-
commit_strategy.as_str(),
87-
err
88-
);
89-
}
90-
}
91-
BufferTaskType::CommitDiff(task) => {
92-
if let Err(err) = self.persistor.set_commit_strategy(
93-
task.commit_id,
94-
&task.committed_account.pubkey,
95-
commit_strategy,
96-
) {
97-
error!(
98-
"Failed to persist commit strategy {}: {}",
99-
commit_strategy.as_str(),
100-
err
101-
);
76+
let commit_strategy = |is_diff: bool| {
77+
if is_diff {
78+
if uses_lookup_tables {
79+
CommitStrategy::DiffBufferWithLookupTable
80+
} else {
81+
CommitStrategy::DiffBuffer
10282
}
83+
} else if uses_lookup_tables {
84+
CommitStrategy::StateBufferWithLookupTable
85+
} else {
86+
CommitStrategy::StateBuffer
10387
}
88+
};
89+
90+
let (commit_id, pubkey, commit_strategy) = match &task.task_type
91+
{
92+
BufferTaskType::Commit(task) => (
93+
task.commit_id,
94+
&task.committed_account.pubkey,
95+
commit_strategy(false),
96+
),
97+
BufferTaskType::CommitDiff(task) => (
98+
task.commit_id,
99+
&task.committed_account.pubkey,
100+
commit_strategy(true),
101+
),
102+
};
103+
104+
if let Err(err) = self.persistor.set_commit_strategy(
105+
commit_id,
106+
pubkey,
107+
commit_strategy,
108+
) {
109+
error!(
110+
"Failed to persist commit strategy {}: {}",
111+
commit_strategy.as_str(),
112+
err
113+
);
104114
}
105115
}
106116
}

0 commit comments

Comments
 (0)