Skip to content

Commit

Permalink
Replace custom retry attempts with BackoffParams
Browse files Browse the repository at this point in the history
  • Loading branch information
Ayiga committed Oct 3, 2024
1 parent 0e9e7ed commit be1229a
Showing 1 changed file with 7 additions and 7 deletions.
14 changes: 7 additions & 7 deletions node-metrics/src/api/node_validator/v0/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ use crate::service::client_message::{ClientMessage, InternalClientMessage};
use crate::service::data_state::{LocationDetails, NodeIdentity};
use crate::service::server_message::ServerMessage;
use async_std::task::JoinHandle;
use espresso_types::SeqTypes;
use espresso_types::{BackoffParams, SeqTypes};
use futures::channel::mpsc::SendError;
use futures::future::Either;
use futures::{
Expand All @@ -20,7 +20,6 @@ use hotshot_types::traits::{signature_key::StakeTableEntryType, stake_table::Sta
use hotshot_types::PeerConfig;
use prometheus_parse::{Sample, Scrape};
use serde::{Deserialize, Serialize};
use std::cmp::max;
use std::fmt;
use std::future::Future;
use std::io::BufRead;
Expand Down Expand Up @@ -597,6 +596,9 @@ impl ProcessProduceLeafStreamTask {
where
R: LeafStreamRetriever<Item = Leaf<SeqTypes>>,
{
let backoff_params = BackoffParams::default();
let mut delay = Duration::ZERO;

for attempt in 1..=100 {
let leaves_stream_result = leaf_stream_receiver.retrieve_stream(None).await;

Expand All @@ -614,13 +616,11 @@ impl ProcessProduceLeafStreamTask {
// For every failed iteration, we will double our delay, up
// to the maximum of 5 seconds.

let retry_penalty = max(
Duration::from_millis(100) * 2u32.pow(attempt),
Duration::from_secs(5),
);
async_std::task::sleep(retry_penalty).await;
delay = backoff_params.backoff(delay);
async_std::task::sleep(delay).await;
continue;
}

Ok(leaves_stream) => leaves_stream,
};

Expand Down

0 comments on commit be1229a

Please sign in to comment.