Skip to content

Commit 4c16095

Browse files
Fix clippy warnings (#310)
* Use variables directly in the format! & write! strings * Remove `clippy::large_enum_variant`, `clippy::ptr_arg`, `clippy::wrong_self_convention` * Fix lint issues identified by clippy 0.1.67 * Replace Box<ValidatorSet> with Vec<Validator> * Add changelog entry
1 parent cec7c31 commit 4c16095

File tree

29 files changed

+72
-116
lines changed

29 files changed

+72
-116
lines changed
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
- Change type of `trusted_validator_set` field in
2+
`MisbehaviourTrustedValidatorHashMismatch` error variant from `ValidatorSet` to
3+
`Vec<Validator>` to avoid clippy catches
4+
([#309](https://github.com/cosmos/ibc-rs/issues/309))
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
- Improve clippy catches and fix lint issues identified by clippy 0.1.67
2+
([#309](https://github.com/cosmos/ibc-rs/issues/309))

crates/ibc/README.md

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,29 +3,30 @@
33
[![Crate][crate-image]][crate-link]
44
[![Docs][docs-image]][docs-link]
55
[![Build Status][build-image]][build-link]
6-
[![End to End testing][e2e-image]][e2e-link]
76
[![Apache 2.0 Licensed][license-image]][license-link]
87
![Rust Stable][rustc-image]
98
![Rust 1.60+][rustc-version]
109

11-
1210
Implementation of the Inter-Blockchain Communication Protocol ([IBC]) in Rust.
1311

1412
## Documentation
1513

1614
See documentation on [docs.rs][docs-link].
1715

1816
## Divergence from the Interchain Standards (ICS)
17+
1918
This crate diverges from the [ICS specification](https://github.com/cosmos/ibc) in a number of ways. See below for more details.
2019

2120
### Module system: no support for untrusted modules
21+
2222
ICS 24 (Host Requirements) gives the [following requirement](https://github.com/cosmos/ibc/blob/master/spec/core/ics-024-host-requirements/README.md#module-system) about the module system that the host state machine must support:
2323

2424
> The host state machine must support a module system, whereby self-contained, potentially mutually distrusted packages of code can safely execute on the same ledger [...].
2525
2626
**This crate currently does not support mutually distrusted packages**. That is, modules on the host state machine are assumed to be fully trusted. In practice, this means that every module has either been written by the host state machine developers, or fully vetted by them.
2727

2828
### Port system: No object capability system
29+
2930
ICS 5 (Port Allocation) requires the host system to support either object-capability reference or source authentication for modules.
3031

3132
> In the former object-capability case, the IBC handler must have the ability to generate object-capabilities, unique, opaque references which can be passed to a module and will not be duplicable by other modules. [...]
@@ -36,6 +37,7 @@ ICS 5 (Port Allocation) requires the host system to support either object-capabi
3637
For more background on this, see [this issue](https://github.com/informalsystems/ibc-rs/issues/2159).
3738

3839
### Port system: transferring and releasing a port
40+
3941
ICS 5 (Port Allocation) requires the IBC handler to permit [transferring ownership of a port](https://github.com/cosmos/ibc/tree/master/spec/core/ics-005-port-allocation#transferring-ownership-of-a-port) and [releasing a port](https://github.com/cosmos/ibc/tree/master/spec/core/ics-005-port-allocation#releasing-a-port).
4042

4143
We currently support neither.
@@ -65,5 +67,4 @@ Unless required by applicable law or agreed to in writing, software distributed
6567

6668
[//]: # (general links)
6769

68-
[ibc-rs]: https://github.com/cosmos/ibc-rs
6970
[IBC]: https://github.com/cosmos/ibc

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ impl Acknowledgement {
3737
}
3838

3939
pub fn from_error(err: TokenTransferError) -> Self {
40-
Self::Error(format!("{}: {}", ACK_ERR_STR, err))
40+
Self::Error(format!("{ACK_ERR_STR}: {err}"))
4141
}
4242
}
4343

@@ -53,8 +53,8 @@ impl AsRef<[u8]> for Acknowledgement {
5353
impl Display for Acknowledgement {
5454
fn fmt(&self, f: &mut Formatter<'_>) -> Result<(), FmtError> {
5555
match self {
56-
Acknowledgement::Success(_) => write!(f, "{}", ACK_SUCCESS_B64),
57-
Acknowledgement::Error(err_str) => write!(f, "{}", err_str),
56+
Acknowledgement::Success(_) => write!(f, "{ACK_SUCCESS_B64}"),
57+
Acknowledgement::Error(err_str) => write!(f, "{err_str}"),
5858
}
5959
}
6060
}

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

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

108108
// https://github.com/cosmos/cosmos-sdk/blob/master/docs/architecture/adr-028-public-key-addresses.md
109109
pub fn cosmos_adr028_escrow_address(port_id: &PortId, channel_id: &ChannelId) -> Vec<u8> {
110-
let contents = format!("{}/{}", port_id, channel_id);
110+
let contents = format!("{port_id}/{channel_id}");
111111

112112
let mut hasher = Sha256::new();
113113
hasher.update(VERSION.as_bytes());

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -142,7 +142,7 @@ impl Display for TracePath {
142142
.map(|prefix| prefix.to_string())
143143
.collect::<Vec<String>>()
144144
.join("/");
145-
write!(f, "{}", path)
145+
write!(f, "{path}")
146146
}
147147
}
148148

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

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

7070
let timeout_height: TimeoutHeight = raw_msg.timeout_height.try_into().map_err(|e| {
7171
TokenTransferError::InvalidPacketTimeoutHeight {
72-
context: format!("invalid timeout height {}", e),
72+
context: format!("invalid timeout height {e}"),
7373
}
7474
})?;
7575

crates/ibc/src/clients/ics07_tendermint/client_state.rs

Lines changed: 6 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -117,26 +117,23 @@ impl ClientState {
117117
if trusting_period <= Duration::new(0, 0) {
118118
return Err(Error::InvalidTrustThreshold {
119119
reason: format!(
120-
"ClientState trusting period ({:?}) must be greater than zero",
121-
trusting_period
120+
"ClientState trusting period ({trusting_period:?}) must be greater than zero"
122121
),
123122
});
124123
}
125124

126125
if unbonding_period <= Duration::new(0, 0) {
127126
return Err(Error::InvalidTrustThreshold {
128127
reason: format!(
129-
"ClientState unbonding period ({:?}) must be greater than zero",
130-
unbonding_period
128+
"ClientState unbonding period ({unbonding_period:?}) must be greater than zero"
131129
),
132130
});
133131
}
134132

135133
if trusting_period >= unbonding_period {
136134
return Err(Error::InvalidTrustThreshold {
137135
reason: format!(
138-
"ClientState trusting period ({:?}) must be smaller than unbonding period ({:?})",
139-
trusting_period, unbonding_period,
136+
"ClientState trusting period ({trusting_period:?}) must be smaller than unbonding period ({unbonding_period:?})"
140137
),
141138
});
142139
}
@@ -166,8 +163,7 @@ impl ClientState {
166163
if key.trim().is_empty() {
167164
return Err(Error::Validation {
168165
reason: format!(
169-
"ClientState upgrade-path key at index {:?} cannot be empty",
170-
idx
166+
"ClientState upgrade-path key at index {idx:?} cannot be empty"
171167
),
172168
});
173169
}
@@ -286,7 +282,7 @@ impl ClientState {
286282

287283
if trusted_consensus_state.next_validators_hash != trusted_val_hash {
288284
return Err(Error::MisbehaviourTrustedValidatorHashMismatch {
289-
trusted_validator_set: header.trusted_validator_set.clone(),
285+
trusted_validator_set: header.trusted_validator_set.validators().clone(),
290286
next_validators_hash: trusted_consensus_state.next_validators_hash,
291287
trusted_val_hash,
292288
}
@@ -1207,7 +1203,7 @@ impl TryFrom<RawTmClientState> for ClientState {
12071203
trust_level
12081204
.try_into()
12091205
.map_err(|e| Error::InvalidTrustThreshold {
1210-
reason: format!("{}", e),
1206+
reason: format!("{e}"),
12111207
})?
12121208
};
12131209

crates/ibc/src/clients/ics07_tendermint/consensus_state.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ impl TryFrom<RawConsensusState> for ConsensusState {
6666
let timestamp = proto_timestamp
6767
.try_into()
6868
.map_err(|e| Error::InvalidRawClientState {
69-
reason: format!("invalid timestamp: {}", e),
69+
reason: format!("invalid timestamp: {e}"),
7070
})?;
7171

7272
Ok(Self {

crates/ibc/src/clients/ics07_tendermint/error.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ use tendermint::account::Id;
1212
use tendermint::{Error as TendermintError, Hash};
1313
use tendermint_light_client_verifier::errors::VerificationErrorDetail as LightClientErrorDetail;
1414
use tendermint_light_client_verifier::operations::VotingPowerTally;
15-
use tendermint_light_client_verifier::types::ValidatorSet;
15+
use tendermint_light_client_verifier::types::Validator;
1616
use tendermint_light_client_verifier::Verdict;
1717

1818
#[derive(Debug, Display)]
@@ -105,7 +105,7 @@ pub enum Error {
105105
},
106106
/// trusted validators `{trusted_validator_set:?}`, does not hash to latest trusted validators. Expected: `{next_validators_hash}`, got: `{trusted_val_hash}`
107107
MisbehaviourTrustedValidatorHashMismatch {
108-
trusted_validator_set: ValidatorSet,
108+
trusted_validator_set: Vec<Validator>,
109109
next_validators_hash: Hash,
110110
trusted_val_hash: Hash,
111111
},

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

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -176,8 +176,7 @@ pub fn process(
176176
)));
177177

178178
output.log(format!(
179-
"success: generated new client identifier: {}",
180-
client_id
179+
"success: generated new client identifier: {client_id}"
181180
));
182181

183182
Ok(output.with_result(result))

crates/ibc/src/core/ics02_client/msgs.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@ pub mod misbehaviour;
1414
pub mod update_client;
1515
pub mod upgrade_client;
1616

17-
#[allow(clippy::large_enum_variant)]
1817
#[derive(Clone, Debug)]
1918
pub enum ClientMsg {
2019
CreateClient(MsgCreateClient),

crates/ibc/src/core/ics03_connection/handler/conn_open_init.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -133,8 +133,7 @@ pub(crate) fn process(
133133
};
134134

135135
output.log(format!(
136-
"success: conn_open_init: generated new connection identifier: {}",
137-
conn_id_on_a
136+
"success: conn_open_init: generated new connection identifier: {conn_id_on_a}",
138137
));
139138

140139
{

crates/ibc/src/core/ics04_channel/channel.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -260,7 +260,6 @@ impl ChannelEnd {
260260
self.ordering.eq(other)
261261
}
262262

263-
#[allow(clippy::ptr_arg)]
264263
pub fn connection_hops_matches(&self, other: &Vec<ConnectionId>) -> bool {
265264
self.connection_hops.eq(other)
266265
}

crates/ibc/src/core/ics04_channel/handler/chan_open_init.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -47,8 +47,7 @@ pub(crate) fn process<Ctx: ChannelReader>(
4747
let chan_id_on_a = ChannelId::new(ctx_a.channel_counter()?);
4848

4949
output.log(format!(
50-
"success: channel open init with channel identifier: {}",
51-
chan_id_on_a
50+
"success: channel open init with channel identifier: {chan_id_on_a}"
5251
));
5352

5453
let result = ChannelResult {

crates/ibc/src/core/ics04_channel/handler/chan_open_try.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -104,8 +104,7 @@ pub(crate) fn process<Ctx: ChannelReader>(
104104
let chan_id_on_b = ChannelId::new(ctx_b.channel_counter()?);
105105

106106
output.log(format!(
107-
"success: channel open try with channel identifier: {}",
108-
chan_id_on_b
107+
"success: channel open try with channel identifier: {chan_id_on_b}"
109108
));
110109

111110
let result = ChannelResult {

crates/ibc/src/core/ics04_channel/timeout.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -133,7 +133,7 @@ impl From<Height> for TimeoutHeight {
133133
impl Display for TimeoutHeight {
134134
fn fmt(&self, f: &mut Formatter<'_>) -> Result<(), FmtError> {
135135
match self {
136-
TimeoutHeight::At(timeout_height) => write!(f, "{}", timeout_height),
136+
TimeoutHeight::At(timeout_height) => write!(f, "{timeout_height}"),
137137
TimeoutHeight::Never => write!(f, "no timeout"),
138138
}
139139
}

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -152,7 +152,7 @@ impl fmt::Debug for CommitmentPrefix {
152152
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
153153
let converted = core::str::from_utf8(self.as_bytes());
154154
match converted {
155-
Ok(s) => write!(f, "{}", s),
155+
Ok(s) => write!(f, "{s}"),
156156
Err(_e) => write!(f, "<not valid UTF8: {:?}>", self.as_bytes()),
157157
}
158158
}
@@ -163,7 +163,7 @@ impl Serialize for CommitmentPrefix {
163163
where
164164
S: serde::Serializer,
165165
{
166-
format!("{:?}", self).serialize(serializer)
166+
format!("{self:?}").serialize(serializer)
167167
}
168168
}
169169

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ use crate::core::ics23_commitment::error::CommitmentError;
1515
use crate::core::ics23_commitment::specs::ProofSpecs;
1616

1717
pub fn apply_prefix(prefix: &CommitmentPrefix, mut path: Vec<String>) -> MerklePath {
18-
let mut key_path: Vec<String> = vec![format!("{:?}", prefix)];
18+
let mut key_path: Vec<String> = vec![format!("{prefix:?}")];
1919
key_path.append(&mut path);
2020
MerklePath { key_path }
2121
}

crates/ibc/src/core/ics24_host/identifier.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ impl ChainId {
5050
/// ```
5151
pub fn new(name: String, version: u64) -> Self {
5252
Self {
53-
id: format!("{}-{}", name, version),
53+
id: format!("{name}-{version}"),
5454
version,
5555
}
5656
}
@@ -203,7 +203,7 @@ impl ClientId {
203203
/// ```
204204
pub fn new(client_type: ClientType, counter: u64) -> Result<Self, ValidationError> {
205205
let prefix = client_type.as_str();
206-
let id = format!("{}-{}", prefix, counter);
206+
let id = format!("{prefix}-{counter}");
207207
Self::from_str(id.as_str())
208208
}
209209

0 commit comments

Comments
 (0)