Skip to content

Commit

Permalink
Change connection and handshake retry strategy to retry max 10 times …
Browse files Browse the repository at this point in the history
…over two blocks (5 times per block) (#3864)

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

* Add changelog entry

* Update 3864-handshake-retry.md

Co-authored-by: Luca Joss <43531661+ljoss17@users.noreply.github.com>
Signed-off-by: Romain Ruetschi <github@romac.me>
  • Loading branch information
romac and ljoss17 authored Mar 12, 2024
1 parent e4aea2a commit bff1ee9
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 24 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
- Change connection and channel handshake retry strategy
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

0 comments on commit bff1ee9

Please sign in to comment.