Skip to content

Commit c68f587

Browse files
committed
[runtime] Fix: correctly comput batcher time metrics
1 parent 0388ca9 commit c68f587

1 file changed

Lines changed: 70 additions & 13 deletions

File tree

  • consensus/src/simplex/actors/batcher

consensus/src/simplex/actors/batcher/actor.rs

Lines changed: 70 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -219,22 +219,41 @@ where
219219
.await
220220
}
221221

222-
async fn construct_certificates(
222+
async fn construct_notarization(
223223
context: ContextCell<E>,
224224
scheme: S,
225225
mut round: Round<S, B, D, Re>,
226-
) -> (
227-
Round<S, B, D, Re>,
228-
Option<Notarization<S, D>>,
229-
Option<Nullification<S>>,
230-
Option<Finalization<S, D>>,
231-
) {
226+
) -> (Round<S, B, D, Re>, Option<Notarization<S, D>>) {
232227
context
233228
.with_strategy(move |strategy| {
234229
let notarization = round.try_construct_notarization(&scheme, strategy);
230+
(round, notarization)
231+
})
232+
.await
233+
}
234+
235+
async fn construct_nullification(
236+
context: ContextCell<E>,
237+
scheme: S,
238+
mut round: Round<S, B, D, Re>,
239+
) -> (Round<S, B, D, Re>, Option<Nullification<S>>) {
240+
context
241+
.with_strategy(move |strategy| {
235242
let nullification = round.try_construct_nullification(&scheme, strategy);
243+
(round, nullification)
244+
})
245+
.await
246+
}
247+
248+
async fn construct_finalization(
249+
context: ContextCell<E>,
250+
scheme: S,
251+
mut round: Round<S, B, D, Re>,
252+
) -> (Round<S, B, D, Re>, Option<Finalization<S, D>>) {
253+
context
254+
.with_strategy(move |strategy| {
236255
let finalization = round.try_construct_finalization(&scheme, strategy);
237-
(round, notarization, nullification, finalization)
256+
(round, finalization)
238257
})
239258
.await
240259
}
@@ -690,30 +709,68 @@ where
690709
);
691710
}
692711

693-
let (round, notarization, nullification, finalization) =
694-
Self::construct_certificates(
712+
let (round, notarization) = {
713+
let mut timer = self.recover_latency.timer();
714+
let result = Self::construct_notarization(
715+
self.context.clone(),
716+
self.scheme.clone(),
717+
round,
718+
)
719+
.await;
720+
if result.1.is_some() {
721+
timer.observe();
722+
} else {
723+
timer.cancel();
724+
}
725+
result
726+
};
727+
let (round, nullification) = {
728+
let mut timer = self.recover_latency.timer();
729+
let result = Self::construct_nullification(
730+
self.context.clone(),
731+
self.scheme.clone(),
732+
round,
733+
)
734+
.await;
735+
if result.1.is_some() {
736+
timer.observe();
737+
} else {
738+
timer.cancel();
739+
}
740+
result
741+
};
742+
let (round, finalization) = {
743+
let mut timer = self.recover_latency.timer();
744+
let result = Self::construct_finalization(
695745
self.context.clone(),
696746
self.scheme.clone(),
697747
round,
698748
)
699749
.await;
750+
if result.1.is_some() {
751+
timer.observe();
752+
} else {
753+
timer.cancel();
754+
}
755+
result
756+
};
700757

701758
// Try to construct and forward certificates
702-
if let Some(notarization) = self.recover_latency.time_some(|| notarization) {
759+
if let Some(notarization) = notarization {
703760
debug!(view = %updated_view, "constructed notarization, forwarding to voter");
704761

705762
// Forward notarization to voter
706763
voter
707764
.recovered(Certificate::Notarization(notarization))
708765
.await;
709766
}
710-
if let Some(nullification) = self.recover_latency.time_some(|| nullification) {
767+
if let Some(nullification) = nullification {
711768
debug!(view = %updated_view, "constructed nullification, forwarding to voter");
712769
voter
713770
.recovered(Certificate::Nullification(nullification))
714771
.await;
715772
}
716-
if let Some(finalization) = self.recover_latency.time_some(|| finalization) {
773+
if let Some(finalization) = finalization {
717774
debug!(view = %updated_view, "constructed finalization, forwarding to voter");
718775
voter
719776
.recovered(Certificate::Finalization(finalization))

0 commit comments

Comments
 (0)