Skip to content
This repository has been archived by the owner on Jun 3, 2020. It is now read-only.

Commit

Permalink
Merge pull request #228 from tendermint/tendermint-rs/updates-and-cle…
Browse files Browse the repository at this point in the history
…anups

tendermint-rs: Fixes, cleanups, and updates
  • Loading branch information
tarcieri committed Apr 16, 2019
2 parents 4c4eb06 + 39cfe2d commit 689f48a
Show file tree
Hide file tree
Showing 32 changed files with 550 additions and 224 deletions.
1 change: 1 addition & 0 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ jobs:
cargo build --features=yubihsm
cargo build --features=ledgertm
cargo build --features=yubihsm,ledgertm,softsign
cd tendermint-rs && cargo build --no-default-features
- run:
name: build --release
command: |
Expand Down
34 changes: 28 additions & 6 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ signatory-dalek = "0.11"
signatory-secp256k1 = "0.11"
subtle = "2"
subtle-encoding = { version = "0.3", features = ["bech32-preview"] }
tendermint = { version = "0.5.0-alpha1", path = "tendermint-rs" }
tendermint = { version = "0.5", path = "tendermint-rs", features = ["amino-types", "secret-connection"] }
tiny-bip39 = "0.6"
wait-timeout = "0.2"
yubihsm = { version = "0.22", features = ["setup", "usb"], optional = true }
Expand Down
10 changes: 5 additions & 5 deletions src/client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
//! as a "Key Management System".

use crate::{
config::{ValidatorAddr, ValidatorConfig},
config::ValidatorConfig,
error::{KmsError, KmsErrorKind},
keyring::SecretKeyEncoding,
session::Session,
Expand All @@ -21,7 +21,7 @@ use std::{
thread::{self, JoinHandle},
time::Duration,
};
use tendermint::{chain, secret_connection};
use tendermint::{chain, node, secret_connection, Address};

/// How long to wait after a crash before respawning (in seconds)
pub const RESPAWN_DELAY: u64 = 1;
Expand Down Expand Up @@ -68,7 +68,7 @@ fn client_loop(config: ValidatorConfig, should_term: &Arc<AtomicBool>) {
}

let session_result = match &addr {
ValidatorAddr::Tcp {
Address::Tcp {
peer_id,
host,
port,
Expand All @@ -82,7 +82,7 @@ fn client_loop(config: ValidatorConfig, should_term: &Arc<AtomicBool>) {
return;
}
},
ValidatorAddr::Unix { socket_path } => unix_session(chain_id, socket_path, should_term),
Address::Unix { path } => unix_session(chain_id, path, should_term),
};

if let Err(e) = session_result {
Expand All @@ -107,7 +107,7 @@ fn client_loop(config: ValidatorConfig, should_term: &Arc<AtomicBool>) {
/// Create a TCP connection to a validator (encrypted with SecretConnection)
fn tcp_session(
chain_id: chain::Id,
validator_peer_id: Option<secret_connection::PeerId>,
validator_peer_id: Option<node::Id>,
host: &str,
port: u16,
secret_key_path: &Path,
Expand Down
8 changes: 2 additions & 6 deletions src/config/validator/mod.rs → src/config/validator.rs
Original file line number Diff line number Diff line change
@@ -1,15 +1,11 @@
mod addr;

use std::path::PathBuf;
use tendermint::chain;

pub use self::addr::ValidatorAddr;
use tendermint::{chain, Address};

/// Validator configuration
#[derive(Clone, Deserialize, Debug)]
pub struct ValidatorConfig {
/// Address of the validator (`tcp://` or `unix://`)
pub addr: ValidatorAddr,
pub addr: Address,

/// Chain ID of the Tendermint network this validator is part of
pub chain_id: chain::Id,
Expand Down
90 changes: 0 additions & 90 deletions src/config/validator/addr.rs

This file was deleted.

9 changes: 4 additions & 5 deletions src/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,7 @@ use std::{
fmt::{self, Display},
io,
};
use tendermint;
use tendermint::amino_types::validate::ValidationError as TmValidationError;
use tendermint::amino_types::validate::ValidationError;

/// Error type
#[derive(Debug)]
Expand Down Expand Up @@ -142,7 +141,7 @@ impl From<signatory::Error> for KmsError {
}

impl From<tendermint::Error> for KmsError {
fn from(other: tendermint::Error) -> Self {
fn from(other: tendermint::error::Error) -> Self {
let kind = match other {
tendermint::Error::Crypto => KmsErrorKind::CryptoError,
tendermint::Error::InvalidKey => KmsErrorKind::InvalidKey,
Expand All @@ -158,8 +157,8 @@ impl From<tendermint::Error> for KmsError {
}
}

impl From<TmValidationError> for KmsError {
fn from(other: TmValidationError) -> Self {
impl From<ValidationError> for KmsError {
fn from(other: ValidationError) -> Self {
err!(KmsErrorKind::InvalidMessageError, other).into()
}
}
Expand Down
11 changes: 6 additions & 5 deletions src/session.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,8 @@ use std::{
};
use subtle::ConstantTimeEq;
use tendermint::{
amino_types::{PingRequest, PingResponse, PubKeyRequest},
amino_types::{PingRequest, PingResponse, PubKeyRequest, PubKeyResponse},
node,
secret_connection::{self, SecretConnection},
};

Expand All @@ -41,7 +42,7 @@ impl Session<SecretConnection<TcpStream>> {
/// Create a new session with the validator at the given address/port
pub fn connect_tcp(
chain_id: chain::Id,
validator_peer_id: Option<secret_connection::PeerId>,
validator_peer_id: Option<node::Id>,
host: &str,
port: u16,
secret_connection_key: &ed25519::Seed,
Expand Down Expand Up @@ -170,8 +171,8 @@ where

/// Get the public key for (the only) public key in the keyring
fn get_public_key(&mut self, _request: &PubKeyRequest) -> Result<Response, KmsError> {
Ok(Response::PublicKey(
KeyRing::default_pubkey()?.to_response(),
))
Ok(Response::PublicKey(PubKeyResponse::from(
*KeyRing::default_pubkey()?,
)))
}
}
30 changes: 15 additions & 15 deletions tendermint-rs/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -32,37 +32,37 @@ bytes = "0.4"
chrono = { version = "0.4", features = ["serde"] }
digest = "0.8"
failure = "0.1"
failure_derive = "0.1"
hkdf = { version = "0.7", optional = true }
prost-amino = { version = "0.4.0", optional = true }
prost-amino-derive = { version = "0.4.0", optional = true }
rand_os = { version = "0.1", optional = true }
ring = { version = "0.14", optional = true }
serde = { version = "1", optional = true }
serde_derive = { version = "1", optional = true }
signatory = { version = "0.11.2", optional = true, features = ["ed25519", "ecdsa"] }
serde = { version = "1", optional = true, features = ["derive"] }
signatory = { version = "0.11.2", features = ["ed25519", "ecdsa"] }
signatory-dalek = { version = "0.11", optional = true }
sha2 = { version = "0.8", optional = true, default-features = false }
subtle = { version = "2", optional = true }
sha2 = { version = "0.8", default-features = false }
subtle = "2"
subtle-encoding = { version = "0.3", features = ["bech32-preview"] }
tai64 = { version = "1", optional = true, features = ["chrono"] }
x25519-dalek = { version = "0.4.4", optional = true, default-features = false, features = ["u64_backend"] }
zeroize = { version = "0.5.2", optional = true }
x25519-dalek = { version = "0.5", optional = true, default-features = false, features = ["u64_backend"] }
zeroize = { version = "0.6", optional = true }

[dev-dependencies]
serde_json = "1"

[features]
default = ["secret-connection", "serializers", "tai64"]
default = ["serde", "tai64"]
amino-types = ["prost-amino", "prost-amino-derive"]
secret-connection = [
"amino-types",
"byteorder",
"hkdf",
"prost-amino",
"prost-amino-derive",
"rand_os",
"ring",
"signatory",
"signatory-dalek",
"sha2",
"subtle",
"x25519-dalek",
"zeroize"
]
serializers = ["serde", "serde_derive"]

[package.metadata.docs.rs]
all-features = true
Loading

0 comments on commit 689f48a

Please sign in to comment.