Skip to content

Commit 2259108

Browse files
imp: minimize prost dependency (#998)
1 parent fe9a26b commit 2259108

File tree

21 files changed

+38
-70
lines changed

21 files changed

+38
-70
lines changed

.changelog/unreleased/improvements/992-making-cosmwasm-compile-apps-transfers.md

Lines changed: 0 additions & 4 deletions
This file was deleted.
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
- [`cw-check`] More rigorous CosmWasm check by upgrading dependencies and
2+
including `std` and `schema` features for `ibc-core`.
3+
([\#992](https://github.com/cosmos/ibc-rs/pull/992))
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
- [`ibc-primitives`] Minimize `prost` dependency by introducing `ToVec` trait
2+
([\#997](https://github.com/cosmos/ibc-rs/issues/997))

ibc-clients/ics07-tendermint/Cargo.toml

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@ all-features = true
1818

1919
[dependencies]
2020
# external dependencies
21-
prost = { workspace = true }
2221
serde = { workspace = true, optional = true }
2322

2423
# ibc dependencies
@@ -36,7 +35,6 @@ tendermint-light-client-verifier = { workspace = true, features = ["rust-crypto"
3635
[features]
3736
default = ["std"]
3837
std = [
39-
"prost/std",
4038
"serde/std",
4139
"ibc-client-tendermint-types/std",
4240
"ibc-core-client/std",

ibc-clients/ics07-tendermint/src/client_state.rs

Lines changed: 3 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ use ibc_core_host::types::path::{
3333
};
3434
use ibc_core_host::ExecutionContext;
3535
use ibc_primitives::prelude::*;
36-
use prost::Message;
36+
use ibc_primitives::ToVec;
3737

3838
use super::consensus_state::ConsensusState as TmConsensusState;
3939
use crate::context::{
@@ -169,32 +169,22 @@ impl ClientStateCommon for ClientState {
169169

170170
let last_height = self.latest_height().revision_height();
171171

172-
let mut client_state_value = Vec::new();
173-
upgraded_client_state
174-
.encode(&mut client_state_value)
175-
.map_err(ClientError::Encode)?;
176-
177172
// Verify the proof of the upgraded client state
178173
self.verify_membership(
179174
&upgrade_path_prefix,
180175
&proof_upgrade_client,
181176
root,
182177
Path::UpgradeClient(UpgradeClientPath::UpgradedClientState(last_height)),
183-
client_state_value,
178+
upgraded_client_state.to_vec(),
184179
)?;
185180

186-
let mut cons_state_value = Vec::new();
187-
upgraded_consensus_state
188-
.encode(&mut cons_state_value)
189-
.map_err(ClientError::Encode)?;
190-
191181
// Verify the proof of the upgraded consensus state
192182
self.verify_membership(
193183
&upgrade_path_prefix,
194184
&proof_upgrade_consensus_state,
195185
root,
196186
Path::UpgradeClient(UpgradeClientPath::UpgradedClientConsensusState(last_height)),
197-
cons_state_value,
187+
upgraded_consensus_state.to_vec(),
198188
)?;
199189

200190
Ok(())

ibc-core/ics02-client/Cargo.toml

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -17,10 +17,6 @@ description = """
1717
all-features = true
1818

1919
[dependencies]
20-
# external dependencies
21-
prost = { workspace = true }
22-
23-
# ibc dependencies
2420
ibc-core-client-types = { workspace = true }
2521
ibc-core-client-context = { workspace = true }
2622
ibc-core-commitment-types = { workspace = true }
@@ -31,7 +27,6 @@ ibc-primitives = { workspace = true }
3127
[features]
3228
default = ["std"]
3329
std = [
34-
"prost/std",
3530
"ibc-core-client-types/std",
3631
"ibc-core-client-context/std",
3732
"ibc-core-commitment-types/std",

ibc-core/ics02-client/context/Cargo.toml

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,6 @@ all-features = true
2121
# external dependencies
2222
derive_more = { workspace = true }
2323
displaydoc = { workspace = true }
24-
prost = { workspace = true }
2524
subtle-encoding = { workspace = true }
2625

2726
# ibc dependencies
@@ -39,7 +38,6 @@ tendermint = { workspace = true }
3938
default = ["std"]
4039
std = [
4140
"displaydoc/std",
42-
"prost/std",
4341
"subtle-encoding/std",
4442
"ibc-core-client-types/std",
4543
"ibc-core-commitment-types/std",

ibc-core/ics02-client/src/handler/update_client.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ use ibc_core_handler_types::error::ContextError;
1111
use ibc_core_handler_types::events::{IbcEvent, MessageEvent};
1212
use ibc_core_host::{ExecutionContext, ValidationContext};
1313
use ibc_primitives::prelude::*;
14-
use prost::Message;
14+
use ibc_primitives::ToVec;
1515

1616
pub fn validate<Ctx>(ctx: &Ctx, msg: MsgUpdateOrMisbehaviour) -> Result<(), ContextError>
1717
where
@@ -108,7 +108,7 @@ where
108108
client_state.client_type(),
109109
*consensus_height,
110110
consensus_heights,
111-
header.encode_to_vec(),
111+
header.to_vec(),
112112
))
113113
};
114114
ctx.emit_ibc_event(IbcEvent::Message(MessageEvent::Client))?;

ibc-core/ics02-client/types/src/error.rs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -58,8 +58,6 @@ pub enum ClientError {
5858
MissingRawConsensusState,
5959
/// invalid client id in the update client message: `{0}`
6060
InvalidMsgUpdateClientId(IdentifierError),
61-
/// encode error: `{0}`
62-
Encode(prost::EncodeError),
6361
/// decode error: `{0}`
6462
Decode(prost::DecodeError),
6563
/// invalid client identifier error: `{0}`

ibc-core/ics03-connection/Cargo.toml

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -17,10 +17,6 @@ description = """
1717
all-features = true
1818

1919
[dependencies]
20-
# external dependencies
21-
prost = { workspace = true }
22-
23-
# ibc dependencies
2420
ibc-core-client = { workspace = true }
2521
ibc-core-connection-types = { workspace = true }
2622
ibc-core-host = { workspace = true }
@@ -30,7 +26,6 @@ ibc-primitives = { workspace = true }
3026
[features]
3127
default = ["std"]
3228
std = [
33-
"prost/std",
3429
"ibc-core-client/std",
3530
"ibc-core-connection-types/std",
3631
"ibc-core-host/std",

ibc-core/ics03-connection/src/handler/conn_open_ack.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ use ibc_core_host::types::path::{ClientConsensusStatePath, ClientStatePath, Conn
1414
use ibc_core_host::{ExecutionContext, ValidationContext};
1515
use ibc_primitives::prelude::*;
1616
use ibc_primitives::proto::Protobuf;
17-
use prost::Message;
17+
use ibc_primitives::ToVec;
1818

1919
pub fn validate<Ctx>(ctx_a: &Ctx, msg: MsgConnectionOpenAck) -> Result<(), ContextError>
2020
where
@@ -106,7 +106,7 @@ where
106106
&msg.proof_client_state_of_a_on_b,
107107
consensus_state_of_b_on_a.root(),
108108
Path::ClientState(ClientStatePath::new(vars.client_id_on_b())),
109-
msg.client_state_of_a_on_b.encode_to_vec(),
109+
msg.client_state_of_a_on_b.to_vec(),
110110
)
111111
.map_err(|e| ConnectionError::ClientStateVerificationFailure {
112112
client_id: vars.client_id_on_b().clone(),

ibc-core/ics03-connection/src/handler/conn_open_try.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ use ibc_core_host::types::path::{
1515
use ibc_core_host::{ExecutionContext, ValidationContext};
1616
use ibc_primitives::prelude::*;
1717
use ibc_primitives::proto::Protobuf;
18-
use prost::Message;
18+
use ibc_primitives::ToVec;
1919

2020
pub fn validate<Ctx>(ctx_b: &Ctx, msg: MsgConnectionOpenTry) -> Result<(), ContextError>
2121
where
@@ -101,7 +101,7 @@ where
101101
&msg.proof_client_state_of_b_on_a,
102102
consensus_state_of_a_on_b.root(),
103103
Path::ClientState(ClientStatePath::new(client_id_on_a)),
104-
msg.client_state_of_b_on_a.encode_to_vec(),
104+
msg.client_state_of_b_on_a.to_vec(),
105105
)
106106
.map_err(|e| ConnectionError::ClientStateVerificationFailure {
107107
client_id: msg.client_id_on_b.clone(),

ibc-core/ics04-channel/Cargo.toml

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -17,10 +17,6 @@ description = """
1717
all-features = true
1818

1919
[dependencies]
20-
# external dependencies
21-
prost = { workspace = true }
22-
23-
# ibc dependencies
2420
ibc-core-client = { workspace = true }
2521
ibc-core-connection = { workspace = true }
2622
ibc-core-channel-types = { workspace = true }
@@ -33,7 +29,6 @@ ibc-primitives = { workspace = true }
3329
[features]
3430
default = ["std"]
3531
std = [
36-
"prost/std",
3732
"ibc-core-client/std",
3833
"ibc-core-connection/std",
3934
"ibc-core-channel-types/std",

ibc-core/ics04-channel/src/handler/timeout.rs

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@ use ibc_core_host::types::path::{
1515
use ibc_core_host::{ExecutionContext, ValidationContext};
1616
use ibc_core_router::module::Module;
1717
use ibc_primitives::prelude::*;
18-
use prost::Message;
1918

2019
use super::timeout_on_close;
2120

@@ -231,19 +230,12 @@ where
231230
let seq_recv_path_on_b =
232231
SeqRecvPath::new(&msg.packet.port_id_on_b, &msg.packet.chan_id_on_b);
233232

234-
let mut value = Vec::new();
235-
u64::from(msg.packet.seq_on_a)
236-
.encode(&mut value)
237-
.map_err(|_| PacketError::CannotEncodeSequence {
238-
sequence: msg.packet.seq_on_a,
239-
})?;
240-
241233
client_state_of_b_on_a.verify_membership(
242234
conn_end_on_a.counterparty().prefix(),
243235
&msg.proof_unreceived_on_b,
244236
consensus_state_of_b_on_a.root(),
245237
Path::SeqRecv(seq_recv_path_on_b),
246-
value,
238+
msg.packet.seq_on_a.to_vec(),
247239
)
248240
} else {
249241
let receipt_path_on_b = ReceiptPath::new(

ibc-core/ics04-channel/src/handler/timeout_on_close.rs

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@ use ibc_core_host::types::path::{
1313
use ibc_core_host::ValidationContext;
1414
use ibc_primitives::prelude::*;
1515
use ibc_primitives::proto::Protobuf;
16-
use prost::Message;
1716

1817
pub fn validate<Ctx>(ctx_a: &Ctx, msg: &MsgTimeoutOnClose) -> Result<(), ContextError>
1918
where
@@ -135,19 +134,12 @@ where
135134
}
136135
let seq_recv_path_on_b = SeqRecvPath::new(&packet.port_id_on_b, &packet.chan_id_on_b);
137136

138-
let mut value = Vec::new();
139-
u64::from(packet.seq_on_a).encode(&mut value).map_err(|_| {
140-
PacketError::CannotEncodeSequence {
141-
sequence: packet.seq_on_a,
142-
}
143-
})?;
144-
145137
client_state_of_b_on_a.verify_membership(
146138
conn_end_on_a.counterparty().prefix(),
147139
&msg.proof_unreceived_on_b,
148140
consensus_state_of_b_on_a.root(),
149141
Path::SeqRecv(seq_recv_path_on_b),
150-
value,
142+
packet.seq_on_a.to_vec(),
151143
)
152144
} else {
153145
let receipt_path_on_b = ReceiptPath::new(

ibc-core/ics04-channel/types/src/error.rs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -164,8 +164,6 @@ pub enum PacketError {
164164
port_id: PortId,
165165
channel_id: ChannelId,
166166
},
167-
/// Cannot encode sequence `{sequence}`
168-
CannotEncodeSequence { sequence: Sequence },
169167
/// other error: `{description}`
170168
Other { description: String },
171169
}

ibc-core/ics24-host/Cargo.toml

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,6 @@ all-features = true
2121
# external dependencies
2222
derive_more = { workspace = true }
2323
displaydoc = { workspace = true }
24-
prost = { workspace = true }
2524
subtle-encoding = { workspace = true }
2625

2726
# ibc dependencies
@@ -41,7 +40,6 @@ rstest = { workspace = true }
4140
default = ["std"]
4241
std = [
4342
"displaydoc/std",
44-
"prost/std",
4543
"subtle-encoding/std",
4644
"ibc-core-client-types/std",
4745
"ibc-core-client-context/std",

ibc-core/ics24-host/cosmos/Cargo.toml

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,6 @@ all-features = true
2222
borsh = { workspace = true, optional = true}
2323
derive_more = { workspace = true }
2424
displaydoc = { workspace = true }
25-
prost = { workspace = true }
2625
serde = { workspace = true, optional = true }
2726
sha2 = { workspace = true }
2827
subtle-encoding = { workspace = true }
@@ -50,7 +49,6 @@ scale-info = { workspace = true, optional = true }
5049
default = ["std"]
5150
std = [
5251
"displaydoc/std",
53-
"prost/std",
5452
"serde/std",
5553
"sha2/std",
5654
"subtle-encoding/std",

ibc-core/ics24-host/types/src/identifiers/sequence.rs

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
use ibc_primitives::prelude::*;
2+
use ibc_primitives::ToVec;
23

34
use crate::error::IdentifierError;
45

@@ -34,16 +35,26 @@ impl core::str::FromStr for Sequence {
3435
}
3536

3637
impl Sequence {
38+
/// Gives the sequence number.
3739
pub fn value(&self) -> u64 {
3840
self.0
3941
}
42+
43+
/// Returns `true` if the sequence number is zero.
4044
pub fn is_zero(&self) -> bool {
4145
self.0 == 0
4246
}
4347

48+
/// Increments the sequence number by one.
4449
pub fn increment(&self) -> Sequence {
4550
Sequence(self.0 + 1)
4651
}
52+
53+
/// Encodes the sequence number into a `Vec<u8>` using
54+
/// `prost::Message::encode_to_vec`.
55+
pub fn to_vec(&self) -> Vec<u8> {
56+
self.0.to_vec()
57+
}
4758
}
4859

4960
impl From<u64> for Sequence {

ibc-core/ics26-routing/Cargo.toml

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@ all-features = true
2020
# external dependencies
2121
derive_more = { workspace = true }
2222
displaydoc = { workspace = true }
23-
prost = { workspace = true }
2423
subtle-encoding = { workspace = true }
2524

2625
# ibc dependencies
@@ -33,7 +32,6 @@ ibc-core-router-types = { workspace = true }
3332
default = ["std"]
3433
std = [
3534
"displaydoc/std",
36-
"prost/std",
3735
"subtle-encoding/std",
3836
"ibc-primitives/std",
3937
"ibc-core-channel-types/std",

ibc-primitives/src/traits/proto.rs

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,3 +31,14 @@ where
3131
<Self as TryFrom<P>>::Error: Display,
3232
{
3333
}
34+
35+
/// Convenient trait for converting types to a raw Protobuf `Vec<u8>`.
36+
pub trait ToVec {
37+
fn to_vec(&self) -> Vec<u8>;
38+
}
39+
40+
impl<T: prost::Message> ToVec for T {
41+
fn to_vec(&self) -> Vec<u8> {
42+
self.encode_to_vec()
43+
}
44+
}

0 commit comments

Comments
 (0)