Skip to content

Commit 95fc7d7

Browse files
authored
refactor: nits from nightly clippy (#962)
* use enum tuple variants directly * use first() over get(0) * use infallible conversion * rm redundant export * cargo fmt
1 parent fe6b5b0 commit 95fc7d7

File tree

8 files changed

+90
-82
lines changed

8 files changed

+90
-82
lines changed

crates/ibc-testkit/src/testapp/ibc/core/core_ctx.rs

Lines changed: 18 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -144,26 +144,28 @@ impl ValidationContext for MockContext {
144144
let self_chain_id = &self.host_chain_id;
145145
let self_revision_number = self_chain_id.revision_number();
146146
if self_revision_number != mock_client_state.latest_height().revision_number() {
147-
return Err(ConnectionError::InvalidClientState {
148-
reason: format!(
149-
"client is not in the same revision as the chain. expected: {}, got: {}",
150-
self_revision_number,
151-
mock_client_state.latest_height().revision_number()
152-
),
153-
})
154-
.map_err(ContextError::ConnectionError);
147+
return Err(ContextError::ConnectionError(
148+
ConnectionError::InvalidClientState {
149+
reason: format!(
150+
"client is not in the same revision as the chain. expected: {}, got: {}",
151+
self_revision_number,
152+
mock_client_state.latest_height().revision_number()
153+
),
154+
},
155+
));
155156
}
156157

157158
let host_current_height = self.latest_height().increment();
158159
if mock_client_state.latest_height() >= host_current_height {
159-
return Err(ConnectionError::InvalidClientState {
160-
reason: format!(
161-
"client has latest height {} greater than or equal to chain height {}",
162-
mock_client_state.latest_height(),
163-
host_current_height
164-
),
165-
})
166-
.map_err(ContextError::ConnectionError);
160+
return Err(ContextError::ConnectionError(
161+
ConnectionError::InvalidClientState {
162+
reason: format!(
163+
"client has latest height {} greater than or equal to chain height {}",
164+
mock_client_state.latest_height(),
165+
host_current_height
166+
),
167+
},
168+
));
167169
}
168170

169171
Ok(())
Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
mod context;
22
mod types;
33

4-
pub use context::*;
54
pub use types::*;

crates/ibc-testkit/src/utils/dummies/core/client/msg_create_client.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ pub fn dummy_raw_msg_create_client() -> MsgCreateClient {
1515

1616
MsgCreateClient {
1717
client_state: Some(Any::from(tm_client_state)),
18-
consensus_state: Some(Any::from(TmConsensusState::try_from(tm_header).unwrap())),
18+
consensus_state: Some(Any::from(TmConsensusState::from(tm_header))),
1919
signer: dummy_bech32_account(),
2020
}
2121
}

crates/ibc/src/applications/transfer/msgs/transfer.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ impl TryFrom<RawMsgTransfer> for MsgTransfer {
7070

7171
// Packet timeout height and packet timeout timestamp cannot both be unset.
7272
if !timeout_height_on_b.is_set() && !timeout_timestamp_on_b.is_set() {
73-
return Err(PacketError::MissingTimeout).map_err(ContextError::from)?;
73+
return Err(ContextError::from(PacketError::MissingTimeout))?;
7474
}
7575

7676
Ok(MsgTransfer {

crates/ibc/src/core/ics02_client/handler/update_client.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,7 @@ where
9999

100100
{
101101
let event = {
102-
let consensus_height = consensus_heights.get(0).ok_or(ClientError::Other {
102+
let consensus_height = consensus_heights.first().ok_or(ClientError::Other {
103103
description: "client update state returned no updated height".to_string(),
104104
})?;
105105

crates/ibc/src/core/ics03_connection/delay.rs

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -33,21 +33,23 @@ where
3333
let earliest_valid_time = (last_client_update_time + conn_delay_time_period)
3434
.map_err(ConnectionError::TimestampOverflow)?;
3535
if current_host_time < earliest_valid_time {
36-
return Err(ConnectionError::NotEnoughTimeElapsed {
37-
current_host_time,
38-
earliest_valid_time,
39-
})
40-
.map_err(ContextError::ConnectionError);
36+
return Err(ContextError::ConnectionError(
37+
ConnectionError::NotEnoughTimeElapsed {
38+
current_host_time,
39+
earliest_valid_time,
40+
},
41+
));
4142
}
4243

4344
// Verify that the current host chain height is later than the last client update height
4445
let earliest_valid_height = last_client_update_height.add(conn_delay_height_period);
4546
if current_host_height < earliest_valid_height {
46-
return Err(ConnectionError::NotEnoughBlocksElapsed {
47-
current_host_height,
48-
earliest_valid_height,
49-
})
50-
.map_err(ContextError::ConnectionError);
47+
return Err(ContextError::ConnectionError(
48+
ConnectionError::NotEnoughBlocksElapsed {
49+
current_host_height,
50+
earliest_valid_height,
51+
},
52+
));
5153
};
5254

5355
Ok(())

crates/ibc/src/core/ics23_commitment/merkle.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -145,10 +145,10 @@ impl MerkleProof {
145145
// verify the absence of key in lowest subtree
146146
let proof = self
147147
.proofs
148-
.get(0)
148+
.first()
149149
.ok_or(CommitmentError::InvalidMerkleProof)?;
150150
let spec = ics23_specs
151-
.get(0)
151+
.first()
152152
.ok_or(CommitmentError::InvalidMerkleProof)?;
153153
// keys are represented from root-to-leaf
154154
let key = keys

crates/ibc/src/hosts/tendermint/validate_self_client.rs

Lines changed: 55 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -38,47 +38,51 @@ pub trait ValidateSelfClientContext {
3838

3939
let self_chain_id = self.chain_id();
4040
if self_chain_id != &tm_client_state.chain_id {
41-
return Err(ConnectionError::InvalidClientState {
42-
reason: format!(
43-
"invalid chain-id. expected: {}, got: {}",
44-
self_chain_id, tm_client_state.chain_id
45-
),
46-
})
47-
.map_err(ContextError::ConnectionError);
41+
return Err(ContextError::ConnectionError(
42+
ConnectionError::InvalidClientState {
43+
reason: format!(
44+
"invalid chain-id. expected: {}, got: {}",
45+
self_chain_id, tm_client_state.chain_id
46+
),
47+
},
48+
));
4849
}
4950

5051
let self_revision_number = self_chain_id.revision_number();
5152
if self_revision_number != tm_client_state.latest_height().revision_number() {
52-
return Err(ConnectionError::InvalidClientState {
53-
reason: format!(
54-
"client is not in the same revision as the chain. expected: {}, got: {}",
55-
self_revision_number,
56-
tm_client_state.latest_height().revision_number()
57-
),
58-
})
59-
.map_err(ContextError::ConnectionError);
53+
return Err(ContextError::ConnectionError(
54+
ConnectionError::InvalidClientState {
55+
reason: format!(
56+
"client is not in the same revision as the chain. expected: {}, got: {}",
57+
self_revision_number,
58+
tm_client_state.latest_height().revision_number()
59+
),
60+
},
61+
));
6062
}
6163

6264
if tm_client_state.latest_height() >= self.host_current_height() {
63-
return Err(ConnectionError::InvalidClientState {
64-
reason: format!(
65-
"client has latest height {} greater than or equal to chain height {}",
66-
tm_client_state.latest_height(),
67-
self.host_current_height()
68-
),
69-
})
70-
.map_err(ContextError::ConnectionError);
65+
return Err(ContextError::ConnectionError(
66+
ConnectionError::InvalidClientState {
67+
reason: format!(
68+
"client has latest height {} greater than or equal to chain height {}",
69+
tm_client_state.latest_height(),
70+
self.host_current_height()
71+
),
72+
},
73+
));
7174
}
7275

7376
if self.proof_specs() != &tm_client_state.proof_specs {
74-
return Err(ConnectionError::InvalidClientState {
75-
reason: format!(
76-
"client has invalid proof specs. expected: {:?}, got: {:?}",
77-
self.proof_specs(),
78-
tm_client_state.proof_specs
79-
),
80-
})
81-
.map_err(ContextError::ConnectionError);
77+
return Err(ContextError::ConnectionError(
78+
ConnectionError::InvalidClientState {
79+
reason: format!(
80+
"client has invalid proof specs. expected: {:?}, got: {:?}",
81+
self.proof_specs(),
82+
tm_client_state.proof_specs
83+
),
84+
},
85+
));
8286
}
8387

8488
let _ = {
@@ -94,36 +98,37 @@ pub trait ValidateSelfClientContext {
9498
};
9599

96100
if self.unbonding_period() != tm_client_state.unbonding_period {
97-
return Err(ConnectionError::InvalidClientState {
98-
reason: format!(
99-
"invalid unbonding period. expected: {:?}, got: {:?}",
100-
self.unbonding_period(),
101-
tm_client_state.unbonding_period,
102-
),
103-
})
104-
.map_err(ContextError::ConnectionError);
101+
return Err(ContextError::ConnectionError(
102+
ConnectionError::InvalidClientState {
103+
reason: format!(
104+
"invalid unbonding period. expected: {:?}, got: {:?}",
105+
self.unbonding_period(),
106+
tm_client_state.unbonding_period,
107+
),
108+
},
109+
));
105110
}
106111

107112
if tm_client_state.unbonding_period < tm_client_state.trusting_period {
108-
return Err(ConnectionError::InvalidClientState{ reason: format!(
113+
return Err(ContextError::ConnectionError(ConnectionError::InvalidClientState{ reason: format!(
109114
"unbonding period must be greater than trusting period. unbonding period ({:?}) < trusting period ({:?})",
110115
tm_client_state.unbonding_period,
111116
tm_client_state.trusting_period
112-
)})
113-
.map_err(ContextError::ConnectionError);
117+
)}));
114118
}
115119

116120
if !tm_client_state.upgrade_path.is_empty()
117121
&& self.upgrade_path() != tm_client_state.upgrade_path
118122
{
119-
return Err(ConnectionError::InvalidClientState {
120-
reason: format!(
121-
"invalid upgrade path. expected: {:?}, got: {:?}",
122-
self.upgrade_path(),
123-
tm_client_state.upgrade_path
124-
),
125-
})
126-
.map_err(ContextError::ConnectionError);
123+
return Err(ContextError::ConnectionError(
124+
ConnectionError::InvalidClientState {
125+
reason: format!(
126+
"invalid upgrade path. expected: {:?}, got: {:?}",
127+
self.upgrade_path(),
128+
tm_client_state.upgrade_path
129+
),
130+
},
131+
));
127132
}
128133

129134
Ok(())

0 commit comments

Comments
 (0)