Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Change connection and handshake retry strategy to retry max 10 times over two blocks (5 times per block) #3864

Merged
merged 3 commits into from
Mar 12, 2024
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
- Change connection and handshake retry strategy
romac marked this conversation as resolved.
Show resolved Hide resolved
to retry at most 10 times (5 times per block max)
([\#3864](https://github.com/informalsystems/hermes/issues/3864))
24 changes: 12 additions & 12 deletions crates/relayer/src/channel.rs
Original file line number Diff line number Diff line change
Expand Up @@ -47,29 +47,29 @@ pub mod channel_handshake_retry {
//! for the channel handshake algorithm.

use crate::channel::ChannelError;
use crate::util::retry::{clamp_total, ConstantGrowth};
use crate::util::retry::{clamp, ConstantGrowth};
use core::time::Duration;

/// Approximate number of retries per block.
const PER_BLOCK_RETRIES: u32 = 10;
const PER_BLOCK_RETRIES: u32 = 5;

/// Defines the increment in delay between subsequent retries.
/// A value of `0` will make the retry delay constant.
const DELAY_INCREMENT: u64 = 0;
const DELAY_INCREMENT: Duration = Duration::from_secs(1);

/// Maximum retry delay expressed in number of blocks
const BLOCK_NUMBER_DELAY: u32 = 10;
/// Maximum number of retries
const MAX_RETRIES: u32 = 10;

/// The default retry strategy.
/// We retry with a constant backoff strategy. The strategy is parametrized by the
/// We retry with a growing backoff strategy. The strategy is parametrized by the
/// maximum block time expressed as a `Duration`.
pub fn default_strategy(max_block_times: Duration) -> impl Iterator<Item = Duration> {
let retry_delay = max_block_times / PER_BLOCK_RETRIES;
pub fn default_strategy(max_block_time: Duration) -> impl Iterator<Item = Duration> {
let retry_delay = max_block_time / PER_BLOCK_RETRIES;

clamp_total(
ConstantGrowth::new(retry_delay, Duration::from_secs(DELAY_INCREMENT)),
retry_delay,
max_block_times * BLOCK_NUMBER_DELAY,
clamp(
ConstantGrowth::new(retry_delay, DELAY_INCREMENT),
retry_delay + DELAY_INCREMENT * MAX_RETRIES,
MAX_RETRIES as usize,
)
}

Expand Down
24 changes: 12 additions & 12 deletions crates/relayer/src/connection.rs
Original file line number Diff line number Diff line change
Expand Up @@ -42,29 +42,29 @@ mod handshake_retry {
//! for the connection handshake algorithm.

use crate::connection::ConnectionError;
use crate::util::retry::{clamp_total, ConstantGrowth};
use crate::util::retry::{clamp, ConstantGrowth};
use core::time::Duration;

/// Approximate number of retries per block.
const PER_BLOCK_RETRIES: u32 = 10;
const PER_BLOCK_RETRIES: u32 = 5;

/// Defines the increment in delay between subsequent retries.
/// A value of `0` will make the retry delay constant.
const DELAY_INCREMENT: u64 = 0;
const DELAY_INCREMENT: Duration = Duration::from_secs(1);

/// Maximum retry delay expressed in number of blocks
const BLOCK_NUMBER_DELAY: u32 = 10;
/// Maximum number of retries
const MAX_RETRIES: u32 = 10;

/// The default retry strategy.
/// We retry with a constant backoff strategy. The strategy is parametrized by the
/// We retry with a growing backoff strategy. The strategy is parametrized by the
/// maximum block time expressed as a `Duration`.
pub fn default_strategy(max_block_times: Duration) -> impl Iterator<Item = Duration> {
let retry_delay = max_block_times / PER_BLOCK_RETRIES;
pub fn default_strategy(max_block_time: Duration) -> impl Iterator<Item = Duration> {
let retry_delay = max_block_time / PER_BLOCK_RETRIES;

clamp_total(
ConstantGrowth::new(retry_delay, Duration::from_secs(DELAY_INCREMENT)),
retry_delay,
max_block_times * BLOCK_NUMBER_DELAY,
clamp(
ConstantGrowth::new(retry_delay, DELAY_INCREMENT),
retry_delay + DELAY_INCREMENT * MAX_RETRIES,
MAX_RETRIES as usize,
)
}

Expand Down
Loading