Skip to content

Commit bd2c1e6

Browse files
authored
use ibc_proto::protobuf::Protobuf to replace tendermint_proto::Protobuf. (#754)
* use ibc_proto::protobuf::Protobuf to replace tendermint_proto::Protobuf. * fix tests * Create 747-fix-747-Protobuf-out-of-memory.md * Fix issue 747 by replacing tendermint_proto::Protobuf with ibc_proto::protobuf::Protobuf (#754)
1 parent e125999 commit bd2c1e6

File tree

10 files changed

+14
-26
lines changed

10 files changed

+14
-26
lines changed
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
- use ibc_proto::protobuf::Protobuf to replace tendermint_proto::Protobuf
2+
([#754](https://github.com/cosmos/ibc-rs/pull/754))
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
- Tendermint ConsensusState -> Any can crash if out of memory
2+
([#747](https://github.com/cosmos/ibc-rs/issues/747))

crates/ibc-derive/src/consensus_state.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ pub fn consensus_state_derive_impl(ast: DeriveInput) -> TokenStream {
3535
}
3636
}
3737

38-
fn encode_vec(&self) -> core::result::Result<Vec<u8>, tendermint_proto::Error> {
38+
fn encode_vec(&self) -> Vec<u8> {
3939
match self {
4040
#(#encode_vec_impl),*
4141
}

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

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,9 @@ use crate::prelude::*;
44

55
use ibc_proto::google::protobuf::Any;
66
use ibc_proto::ibc::lightclients::tendermint::v1::ConsensusState as RawConsensusState;
7+
use ibc_proto::protobuf::Protobuf;
78
use tendermint::{hash::Algorithm, time::Time, Hash};
89
use tendermint_proto::google::protobuf as tpb;
9-
use tendermint_proto::Error as TmProtoError;
10-
use tendermint_proto::Protobuf;
1110

1211
use crate::clients::ics07_tendermint::error::Error;
1312
use crate::clients::ics07_tendermint::header::Header;
@@ -125,8 +124,7 @@ impl From<ConsensusState> for Any {
125124
fn from(consensus_state: ConsensusState) -> Self {
126125
Any {
127126
type_url: TENDERMINT_CONSENSUS_STATE_TYPE_URL.to_string(),
128-
value: Protobuf::<RawConsensusState>::encode_vec(&consensus_state)
129-
.expect("Out of memory"),
127+
value: Protobuf::<RawConsensusState>::encode_vec(&consensus_state),
130128
}
131129
}
132130
}
@@ -156,7 +154,7 @@ impl ConsensusStateTrait for ConsensusState {
156154
self.timestamp.into()
157155
}
158156

159-
fn encode_vec(&self) -> Result<Vec<u8>, TmProtoError> {
157+
fn encode_vec(&self) -> Vec<u8> {
160158
<Self as Protobuf<Any>>::encode_vec(self)
161159
}
162160
}

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

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,5 @@ pub trait ConsensusState: Send + Sync {
2525
/// Serializes the `ConsensusState`. This is expected to be implemented as
2626
/// first converting to the raw type (i.e. the protobuf definition), and then
2727
/// serializing that.
28-
///
29-
/// Note that the `Protobuf` trait in `tendermint-proto` provides convenience methods
30-
/// to do this automatically.
31-
fn encode_vec(&self) -> Result<Vec<u8>, tendermint_proto::Error>;
28+
fn encode_vec(&self) -> Vec<u8>;
3229
}

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

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,16 +9,13 @@ use crate::Height;
99
use alloc::string::String;
1010
use displaydoc::Display;
1111
use ibc_proto::protobuf::Error as ProtoError;
12-
use tendermint_proto::Error as TmProtoError;
1312

1413
#[derive(Debug, Display)]
1514
pub enum ConnectionError {
1615
/// client error: `{0}`
1716
Client(client_error::ClientError),
1817
/// invalid connection state: expected `{expected}`, actual `{actual}`
1918
InvalidState { expected: String, actual: String },
20-
/// failed to encode consensus state: `{0}`
21-
ConsensusStateEncodeFailure(TmProtoError),
2219
/// invalid connection end error: `{0}`
2320
InvalidConnectionEnd(ProtoError),
2421
/// consensus height claimed by the client on the other party is too advanced: `{target_height}` (host chain current height: `{current_height}`)

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

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -117,9 +117,7 @@ where
117117
&msg.proof_consensus_state_of_a_on_b,
118118
consensus_state_of_b_on_a.root(),
119119
Path::ClientConsensusState(client_cons_state_path_on_b),
120-
expected_consensus_state_of_a_on_b
121-
.encode_vec()
122-
.map_err(ConnectionError::ConsensusStateEncodeFailure)?,
120+
expected_consensus_state_of_a_on_b.encode_vec(),
123121
)
124122
.map_err(|e| ConnectionError::ConsensusStateVerificationFailure {
125123
height: msg.proofs_height_on_b,

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

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -114,9 +114,7 @@ where
114114
&msg.proof_consensus_state_of_b_on_a,
115115
consensus_state_of_a_on_b.root(),
116116
Path::ClientConsensusState(client_cons_state_path_on_a),
117-
expected_consensus_state_of_b_on_a
118-
.encode_vec()
119-
.map_err(ConnectionError::ConsensusStateEncodeFailure)?,
117+
expected_consensus_state_of_b_on_a.encode_vec(),
120118
)
121119
.map_err(|e| ConnectionError::ConsensusStateVerificationFailure {
122120
height: msg.proofs_height_on_a,

crates/ibc/src/mock/consensus_state.rs

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,6 @@ use ibc_proto::google::protobuf::Any;
44
use ibc_proto::ibc::mock::ConsensusState as RawMockConsensusState;
55
use ibc_proto::protobuf::Protobuf;
66

7-
use tendermint_proto::{Error, Protobuf as TmProtobuf};
8-
97
use crate::core::ics02_client::consensus_state::ConsensusState;
108
use crate::core::ics02_client::error::ClientError;
119
use crate::core::ics23_commitment::commitment::CommitmentRoot;
@@ -96,8 +94,6 @@ impl From<MockConsensusState> for Any {
9694
}
9795
}
9896

99-
impl TmProtobuf<Any> for MockConsensusState {}
100-
10197
impl ConsensusState for MockConsensusState {
10298
fn root(&self) -> &CommitmentRoot {
10399
&self.root
@@ -107,7 +103,7 @@ impl ConsensusState for MockConsensusState {
107103
self.header.timestamp
108104
}
109105

110-
fn encode_vec(&self) -> Result<Vec<u8>, Error> {
111-
<Self as TmProtobuf<Any>>::encode_vec(self)
106+
fn encode_vec(&self) -> Vec<u8> {
107+
<Self as Protobuf<Any>>::encode_vec(self)
112108
}
113109
}

crates/ibc/src/mock/context.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,8 @@ use core::fmt::Debug;
1717
use core::ops::{Add, Sub};
1818
use core::time::Duration;
1919
use derive_more::{From, TryInto};
20+
use ibc_proto::protobuf::Protobuf;
2021
use parking_lot::Mutex;
21-
use tendermint_proto::Protobuf;
2222

2323
use ibc_proto::google::protobuf::Any;
2424
use tracing::debug;

0 commit comments

Comments
 (0)