Skip to content

Commit

Permalink
Update to tendermint-rs v0.36.0 (#3966)
Browse files Browse the repository at this point in the history
* Adapt to upcoming changes in tendermint-rs regarding `EventAttribute` keys and values

informalsystems/tendermint-rs#1405

* Update tendermint-rs to 0.36.0

* Remove ibc-proto patch
  • Loading branch information
romac authored Apr 25, 2024
1 parent df5d09b commit 954c2f1
Show file tree
Hide file tree
Showing 11 changed files with 113 additions and 64 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
- Update to tendermint-rs v0.36.0
([\#3966](https://github.com/informalsystems/hermes/issues/3966))
49 changes: 18 additions & 31 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

16 changes: 8 additions & 8 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -30,13 +30,13 @@ ibc-test-framework = { version = "0.27.2", path = "tools/test-framework" }
ibc-integration-test = { version = "0.27.2", path = "tools/integration-test" }

# Tendermint dependencies
tendermint = { version = "0.35.0", default-features = false }
tendermint-light-client = { version = "0.35.0", default-features = false }
tendermint-light-client-detector = { version = "0.35.0", default-features = false }
tendermint-light-client-verifier = { version = "0.35.0", default-features = false }
tendermint-proto = "0.35.0"
tendermint-rpc = "0.35.0"
tendermint-testgen = "0.35.0"
tendermint = { version = "0.36.0", default-features = false }
tendermint-light-client = { version = "0.36.0", default-features = false }
tendermint-light-client-detector = { version = "0.36.0", default-features = false }
tendermint-light-client-verifier = { version = "0.36.0", default-features = false }
tendermint-proto = { version = "0.36.0" }
tendermint-rpc = { version = "0.36.0" }
tendermint-testgen = { version = "0.36.0" }

# Other dependencies
abscissa_core = "=0.6.0"
Expand Down Expand Up @@ -72,7 +72,7 @@ hex = "0.4.3"
http = "0.2.9"
humantime = "2.1.0"
humantime-serde = "1.1.1"
ibc-proto = "0.43.0"
ibc-proto = "0.44.0"
ics23 = "0.11.1"
itertools = "0.12.1"
moka = "0.12.5"
Expand Down
6 changes: 5 additions & 1 deletion crates/relayer-types/src/applications/ics29_fee/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,10 @@ define_error! {

EventAttributeNotFound
{ key: String }
| e | { format_args!("IBC event attribute not found for key: {}", e.key) },
| e | { format_args!("IBC event attribute not found for key `{}`", e.key) },

EventAttributeInvalidUtf8
{ key: String }
| e | { format_args!("IBC event attribute value for key `{}` is not a valid UTF-8 string", e.key) },
}
}
9 changes: 7 additions & 2 deletions crates/relayer-types/src/applications/ics29_fee/events.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,12 +26,17 @@ fn find_value<'a>(key: &str, entries: &'a [abci::EventAttribute]) -> Result<&'a
entries
.iter()
.find_map(|entry| {
if entry.key == key {
Some(entry.value.as_str())
if entry.key_bytes() == key.as_bytes() {
Some(
entry
.value_str()
.map_err(|_| Error::event_attribute_invalid_utf8(key.to_owned())),
)
} else {
None
}
})
.transpose()?
.ok_or_else(|| Error::event_attribute_not_found(key.to_owned()))
}

Expand Down
15 changes: 8 additions & 7 deletions crates/relayer-types/src/applications/ics31_icq/events.rs
Original file line number Diff line number Diff line change
Expand Up @@ -32,21 +32,22 @@ fn find_value<'a>(key: &str, entries: &'a [abci::EventAttribute]) -> Result<&'a
entries
.iter()
.find_map(|entry| {
if entry.key == key {
Some(entry.value.as_str())
if entry.key_bytes() == key.as_bytes() {
Some(entry.value_str().map_err(|_| {
Error::event(format!(
"attribute value for key {key} is not a valid UTF-8 string"
))
}))
} else {
None
}
})
.transpose()?
.ok_or_else(|| Error::event(format!("attribute not found for key: {key}")))
}

fn new_attr(key: &str, value: &str) -> abci::EventAttribute {
abci::EventAttribute {
key: String::from(key),
value: String::from(value),
index: true,
}
abci::EventAttribute::from((key, value, true))
}

impl From<CrossChainQueryPacket> for abci::Event {
Expand Down
7 changes: 7 additions & 0 deletions crates/relayer-types/src/core/ics02_client/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -280,5 +280,12 @@ define_error! {
ClientSpecific
{ description: String }
| e | { format_args!("client specific error: {0}", e.description) },

MalformedEventAttributeKey
| _ | { format_args!("event attribute key is not valid UTF-8") },

MalformedEventAttributeValue
{ key: String }
| e | { format_args!("event attribute value for key {} is not valid UTF-8", e.key) },
}
}
7 changes: 7 additions & 0 deletions crates/relayer-types/src/core/ics03_connection/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -157,5 +157,12 @@ define_error! {

ImplementationSpecific
| _ | { "implementation specific error" },

MalformedEventAttributeKey
| _ | { format_args!("event attribute key is not valid UTF-8") },

MalformedEventAttributeValue
{ key: String }
| e | { format_args!("event attribute value for key {} is not valid UTF-8", e.key) },
}
}
9 changes: 8 additions & 1 deletion crates/relayer-types/src/core/ics04_channel/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -359,7 +359,14 @@ define_error! {

AbciConversionFailed
{ abci_event: String }
| e | { format_args!("Failed to convert abci event to IbcEvent: {}", e.abci_event)}
| e | { format_args!("Failed to convert abci event to IbcEvent: {}", e.abci_event)},

MalformedEventAttributeKey
| _ | { format_args!("event attribute key is not valid UTF-8") },

MalformedEventAttributeValue
{ key: String }
| e | { format_args!("event attribute value for key {} is not valid UTF-8", e.key) },
}
}

Expand Down
49 changes: 38 additions & 11 deletions crates/relayer/src/event.rs
Original file line number Diff line number Diff line change
Expand Up @@ -301,8 +301,14 @@ fn client_extract_attributes_from_tx(event: &AbciEvent) -> Result<ClientAttribut
let mut attr = ClientAttributes::default();

for tag in &event.attributes {
let key = tag.key.as_str();
let value = tag.value.as_str();
let key = tag
.key_str()
.map_err(|_| ClientError::malformed_event_attribute_key())?;

let value = tag
.value_str()
.map_err(|_| ClientError::malformed_event_attribute_value(key.to_owned()))?;

match key {
client_events::CLIENT_ID_ATTRIBUTE_KEY => {
attr.client_id = value
Expand All @@ -328,9 +334,13 @@ fn client_extract_attributes_from_tx(event: &AbciEvent) -> Result<ClientAttribut

pub fn extract_header_from_tx(event: &AbciEvent) -> Result<AnyHeader, ClientError> {
for tag in &event.attributes {
if tag.key == HEADER_ATTRIBUTE_KEY {
let header_bytes = hex::decode(tag.value.to_lowercase())
.map_err(|_| ClientError::malformed_header())?;
if tag.key_bytes() == HEADER_ATTRIBUTE_KEY.as_bytes() {
let header_bytes = hex::decode(
tag.value_str()
.map_err(|_| ClientError::malformed_header())?
.to_lowercase(),
)
.map_err(|_| ClientError::malformed_header())?;
return decode_header(&header_bytes);
}
}
Expand All @@ -344,8 +354,14 @@ fn connection_extract_attributes_from_tx(
let mut attr = ConnectionAttributes::default();

for tag in &event.attributes {
let key = tag.key.as_str();
let value = tag.value.as_str();
let key = tag
.key_str()
.map_err(|_| ConnectionError::malformed_event_attribute_key())?;

let value = tag
.value_str()
.map_err(|_| ConnectionError::malformed_event_attribute_value(key.to_owned()))?;

match key {
connection_events::CONN_ID_ATTRIBUTE_KEY => {
attr.connection_id = value.parse().ok();
Expand Down Expand Up @@ -373,8 +389,14 @@ fn channel_extract_attributes_from_tx(
let mut attr = ChannelAttributes::default();

for tag in &event.attributes {
let key = tag.key.as_str();
let value = tag.value.as_str();
let key = tag
.key_str()
.map_err(|_| ChannelError::malformed_event_attribute_key())?;

let value = tag
.value_str()
.map_err(|_| ChannelError::malformed_event_attribute_value(key.to_owned()))?;

match key {
channel_events::PORT_ID_ATTRIBUTE_KEY => {
attr.port_id = value.parse().map_err(ChannelError::identifier)?
Expand Down Expand Up @@ -405,8 +427,13 @@ pub fn extract_packet_and_write_ack_from_tx(
let mut write_ack: Vec<u8> = Vec::new();

for tag in &event.attributes {
let key = tag.key.as_str();
let value = tag.value.as_str();
let key = tag
.key_str()
.map_err(|_| ChannelError::malformed_event_attribute_key())?;

let value = tag
.value_str()
.map_err(|_| ChannelError::malformed_event_attribute_value(key.to_owned()))?;

match key {
channel_events::PKT_SRC_PORT_ATTRIBUTE_KEY => {
Expand Down
8 changes: 5 additions & 3 deletions crates/relayer/src/event/source/rpc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -292,7 +292,9 @@ fn dedupe(events: Vec<abci::Event>) -> Vec<abci::Event> {
.attributes
.iter()
.zip(other.0.attributes.iter())
.all(|(a, b)| a.key == b.key && a.value == b.value)
.all(|(a, b)| {
a.key_bytes() == b.key_bytes() && a.value_bytes() == b.value_bytes()
})
}
}

Expand All @@ -304,8 +306,8 @@ fn dedupe(events: Vec<abci::Event>) -> Vec<abci::Event> {

for attr in &self.0.attributes {
// NOTE: We don't hash the index because it is not deterministic
attr.key.hash(state);
attr.value.hash(state);
attr.key_bytes().hash(state);
attr.value_bytes().hash(state);
}
}
}
Expand Down

0 comments on commit 954c2f1

Please sign in to comment.