Skip to content

Commit

Permalink
Rename trust_level to trust_threshold across the codebase (inform…
Browse files Browse the repository at this point in the history
…alsystems#2860)

* Rename `trust_level` to `trust_threshold` across the codebase

* Rename TrustLevel type to TrustThreshold in e2e test
  • Loading branch information
romac authored Nov 14, 2022
1 parent 32e3723 commit 16beffa
Show file tree
Hide file tree
Showing 9 changed files with 28 additions and 27 deletions.
31 changes: 16 additions & 15 deletions crates/relayer-types/src/clients/ics07_tendermint/client_state.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -111,7 +111,7 @@ impl ClientState {

Ok(Self {
chain_id,
trust_level: trust_threshold,
trust_threshold,
trusting_period,
unbonding_period,
max_clock_drift,
Expand Down Expand Up @@ -156,7 +156,7 @@ impl ClientState {
pub fn as_light_client_options(&self) -> Result<Options, Error> {
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,
Expand Down Expand Up @@ -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;
Expand All @@ -265,13 +265,14 @@ impl TryFrom<RawTmClientState> for ClientState {
type Error = Error;

fn try_from(raw: RawTmClientState) -> Result<Self, Self::Error> {
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)))?
};
Expand All @@ -286,7 +287,7 @@ impl TryFrom<RawTmClientState> 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)?
Expand Down Expand Up @@ -324,7 +325,7 @@ impl From<ClientState> 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()),
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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),
Expand Down Expand Up @@ -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,
Expand All @@ -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,
Expand Down Expand Up @@ -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),
Expand Down Expand Up @@ -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,
Expand Down
2 changes: 1 addition & 1 deletion crates/relayer/src/client_state.rs
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ impl AnyClientState {

pub fn trust_threshold(&self) -> Option<TrustThreshold> {
match self {
AnyClientState::Tendermint(state) => Some(state.trust_level),
AnyClientState::Tendermint(state) => Some(state.trust_threshold),

#[cfg(test)]
AnyClientState::Mock(_) => None,
Expand Down
2 changes: 1 addition & 1 deletion crates/relayer/src/light_client/tendermint.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
2 changes: 1 addition & 1 deletion e2e/e2e/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand Down
2 changes: 1 addition & 1 deletion e2e/e2e/common.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ class Duration:


@dataclass
class TrustLevel:
class TrustThreshold:
denominator: int
numerator: int

Expand Down
2 changes: 1 addition & 1 deletion guide/src/documentation/commands/misbehaviour/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ Which should output:
"nanos": 0,
"secs": 3
},
"trust_level": {
"trust_threshold": {
"denominator": "3",
"numerator": "1"
},
Expand Down
4 changes: 2 additions & 2 deletions guide/src/documentation/commands/queries/channel.md
Original file line number Diff line number Diff line change
Expand Up @@ -164,7 +164,7 @@ Success: Some(
id: "network2",
version: 0,
},
trust_level: TrustThreshold {
trust_threshold: TrustThreshold {
numerator: 1,
denominator: 3,
},
Expand Down Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion guide/src/documentation/commands/queries/client.md
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ Success: ClientState {
id: "ibc-2",
version: 2,
},
trust_level: TrustThresholdFraction {
trust_threshold: TrustThresholdFraction {
numerator: 1,
denominator: 3,
},
Expand Down
8 changes: 4 additions & 4 deletions tools/integration-test/src/tests/client_settings.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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(())
}
}
Expand Down Expand Up @@ -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(())
}
}
Expand Down

0 comments on commit 16beffa

Please sign in to comment.