From 7ad20becb0f304c09616a65f5f63738d9d98d375 Mon Sep 17 00:00:00 2001 From: Mikhail Zabaluev Date: Thu, 9 Jun 2022 18:09:40 +0200 Subject: [PATCH] Fix JSON deserialization of abci::ResponseInfo (#1131) * 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 #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 11396ba3384feeb03087b3b771f58d5858624f49. --- .../1132-allow-omitted-fields-in-abci_info.md | 4 ++++ proto/src/prost/tendermint.abci.rs | 7 +++++-- tools/proto-compiler/src/constants.rs | 14 ++++++++++++-- 3 files changed, 21 insertions(+), 4 deletions(-) create mode 100644 .changelog/unreleased/bug-fixes/1132-allow-omitted-fields-in-abci_info.md diff --git a/.changelog/unreleased/bug-fixes/1132-allow-omitted-fields-in-abci_info.md b/.changelog/unreleased/bug-fixes/1132-allow-omitted-fields-in-abci_info.md new file mode 100644 index 000000000..3f79fbd3a --- /dev/null +++ b/.changelog/unreleased/bug-fixes/1132-allow-omitted-fields-in-abci_info.md @@ -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)) diff --git a/proto/src/prost/tendermint.abci.rs b/proto/src/prost/tendermint.abci.rs index 2a42bbd53..f8ad292ce 100644 --- a/proto/src/prost/tendermint.abci.rs +++ b/proto/src/prost/tendermint.abci.rs @@ -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, } diff --git a/tools/proto-compiler/src/constants.rs b/tools/proto-compiler/src/constants.rs index e5869ee4b..9d41d78d8 100644 --- a/tools/proto-compiler/src/constants.rs +++ b/tools/proto-compiler/src/constants.rs @@ -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")]"#; @@ -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), (