Skip to content

Commit 151df5f

Browse files
committed
apollo_batcher: wait for revert result
1 parent a75f4b6 commit 151df5f

File tree

1 file changed

+21
-0
lines changed

1 file changed

+21
-0
lines changed

crates/apollo_batcher/src/commitment_manager/commitment_manager_impl.rs

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ use crate::commitment_manager::types::{
2424
CommitterTaskInput,
2525
CommitterTaskOutput,
2626
FinalBlockCommitment,
27+
RevertTaskOutput,
2728
};
2829

2930
pub(crate) const DEFAULT_TASKS_CHANNEL_SIZE: usize = 1000;
@@ -164,6 +165,26 @@ impl<S: StateCommitterTrait> CommitmentManager<S> {
164165
results
165166
}
166167

168+
/// Fetches all ready commitment results from the state committer, until a revert result is
169+
/// received.
170+
pub(crate) async fn wait_for_revert_results(
171+
&mut self,
172+
) -> (Vec<CommitmentTaskOutput>, RevertTaskOutput) {
173+
let mut commitment_results = Vec::new();
174+
loop {
175+
// Sleep until a message is sent or the channel is closed.
176+
match self.results_receiver.recv().await {
177+
Some(CommitterTaskOutput::Commit(commitment_task_result)) => {
178+
commitment_results.push(commitment_task_result)
179+
}
180+
Some(CommitterTaskOutput::Revert(revert_task_result)) => {
181+
return (commitment_results, revert_task_result);
182+
}
183+
None => panic!("Channel closed while waiting for revert results."),
184+
}
185+
}
186+
}
187+
167188
// Private methods.
168189

169190
fn successfully_added_commitment_task(

0 commit comments

Comments
 (0)