Skip to content

Commit

Permalink
Fix master: ed25519-dalek dep, adapt to renaming (simple_merkle hicku…
Browse files Browse the repository at this point in the history
…p), and fmt: (#83)

- #77 introduced an fmt issue
 - #36 was not up-to date regarding changes which were merged to master (renaming
   of simple_merkle)
 - new upstream release of made build of master fail (solution: explicitly add it
 ed25519-dalek (1.0.0-pre.3) with rand feature fixes that
  • Loading branch information
liamsi authored and ebuchman committed Dec 10, 2019
1 parent b30991f commit 9415981
Show file tree
Hide file tree
Showing 8 changed files with 51 additions and 54 deletions.
1 change: 1 addition & 0 deletions tendermint/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ tai64 = { version = "3", features = ["chrono"] }
toml = { version = "0.5" }
uuid = { version = "0.7", default-features = false }
zeroize = { version = "1.0", features = ["zeroize_derive"] }
ed25519-dalek = {version = "1.0.0-pre.3", features = ["rand"]}

[dev-dependencies]
serde_json = "1"
2 changes: 1 addition & 1 deletion tendermint/src/amino_types/proposal.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
use std::convert::TryFrom;
use super::{
block_id::{BlockId, CanonicalBlockId, CanonicalPartSetHeader},
remote_error::RemoteError,
Expand All @@ -14,6 +13,7 @@ use crate::{
use bytes::BufMut;
use prost::{EncodeError, Message};
use signatory::{ed25519, Signature};
use std::convert::TryFrom;

#[derive(Clone, PartialEq, Message)]
pub struct Proposal {
Expand Down
2 changes: 1 addition & 1 deletion tendermint/src/amino_types/vote.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
use std::convert::TryFrom;
use super::{
block_id::{BlockId, CanonicalBlockId, CanonicalPartSetHeader},
remote_error::RemoteError,
Expand All @@ -17,6 +16,7 @@ use crate::{
use bytes::BufMut;
use prost::{error::EncodeError, Message};
use signatory::{ed25519, Signature};
use std::convert::TryFrom;

const VALIDATOR_ADDR_SIZE: usize = 20;

Expand Down
40 changes: 20 additions & 20 deletions tendermint/src/block/header.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
//! Block headers
use crate::merkle::simple_hash_from_byte_slices;
use crate::merkle::simple_hash_from_byte_vectors;
use crate::{account, amino_types, block, chain, lite, Hash, Time};
use prost::Message;
use {
Expand Down Expand Up @@ -122,25 +122,25 @@ impl lite::Header for Header {
let proposer_address_bytes = self.proposer_address.as_bytes();
let proposer_address_enc = bytes_enc(&proposer_address_bytes);

let mut byteslices: Vec<&[u8]> = vec![];
byteslices.push(version_enc.as_slice());
byteslices.push(chain_id_enc.as_slice());
byteslices.push(height_enc.as_slice());
byteslices.push(time_enc.as_slice());
byteslices.push(num_tx_enc.as_slice());
byteslices.push(total_tx_enc.as_slice());
byteslices.push(last_block_id_enc.as_slice());
byteslices.push(last_commit_hash_enc.as_slice());
byteslices.push(data_hash_enc.as_slice());
byteslices.push(validator_hash_enc.as_slice());
byteslices.push(next_validator_hash_enc.as_slice());
byteslices.push(consensus_hash_enc.as_slice());
byteslices.push(app_hash_enc.as_slice());
byteslices.push(last_result_hash_enc.as_slice());
byteslices.push(evidence_hash_enc.as_slice());
byteslices.push(proposer_address_enc.as_slice());

Hash::Sha256(simple_hash_from_byte_slices(byteslices.as_slice()))
let mut byteslices: Vec<Vec<u8>> = vec![];
byteslices.push(version_enc);
byteslices.push(chain_id_enc);
byteslices.push(height_enc);
byteslices.push(time_enc);
byteslices.push(num_tx_enc);
byteslices.push(total_tx_enc);
byteslices.push(last_block_id_enc);
byteslices.push(last_commit_hash_enc);
byteslices.push(data_hash_enc);
byteslices.push(validator_hash_enc);
byteslices.push(next_validator_hash_enc);
byteslices.push(consensus_hash_enc);
byteslices.push(app_hash_enc);
byteslices.push(last_result_hash_enc);
byteslices.push(evidence_hash_enc);
byteslices.push(proposer_address_enc);

Hash::Sha256(simple_hash_from_byte_vectors(byteslices))
}
}

Expand Down
2 changes: 1 addition & 1 deletion tendermint/src/block/height.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ use std::{

/// Block height for a particular chain (i.e. number of blocks created since
/// the chain began)
///
///
/// A height of 0 represents a chain which has not yet produced a block.
#[derive(Copy, Clone, Eq, Hash, PartialEq, PartialOrd, Ord)]
pub struct Height(pub u64);
Expand Down
43 changes: 23 additions & 20 deletions tendermint/src/serializers.rs
Original file line number Diff line number Diff line change
Expand Up @@ -64,61 +64,64 @@ where
}

pub(crate) fn serialize_hex<S, T>(bytes: T, serializer: S) -> Result<S::Ok, S::Error>
where
S: Serializer,
T: AsRef<[u8]>
where
S: Serializer,
T: AsRef<[u8]>,
{
use serde::ser::Error;
let hex_bytes = hex::encode(bytes.as_ref());
let hex_string = String::from_utf8(hex_bytes)
.map_err(Error::custom)?;
let hex_string = String::from_utf8(hex_bytes).map_err(Error::custom)?;
serializer.serialize_str(&hex_string)
}

pub(crate) fn parse_hex<'de, D>(deserializer: D) -> Result<Vec<u8>, D::Error>
where D: Deserializer<'de>
where
D: Deserializer<'de>,
{
use serde::de::Error;
let string = String::deserialize(deserializer)?;
hex::decode(&string)
.map_err(Error::custom)
hex::decode(&string).map_err(Error::custom)
}

pub(crate) fn serialize_base64<S, T>(bytes: T, serializer: S) -> Result<S::Ok, S::Error>
where
S: Serializer,
T: AsRef<[u8]>
where
S: Serializer,
T: AsRef<[u8]>,
{
use serde::ser::Error;
let base64_bytes = base64::encode(bytes.as_ref());
let base64_string = String::from_utf8(base64_bytes)
.map_err(Error::custom)?;
let base64_string = String::from_utf8(base64_bytes).map_err(Error::custom)?;
serializer.serialize_str(&base64_string)
}

pub(crate) fn parse_base64<'de, D>(deserializer: D) -> Result<Vec<u8>, D::Error>
where D: Deserializer<'de>
where
D: Deserializer<'de>,
{
use serde::de::Error;
let string = String::deserialize(deserializer)?;
base64::decode(&string)
.map_err(Error::custom)
base64::decode(&string).map_err(Error::custom)
}

pub(crate) fn serialize_option_base64<S>(maybe_bytes: &Option<Vec<u8>>, serializer: S) -> Result<S::Ok, S::Error>
where S: Serializer
pub(crate) fn serialize_option_base64<S>(
maybe_bytes: &Option<Vec<u8>>,
serializer: S,
) -> Result<S::Ok, S::Error>
where
S: Serializer,
{
#[derive(Serialize)]
struct Wrapper<'a>(#[serde(serialize_with = "serialize_base64")] &'a Vec<u8>);

match maybe_bytes {
Some(bytes) => Wrapper(bytes).serialize(serializer),
None => maybe_bytes.serialize(serializer)
None => maybe_bytes.serialize(serializer),
}
}

pub(crate) fn parse_option_base64<'de, D>(deserializer: D) -> Result<Option<Vec<u8>>, D::Error>
where D: Deserializer<'de>
where
D: Deserializer<'de>,
{
#[derive(Deserialize)]
struct Wrapper(#[serde(deserialize_with = "parse_base64")] Vec<u8>);
Expand Down
10 changes: 3 additions & 7 deletions tendermint/src/validator.rs
Original file line number Diff line number Diff line change
Expand Up @@ -40,13 +40,9 @@ impl lite::ValidatorSet for Set {

fn hash(&self) -> Hash {
// TODO almost the same as above's pub fn hash(self) -> merkle::Hash
let validator_bytes: &Vec<Vec<u8>> =
&self.validators.iter().map(|x| x.hash_bytes()).collect();
let validator_byteslices: Vec<&[u8]> =
(&validator_bytes).iter().map(|x| x.as_slice()).collect();
Hash::Sha256(merkle::simple_hash_from_byte_slices(
validator_byteslices.as_slice(),
))
let validator_bytes: Vec<Vec<u8>> =
self.validators.iter().map(|x| x.hash_bytes()).collect();
Hash::Sha256(merkle::simple_hash_from_byte_vectors(validator_bytes))
}

fn total_power(&self) -> u64 {
Expand Down
5 changes: 1 addition & 4 deletions tendermint/tests/integration.rs
Original file line number Diff line number Diff line change
Expand Up @@ -97,9 +97,6 @@ mod rpc {
let status = localhost_rpc_client().status().unwrap();

// For lack of better things to test
assert_eq!(
status.validator_info.voting_power.value(),
10
);
assert_eq!(status.validator_info.voting_power.value(), 10);
}
}

0 comments on commit 9415981

Please sign in to comment.