Skip to content

Commit

Permalink
Fix JSON deserialization of abci::ResponseInfo (informalsystems#1131)
Browse files Browse the repository at this point in the history
* Fix JSON deserialization of abci::ResponseInfo

The fields are annotated with json:"omitempty" in the Go source,
so give them default values for Deserialize. The /abci_info endpoint
is known to omit the app_version field in some recent revisions of Gaia.

* Changelog entry for informalsystems#1131

* Annotate last_block_add_hash with serde(default)

The only field of abci::ResponseInfo where it remained missing,
 to match the json:"omitempty" flag in Go.

* rpc: Drop "std" feature from serde_json dependency

* Revert "rpc: Drop "std" feature from serde_json dependency"

This reverts commit 11396ba.
  • Loading branch information
mzabaluev authored Jun 9, 2022
1 parent 1a252a8 commit 7ad20be
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 4 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
- `[tools/proto-compiler]` Annotate serde to fall back to `Default` for the
omitted fields when deserializing `tendermint_proto::abci::ResponseInfo` struct,
also providing deserialization for the response at the `/abci_info` RPC endpoint.
([#1132](https://github.com/informalsystems/tendermint-rs/issues/1132))
7 changes: 5 additions & 2 deletions proto/src/prost/tendermint.abci.rs
Original file line number Diff line number Diff line change
Expand Up @@ -216,17 +216,20 @@ pub struct ResponseFlush {
#[derive(Clone, PartialEq, ::prost::Message)]
pub struct ResponseInfo {
#[prost(string, tag="1")]
#[serde(default)]
pub data: ::prost::alloc::string::String,
/// this is the software version of the application. TODO: remove?
#[prost(string, tag="2")]
#[serde(default)]
pub version: ::prost::alloc::string::String,
#[prost(uint64, tag="3")]
#[serde(with = "crate::serializers::from_str")]
#[serde(with = "crate::serializers::from_str", default)]
pub app_version: u64,
#[prost(int64, tag="4")]
#[serde(with = "crate::serializers::from_str")]
#[serde(with = "crate::serializers::from_str", default)]
pub last_block_height: i64,
#[prost(bytes="bytes", tag="5")]
#[serde(default)]
#[serde(skip_serializing_if = "bytes::Bytes::is_empty")]
pub last_block_app_hash: ::prost::bytes::Bytes,
}
Expand Down
14 changes: 12 additions & 2 deletions tools/proto-compiler/src/constants.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ const SERIALIZED: &str = r#"#[derive(::serde::Deserialize, ::serde::Serialize)]"
const TYPE_TAG: &str = r#"#[serde(tag = "type", content = "value")]"#;

/// Predefined custom attributes for field annotations
const DEFAULT: &str = r#"#[serde(default)]"#;
const QUOTED: &str = r#"#[serde(with = "crate::serializers::from_str")]"#;
const QUOTED_WITH_DEFAULT: &str = r#"#[serde(with = "crate::serializers::from_str", default)]"#;
const HEXSTRING: &str = r#"#[serde(with = "crate::serializers::bytes::hexstring")]"#;
Expand Down Expand Up @@ -85,14 +86,23 @@ pub static CUSTOM_FIELD_ATTRIBUTES: &[(&str, &str)] = &[
".tendermint.types.EvidenceParams.max_bytes",
QUOTED_WITH_DEFAULT,
),
(".tendermint.abci.ResponseInfo.last_block_height", QUOTED),
(".tendermint.version.Consensus.block", QUOTED),
(".tendermint.version.Consensus.app", QUOTED_WITH_DEFAULT),
(".tendermint.abci.ResponseInfo.data", DEFAULT),
(".tendermint.abci.ResponseInfo.version", DEFAULT),
(
".tendermint.abci.ResponseInfo.app_version",
QUOTED_WITH_DEFAULT,
),
(
".tendermint.abci.ResponseInfo.last_block_height",
QUOTED_WITH_DEFAULT,
),
(".tendermint.abci.ResponseInfo.last_block_app_hash", DEFAULT),
(
".tendermint.abci.ResponseInfo.last_block_app_hash",
BYTES_SKIP_IF_EMPTY,
),
(".tendermint.abci.ResponseInfo.app_version", QUOTED),
(".tendermint.types.BlockID.hash", HEXSTRING),
(".tendermint.types.BlockID.part_set_header", ALIAS_PARTS),
(
Expand Down

0 comments on commit 7ad20be

Please sign in to comment.