From 1efe42c8625045fd99072718faf96e81aeb9c6e6 Mon Sep 17 00:00:00 2001 From: Romain Ruetschi Date: Fri, 9 Jul 2021 16:28:55 +0200 Subject: [PATCH] Update `prost` and `prost-types` to version 0.8 (#926) * Update prost to 0.8 * Update `tendermint::time::Time`'s `TryFrom` instance * Add changelog entry --- .../improvements/925-timestamp-conversion.md | 3 + abci/Cargo.toml | 2 +- p2p/Cargo.toml | 2 +- proto/Cargo.toml | 4 +- proto/src/prost/tendermint.crypto.rs | 42 +++---- proto/src/prost/tendermint.p2p.rs | 46 +++---- proto/src/prost/tendermint.types.rs | 112 +++++++++--------- proto/src/tendermint.rs | 64 +++++----- tendermint/Cargo.toml | 4 +- tendermint/src/time.rs | 18 +-- 10 files changed, 151 insertions(+), 146 deletions(-) create mode 100644 .changelog/unreleased/improvements/925-timestamp-conversion.md diff --git a/.changelog/unreleased/improvements/925-timestamp-conversion.md b/.changelog/unreleased/improvements/925-timestamp-conversion.md new file mode 100644 index 000000000..b408f9905 --- /dev/null +++ b/.changelog/unreleased/improvements/925-timestamp-conversion.md @@ -0,0 +1,3 @@ +* `[tendermint]` Fix potential panic on `SystemTime` conversion by upgrading `prost` and `prost-types` to version 0.8.0 + ([#925](https://github.com/informalsystems/tendermint-rs/issues/925)) + diff --git a/abci/Cargo.toml b/abci/Cargo.toml index 0d40662cb..27c57fe50 100644 --- a/abci/Cargo.toml +++ b/abci/Cargo.toml @@ -29,7 +29,7 @@ binary = [ "structopt", "tracing-subscriber" ] [dependencies] bytes = "1.0" eyre = "0.6" -prost = "0.7" +prost = "0.8" tendermint-proto = { version = "0.20.0", path = "../proto" } thiserror = "1.0" tracing = "0.1" diff --git a/p2p/Cargo.toml b/p2p/Cargo.toml index 9be2114b2..b4b8e7fb6 100644 --- a/p2p/Cargo.toml +++ b/p2p/Cargo.toml @@ -30,7 +30,7 @@ eyre = "0.6" flume = "0.10.7" hkdf = "0.10.0" merlin = "2" -prost = "0.7" +prost = "0.8" rand_core = { version = "0.5", features = ["std"] } sha2 = "0.9" subtle = "2" diff --git a/proto/Cargo.toml b/proto/Cargo.toml index 37e83189c..f3a28fe91 100644 --- a/proto/Cargo.toml +++ b/proto/Cargo.toml @@ -17,8 +17,8 @@ description = """ all-features = true [dependencies] -prost = "0.7" -prost-types = "0.7" +prost = "0.8" +prost-types = "0.8" bytes = "1.0" anomaly = "0.2" thiserror = "1.0" diff --git a/proto/src/prost/tendermint.crypto.rs b/proto/src/prost/tendermint.crypto.rs index 4b47ef593..0fac07973 100644 --- a/proto/src/prost/tendermint.crypto.rs +++ b/proto/src/prost/tendermint.crypto.rs @@ -1,24 +1,3 @@ -/// PublicKey defines the keys available for use with Tendermint Validators -#[derive(::serde::Deserialize, ::serde::Serialize)] -#[derive(Clone, PartialEq, ::prost::Message)] -pub struct PublicKey { - #[prost(oneof="public_key::Sum", tags="1, 2")] - pub sum: ::core::option::Option, -} -/// Nested message and enum types in `PublicKey`. -pub mod public_key { - #[derive(::serde::Deserialize, ::serde::Serialize)] - #[serde(tag = "type", content = "value")] - #[derive(Clone, PartialEq, ::prost::Oneof)] - pub enum Sum { - #[prost(bytes, tag="1")] - #[serde(rename = "tendermint/PubKeyEd25519", with = "crate::serializers::bytes::base64string")] - Ed25519(::prost::alloc::vec::Vec), - #[prost(bytes, tag="2")] - #[serde(rename = "tendermint/PubKeySecp256k1", with = "crate::serializers::bytes::base64string")] - Secp256k1(::prost::alloc::vec::Vec), - } -} #[derive(::serde::Deserialize, ::serde::Serialize)] #[derive(Clone, PartialEq, ::prost::Message)] pub struct Proof { @@ -71,3 +50,24 @@ pub struct ProofOps { #[prost(message, repeated, tag="1")] pub ops: ::prost::alloc::vec::Vec, } +/// PublicKey defines the keys available for use with Tendermint Validators +#[derive(::serde::Deserialize, ::serde::Serialize)] +#[derive(Clone, PartialEq, ::prost::Message)] +pub struct PublicKey { + #[prost(oneof="public_key::Sum", tags="1, 2")] + pub sum: ::core::option::Option, +} +/// Nested message and enum types in `PublicKey`. +pub mod public_key { + #[derive(::serde::Deserialize, ::serde::Serialize)] + #[serde(tag = "type", content = "value")] + #[derive(Clone, PartialEq, ::prost::Oneof)] + pub enum Sum { + #[prost(bytes, tag="1")] + #[serde(rename = "tendermint/PubKeyEd25519", with = "crate::serializers::bytes::base64string")] + Ed25519(::prost::alloc::vec::Vec), + #[prost(bytes, tag="2")] + #[serde(rename = "tendermint/PubKeySecp256k1", with = "crate::serializers::bytes::base64string")] + Secp256k1(::prost::alloc::vec::Vec), + } +} diff --git a/proto/src/prost/tendermint.p2p.rs b/proto/src/prost/tendermint.p2p.rs index 8ed7b702f..4dc33809c 100644 --- a/proto/src/prost/tendermint.p2p.rs +++ b/proto/src/prost/tendermint.p2p.rs @@ -43,29 +43,6 @@ pub struct DefaultNodeInfoOther { pub rpc_address: ::prost::alloc::string::String, } #[derive(Clone, PartialEq, ::prost::Message)] -pub struct PexRequest { -} -#[derive(Clone, PartialEq, ::prost::Message)] -pub struct PexAddrs { - #[prost(message, repeated, tag="1")] - pub addrs: ::prost::alloc::vec::Vec, -} -#[derive(Clone, PartialEq, ::prost::Message)] -pub struct Message { - #[prost(oneof="message::Sum", tags="1, 2")] - pub sum: ::core::option::Option, -} -/// Nested message and enum types in `Message`. -pub mod message { - #[derive(Clone, PartialEq, ::prost::Oneof)] - pub enum Sum { - #[prost(message, tag="1")] - PexRequest(super::PexRequest), - #[prost(message, tag="2")] - PexAddrs(super::PexAddrs), - } -} -#[derive(Clone, PartialEq, ::prost::Message)] pub struct PacketPing { } #[derive(Clone, PartialEq, ::prost::Message)] @@ -104,3 +81,26 @@ pub struct AuthSigMessage { #[prost(bytes="vec", tag="2")] pub sig: ::prost::alloc::vec::Vec, } +#[derive(Clone, PartialEq, ::prost::Message)] +pub struct PexRequest { +} +#[derive(Clone, PartialEq, ::prost::Message)] +pub struct PexAddrs { + #[prost(message, repeated, tag="1")] + pub addrs: ::prost::alloc::vec::Vec, +} +#[derive(Clone, PartialEq, ::prost::Message)] +pub struct Message { + #[prost(oneof="message::Sum", tags="1, 2")] + pub sum: ::core::option::Option, +} +/// Nested message and enum types in `Message`. +pub mod message { + #[derive(Clone, PartialEq, ::prost::Oneof)] + pub enum Sum { + #[prost(message, tag="1")] + PexRequest(super::PexRequest), + #[prost(message, tag="2")] + PexAddrs(super::PexAddrs), + } +} diff --git a/proto/src/prost/tendermint.types.rs b/proto/src/prost/tendermint.types.rs index a39adc1a3..655ad0729 100644 --- a/proto/src/prost/tendermint.types.rs +++ b/proto/src/prost/tendermint.types.rs @@ -276,62 +276,6 @@ pub enum SignedMsgType { /// Proposals Proposal = 32, } -#[derive(::serde::Deserialize, ::serde::Serialize)] -#[derive(Clone, PartialEq, ::prost::Message)] -pub struct CanonicalBlockId { - #[prost(bytes="vec", tag="1")] - pub hash: ::prost::alloc::vec::Vec, - #[prost(message, optional, tag="2")] - #[serde(alias = "parts")] - pub part_set_header: ::core::option::Option, -} -#[derive(::serde::Deserialize, ::serde::Serialize)] -#[derive(Clone, PartialEq, ::prost::Message)] -pub struct CanonicalPartSetHeader { - #[prost(uint32, tag="1")] - pub total: u32, - #[prost(bytes="vec", tag="2")] - pub hash: ::prost::alloc::vec::Vec, -} -#[derive(Clone, PartialEq, ::prost::Message)] -pub struct CanonicalProposal { - /// type alias for byte - #[prost(enumeration="SignedMsgType", tag="1")] - pub r#type: i32, - /// canonicalization requires fixed size encoding here - #[prost(sfixed64, tag="2")] - pub height: i64, - /// canonicalization requires fixed size encoding here - #[prost(sfixed64, tag="3")] - pub round: i64, - #[prost(int64, tag="4")] - pub pol_round: i64, - #[prost(message, optional, tag="5")] - pub block_id: ::core::option::Option, - #[prost(message, optional, tag="6")] - pub timestamp: ::core::option::Option, - #[prost(string, tag="7")] - pub chain_id: ::prost::alloc::string::String, -} -#[derive(::serde::Deserialize, ::serde::Serialize)] -#[derive(Clone, PartialEq, ::prost::Message)] -pub struct CanonicalVote { - /// type alias for byte - #[prost(enumeration="SignedMsgType", tag="1")] - pub r#type: i32, - /// canonicalization requires fixed size encoding here - #[prost(sfixed64, tag="2")] - pub height: i64, - /// canonicalization requires fixed size encoding here - #[prost(sfixed64, tag="3")] - pub round: i64, - #[prost(message, optional, tag="4")] - pub block_id: ::core::option::Option, - #[prost(message, optional, tag="5")] - pub timestamp: ::core::option::Option, - #[prost(string, tag="6")] - pub chain_id: ::prost::alloc::string::String, -} #[derive(Clone, PartialEq, ::prost::Message)] pub struct EventDataRoundState { #[prost(int64, tag="1")] @@ -480,6 +424,62 @@ pub struct EvidenceList { } #[derive(::serde::Deserialize, ::serde::Serialize)] #[derive(Clone, PartialEq, ::prost::Message)] +pub struct CanonicalBlockId { + #[prost(bytes="vec", tag="1")] + pub hash: ::prost::alloc::vec::Vec, + #[prost(message, optional, tag="2")] + #[serde(alias = "parts")] + pub part_set_header: ::core::option::Option, +} +#[derive(::serde::Deserialize, ::serde::Serialize)] +#[derive(Clone, PartialEq, ::prost::Message)] +pub struct CanonicalPartSetHeader { + #[prost(uint32, tag="1")] + pub total: u32, + #[prost(bytes="vec", tag="2")] + pub hash: ::prost::alloc::vec::Vec, +} +#[derive(Clone, PartialEq, ::prost::Message)] +pub struct CanonicalProposal { + /// type alias for byte + #[prost(enumeration="SignedMsgType", tag="1")] + pub r#type: i32, + /// canonicalization requires fixed size encoding here + #[prost(sfixed64, tag="2")] + pub height: i64, + /// canonicalization requires fixed size encoding here + #[prost(sfixed64, tag="3")] + pub round: i64, + #[prost(int64, tag="4")] + pub pol_round: i64, + #[prost(message, optional, tag="5")] + pub block_id: ::core::option::Option, + #[prost(message, optional, tag="6")] + pub timestamp: ::core::option::Option, + #[prost(string, tag="7")] + pub chain_id: ::prost::alloc::string::String, +} +#[derive(::serde::Deserialize, ::serde::Serialize)] +#[derive(Clone, PartialEq, ::prost::Message)] +pub struct CanonicalVote { + /// type alias for byte + #[prost(enumeration="SignedMsgType", tag="1")] + pub r#type: i32, + /// canonicalization requires fixed size encoding here + #[prost(sfixed64, tag="2")] + pub height: i64, + /// canonicalization requires fixed size encoding here + #[prost(sfixed64, tag="3")] + pub round: i64, + #[prost(message, optional, tag="4")] + pub block_id: ::core::option::Option, + #[prost(message, optional, tag="5")] + pub timestamp: ::core::option::Option, + #[prost(string, tag="6")] + pub chain_id: ::prost::alloc::string::String, +} +#[derive(::serde::Deserialize, ::serde::Serialize)] +#[derive(Clone, PartialEq, ::prost::Message)] pub struct Block { #[prost(message, optional, tag="1")] pub header: ::core::option::Option
, diff --git a/proto/src/tendermint.rs b/proto/src/tendermint.rs index 335cb2877..ca4916bce 100644 --- a/proto/src/tendermint.rs +++ b/proto/src/tendermint.rs @@ -1,63 +1,63 @@ //! Tendermint-proto auto-generated sub-modules for Tendermint -pub mod consensus { - include!("prost/tendermint.consensus.rs"); +pub mod statesync { + include!("prost/tendermint.statesync.rs"); } -pub mod types { - include!("prost/tendermint.types.rs"); +pub mod abci { + include!("prost/tendermint.abci.rs"); } -pub mod mempool { - include!("prost/tendermint.mempool.rs"); +pub mod store { + include!("prost/tendermint.store.rs"); } -pub mod rpc { - pub mod grpc { - include!("prost/tendermint.rpc.grpc.rs"); - } +pub mod version { + include!("prost/tendermint.version.rs"); } -pub mod blockchain { - include!("prost/tendermint.blockchain.rs"); +pub mod types { + include!("prost/tendermint.types.rs"); } -pub mod libs { - pub mod bits { - include!("prost/tendermint.libs.bits.rs"); - } +pub mod consensus { + include!("prost/tendermint.consensus.rs"); } -pub mod state { - include!("prost/tendermint.state.rs"); +pub mod p2p { + include!("prost/tendermint.p2p.rs"); } -pub mod version { - include!("prost/tendermint.version.rs"); +pub mod privval { + include!("prost/tendermint.privval.rs"); } -pub mod store { - include!("prost/tendermint.store.rs"); +pub mod blockchain { + include!("prost/tendermint.blockchain.rs"); } -pub mod privval { - include!("prost/tendermint.privval.rs"); +pub mod crypto { + include!("prost/tendermint.crypto.rs"); } -pub mod statesync { - include!("prost/tendermint.statesync.rs"); +pub mod mempool { + include!("prost/tendermint.mempool.rs"); } -pub mod p2p { - include!("prost/tendermint.p2p.rs"); +pub mod state { + include!("prost/tendermint.state.rs"); } -pub mod abci { - include!("prost/tendermint.abci.rs"); +pub mod libs { + pub mod bits { + include!("prost/tendermint.libs.bits.rs"); + } } -pub mod crypto { - include!("prost/tendermint.crypto.rs"); +pub mod rpc { + pub mod grpc { + include!("prost/tendermint.rpc.grpc.rs"); + } } pub mod meta { diff --git a/tendermint/Cargo.toml b/tendermint/Cargo.toml index 343065601..ebeb1ad6d 100644 --- a/tendermint/Cargo.toml +++ b/tendermint/Cargo.toml @@ -42,8 +42,8 @@ ed25519-dalek = { version = "1", features = ["serde"] } futures = "0.3" num-traits = "0.2" once_cell = "1.3" -prost = "0.7" -prost-types = "0.7" +prost = "0.8" +prost-types = "0.8" serde = { version = "1", features = ["derive"] } serde_json = "1" serde_bytes = "0.11" diff --git a/tendermint/src/time.rs b/tendermint/src/time.rs index 12d204b0f..436191b6a 100644 --- a/tendermint/src/time.rs +++ b/tendermint/src/time.rs @@ -1,19 +1,21 @@ //! Timestamps used by Tendermint blockchains -use crate::error::{Error, Kind}; - -use chrono::{DateTime, Utc}; -use serde::{Deserialize, Serialize}; - -use std::convert::{Infallible, TryFrom}; +use std::convert::TryFrom; use std::fmt; use std::ops::{Add, Sub}; use std::str::FromStr; use std::time::{Duration, SystemTime, UNIX_EPOCH}; + +use chrono::{DateTime, Utc}; +use prost_types::TimestampOutOfSystemRangeError; +use serde::{Deserialize, Serialize}; + use tendermint_proto::google::protobuf::Timestamp; use tendermint_proto::serializers::timestamp; use tendermint_proto::Protobuf; +use crate::error::{Error, Kind}; + /// Tendermint timestamps /// #[derive(Copy, Clone, Debug, Eq, PartialEq, PartialOrd, Ord, Serialize, Deserialize)] @@ -23,7 +25,7 @@ pub struct Time(DateTime); impl Protobuf for Time {} impl TryFrom for Time { - type Error = Infallible; + type Error = TimestampOutOfSystemRangeError; fn try_from(value: Timestamp) -> Result { // prost_types::Timestamp has a SystemTime converter but @@ -33,7 +35,7 @@ impl TryFrom for Time { nanos: value.nanos, }; - Ok(SystemTime::from(prost_value).into()) + SystemTime::try_from(prost_value).map(Into::into) } }