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)
  • Loading branch information
romac committed Feb 29, 2024
1 parent df6cd29 commit 240d82f
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 24 deletions.
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 240d82f

Please sign in to comment.