Replicate Rob's PR (#4337)

This commit is contained in:
Lldenaurois
2021-11-20 12:36:23 +01:00
committed by GitHub
parent be7dedd20c
commit e35ebee0f1
3 changed files with 16 additions and 41 deletions
@@ -58,16 +58,6 @@ pub struct SendTask {
/// Whether we have any tasks failed since the last refresh.
has_failed_sends: bool,
/// Total count of failed transmissions.
///
/// Used for issuing a warning, if that number gets above a certain threshold.
failed_count: usize,
/// Total number of initiated requests.
///
/// Used together with `failed_count` for issuing a warning on too many failed attempts.
send_count: usize,
/// Sender to be cloned for tasks.
tx: mpsc::Sender<TaskFinish>,
}
@@ -120,14 +110,8 @@ impl SendTask {
request: DisputeRequest,
metrics: &Metrics,
) -> Result<Self> {
let mut send_task = Self {
request,
deliveries: HashMap::new(),
has_failed_sends: false,
tx,
failed_count: 0,
send_count: 0,
};
let mut send_task =
Self { request, deliveries: HashMap::new(), has_failed_sends: false, tx };
send_task.refresh_sends(ctx, runtime, active_sessions, metrics).await?;
Ok(send_task)
}
@@ -160,7 +144,6 @@ impl SendTask {
.await?;
self.has_failed_sends = false;
self.send_count += new_statuses.len();
self.deliveries.extend(new_statuses.into_iter());
Ok(())
}
@@ -176,7 +159,7 @@ impl SendTask {
pub fn on_finished_send(&mut self, authority: &AuthorityDiscoveryId, result: TaskResult) {
match result {
TaskResult::Failed(err) => {
tracing::debug!(
tracing::trace!(
target: LOG_TARGET,
?authority,
candidate_hash = %self.request.0.candidate_receipt.hash(),
@@ -184,25 +167,6 @@ impl SendTask {
"Error sending dispute statements to node."
);
self.failed_count += 1;
let error_rate = (100 * self.failed_count).checked_div(self.send_count).expect(
"We cannot receive a failed request, without having sent one first. qed.",
);
// 10% seems to be a sensible threshold to become alert - note that
// self.send_count gets increased in batches of the full validator set, so we don't
// need to account for a low send_count.
if error_rate > 10 {
tracing::warn!(
target: LOG_TARGET,
candidate_hash = %self.request.0.candidate_receipt.hash(),
last_authority = ?authority,
last_error = %err,
failed_count = ?self.failed_count,
total_attempts = ?self.send_count,
"Sending our dispute vote failed for more than 10% of total attempts!"
);
}
self.has_failed_sends = true;
// Remove state, so we know what to try again:
self.deliveries.remove(authority);