From 0b4aa76fc744118ccaf7fbbc01343d538dd38040 Mon Sep 17 00:00:00 2001 From: Shoaib Ahmed Date: Tue, 28 Sep 2021 00:47:08 +0530 Subject: [PATCH 1/4] Set default trusting period to be 2/3 of unbonding period for Cosmos chains --- relayer/src/chain/cosmos.rs | 11 +++++++++-- relayer/src/chain/mock.rs | 14 +++++++++++--- relayer/src/config.rs | 7 +------ 3 files changed, 21 insertions(+), 11 deletions(-) diff --git a/relayer/src/chain/cosmos.rs b/relayer/src/chain/cosmos.rs index 39a29cc74a..65d74d76a6 100644 --- a/relayer/src/chain/cosmos.rs +++ b/relayer/src/chain/cosmos.rs @@ -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 { @@ -1635,12 +1641,13 @@ impl ChainEndpoint for CosmosSdkChain { } fn build_client_state(&self, height: ICSHeight) -> Result { + 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(), diff --git a/relayer/src/chain/mock.rs b/relayer/src/chain/mock.rs index 1b80b9582e..16a86d66c0 100644 --- a/relayer/src/chain/mock.rs +++ b/relayer/src/chain/mock.rs @@ -61,6 +61,14 @@ pub struct MockChain { event_receiver: EventReceiver, } +impl MockChain { + fn trusting_period(&self) -> Duration { + self.config + .trusting_period + .unwrap_or(Duration::from_secs(14 * 24 * 60 * 60)) // 14 days + } +} + impl ChainEndpoint for MockChain { type LightBlock = TmLightBlock; type Header = TendermintHeader; @@ -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(), @@ -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(), diff --git a/relayer/src/config.rs b/relayer/src/config.rs index 6e57f1acc9..fbe87bbc6b 100644 --- a/relayer/src/config.rs +++ b/relayer/src/config.rs @@ -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) } @@ -322,8 +318,7 @@ 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, + pub trusting_period: Option, // these two need to be last otherwise we run into `ValueAfterTable` error when serializing to TOML #[serde(default)] From a97f733fb7bedb4d214cd13fdb180f47d9a92df0 Mon Sep 17 00:00:00 2001 From: Romain Ruetschi Date: Tue, 28 Sep 2021 17:12:56 +0200 Subject: [PATCH 2/4] Fix clippy warning --- relayer/src/chain/mock.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/relayer/src/chain/mock.rs b/relayer/src/chain/mock.rs index 16a86d66c0..a4d2ca6d2c 100644 --- a/relayer/src/chain/mock.rs +++ b/relayer/src/chain/mock.rs @@ -65,7 +65,7 @@ impl MockChain { fn trusting_period(&self) -> Duration { self.config .trusting_period - .unwrap_or(Duration::from_secs(14 * 24 * 60 * 60)) // 14 days + .unwrap_or_else(|| Duration::from_secs(14 * 24 * 60 * 60)) // 14 days } } From feed9afae39bb885fd662de6e70a5bfc56891aa4 Mon Sep 17 00:00:00 2001 From: Romain Ruetschi Date: Tue, 28 Sep 2021 17:16:03 +0200 Subject: [PATCH 3/4] Add .changelog entry --- .../improvements/ibc-relayer/1392-trusting-period-default.md | 2 ++ 1 file changed, 2 insertions(+) create mode 100644 .changelog/unreleased/improvements/ibc-relayer/1392-trusting-period-default.md diff --git a/.changelog/unreleased/improvements/ibc-relayer/1392-trusting-period-default.md b/.changelog/unreleased/improvements/ibc-relayer/1392-trusting-period-default.md new file mode 100644 index 0000000000..42d997a229 --- /dev/null +++ b/.changelog/unreleased/improvements/ibc-relayer/1392-trusting-period-default.md @@ -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)) \ No newline at end of file From e53a25a4ce53e6a370a3905f5c739b8ba91f5951 Mon Sep 17 00:00:00 2001 From: Shoaib Ahmed Date: Wed, 29 Sep 2021 13:00:29 +0530 Subject: [PATCH 4/4] Fix serde for trusting_period --- relayer/src/config.rs | 1 + 1 file changed, 1 insertion(+) diff --git a/relayer/src/config.rs b/relayer/src/config.rs index fbe87bbc6b..efe72a0979 100644 --- a/relayer/src/config.rs +++ b/relayer/src/config.rs @@ -318,6 +318,7 @@ pub struct ChainConfig { pub max_tx_size: MaxTxSize, #[serde(default = "default::clock_drift", with = "humantime_serde")] pub clock_drift: Duration, + #[serde(with = "humantime_serde")] pub trusting_period: Option, // these two need to be last otherwise we run into `ValueAfterTable` error when serializing to TOML