Skip to content

Commit 7125d3b

Browse files
committed
apollo_batcher: wait for revert result
1 parent 38f59ce commit 7125d3b

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) type CommitmentManagerResult<T> = Result<T, CommitmentManagerError>;
@@ -142,6 +143,26 @@ impl<S: StateCommitterTrait> CommitmentManager<S> {
142143
results
143144
}
144145

146+
/// Fetches all ready commitment results from the state committer, until a revert result is
147+
/// received.
148+
pub(crate) async fn wait_for_revert_results(
149+
&mut self,
150+
) -> (Vec<CommitmentTaskOutput>, RevertTaskOutput) {
151+
let mut commitment_results = Vec::new();
152+
loop {
153+
// Sleep until a message is sent or the channel is closed.
154+
match self.results_receiver.recv().await {
155+
Some(CommitterTaskOutput::Commit(commitment_task_result)) => {
156+
commitment_results.push(commitment_task_result)
157+
}
158+
Some(CommitterTaskOutput::Revert(revert_task_result)) => {
159+
return (commitment_results, revert_task_result);
160+
}
161+
None => panic!("Channel closed while waiting for revert results."),
162+
}
163+
}
164+
}
165+
145166
// Private methods.
146167

147168
fn successfully_added_commitment_task(

0 commit comments

Comments
 (0)