Skip to content

Commit a8cb56a

Browse files
committed
Add more members to CommitStrategy
1 parent b87ac56 commit a8cb56a

3 files changed

Lines changed: 120 additions & 90 deletions

File tree

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

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,15 @@ 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 {
@@ -29,6 +38,10 @@ impl CommitStrategy {
2938
StateArgsWithLookupTable => "StateArgsWithLookupTable",
3039
StateBuffer => "StateBuffer",
3140
StateBufferWithLookupTable => "StateBufferWithLookupTable",
41+
DiffArgs => "DiffArgs",
42+
DiffArgsWithLookupTable => "DiffArgsWithLookupTable",
43+
DiffBuffer => "DiffBuffer",
44+
DiffBufferWithLookupTable => "DiffBufferWithLookupTable",
3245
}
3346
}
3447

@@ -53,6 +66,10 @@ impl TryFrom<&str> for CommitStrategy {
5366
"FromBufferWithLookupTable" | "StateBufferWithLookupTable" => {
5467
Ok(Self::StateBufferWithLookupTable)
5568
}
69+
"DiffArgs" => Ok(Self::DiffArgs),
70+
"DiffArgsWithLookupTable" => Ok(Self::DiffArgsWithLookupTable),
71+
"DiffBuffer" => Ok(Self::DiffBuffer),
72+
"DiffBufferWithLookupTable" => Ok(Self::DiffBufferWithLookupTable),
5673
_ => Err(CommitPersistError::InvalidCommitStrategy(
5774
value.to_string(),
5875
)),

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

Lines changed: 75 additions & 61 deletions
Original file line numberDiff line numberDiff line change
@@ -26,40 +26,47 @@ 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-
);
29+
let commit_strategy = |is_diff: bool| {
30+
if is_diff {
31+
if uses_lookup_tables {
32+
CommitStrategy::DiffArgsWithLookupTable
33+
} else {
34+
CommitStrategy::DiffArgs
4735
}
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-
);
36+
} else {
37+
if uses_lookup_tables {
38+
CommitStrategy::StateArgsWithLookupTable
39+
} else {
40+
CommitStrategy::StateArgs
6041
}
6142
}
62-
_ => {}
43+
};
44+
45+
let (commit_id, pubkey, commit_strategy) = match &task.task_type
46+
{
47+
ArgsTaskType::Commit(task) => (
48+
task.commit_id,
49+
&task.committed_account.pubkey,
50+
commit_strategy(false),
51+
),
52+
ArgsTaskType::CommitDiff(task) => (
53+
task.commit_id,
54+
&task.committed_account.pubkey,
55+
commit_strategy(true),
56+
),
57+
_ => return,
58+
};
59+
60+
if let Err(err) = self.persistor.set_commit_strategy(
61+
commit_id,
62+
&pubkey,
63+
commit_strategy,
64+
) {
65+
error!(
66+
"Failed to persist commit strategy {}: {}",
67+
commit_strategy.as_str(),
68+
err
69+
);
6370
}
6471
}
6572
}
@@ -68,39 +75,46 @@ where
6875
fn visit_buffer_task(&mut self, task: &BufferTask) {
6976
match self.context {
7077
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-
);
78+
let commit_strategy = |is_diff: bool| {
79+
if is_diff {
80+
if uses_lookup_tables {
81+
CommitStrategy::DiffBufferWithLookupTable
82+
} else {
83+
CommitStrategy::DiffBuffer
8984
}
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-
);
85+
} else {
86+
if uses_lookup_tables {
87+
CommitStrategy::StateBufferWithLookupTable
88+
} else {
89+
CommitStrategy::StateBuffer
10290
}
10391
}
92+
};
93+
94+
let (commit_id, pubkey, commit_strategy) = match &task.task_type
95+
{
96+
BufferTaskType::Commit(task) => (
97+
task.commit_id,
98+
&task.committed_account.pubkey,
99+
commit_strategy(false),
100+
),
101+
BufferTaskType::CommitDiff(task) => (
102+
task.commit_id,
103+
&task.committed_account.pubkey,
104+
commit_strategy(true),
105+
),
106+
};
107+
108+
if let Err(err) = self.persistor.set_commit_strategy(
109+
commit_id,
110+
&pubkey,
111+
commit_strategy,
112+
) {
113+
error!(
114+
"Failed to persist commit strategy {}: {}",
115+
commit_strategy.as_str(),
116+
err
117+
);
104118
}
105119
}
106120
}

0 commit comments

Comments
 (0)