From b7e300fd6e14df967efaa3244e4aa1f774f6d149 Mon Sep 17 00:00:00 2001 From: Alexander Simmerl Date: Fri, 3 Jan 2020 11:36:40 +0100 Subject: [PATCH 01/55] Set clippy rules in root --- tendermint/src/lib.rs | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/tendermint/src/lib.rs b/tendermint/src/lib.rs index 5edfdc293..d778da96a 100644 --- a/tendermint/src/lib.rs +++ b/tendermint/src/lib.rs @@ -13,6 +13,14 @@ unused_qualifications )] #![forbid(unsafe_code)] +#![deny( + clippy::all, + clippy::cargo, + clippy::nursery, + clippy::pedantic, + clippy::restriction, + clippy::result_unrwap_used +)] #![doc( html_logo_url = "https://raw.githubusercontent.com/tendermint/kms/master/img/tendermint.png", html_root_url = "https://docs.rs/tendermint/0.11.0" From f4bc257730a671b3d8fe696d83b2387e9394528e Mon Sep 17 00:00:00 2001 From: Alexander Simmerl Date: Fri, 3 Jan 2020 13:53:27 +0100 Subject: [PATCH 02/55] Remove Error prefix in kind enum --- tendermint/src/abci/transaction/hash.rs | 2 +- tendermint/src/account.rs | 2 +- tendermint/src/block/height.rs | 2 +- tendermint/src/chain/id.rs | 2 +- tendermint/src/config.rs | 7 +---- tendermint/src/config/node_key.rs | 5 +--- tendermint/src/config/priv_validator_key.rs | 7 +---- tendermint/src/error.rs | 32 ++++++++++----------- tendermint/src/hash.rs | 2 +- tendermint/src/lib.rs | 6 ++-- tendermint/src/net.rs | 3 +- tendermint/src/node/id.rs | 2 +- tendermint/src/public_key.rs | 2 +- tendermint/src/time.rs | 2 +- tendermint/src/timeout.rs | 2 +- 15 files changed, 32 insertions(+), 46 deletions(-) diff --git a/tendermint/src/abci/transaction/hash.rs b/tendermint/src/abci/transaction/hash.rs index 3d90c3740..745199e48 100644 --- a/tendermint/src/abci/transaction/hash.rs +++ b/tendermint/src/abci/transaction/hash.rs @@ -1,6 +1,6 @@ //! Transaction hashes -use crate::error::{Error, ErrorKind}; +use crate::{Error, ErrorKind}; use serde::{de, Deserialize, Deserializer, Serialize, Serializer}; use std::{ fmt::{self, Debug, Display}, diff --git a/tendermint/src/account.rs b/tendermint/src/account.rs index 59045c4e7..a50aee39d 100644 --- a/tendermint/src/account.rs +++ b/tendermint/src/account.rs @@ -1,6 +1,6 @@ //! Tendermint accounts -use crate::error::{Error, ErrorKind}; +use crate::{Error, ErrorKind}; use serde::{de, Deserialize, Deserializer, Serialize, Serializer}; use sha2::{Digest, Sha256}; use signatory::{ecdsa::curve::secp256k1, ed25519}; diff --git a/tendermint/src/block/height.rs b/tendermint/src/block/height.rs index 1934af69e..0ec04435f 100644 --- a/tendermint/src/block/height.rs +++ b/tendermint/src/block/height.rs @@ -1,4 +1,4 @@ -use crate::error::{Error, ErrorKind}; +use crate::{Error, ErrorKind}; use serde::{de::Error as _, Deserialize, Deserializer, Serialize, Serializer}; use std::{ convert::TryFrom, diff --git a/tendermint/src/chain/id.rs b/tendermint/src/chain/id.rs index 85279ad26..fc7c3ebf0 100644 --- a/tendermint/src/chain/id.rs +++ b/tendermint/src/chain/id.rs @@ -1,6 +1,6 @@ //! Tendermint blockchain identifiers -use crate::error::{Error, ErrorKind}; +use crate::{Error, ErrorKind}; use serde::{de::Error as _, Deserialize, Deserializer, Serialize, Serializer}; use std::{ cmp::Ordering, diff --git a/tendermint/src/config.rs b/tendermint/src/config.rs index d483cc522..060744e43 100644 --- a/tendermint/src/config.rs +++ b/tendermint/src/config.rs @@ -11,12 +11,7 @@ mod priv_validator_key; pub use self::{node_key::NodeKey, priv_validator_key::PrivValidatorKey}; -use crate::{ - abci::tag, - error::{Error, ErrorKind}, - genesis::Genesis, - net, node, Moniker, Timeout, -}; +use crate::{abci::tag, genesis::Genesis, net, node, Error, ErrorKind, Moniker, Timeout}; use serde::{de, de::Error as _, ser, Deserialize, Serialize}; use std::{ collections::BTreeMap, diff --git a/tendermint/src/config/node_key.rs b/tendermint/src/config/node_key.rs index e68c627d8..bd9d8f918 100644 --- a/tendermint/src/config/node_key.rs +++ b/tendermint/src/config/node_key.rs @@ -1,10 +1,7 @@ //! Node keys -use crate::{ - error::{Error, ErrorKind}, - private_key::PrivateKey, -}; use crate::{node, public_key::PublicKey}; +use crate::{private_key::PrivateKey, Error, ErrorKind}; use serde::{Deserialize, Serialize}; use std::{fs, path::Path}; diff --git a/tendermint/src/config/priv_validator_key.rs b/tendermint/src/config/priv_validator_key.rs index 0ba4189e7..aa9a009b8 100644 --- a/tendermint/src/config/priv_validator_key.rs +++ b/tendermint/src/config/priv_validator_key.rs @@ -1,12 +1,7 @@ //! Validator private keys use crate::public_key::TendermintKey; -use crate::{ - account, - error::{Error, ErrorKind}, - private_key::PrivateKey, - public_key::PublicKey, -}; +use crate::{account, private_key::PrivateKey, public_key::PublicKey, Error, ErrorKind}; use serde::{Deserialize, Serialize}; use std::{fs, path::Path}; diff --git a/tendermint/src/error.rs b/tendermint/src/error.rs index ef13ba75b..f8231c5b2 100644 --- a/tendermint/src/error.rs +++ b/tendermint/src/error.rs @@ -22,7 +22,7 @@ macro_rules! err { #[derive(Debug)] pub struct Error { /// Contextual information about the error - inner: Context, + inner: Context, /// Optional message to associate with the error msg: Option, @@ -32,7 +32,7 @@ impl Error { /// Create a new error from the given context and optional message pub fn new(context: C, msg: Option) -> Self where - C: Into>, + C: Into>, { Self { inner: context.into(), @@ -40,8 +40,8 @@ impl Error { } } - /// Obtain the error's `ErrorKind` - pub fn kind(&self) -> &ErrorKind { + /// Obtain the error's `Kind` + pub fn kind(&self) -> &Kind { self.inner.get_context() } @@ -71,39 +71,39 @@ impl Fail for Error { } } -impl From for Error { - fn from(kind: ErrorKind) -> Self { +impl From for Error { + fn from(kind: Kind) -> Self { Error::new(kind, None) } } impl From for Error { fn from(err: chrono::ParseError) -> Error { - err!(ErrorKind::Parse, err) + err!(Kind::Parse, err) } } impl From for Error { fn from(err: io::Error) -> Self { - err!(ErrorKind::Io, err) + err!(Kind::Io, err) } } impl From for Error { fn from(err: prost::DecodeError) -> Self { - err!(ErrorKind::Parse, err) + err!(Kind::Parse, err) } } impl From for Error { fn from(err: prost::EncodeError) -> Self { - err!(ErrorKind::Parse, err) + err!(Kind::Parse, err) } } impl From for Error { fn from(err: serde_json::error::Error) -> Self { - err!(ErrorKind::Parse, err) + err!(Kind::Parse, err) } } @@ -112,28 +112,28 @@ impl From for Error { use std::error::Error as _; if let Some(source) = err.source() { - err!(ErrorKind::Crypto, "signature error: {}", source) + err!(Kind::Crypto, "signature error: {}", source) } else { - err!(ErrorKind::Crypto, "signature error") + err!(Kind::Crypto, "signature error") } } } impl From for Error { fn from(err: subtle_encoding::Error) -> Error { - err!(ErrorKind::Parse, err) + err!(Kind::Parse, err) } } impl From for Error { fn from(err: toml::de::Error) -> Self { - err!(ErrorKind::Parse, err) + err!(Kind::Parse, err) } } /// Kinds of errors #[derive(Clone, Eq, PartialEq, Debug, Fail)] -pub enum ErrorKind { +pub enum Kind { /// Cryptographic operation failed #[fail(display = "cryptographic error")] Crypto, diff --git a/tendermint/src/hash.rs b/tendermint/src/hash.rs index 236ee4114..1c9471c9f 100644 --- a/tendermint/src/hash.rs +++ b/tendermint/src/hash.rs @@ -1,6 +1,6 @@ //! Hash functions and their outputs -use crate::error::{Error, ErrorKind}; +use crate::{Error, ErrorKind}; use serde::{de::Error as _, Deserialize, Deserializer, Serialize, Serializer}; use std::{ fmt::{self, Debug, Display}, diff --git a/tendermint/src/lib.rs b/tendermint/src/lib.rs index d778da96a..9c8e8335c 100644 --- a/tendermint/src/lib.rs +++ b/tendermint/src/lib.rs @@ -12,8 +12,7 @@ unused_import_braces, unused_qualifications )] -#![forbid(unsafe_code)] -#![deny( +#![allow( clippy::all, clippy::cargo, clippy::nursery, @@ -21,6 +20,7 @@ clippy::restriction, clippy::result_unrwap_used )] +#![forbid(clippy::module_name_repetitions)] #![doc( html_logo_url = "https://raw.githubusercontent.com/tendermint/kms/master/img/tendermint.png", html_root_url = "https://docs.rs/tendermint/0.11.0" @@ -69,7 +69,7 @@ pub mod vote; pub use crate::genesis::Genesis; pub use crate::{ block::Block, - error::{Error, ErrorKind}, + error::{Error, Kind as ErrorKind}, hash::Hash, moniker::Moniker, public_key::{PublicKey, TendermintKey}, diff --git a/tendermint/src/net.rs b/tendermint/src/net.rs index fe8d419ad..45043147f 100644 --- a/tendermint/src/net.rs +++ b/tendermint/src/net.rs @@ -1,8 +1,7 @@ //! Remote addresses (`tcp://` or `unix://`) use crate::{ - error::{Error, ErrorKind}, - node, + node, {Error, ErrorKind}, }; use serde::{de::Error as _, Deserialize, Deserializer, Serialize, Serializer}; use std::{ diff --git a/tendermint/src/node/id.rs b/tendermint/src/node/id.rs index b2c56b980..ff61b1e20 100644 --- a/tendermint/src/node/id.rs +++ b/tendermint/src/node/id.rs @@ -1,6 +1,6 @@ //! Tendermint node IDs -use crate::error::{Error, ErrorKind}; +use crate::{Error, ErrorKind}; use serde::{de, Deserialize, Deserializer, Serialize, Serializer}; use sha2::{Digest, Sha256}; use signatory::ed25519; diff --git a/tendermint/src/public_key.rs b/tendermint/src/public_key.rs index 229a029b0..54f82c90d 100644 --- a/tendermint/src/public_key.rs +++ b/tendermint/src/public_key.rs @@ -1,6 +1,6 @@ //! Public keys used in Tendermint networks -use crate::error::{Error, ErrorKind}; +use crate::{Error, ErrorKind}; use serde::{de::Error as _, Deserialize, Deserializer, Serialize, Serializer}; use signatory::{ecdsa::curve::secp256k1, ed25519}; use std::{ diff --git a/tendermint/src/time.rs b/tendermint/src/time.rs index 52e089b9d..d7dd86f39 100644 --- a/tendermint/src/time.rs +++ b/tendermint/src/time.rs @@ -1,6 +1,6 @@ //! Timestamps used by Tendermint blockchains -use crate::error::{Error, ErrorKind}; +use crate::{Error, ErrorKind}; use chrono::{DateTime, SecondsFormat, Utc}; use serde::{Deserialize, Serialize}; use std::fmt; diff --git a/tendermint/src/timeout.rs b/tendermint/src/timeout.rs index 23177b6f1..637856a71 100644 --- a/tendermint/src/timeout.rs +++ b/tendermint/src/timeout.rs @@ -82,7 +82,7 @@ impl Serialize for Timeout { #[cfg(test)] mod tests { use super::Timeout; - use crate::error::ErrorKind; + use crate::ErrorKind; #[test] fn parse_seconds() { From 4d82f360f8102bd706a45392620764fe1e56c364 Mon Sep 17 00:00:00 2001 From: Alexander Simmerl Date: Fri, 3 Jan 2020 13:58:34 +0100 Subject: [PATCH 03/55] Remove superfluours Info suffix --- tendermint/src/node/info.rs | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/tendermint/src/node/info.rs b/tendermint/src/node/info.rs index 11cc44b62..d138dd992 100644 --- a/tendermint/src/node/info.rs +++ b/tendermint/src/node/info.rs @@ -8,7 +8,7 @@ use std::fmt::{self, Display}; #[derive(Clone, Debug, Deserialize, Eq, PartialEq, Serialize)] pub struct Info { /// Protocol version information - pub protocol_version: ProtocolVersionInfo, + pub protocol_version: ProtocolVersion, /// Node ID pub id: node::Id, @@ -29,12 +29,12 @@ pub struct Info { pub moniker: Moniker, /// Other status information - pub other: OtherInfo, + pub other: Other, } /// Protocol version information #[derive(Clone, Debug, Deserialize, Eq, PartialEq, Serialize)] -pub struct ProtocolVersionInfo { +pub struct ProtocolVersion { /// P2P protocol version #[serde( serialize_with = "serializers::serialize_u64", @@ -86,7 +86,7 @@ impl Display for ListenAddress { /// Other information #[derive(Clone, Debug, Deserialize, Eq, PartialEq, Serialize)] -pub struct OtherInfo { +pub struct Other { /// TX index status pub tx_index: TxIndexStatus, From ae598b753439d0a8605e4c102c0e3165edc9895c Mon Sep 17 00:00:00 2001 From: Alexander Simmerl Date: Fri, 3 Jan 2020 13:59:49 +0100 Subject: [PATCH 04/55] Remove superfluours Params suffix --- tendermint/src/consensus/params.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tendermint/src/consensus/params.rs b/tendermint/src/consensus/params.rs index cbe051297..5a16fbe62 100644 --- a/tendermint/src/consensus/params.rs +++ b/tendermint/src/consensus/params.rs @@ -13,12 +13,12 @@ pub struct Params { pub evidence: evidence::Params, /// Validator parameters - pub validator: ValidatorParams, + pub validator: Validator, } /// Validator consensus parameters #[derive(Serialize, Deserialize, Clone, Debug, Eq, PartialEq)] -pub struct ValidatorParams { +pub struct Validator { /// Allowed algorithms for validator signing pub pub_key_types: Vec, } From f1f4f9ffdd5ca47ba18d3f8ab709b0b3737e5010 Mon Sep 17 00:00:00 2001 From: Alexander Simmerl Date: Fri, 3 Jan 2020 14:08:32 +0100 Subject: [PATCH 05/55] Remove superfluours Config suffix --- tendermint/src/config.rs | 30 +++++++++++++++--------------- tendermint/tests/config.rs | 6 +++++- 2 files changed, 20 insertions(+), 16 deletions(-) diff --git a/tendermint/src/config.rs b/tendermint/src/config.rs index 9ac32ad52..3bf519134 100644 --- a/tendermint/src/config.rs +++ b/tendermint/src/config.rs @@ -2,7 +2,7 @@ //! //! This module contains types which correspond to the following config files: //! -//! - `config.toml`: `config::TendermintConfig` +//! - `config.toml`: `config::Tendermint` //! - `node_key.rs`: `config::node_key::NodeKey` //! - `priv_validator_key.rs`: `config::priv_validator_key::PrivValidatorKey` @@ -22,7 +22,7 @@ use std::{ /// Tendermint `config.toml` file #[derive(Clone, Debug, Deserialize, Serialize)] -pub struct TendermintConfig { +pub struct Tendermint { /// TCP or UNIX socket address of the ABCI application, /// or the name of an ABCI application compiled in with the Tendermint binary. pub proxy_app: net::Address, @@ -78,25 +78,25 @@ pub struct TendermintConfig { pub filter_peers: bool, /// rpc server configuration options - pub rpc: RpcConfig, + pub rpc: Rpc, /// peer to peer configuration options - pub p2p: P2PConfig, + pub p2p: P2P, /// mempool configuration options - pub mempool: MempoolConfig, + pub mempool: Mempool, /// consensus configuration options - pub consensus: ConsensusConfig, + pub consensus: Consensus, /// transactions indexer configuration options - pub tx_index: TxIndexConfig, + pub tx_index: TxIndex, /// instrumentation configuration options - pub instrumentation: InstrumentationConfig, + pub instrumentation: Instrumentation, } -impl TendermintConfig { +impl Tendermint { /// Parse Tendermint `config.toml` pub fn parse_toml>(toml_string: T) -> Result { Ok(toml::from_str(toml_string.as_ref())?) @@ -255,7 +255,7 @@ pub enum AbciMode { /// Tendermint `config.toml` file's `[rpc]` section #[derive(Clone, Debug, Deserialize, Serialize)] -pub struct RpcConfig { +pub struct Rpc { /// TCP or UNIX socket address for the RPC server to listen on pub laddr: net::Address, @@ -358,7 +358,7 @@ impl fmt::Display for CorsHeader { /// peer to peer configuration options #[derive(Clone, Debug, Deserialize, Serialize)] -pub struct P2PConfig { +pub struct P2P { /// Address to listen for incoming connections pub laddr: net::Address, @@ -439,7 +439,7 @@ pub struct P2PConfig { /// mempool configuration options #[derive(Clone, Debug, Deserialize, Serialize)] -pub struct MempoolConfig { +pub struct Mempool { /// Recheck enabled pub recheck: bool, @@ -464,7 +464,7 @@ pub struct MempoolConfig { /// consensus configuration options #[derive(Clone, Debug, Deserialize, Serialize)] -pub struct ConsensusConfig { +pub struct Consensus { /// Path to WAL file pub wal_file: PathBuf, @@ -507,7 +507,7 @@ pub struct ConsensusConfig { /// transactions indexer configuration options #[derive(Clone, Debug, Deserialize, Serialize)] -pub struct TxIndexConfig { +pub struct TxIndex { /// What indexer to use for transactions #[serde(default)] pub indexer: TxIndexer, @@ -547,7 +547,7 @@ impl Default for TxIndexer { /// instrumentation configuration options #[derive(Clone, Debug, Deserialize, Serialize)] -pub struct InstrumentationConfig { +pub struct Instrumentation { /// When `true`, Prometheus metrics are served under /metrics on /// PrometheusListenAddr. pub prometheus: bool, diff --git a/tendermint/tests/config.rs b/tendermint/tests/config.rs index 4fbad50f2..c14ce8ad5 100644 --- a/tendermint/tests/config.rs +++ b/tendermint/tests/config.rs @@ -4,7 +4,11 @@ mod files { use std::{fs, path::PathBuf, time::Duration}; - use tendermint::{config::*, net, node}; + use tendermint::config::{ + AbciMode, DbBackend, LogFormat, NodeKey, PrivValidatorKey, Tendermint as TendermintConfig, + TxIndexer, + }; + use tendermint::{net, node}; /// Read a fixture file from the `support/config` directory fn read_fixture(name: &str) -> String { From 6f423a788bbad2a067a29b0dc7c3a616a5b723a0 Mon Sep 17 00:00:00 2001 From: Alexander Simmerl Date: Fri, 3 Jan 2020 14:10:00 +0100 Subject: [PATCH 06/55] Remove superfluours Id suffix --- tendermint/src/block.rs | 2 +- tendermint/src/block/id.rs | 2 +- tendermint/src/chain.rs | 2 +- tendermint/src/chain/id.rs | 2 +- 4 files changed, 4 insertions(+), 4 deletions(-) diff --git a/tendermint/src/block.rs b/tendermint/src/block.rs index 3cccbf888..bd1f56fde 100644 --- a/tendermint/src/block.rs +++ b/tendermint/src/block.rs @@ -13,7 +13,7 @@ pub use self::{ commit::*, header::{parse_non_empty_block_id, Header}, height::*, - id::{Id, ParseId}, + id::{Id, Parse as ParseId}, meta::Meta, size::Size, }; diff --git a/tendermint/src/block/id.rs b/tendermint/src/block/id.rs index 37ceff027..4a299ecfb 100644 --- a/tendermint/src/block/id.rs +++ b/tendermint/src/block/id.rs @@ -68,7 +68,7 @@ impl FromStr for Id { } /// Parse `block::Id` from a type -pub trait ParseId { +pub trait Parse { /// Parse `block::Id`, or return an `Error` if parsing failed fn parse_block_id(&self) -> Result; } diff --git a/tendermint/src/chain.rs b/tendermint/src/chain.rs index f8550a1d3..ef7ea762d 100644 --- a/tendermint/src/chain.rs +++ b/tendermint/src/chain.rs @@ -4,6 +4,6 @@ pub mod id; mod info; pub use self::{ - id::{Id, ParseId}, + id::{Id, Parse as ParseId}, info::*, }; diff --git a/tendermint/src/chain/id.rs b/tendermint/src/chain/id.rs index fc7c3ebf0..a0f372be0 100644 --- a/tendermint/src/chain/id.rs +++ b/tendermint/src/chain/id.rs @@ -122,7 +122,7 @@ impl<'de> Deserialize<'de> for Id { } /// Parse `chain::Id` from a type -pub trait ParseId { +pub trait Parse { /// Parse `chain::Id`, or return an `Error` if parsing failed fn parse_chain_id(&self) -> Result; } From e2220a1ae5b3a472d63da358ec44ca03d5f6ee21 Mon Sep 17 00:00:00 2001 From: Alexander Simmerl Date: Fri, 3 Jan 2020 14:16:48 +0100 Subject: [PATCH 07/55] Remove superfluours Version suffix --- tendermint/src/amino_types.rs | 2 +- tendermint/src/amino_types/version.rs | 8 ++++---- tendermint/src/block.rs | 2 +- tendermint/src/block/height.rs | 2 +- 4 files changed, 7 insertions(+), 7 deletions(-) diff --git a/tendermint/src/amino_types.rs b/tendermint/src/amino_types.rs index 448c4f009..0a27ff458 100644 --- a/tendermint/src/amino_types.rs +++ b/tendermint/src/amino_types.rs @@ -24,6 +24,6 @@ pub use self::{ signature::{SignableMsg, SignedMsgType}, time::TimeMsg, validate::ConsensusMessage, - version::ConsensusVersion, + version::Consensus as ConsensusVersion, vote::{SignVoteRequest, SignedVoteResponse, AMINO_NAME as VOTE_AMINO_NAME}, }; diff --git a/tendermint/src/amino_types/version.rs b/tendermint/src/amino_types/version.rs index b9561654f..587ca939b 100644 --- a/tendermint/src/amino_types/version.rs +++ b/tendermint/src/amino_types/version.rs @@ -1,7 +1,7 @@ -use crate::block::*; +use crate::block::header; #[derive(Clone, Message)] -pub struct ConsensusVersion { +pub struct Consensus { /// Block version #[prost(uint64, tag = "1")] pub block: u64, @@ -11,9 +11,9 @@ pub struct ConsensusVersion { pub app: u64, } -impl From<&header::Version> for ConsensusVersion { +impl From<&header::Version> for Consensus { fn from(version: &header::Version) -> Self { - ConsensusVersion { + Consensus { block: version.block, app: version.app, } diff --git a/tendermint/src/block.rs b/tendermint/src/block.rs index bd1f56fde..64c1686a5 100644 --- a/tendermint/src/block.rs +++ b/tendermint/src/block.rs @@ -12,7 +12,7 @@ mod size; pub use self::{ commit::*, header::{parse_non_empty_block_id, Header}, - height::*, + height::{Height, Parse as ParseHeight}, id::{Id, Parse as ParseId}, meta::Meta, size::Size, diff --git a/tendermint/src/block/height.rs b/tendermint/src/block/height.rs index 0ec04435f..1cfcee991 100644 --- a/tendermint/src/block/height.rs +++ b/tendermint/src/block/height.rs @@ -95,7 +95,7 @@ impl Serialize for Height { } /// Parse `block::Height` from a type -pub trait ParseHeight { +pub trait Parse { /// Parse `block::Height`, or return an `Error` if parsing failed fn parse_block_height(&self) -> Result; } From 2810c8939bf9232c6742313a4c11274f3022297f Mon Sep 17 00:00:00 2001 From: Alexander Simmerl Date: Fri, 3 Jan 2020 16:39:32 +0100 Subject: [PATCH 08/55] Remove superfluous BlockId suffix --- tendermint/src/amino_types.rs | 2 +- tendermint/src/amino_types/block_id.rs | 4 ++-- tendermint/src/amino_types/proposal.rs | 2 +- tendermint/src/amino_types/vote.rs | 3 +-- 4 files changed, 5 insertions(+), 6 deletions(-) diff --git a/tendermint/src/amino_types.rs b/tendermint/src/amino_types.rs index 0a27ff458..72db73d7e 100644 --- a/tendermint/src/amino_types.rs +++ b/tendermint/src/amino_types.rs @@ -16,7 +16,7 @@ pub mod version; pub mod vote; pub use self::{ - block_id::{BlockId, CanonicalBlockId, CanonicalPartSetHeader, PartsSetHeader}, + block_id::{BlockId, Canonical as CanonicalBlockId, CanonicalPartSetHeader, PartsSetHeader}, ed25519::{PubKeyRequest, PubKeyResponse, AMINO_NAME as PUBKEY_AMINO_NAME}, ping::{PingRequest, PingResponse, AMINO_NAME as PING_AMINO_NAME}, proposal::{SignProposalRequest, SignedProposalResponse, AMINO_NAME as PROPOSAL_AMINO_NAME}, diff --git a/tendermint/src/amino_types/block_id.rs b/tendermint/src/amino_types/block_id.rs index f3701c0bc..422098c58 100644 --- a/tendermint/src/amino_types/block_id.rs +++ b/tendermint/src/amino_types/block_id.rs @@ -55,14 +55,14 @@ impl ConsensusMessage for BlockId { } #[derive(Clone, PartialEq, Message)] -pub struct CanonicalBlockId { +pub struct Canonical { #[prost(bytes, tag = "1")] pub hash: Vec, #[prost(message, tag = "2")] pub parts_header: Option, } -impl block::ParseId for CanonicalBlockId { +impl block::ParseId for Canonical { fn parse_block_id(&self) -> Result { let hash = Hash::new(hash::Algorithm::Sha256, &self.hash)?; let parts_header = self diff --git a/tendermint/src/amino_types/proposal.rs b/tendermint/src/amino_types/proposal.rs index a018a2d15..965f2aa70 100644 --- a/tendermint/src/amino_types/proposal.rs +++ b/tendermint/src/amino_types/proposal.rs @@ -1,9 +1,9 @@ use super::{ - block_id::{BlockId, CanonicalBlockId, CanonicalPartSetHeader}, remote_error::RemoteError, signature::{SignableMsg, SignedMsgType}, time::TimeMsg, validate::{ConsensusMessage, ValidationError, ValidationErrorKind::*}, + BlockId, CanonicalBlockId, CanonicalPartSetHeader, }; use crate::{ block::{self, ParseId}, diff --git a/tendermint/src/amino_types/vote.rs b/tendermint/src/amino_types/vote.rs index 57b787970..3a7482932 100644 --- a/tendermint/src/amino_types/vote.rs +++ b/tendermint/src/amino_types/vote.rs @@ -1,10 +1,9 @@ use super::{ - block_id::{BlockId, CanonicalBlockId, CanonicalPartSetHeader}, remote_error::RemoteError, signature::SignableMsg, time::TimeMsg, validate::{ConsensusMessage, ValidationError, ValidationErrorKind::*}, - SignedMsgType, + BlockId, CanonicalBlockId, CanonicalPartSetHeader, SignedMsgType, }; use crate::amino_types::PartsSetHeader; use crate::{ From faf0fe66af8213cb49113b52622a518eae1513f2 Mon Sep 17 00:00:00 2001 From: Alexander Simmerl Date: Fri, 3 Jan 2020 16:43:50 +0100 Subject: [PATCH 09/55] Remove superfluous Amino prefix --- tendermint/src/amino_types.rs | 1 + tendermint/src/amino_types/message.rs | 4 ++-- tendermint/src/amino_types/vote.rs | 2 +- tendermint/src/block/header.rs | 2 +- tendermint/src/validator.rs | 2 +- tendermint/src/vote.rs | 2 +- 6 files changed, 7 insertions(+), 6 deletions(-) diff --git a/tendermint/src/amino_types.rs b/tendermint/src/amino_types.rs index 72db73d7e..b248455d6 100644 --- a/tendermint/src/amino_types.rs +++ b/tendermint/src/amino_types.rs @@ -18,6 +18,7 @@ pub mod vote; pub use self::{ block_id::{BlockId, Canonical as CanonicalBlockId, CanonicalPartSetHeader, PartsSetHeader}, ed25519::{PubKeyRequest, PubKeyResponse, AMINO_NAME as PUBKEY_AMINO_NAME}, + message::Message as AminoMessage, ping::{PingRequest, PingResponse, AMINO_NAME as PING_AMINO_NAME}, proposal::{SignProposalRequest, SignedProposalResponse, AMINO_NAME as PROPOSAL_AMINO_NAME}, remote_error::RemoteError, diff --git a/tendermint/src/amino_types/message.rs b/tendermint/src/amino_types/message.rs index 9600699ef..35458675a 100644 --- a/tendermint/src/amino_types/message.rs +++ b/tendermint/src/amino_types/message.rs @@ -3,7 +3,7 @@ use std::convert::TryInto; /// Extend the original prost::Message trait with a few helper functions in order to /// reduce boiler-plate code (and without modifying the prost-amino dependency). -pub trait AminoMessage: prost_amino::Message { +pub trait Message: prost_amino::Message { /// Directly amino encode a prost-amino message into a freshly created Vec. /// This can be useful when passing those bytes directly to a hasher, or, /// to reduce boiler plate code when working with the encoded bytes. @@ -34,6 +34,6 @@ pub trait AminoMessage: prost_amino::Message { res } } -impl AminoMessage for M { +impl Message for M { // blanket impl } diff --git a/tendermint/src/amino_types/vote.rs b/tendermint/src/amino_types/vote.rs index 3a7482932..c9926e808 100644 --- a/tendermint/src/amino_types/vote.rs +++ b/tendermint/src/amino_types/vote.rs @@ -239,7 +239,7 @@ impl ConsensusMessage for Vote { mod tests { use super::super::PartsSetHeader; use super::*; - use crate::amino_types::message::AminoMessage; + use crate::amino_types::AminoMessage; use crate::amino_types::SignedMsgType; use chrono::{DateTime, Utc}; diff --git a/tendermint/src/block/header.rs b/tendermint/src/block/header.rs index 427177569..c4a76275c 100644 --- a/tendermint/src/block/header.rs +++ b/tendermint/src/block/header.rs @@ -2,7 +2,7 @@ use crate::merkle::simple_hash_from_byte_vectors; use crate::serializers; use crate::{account, amino_types, block, chain, lite, Hash, Time}; -use amino_types::{message::AminoMessage, BlockId, ConsensusVersion, TimeMsg}; +use amino_types::{AminoMessage, BlockId, ConsensusVersion, TimeMsg}; use serde::{de::Error as _, Deserialize, Deserializer, Serialize}; use std::str::FromStr; diff --git a/tendermint/src/validator.rs b/tendermint/src/validator.rs index dc2090ec6..8802562eb 100644 --- a/tendermint/src/validator.rs +++ b/tendermint/src/validator.rs @@ -1,6 +1,6 @@ //! Tendermint validators -use crate::amino_types::message::AminoMessage; +use crate::amino_types::AminoMessage; use crate::{account, lite, merkle, vote, Hash, PublicKey}; use serde::{de::Error as _, Deserialize, Deserializer, Serialize, Serializer}; use signatory::{ diff --git a/tendermint/src/vote.rs b/tendermint/src/vote.rs index 38070e9ff..a2e509fb1 100644 --- a/tendermint/src/vote.rs +++ b/tendermint/src/vote.rs @@ -4,7 +4,7 @@ mod power; pub use self::power::Power; use crate::amino_types; -use crate::amino_types::message::AminoMessage; +use crate::amino_types::AminoMessage; use crate::{account, block, Signature, Time}; use { crate::serializers, From 827285ef3d78fd1118f54224e597bca3df0ffe43 Mon Sep 17 00:00:00 2001 From: Alexander Simmerl Date: Fri, 3 Jan 2020 16:45:13 +0100 Subject: [PATCH 10/55] Remove superfluous Ping prefix --- tendermint/src/amino_types.rs | 2 +- tendermint/src/amino_types/ping.rs | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/tendermint/src/amino_types.rs b/tendermint/src/amino_types.rs index b248455d6..8f309a010 100644 --- a/tendermint/src/amino_types.rs +++ b/tendermint/src/amino_types.rs @@ -19,7 +19,7 @@ pub use self::{ block_id::{BlockId, Canonical as CanonicalBlockId, CanonicalPartSetHeader, PartsSetHeader}, ed25519::{PubKeyRequest, PubKeyResponse, AMINO_NAME as PUBKEY_AMINO_NAME}, message::Message as AminoMessage, - ping::{PingRequest, PingResponse, AMINO_NAME as PING_AMINO_NAME}, + ping::{Request as PingRequest, Response as PingResponse, AMINO_NAME as PING_AMINO_NAME}, proposal::{SignProposalRequest, SignedProposalResponse, AMINO_NAME as PROPOSAL_AMINO_NAME}, remote_error::RemoteError, signature::{SignableMsg, SignedMsgType}, diff --git a/tendermint/src/amino_types/ping.rs b/tendermint/src/amino_types/ping.rs index 60fd6425d..4b5d0e8b4 100644 --- a/tendermint/src/amino_types/ping.rs +++ b/tendermint/src/amino_types/ping.rs @@ -2,8 +2,8 @@ pub const AMINO_NAME: &str = "tendermint/remotesigner/PingRequest"; #[derive(Clone, PartialEq, Message)] #[amino_name = "tendermint/remotesigner/PingRequest"] -pub struct PingRequest {} +pub struct Request {} #[derive(Clone, PartialEq, Message)] #[amino_name = "tendermint/remotesigner/PingResponse"] -pub struct PingResponse {} +pub struct Response {} From 17c7996283593973aa135e1dc2c11e9de6d631dc Mon Sep 17 00:00:00 2001 From: Alexander Simmerl Date: Fri, 3 Jan 2020 16:48:10 +0100 Subject: [PATCH 11/55] Remove superfluous RemoteError prefix --- tendermint/src/amino_types/remote_error.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tendermint/src/amino_types/remote_error.rs b/tendermint/src/amino_types/remote_error.rs index 8c867166c..2bcdfbc8e 100644 --- a/tendermint/src/amino_types/remote_error.rs +++ b/tendermint/src/amino_types/remote_error.rs @@ -11,7 +11,7 @@ pub struct RemoteError { // #[derive(Copy, Clone, Debug, Eq, PartialEq)] #[repr(i32)] -pub enum RemoteErrorCode { +pub enum Code { /// Generic error code useful when the others don't apply RemoteSignerError = 1, @@ -23,7 +23,7 @@ impl RemoteError { /// Create a new double signing error with the given message pub fn double_sign(height: i64) -> Self { RemoteError { - code: RemoteErrorCode::DoubleSignError as i32, + code: Code::DoubleSignError as i32, description: format!("double signing requested at height: {}", height), } } From 2d7607d1596fa56f19d75a6d28db5851063f16c9 Mon Sep 17 00:00:00 2001 From: Alexander Simmerl Date: Fri, 3 Jan 2020 16:48:10 +0100 Subject: [PATCH 12/55] Remove superfluous RemoteError prefix --- tendermint/src/amino_types/remote_error.rs | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/tendermint/src/amino_types/remote_error.rs b/tendermint/src/amino_types/remote_error.rs index 2bcdfbc8e..9b2067558 100644 --- a/tendermint/src/amino_types/remote_error.rs +++ b/tendermint/src/amino_types/remote_error.rs @@ -11,7 +11,8 @@ pub struct RemoteError { // #[derive(Copy, Clone, Debug, Eq, PartialEq)] #[repr(i32)] -pub enum Code { +enum Code { + #[allow(dead_code)] /// Generic error code useful when the others don't apply RemoteSignerError = 1, From 5ddb642b2edb8a3b21815a1211652557e082e7d4 Mon Sep 17 00:00:00 2001 From: Alexander Simmerl Date: Fri, 3 Jan 2020 16:59:21 +0100 Subject: [PATCH 13/55] Lock down amino module surface --- tendermint/src/amino_types.rs | 26 ++++++++++++++------------ tendermint/src/vote.rs | 9 ++++----- 2 files changed, 18 insertions(+), 17 deletions(-) diff --git a/tendermint/src/amino_types.rs b/tendermint/src/amino_types.rs index 8f309a010..d04dc94a1 100644 --- a/tendermint/src/amino_types.rs +++ b/tendermint/src/amino_types.rs @@ -3,17 +3,17 @@ #![allow(missing_docs)] -pub mod block_id; -pub mod ed25519; -pub mod message; -pub mod ping; -pub mod proposal; -pub mod remote_error; -pub mod signature; -pub mod time; -pub mod validate; -pub mod version; -pub mod vote; +mod block_id; +mod ed25519; +mod message; +mod ping; +mod proposal; +mod remote_error; +mod signature; +mod time; +mod validate; +mod version; +mod vote; pub use self::{ block_id::{BlockId, Canonical as CanonicalBlockId, CanonicalPartSetHeader, PartsSetHeader}, @@ -26,5 +26,7 @@ pub use self::{ time::TimeMsg, validate::ConsensusMessage, version::Consensus as ConsensusVersion, - vote::{SignVoteRequest, SignedVoteResponse, AMINO_NAME as VOTE_AMINO_NAME}, + vote::{ + CanonicalVote, SignVoteRequest, SignedVoteResponse, Vote, AMINO_NAME as VOTE_AMINO_NAME, + }, }; diff --git a/tendermint/src/vote.rs b/tendermint/src/vote.rs index a2e509fb1..8c4b63be8 100644 --- a/tendermint/src/vote.rs +++ b/tendermint/src/vote.rs @@ -3,8 +3,7 @@ mod power; pub use self::power::Power; -use crate::amino_types; -use crate::amino_types::AminoMessage; +use crate::amino_types::{self, AminoMessage}; use crate::{account, block, Signature, Time}; use { crate::serializers, @@ -72,7 +71,7 @@ impl Vote { /// SignedVote is the union of a canonicalized vote, the signature on /// the sign bytes of that vote and the id of the validator who signed it. pub struct SignedVote { - vote: amino_types::vote::CanonicalVote, + vote: amino_types::CanonicalVote, validator_address: account::Id, signature: Signature, } @@ -81,12 +80,12 @@ impl SignedVote { /// Create new SignedVote from provided canonicalized vote, validator id, and /// the signature of that validator. pub fn new( - vote: amino_types::vote::Vote, + vote: amino_types::Vote, chain_id: &str, validator_address: account::Id, signature: Signature, ) -> SignedVote { - let canonical_vote = amino_types::vote::CanonicalVote::new(vote, chain_id); + let canonical_vote = amino_types::CanonicalVote::new(vote, chain_id); SignedVote { vote: canonical_vote, signature, From 7e3b87fa1b69bc2dd5bbeaa03f1ca127591712f2 Mon Sep 17 00:00:00 2001 From: Alexander Simmerl Date: Fri, 3 Jan 2020 17:09:00 +0100 Subject: [PATCH 14/55] Remove superfluous Time prefix --- tendermint/src/amino_types.rs | 2 +- tendermint/src/amino_types/proposal.rs | 3 +-- tendermint/src/amino_types/time.rs | 14 +++++++------- tendermint/src/amino_types/vote.rs | 3 +-- 4 files changed, 10 insertions(+), 12 deletions(-) diff --git a/tendermint/src/amino_types.rs b/tendermint/src/amino_types.rs index d04dc94a1..39480058c 100644 --- a/tendermint/src/amino_types.rs +++ b/tendermint/src/amino_types.rs @@ -23,7 +23,7 @@ pub use self::{ proposal::{SignProposalRequest, SignedProposalResponse, AMINO_NAME as PROPOSAL_AMINO_NAME}, remote_error::RemoteError, signature::{SignableMsg, SignedMsgType}, - time::TimeMsg, + time::Msg as TimeMsg, validate::ConsensusMessage, version::Consensus as ConsensusVersion, vote::{ diff --git a/tendermint/src/amino_types/proposal.rs b/tendermint/src/amino_types/proposal.rs index 965f2aa70..533444179 100644 --- a/tendermint/src/amino_types/proposal.rs +++ b/tendermint/src/amino_types/proposal.rs @@ -1,9 +1,8 @@ use super::{ remote_error::RemoteError, signature::{SignableMsg, SignedMsgType}, - time::TimeMsg, validate::{ConsensusMessage, ValidationError, ValidationErrorKind::*}, - BlockId, CanonicalBlockId, CanonicalPartSetHeader, + BlockId, CanonicalBlockId, CanonicalPartSetHeader, TimeMsg, }; use crate::{ block::{self, ParseId}, diff --git a/tendermint/src/amino_types/time.rs b/tendermint/src/amino_types/time.rs index af942c1dc..e0d01f31b 100644 --- a/tendermint/src/amino_types/time.rs +++ b/tendermint/src/amino_types/time.rs @@ -8,7 +8,7 @@ use chrono::{TimeZone, Utc}; use std::time::{Duration, SystemTime, UNIX_EPOCH}; #[derive(Clone, PartialEq, Message)] -pub struct TimeMsg { +pub struct Msg { // TODO(ismail): switch to protobuf's well known type as soon as // https://github.com/tendermint/go-amino/pull/224 was merged // and tendermint caught up on the latest amino release. @@ -18,26 +18,26 @@ pub struct TimeMsg { pub nanos: i32, } -impl ParseTimestamp for TimeMsg { +impl ParseTimestamp for Msg { fn parse_timestamp(&self) -> Result { Ok(Utc.timestamp(self.seconds, self.nanos as u32).into()) } } -impl From