cosmos / ibc-rs

Rust implementation of the Inter-Blockchain Communication (IBC) protocol.
Apache License 2.0
181 stars 73 forks source link

wasm client fails to query `TimestampAtHeight` #1262

Open rnbguy opened 2 weeks ago

rnbguy commented 2 weeks ago

Bug Summary

With a wasm light client, compiled from ibc-rs, ibc-go fails to query TimestampAtHeight. The error it raises:

Error: Status { code: Unknown, message: "failed to execute message; message index: 0: height (0-32): Error parsing into type ibc_client_cw::types::msgs::QueryMsg: missing field revision_number: wasm contract call failed [cosmos/ibc-go/modules/light-clients/08-wasm/types/vm.go:212] With gas wanted: '18446744073709551615' and gas used: '106008' ", metadata: MetadataMap { headers: {"content-type": "application/grpc", "x-cosmos-block-height": "56"} }, source: None }

Details

This happens as ibc-go omits revision_number field if it is set to zero while mashaling to JSON. From json go package:

The "omitempty" option specifies that the field should be omitted from the encoding if the field has an empty value, defined as false, 0, a nil pointer, a nil interface value, and any empty array, slice, map, or string.

type Height struct {
    RevisionNumber int `json:"revision_number,omitempty"`
    RevisionHeight int `json:"revision_height,omitempty"`
}
h := Height{RevisionNumber: 0, RevisionHeight: 12}
hJSON, _ := json.Marshal(h)
fmt.Printf("%s", hJSON) // {"revision_height":12}

To make it work, we need to annotate our revision_number field with #[serde(default)]. https://github.com/cosmos/ibc-rs/blob/8424f6903045b203614f12a5839c330a3559cece/ibc-core/ics02-client/types/src/height.rs#L32-L34

Version

v0.53.0

rnbguy commented 2 weeks ago

This requires a design decision. So, please refrain from creating a PR for this.