From 16beffa89f8b52e41bbb67f6a42ed41f551b1a8b Mon Sep 17 00:00:00 2001 From: Romain Ruetschi Date: Mon, 14 Nov 2022 18:50:26 +0100 Subject: [PATCH] Rename `trust_level` to `trust_threshold` across the codebase (#2860) * Rename `trust_level` to `trust_threshold` across the codebase * Rename TrustLevel type to TrustThreshold in e2e test --- .../clients/ics07_tendermint/client_state.rs | 31 ++++++++++--------- crates/relayer/src/client_state.rs | 2 +- crates/relayer/src/light_client/tendermint.rs | 2 +- e2e/e2e/client.py | 2 +- e2e/e2e/common.py | 2 +- .../commands/misbehaviour/index.md | 2 +- .../documentation/commands/queries/channel.md | 4 +-- .../documentation/commands/queries/client.md | 2 +- .../src/tests/client_settings.rs | 8 ++--- 9 files changed, 28 insertions(+), 27 deletions(-) diff --git a/crates/relayer-types/src/clients/ics07_tendermint/client_state.rs b/crates/relayer-types/src/clients/ics07_tendermint/client_state.rs index d009bb1b7e..80be9f315d 100644 --- a/crates/relayer-types/src/clients/ics07_tendermint/client_state.rs +++ b/crates/relayer-types/src/clients/ics07_tendermint/client_state.rs @@ -31,7 +31,7 @@ pub const TENDERMINT_CLIENT_STATE_TYPE_URL: &str = "/ibc.lightclients.tendermint #[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize)] pub struct ClientState { pub chain_id: ChainId, - pub trust_level: TrustThreshold, + pub trust_threshold: TrustThreshold, pub trusting_period: Duration, pub unbonding_period: Duration, pub max_clock_drift: Duration, @@ -111,7 +111,7 @@ impl ClientState { Ok(Self { chain_id, - trust_level: trust_threshold, + trust_threshold, trusting_period, unbonding_period, max_clock_drift, @@ -156,7 +156,7 @@ impl ClientState { pub fn as_light_client_options(&self) -> Result { Ok(Options { trust_threshold: self - .trust_level + .trust_threshold .try_into() .map_err(|e: Ics02Error| Error::invalid_trust_threshold(e.to_string()))?, trusting_period: self.trusting_period, @@ -242,7 +242,7 @@ impl Ics2ClientState for ClientState { // Reset custom fields to zero values self.trusting_period = ZERO_DURATION; - self.trust_level = TrustThreshold::CLIENT_STATE_RESET; + self.trust_threshold = TrustThreshold::CLIENT_STATE_RESET; self.allow_update.after_expiry = false; self.allow_update.after_misbehaviour = false; self.frozen_height = None; @@ -265,13 +265,14 @@ impl TryFrom for ClientState { type Error = Error; fn try_from(raw: RawTmClientState) -> Result { - let trust_level = raw.trust_level.ok_or_else(Error::missing_trust_threshold)?; + let trust_threshold = raw.trust_level.ok_or_else(Error::missing_trust_threshold)?; // We need to handle the case where the client is being upgraded and the trust threshold is set to 0/0 - let trust_threshold = if trust_level.denominator == 0 && trust_level.numerator == 0 { + let trust_threshold = if trust_threshold.denominator == 0 && trust_threshold.numerator == 0 + { TrustThreshold::CLIENT_STATE_RESET } else { - trust_level + trust_threshold .try_into() .map_err(|e| Error::invalid_trust_threshold(format!("{}", e)))? }; @@ -286,7 +287,7 @@ impl TryFrom for ClientState { #[allow(deprecated)] Ok(Self { chain_id: ChainId::from_string(raw.chain_id.as_str()), - trust_level: trust_threshold, + trust_threshold, trusting_period: raw .trusting_period .ok_or_else(Error::missing_trusting_period)? @@ -324,7 +325,7 @@ impl From for RawTmClientState { #[allow(deprecated)] Self { chain_id: value.chain_id.to_string(), - trust_level: Some(value.trust_level.into()), + trust_level: Some(value.trust_threshold.into()), trusting_period: Some(value.trusting_period.into()), unbonding_period: Some(value.unbonding_period.into()), max_clock_drift: Some(value.max_clock_drift.into()), @@ -397,7 +398,7 @@ mod tests { #[derive(Clone, Debug, PartialEq)] struct ClientStateParams { id: ChainId, - trust_level: TrustThreshold, + trust_threshold: TrustThreshold, trusting_period: Duration, unbonding_period: Duration, max_clock_drift: Duration, @@ -426,7 +427,7 @@ mod tests { // Define a "default" set of parameters to reuse throughout these tests. let default_params: ClientStateParams = ClientStateParams { id: ChainId::default(), - trust_level: TrustThreshold::ONE_THIRD, + trust_threshold: TrustThreshold::ONE_THIRD, trusting_period: Duration::new(64000, 0), unbonding_period: Duration::new(128000, 0), max_clock_drift: Duration::new(3, 0), @@ -479,7 +480,7 @@ mod tests { Test { name: "Invalid (zero) trust threshold".to_string(), params: ClientStateParams { - trust_level: TrustThreshold::new(0, 3).unwrap(), + trust_threshold: TrustThreshold::new(0, 3).unwrap(), ..default_params.clone() }, want_pass: false, @@ -501,7 +502,7 @@ mod tests { let cs_result = ClientState::new( p.id, - p.trust_level, + p.trust_threshold, p.trusting_period, p.unbonding_period, p.max_clock_drift, @@ -605,7 +606,7 @@ mod tests { // Define a "default" set of parameters to reuse throughout these tests. let default_params: ClientStateParams = ClientStateParams { id: ChainId::default(), - trust_level: TrustThreshold::ONE_THIRD, + trust_threshold: TrustThreshold::ONE_THIRD, trusting_period: Duration::new(64000, 0), unbonding_period: Duration::new(128000, 0), max_clock_drift: Duration::new(3, 0), @@ -654,7 +655,7 @@ mod tests { let p = default_params.clone(); let client_state = ClientState::new( p.id, - p.trust_level, + p.trust_threshold, p.trusting_period, p.unbonding_period, p.max_clock_drift, diff --git a/crates/relayer/src/client_state.rs b/crates/relayer/src/client_state.rs index 4b26fcfc27..42c5e8f5d6 100644 --- a/crates/relayer/src/client_state.rs +++ b/crates/relayer/src/client_state.rs @@ -78,7 +78,7 @@ impl AnyClientState { pub fn trust_threshold(&self) -> Option { match self { - AnyClientState::Tendermint(state) => Some(state.trust_level), + AnyClientState::Tendermint(state) => Some(state.trust_threshold), #[cfg(test)] AnyClientState::Mock(_) => None, diff --git a/crates/relayer/src/light_client/tendermint.rs b/crates/relayer/src/light_client/tendermint.rs index 5b9e6c5da5..bcb141412b 100644 --- a/crates/relayer/src/light_client/tendermint.rs +++ b/crates/relayer/src/light_client/tendermint.rs @@ -190,7 +190,7 @@ impl LightClient { let params = TmOptions { trust_threshold: client_state - .trust_level + .trust_threshold .try_into() .map_err(Error::light_client_state)?, trusting_period: client_state.trusting_period, diff --git a/e2e/e2e/client.py b/e2e/e2e/client.py index d76b7dc6ca..c5a73c3ac6 100644 --- a/e2e/e2e/client.py +++ b/e2e/e2e/client.py @@ -61,7 +61,7 @@ class ClientState: frozen_height: Optional[Height] latest_height: Height max_clock_drift: Duration - trust_level: TrustLevel + trust_threshold: TrustThreshold trusting_period: Duration unbonding_period: Duration upgrade_path: List[str] diff --git a/e2e/e2e/common.py b/e2e/e2e/common.py index 5d70991fa7..664df0abf5 100644 --- a/e2e/e2e/common.py +++ b/e2e/e2e/common.py @@ -23,7 +23,7 @@ class Duration: @dataclass -class TrustLevel: +class TrustThreshold: denominator: int numerator: int diff --git a/guide/src/documentation/commands/misbehaviour/index.md b/guide/src/documentation/commands/misbehaviour/index.md index 68869ea1f1..dd4ae8c2b8 100644 --- a/guide/src/documentation/commands/misbehaviour/index.md +++ b/guide/src/documentation/commands/misbehaviour/index.md @@ -98,7 +98,7 @@ Which should output: "nanos": 0, "secs": 3 }, - "trust_level": { + "trust_threshold": { "denominator": "3", "numerator": "1" }, diff --git a/guide/src/documentation/commands/queries/channel.md b/guide/src/documentation/commands/queries/channel.md index f9e4c8dfe6..726986da96 100644 --- a/guide/src/documentation/commands/queries/channel.md +++ b/guide/src/documentation/commands/queries/channel.md @@ -164,7 +164,7 @@ Success: Some( id: "network2", version: 0, }, - trust_level: TrustThreshold { + trust_threshold: TrustThreshold { numerator: 1, denominator: 3, }, @@ -331,7 +331,7 @@ If the command is successful a message with the following format will be display "min_depth":0 } ], - "trust_level": + "trust_threshold": { "denominator":3, "numerator":1 diff --git a/guide/src/documentation/commands/queries/client.md b/guide/src/documentation/commands/queries/client.md index 7322d71f92..27c4d576eb 100644 --- a/guide/src/documentation/commands/queries/client.md +++ b/guide/src/documentation/commands/queries/client.md @@ -87,7 +87,7 @@ Success: ClientState { id: "ibc-2", version: 2, }, - trust_level: TrustThresholdFraction { + trust_threshold: TrustThresholdFraction { numerator: 1, denominator: 3, }, diff --git a/tools/integration-test/src/tests/client_settings.rs b/tools/integration-test/src/tests/client_settings.rs index 764fa80bc7..7df6858101 100644 --- a/tools/integration-test/src/tests/client_settings.rs +++ b/tools/integration-test/src/tests/client_settings.rs @@ -50,13 +50,13 @@ impl BinaryChainTest for ClientDefaultsTest { let state = query_client_state(chains.handle_b, client_id)?; assert_eq!(state.max_clock_drift, Duration::from_secs(24)); assert_eq!(state.trusting_period, Duration::from_secs(120_000)); - assert_eq!(state.trust_level, TrustThreshold::new(13, 23).unwrap()); + assert_eq!(state.trust_threshold, TrustThreshold::new(13, 23).unwrap()); let client_id = chains.foreign_clients.client_b_to_a.id(); let state = query_client_state(chains.handle_a, client_id)?; assert_eq!(state.max_clock_drift, Duration::from_secs(14)); assert_eq!(state.trusting_period, Duration::from_secs(340_000)); - assert_eq!(state.trust_level, TrustThreshold::TWO_THIRDS); + assert_eq!(state.trust_threshold, TrustThreshold::TWO_THIRDS); Ok(()) } } @@ -90,13 +90,13 @@ impl BinaryChainTest for ClientOptionsTest { let state = query_client_state(chains.handle_b, client_id)?; assert_eq!(state.max_clock_drift, Duration::from_secs(3)); assert_eq!(state.trusting_period, Duration::from_secs(120_000)); - assert_eq!(state.trust_level, TrustThreshold::new(13, 23).unwrap()); + assert_eq!(state.trust_threshold, TrustThreshold::new(13, 23).unwrap()); let client_id = chains.foreign_clients.client_b_to_a.id(); let state = query_client_state(chains.handle_a, client_id)?; assert_eq!(state.max_clock_drift, Duration::from_secs(6)); assert_eq!(state.trusting_period, Duration::from_secs(340_000)); - assert_eq!(state.trust_level, TrustThreshold::TWO_THIRDS); + assert_eq!(state.trust_threshold, TrustThreshold::TWO_THIRDS); Ok(()) } }