diff --git a/.changelog/unreleased/improvements/925-timestamp-conversion.md b/.changelog/unreleased/improvements/925-timestamp-conversion.md deleted file mode 100644 index b408f9905..000000000 --- a/.changelog/unreleased/improvements/925-timestamp-conversion.md +++ /dev/null @@ -1,3 +0,0 @@ -* `[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 27c57fe50..0d40662cb 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.8" +prost = "0.7" 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 b4b8e7fb6..9be2114b2 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.8" +prost = "0.7" rand_core = { version = "0.5", features = ["std"] } sha2 = "0.9" subtle = "2" diff --git a/proto/Cargo.toml b/proto/Cargo.toml index f3a28fe91..37e83189c 100644 --- a/proto/Cargo.toml +++ b/proto/Cargo.toml @@ -17,8 +17,8 @@ description = """ all-features = true [dependencies] -prost = "0.8" -prost-types = "0.8" +prost = "0.7" +prost-types = "0.7" 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 0fac07973..4b47ef593 100644 --- a/proto/src/prost/tendermint.crypto.rs +++ b/proto/src/prost/tendermint.crypto.rs @@ -1,3 +1,24 @@ +/// 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 { @@ -50,24 +71,3 @@ 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 4dc33809c..8ed7b702f 100644 --- a/proto/src/prost/tendermint.p2p.rs +++ b/proto/src/prost/tendermint.p2p.rs @@ -43,6 +43,29 @@ 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)] @@ -81,26 +104,3 @@ 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 655ad0729..a39adc1a3 100644 --- a/proto/src/prost/tendermint.types.rs +++ b/proto/src/prost/tendermint.types.rs @@ -276,6 +276,62 @@ 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")] @@ -424,62 +480,6 @@ 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 ca4916bce..335cb2877 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 statesync { - include!("prost/tendermint.statesync.rs"); +pub mod consensus { + include!("prost/tendermint.consensus.rs"); } -pub mod abci { - include!("prost/tendermint.abci.rs"); +pub mod types { + include!("prost/tendermint.types.rs"); } -pub mod store { - include!("prost/tendermint.store.rs"); +pub mod mempool { + include!("prost/tendermint.mempool.rs"); } -pub mod version { - include!("prost/tendermint.version.rs"); +pub mod rpc { + pub mod grpc { + include!("prost/tendermint.rpc.grpc.rs"); + } } -pub mod types { - include!("prost/tendermint.types.rs"); +pub mod blockchain { + include!("prost/tendermint.blockchain.rs"); } -pub mod consensus { - include!("prost/tendermint.consensus.rs"); +pub mod libs { + pub mod bits { + include!("prost/tendermint.libs.bits.rs"); + } } -pub mod p2p { - include!("prost/tendermint.p2p.rs"); +pub mod state { + include!("prost/tendermint.state.rs"); } -pub mod privval { - include!("prost/tendermint.privval.rs"); +pub mod version { + include!("prost/tendermint.version.rs"); } -pub mod blockchain { - include!("prost/tendermint.blockchain.rs"); +pub mod store { + include!("prost/tendermint.store.rs"); } -pub mod crypto { - include!("prost/tendermint.crypto.rs"); +pub mod privval { + include!("prost/tendermint.privval.rs"); } -pub mod mempool { - include!("prost/tendermint.mempool.rs"); +pub mod statesync { + include!("prost/tendermint.statesync.rs"); } -pub mod state { - include!("prost/tendermint.state.rs"); +pub mod p2p { + include!("prost/tendermint.p2p.rs"); } -pub mod libs { - pub mod bits { - include!("prost/tendermint.libs.bits.rs"); - } +pub mod abci { + include!("prost/tendermint.abci.rs"); } -pub mod rpc { - pub mod grpc { - include!("prost/tendermint.rpc.grpc.rs"); - } +pub mod crypto { + include!("prost/tendermint.crypto.rs"); } pub mod meta { diff --git a/tendermint/Cargo.toml b/tendermint/Cargo.toml index ebeb1ad6d..343065601 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.8" -prost-types = "0.8" +prost = "0.7" +prost-types = "0.7" 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 436191b6a..12d204b0f 100644 --- a/tendermint/src/time.rs +++ b/tendermint/src/time.rs @@ -1,21 +1,19 @@ //! Timestamps used by Tendermint blockchains -use std::convert::TryFrom; -use std::fmt; -use std::ops::{Add, Sub}; -use std::str::FromStr; -use std::time::{Duration, SystemTime, UNIX_EPOCH}; +use crate::error::{Error, Kind}; use chrono::{DateTime, Utc}; -use prost_types::TimestampOutOfSystemRangeError; use serde::{Deserialize, Serialize}; +use std::convert::{Infallible, TryFrom}; +use std::fmt; +use std::ops::{Add, Sub}; +use std::str::FromStr; +use std::time::{Duration, SystemTime, UNIX_EPOCH}; 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)] @@ -25,7 +23,7 @@ pub struct Time(DateTime); impl Protobuf for Time {} impl TryFrom for Time { - type Error = TimestampOutOfSystemRangeError; + type Error = Infallible; fn try_from(value: Timestamp) -> Result { // prost_types::Timestamp has a SystemTime converter but @@ -35,7 +33,7 @@ impl TryFrom for Time { nanos: value.nanos, }; - SystemTime::try_from(prost_value).map(Into::into) + Ok(SystemTime::from(prost_value).into()) } }