Skip to content

Commit

Permalink
Set default trusting period to be 2/3 of unbonding period for Cosmos …
Browse files Browse the repository at this point in the history
…chains (#1392)
  • Loading branch information
hu55a1n1 committed Sep 29, 2021
1 parent 7b76a1f commit 6959e05
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 11 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
- Set default trusting period to be 2/3 of unbonding period for Cosmos chains
([#1392](https://github.com/informalsystems/ibc-rs/issues/1392))
11 changes: 9 additions & 2 deletions relayer/src/chain/cosmos.rs
Original file line number Diff line number Diff line change
Expand Up @@ -599,6 +599,12 @@ impl CosmosSdkChain {
Err(_) => Err(Error::tx_no_confirmation()),
}
}

fn trusting_period(&self, unbonding_period: Duration) -> Duration {
self.config
.trusting_period
.unwrap_or(2 * unbonding_period / 3)
}
}

fn empty_event_present(events: &[IbcEvent]) -> bool {
Expand Down Expand Up @@ -1635,12 +1641,13 @@ impl ChainEndpoint for CosmosSdkChain {
}

fn build_client_state(&self, height: ICSHeight) -> Result<Self::ClientState, Error> {
let unbonding_period = self.unbonding_period()?;
// Build the client state.
ClientState::new(
self.id().clone(),
self.config.trust_threshold.into(),
self.config.trusting_period,
self.unbonding_period()?,
self.trusting_period(unbonding_period),
unbonding_period,
self.config.clock_drift,
height,
ICSHeight::zero(),
Expand Down
14 changes: 11 additions & 3 deletions relayer/src/chain/mock.rs
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,14 @@ pub struct MockChain {
event_receiver: EventReceiver,
}

impl MockChain {
fn trusting_period(&self) -> Duration {
self.config
.trusting_period
.unwrap_or_else(|| Duration::from_secs(14 * 24 * 60 * 60)) // 14 days
}
}

impl ChainEndpoint for MockChain {
type LightBlock = TmLightBlock;
type Header = TendermintHeader;
Expand Down Expand Up @@ -317,8 +325,8 @@ impl ChainEndpoint for MockChain {
let client_state = TendermintClientState::new(
self.id().clone(),
self.config.trust_threshold.into(),
self.config.trusting_period,
self.config.trusting_period.add(Duration::from_secs(1000)),
self.trusting_period(),
self.trusting_period().add(Duration::from_secs(1000)),
Duration::from_millis(3000),
height,
Height::zero(),
Expand Down Expand Up @@ -426,7 +434,7 @@ pub mod test_utils {
max_msg_num: Default::default(),
max_tx_size: Default::default(),
clock_drift: Duration::from_secs(5),
trusting_period: Duration::from_secs(14 * 24 * 60 * 60), // 14 days
trusting_period: Some(Duration::from_secs(14 * 24 * 60 * 60)), // 14 days
trust_threshold: Default::default(),
packet_filter: PacketFilter::default(),
address_type: AddressType::default(),
Expand Down
8 changes: 2 additions & 6 deletions relayer/src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -97,10 +97,6 @@ pub mod default {
Duration::from_secs(10)
}

pub fn trusting_period() -> Duration {
Duration::from_secs(336 * 60 * 60) // 336 hours ~ 14 days
}

pub fn clock_drift() -> Duration {
Duration::from_secs(5)
}
Expand Down Expand Up @@ -322,8 +318,8 @@ pub struct ChainConfig {
pub max_tx_size: MaxTxSize,
#[serde(default = "default::clock_drift", with = "humantime_serde")]
pub clock_drift: Duration,
#[serde(default = "default::trusting_period", with = "humantime_serde")]
pub trusting_period: Duration,
#[serde(with = "humantime_serde")]
pub trusting_period: Option<Duration>,

// these two need to be last otherwise we run into `ValueAfterTable` error when serializing to TOML
#[serde(default)]
Expand Down

0 comments on commit 6959e05

Please sign in to comment.