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

Set default trusting period to be 2/3 of unbonding period for Cosmos chains #1392

Merged
merged 4 commits into from
Sep 29, 2021
Merged
Show file tree
Hide file tree
Changes from all 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,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")]
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Removing the serde(with) attribute means we cannot express the trusting period as a human readable string, eg. 14days. Let's find a way to re-enable it :)

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done! Thanks for reviewing, @romac!

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