Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update to bytes 0.5 and amino_rs 0.5 #126

Merged
merged 5 commits into from
Jan 19, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions CHANGES.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
## Pending [0.12.0] (2019-12-11)

Dependencies
- Update to bytes `0.5` and amino_rs `0.5`.
- Tokens for amino_rs are now fully non-conflicting with prost. Allowing both to be used together


## [0.11.0] (2019-12-11)

Expand Down
7 changes: 3 additions & 4 deletions tendermint/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -31,15 +31,14 @@ all-features = true
circle-ci = { repository = "interchainio/tendermint-rs" }

[dependencies]
bytes = "0.4"
bytes_0_5 = { version = "0.5", package = "bytes" }
bytes = "0.5"
chrono = { version = "0.4", features = ["serde"] }
failure = "0.1"
getrandom = "0.1"
http = "0.2"
hyper = "0.13"
prost-amino = { version = "0.4.0" }
prost-amino-derive = { version = "0.4.0" }
prost-amino = "0.5"
prost-amino-derive = "0.5"
serde = { version = "1", features = ["derive"] }
serde_json = { version = "1" }
signatory = { version = "0.17", features = ["ed25519", "ecdsa"] }
Expand Down
16 changes: 8 additions & 8 deletions tendermint/src/amino_types/block_id.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,9 @@ use crate::{

#[derive(Clone, PartialEq, Message)]
pub struct BlockId {
#[prost(bytes, tag = "1")]
#[prost_amino(bytes, tag = "1")]
pub hash: Vec<u8>,
#[prost(message, tag = "2")]
#[prost_amino(message, tag = "2")]
pub parts_header: Option<PartsSetHeader>,
}

Expand Down Expand Up @@ -56,9 +56,9 @@ impl ConsensusMessage for BlockId {

#[derive(Clone, PartialEq, Message)]
pub struct CanonicalBlockId {
#[prost(bytes, tag = "1")]
#[prost_amino(bytes, tag = "1")]
pub hash: Vec<u8>,
#[prost(message, tag = "2")]
#[prost_amino(message, tag = "2")]
pub parts_header: Option<CanonicalPartSetHeader>,
}

Expand All @@ -75,9 +75,9 @@ impl block::ParseId for CanonicalBlockId {

#[derive(Clone, PartialEq, Message)]
pub struct PartsSetHeader {
#[prost(int64, tag = "1")]
#[prost_amino(int64, tag = "1")]
pub total: i64,
#[prost(bytes, tag = "2")]
#[prost_amino(bytes, tag = "2")]
pub hash: Vec<u8>,
}

Expand Down Expand Up @@ -116,9 +116,9 @@ impl ConsensusMessage for PartsSetHeader {

#[derive(Clone, PartialEq, Message)]
pub struct CanonicalPartSetHeader {
#[prost(bytes, tag = "1")]
#[prost_amino(bytes, tag = "1")]
pub hash: Vec<u8>,
#[prost(int64, tag = "2")]
#[prost_amino(int64, tag = "2")]
pub total: i64,
}

Expand Down
9 changes: 4 additions & 5 deletions tendermint/src/amino_types/ed25519.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ pub const AMINO_NAME: &str = "tendermint/remotesigner/PubKeyRequest";
#[derive(Clone, PartialEq, Message)]
#[amino_name = "tendermint/remotesigner/PubKeyResponse"]
pub struct PubKeyResponse {
#[prost(bytes, tag = "1", amino_name = "tendermint/PubKeyEd25519")]
#[prost_amino(bytes, tag = "1", amino_name = "tendermint/PubKeyEd25519")]
pub pub_key_ed25519: Vec<u8>,
}

Expand Down Expand Up @@ -45,7 +45,6 @@ impl From<PublicKey> for PubKeyResponse {
mod tests {
use super::*;
use prost::Message;
use std::error::Error;

#[test]
fn test_empty_pubkey_msg() {
Expand Down Expand Up @@ -86,9 +85,9 @@ mod tests {

assert_eq!(got, want);

match PubKeyRequest::decode(&want) {
match PubKeyRequest::decode(want.as_ref()) {
Ok(have) => assert_eq!(have, msg),
Err(err) => panic!(err.description().to_string()),
Err(err) => panic!(err.to_string()),
}
}

Expand Down Expand Up @@ -128,7 +127,7 @@ mod tests {

assert_eq!(got, encoded);

match PubKeyResponse::decode(&encoded) {
match PubKeyResponse::decode(encoded.as_ref()) {
Ok(have) => assert_eq!(have, msg),
Err(err) => panic!(err),
}
Expand Down
39 changes: 19 additions & 20 deletions tendermint/src/amino_types/proposal.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,19 +17,19 @@ use std::convert::TryFrom;

#[derive(Clone, PartialEq, Message)]
pub struct Proposal {
#[prost(uint32, tag = "1")]
#[prost_amino(uint32, tag = "1")]
pub msg_type: u32,
#[prost(int64)]
#[prost_amino(int64)]
pub height: i64,
#[prost(int64)]
#[prost_amino(int64)]
pub round: i64,
#[prost(int64)]
#[prost_amino(int64)]
pub pol_round: i64,
#[prost(message)]
#[prost_amino(message)]
pub block_id: Option<BlockId>,
#[prost(message)]
#[prost_amino(message)]
pub timestamp: Option<TimeMsg>,
#[prost(bytes)]
#[prost_amino(bytes)]
pub signature: Vec<u8>,
}

Expand All @@ -45,26 +45,26 @@ pub const AMINO_NAME: &str = "tendermint/remotesigner/SignProposalRequest";
#[derive(Clone, PartialEq, Message)]
#[amino_name = "tendermint/remotesigner/SignProposalRequest"]
pub struct SignProposalRequest {
#[prost(message, tag = "1")]
#[prost_amino(message, tag = "1")]
pub proposal: Option<Proposal>,
}

#[derive(Clone, PartialEq, Message)]
struct CanonicalProposal {
#[prost(uint32, tag = "1")]
#[prost_amino(uint32, tag = "1")]
msg_type: u32, /* this is a byte in golang, which is a varint encoded UInt8 (using amino's
* EncodeUvarint) */
#[prost(sfixed64)]
#[prost_amino(sfixed64)]
height: i64,
#[prost(sfixed64)]
#[prost_amino(sfixed64)]
round: i64,
#[prost(sfixed64)]
#[prost_amino(sfixed64)]
pol_round: i64,
#[prost(message)]
#[prost_amino(message)]
block_id: Option<CanonicalBlockId>,
#[prost(message)]
#[prost_amino(message)]
timestamp: Option<TimeMsg>,
#[prost(string)]
#[prost_amino(string)]
pub chain_id: String,
}

Expand All @@ -83,9 +83,9 @@ impl block::ParseHeight for CanonicalProposal {
#[derive(Clone, PartialEq, Message)]
#[amino_name = "tendermint/remotesigner/SignedProposalResponse"]
pub struct SignedProposalResponse {
#[prost(message, tag = "1")]
#[prost_amino(message, tag = "1")]
pub proposal: Option<Proposal>,
#[prost(message, tag = "2")]
#[prost_amino(message, tag = "2")]
pub err: Option<RemoteError>,
}

Expand Down Expand Up @@ -195,7 +195,6 @@ mod tests {
use crate::amino_types::block_id::PartsSetHeader;
use chrono::{DateTime, Utc};
use prost::Message;
use std::error::Error;

#[test]
fn test_serialization() {
Expand Down Expand Up @@ -292,9 +291,9 @@ mod tests {
242, 227, 236, 2,
];

match SignProposalRequest::decode(&data) {
match SignProposalRequest::decode(data.as_ref()) {
Ok(have) => assert_eq!(have, want),
Err(err) => panic!(err.description().to_string()),
Err(err) => panic!(err.to_string()),
}
}
}
4 changes: 2 additions & 2 deletions tendermint/src/amino_types/remote_error.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
#[derive(Clone, PartialEq, Message)]
pub struct RemoteError {
#[prost(sint32, tag = "1")]
#[prost_amino(sint32, tag = "1")]
pub code: i32,
#[prost(string, tag = "2")]
#[prost_amino(string, tag = "2")]
pub description: String,
}

Expand Down
4 changes: 2 additions & 2 deletions tendermint/src/amino_types/time.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,9 @@ pub struct TimeMsg {
// 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.
#[prost(int64, tag = "1")]
#[prost_amino(int64, tag = "1")]
pub seconds: i64,
#[prost(int32, tag = "2")]
#[prost_amino(int32, tag = "2")]
pub nanos: i32,
}

Expand Down
4 changes: 2 additions & 2 deletions tendermint/src/amino_types/version.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,11 @@ use crate::block::*;
#[derive(Clone, Message)]
pub struct ConsensusVersion {
/// Block version
#[prost(uint64, tag = "1")]
#[prost_amino(uint64, tag = "1")]
pub block: u64,

/// App version
#[prost(uint64, tag = "2")]
#[prost_amino(uint64, tag = "2")]
pub app: u64,
}

Expand Down
42 changes: 21 additions & 21 deletions tendermint/src/amino_types/vote.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,21 +22,21 @@ const VALIDATOR_ADDR_SIZE: usize = 20;

#[derive(Clone, PartialEq, Message)]
pub struct Vote {
#[prost(uint32, tag = "1")]
#[prost_amino(uint32, tag = "1")]
pub vote_type: u32,
#[prost(int64)]
#[prost_amino(int64)]
pub height: i64,
#[prost(int64)]
#[prost_amino(int64)]
pub round: i64,
#[prost(message)]
#[prost_amino(message)]
pub block_id: Option<BlockId>,
#[prost(message)]
#[prost_amino(message)]
pub timestamp: Option<TimeMsg>,
#[prost(bytes)]
#[prost_amino(bytes)]
pub validator_address: Vec<u8>,
#[prost(int64)]
#[prost_amino(int64)]
pub validator_index: i64,
#[prost(bytes)]
#[prost_amino(bytes)]
pub signature: Vec<u8>,
}

Expand Down Expand Up @@ -81,32 +81,32 @@ pub const AMINO_NAME: &str = "tendermint/remotesigner/SignVoteRequest";
#[derive(Clone, PartialEq, Message)]
#[amino_name = "tendermint/remotesigner/SignVoteRequest"]
pub struct SignVoteRequest {
#[prost(message, tag = "1")]
#[prost_amino(message, tag = "1")]
pub vote: Option<Vote>,
}

#[derive(Clone, PartialEq, Message)]
#[amino_name = "tendermint/remotesigner/SignedVoteResponse"]
pub struct SignedVoteResponse {
#[prost(message, tag = "1")]
#[prost_amino(message, tag = "1")]
pub vote: Option<Vote>,
#[prost(message, tag = "2")]
#[prost_amino(message, tag = "2")]
pub err: Option<RemoteError>,
}

#[derive(Clone, PartialEq, Message)]
pub struct CanonicalVote {
#[prost(uint32, tag = "1")]
#[prost_amino(uint32, tag = "1")]
pub vote_type: u32,
#[prost(sfixed64)]
#[prost_amino(sfixed64)]
pub height: i64,
#[prost(sfixed64)]
#[prost_amino(sfixed64)]
pub round: i64,
#[prost(message)]
#[prost_amino(message)]
pub block_id: Option<CanonicalBlockId>,
#[prost(message)]
#[prost_amino(message)]
pub timestamp: Option<TimeMsg>,
#[prost(string)]
#[prost_amino(string)]
pub chain_id: String,
}

Expand Down Expand Up @@ -307,7 +307,7 @@ mod tests {
113, 134, 241, 104, 95, 33, 242, 72, 42, 244, 251, 52, 70, 168, 75, 53, 56, 213, 187,
3,
];
let svr = SignVoteRequest::decode(got.clone()).unwrap();
let svr = SignVoteRequest::decode(got.as_ref()).unwrap();
println!("got back: {:?}", svr);
assert_eq!(got, want);
}
Expand Down Expand Up @@ -447,7 +447,7 @@ mod tests {
};
let mut got = vec![];
let _have = vote.encode(&mut got);
let v = Vote::decode(&got).unwrap();
let v = Vote::decode(got.as_ref()).unwrap();

assert_eq!(v, vote);
// SignVoteRequest
Expand All @@ -456,7 +456,7 @@ mod tests {
let mut got = vec![];
let _have = svr.encode(&mut got);

let svr2 = SignVoteRequest::decode(&got).unwrap();
let svr2 = SignVoteRequest::decode(got.as_ref()).unwrap();
assert_eq!(svr, svr2);
}
}
Expand Down Expand Up @@ -495,7 +495,7 @@ mod tests {
signature: vec![],
};
let want = SignVoteRequest { vote: Some(vote) };
match SignVoteRequest::decode(&encoded) {
match SignVoteRequest::decode(encoded.as_ref()) {
Ok(have) => {
assert_eq!(have, want);
}
Expand Down
1 change: 1 addition & 0 deletions tendermint/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ extern crate prost_amino as prost;
#[allow(unused_extern_crates)]
#[macro_use]
extern crate prost_amino_derive as prost_derive;
extern crate bytes;
Copy link
Contributor

@tarcieri tarcieri Jan 19, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Are either of these extern crates still needed? I know prost was looking directly in the sysroot for them before which precluded renaming them any other way than through the extern crate directive, but if everything is namespaced correctly, it seems like it should be possible to get rid of them?

Copy link
Member

@liamsi liamsi Jan 19, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@xla might have addressed some of this here: #122

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.


#[macro_use]
pub mod error;
Expand Down
2 changes: 1 addition & 1 deletion tendermint/src/rpc/client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ use crate::{
rpc::{self, endpoint::*, Error, Response},
Genesis,
};
use bytes_0_5::buf::ext::BufExt;
use bytes::buf::ext::BufExt;
use hyper::header;

/// Tendermint RPC client.
Expand Down
4 changes: 2 additions & 2 deletions tendermint/src/validator.rs
Original file line number Diff line number Diff line change
Expand Up @@ -115,9 +115,9 @@ impl Info {
/// TODO: currently only works for Ed25519 pubkeys
#[derive(Clone, PartialEq, Message)]
struct InfoHashable {
#[prost(bytes, tag = "1", amino_name = "tendermint/PubKeyEd25519")]
#[prost_amino(bytes, tag = "1", amino_name = "tendermint/PubKeyEd25519")]
pub pub_key: Vec<u8>,
#[prost(uint64, tag = "2")]
#[prost_amino(uint64, tag = "2")]
voting_power: u64,
}

Expand Down