Skip to content

Commit

Permalink
tendermint: box headers in Misbehaviour message (cosmos#1145)
Browse files Browse the repository at this point in the history
Header type is quite large.  Misbehaviour holds two of those.  This becomes
an issue on platforms with small stack—such as Solana—where keeping (even
temporary) local variable may lead to stack overflow.

Fix that by Boxing each of the headers in the Misbehaviour message.

Co-authored-by: dhruvja <[email protected]>
  • Loading branch information
mina86 and dhruvja committed Apr 8, 2024
1 parent 6dd3c64 commit b4de348
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 6 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
- [ibc-client-tendermint-types] Box header fields inside of Misbehaviour type so
that the type is smaller (i.e. trade size of the type for heap memory). This
prevents stack overflows on systems with small stack (e.g. Solana).
([\#1145](https://github.com/cosmos/ibc-rs/pull/1145))
12 changes: 6 additions & 6 deletions ibc-clients/ics07-tendermint/types/src/misbehaviour.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,16 +17,16 @@ pub const TENDERMINT_MISBEHAVIOUR_TYPE_URL: &str = "/ibc.lightclients.tendermint
#[derive(Clone, Debug, PartialEq, Eq)]
pub struct Misbehaviour {
client_id: ClientId,
header1: Header,
header2: Header,
header1: Box<Header>,
header2: Box<Header>,
}

impl Misbehaviour {
pub fn new(client_id: ClientId, header1: Header, header2: Header) -> Self {
Self {
client_id,
header1,
header2,
header1: Box::new(header1),
header2: Box::new(header2),
}
}

Expand Down Expand Up @@ -98,8 +98,8 @@ impl From<Misbehaviour> for RawMisbehaviour {
#[allow(deprecated)]
RawMisbehaviour {
client_id: value.client_id.to_string(),
header_1: Some(value.header1.into()),
header_2: Some(value.header2.into()),
header_1: Some((*value.header1).into()),
header_2: Some((*value.header2).into()),
}
}
}
Expand Down

0 comments on commit b4de348

Please sign in to comment.