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

Support both the Tendermint legacy and v0.33 secret connection handshake #58

Merged
merged 6 commits into from
Jun 7, 2020
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
Prev Previous commit
Next Next commit
Change config schema to use version strings for the connection protocolw
  • Loading branch information
zmanian committed Jun 7, 2020
commit 6a147e585ef2c72c824f02dbeac2ed86d4773de3
22 changes: 17 additions & 5 deletions src/config/validator.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ use crate::{
keyring::SecretKeyEncoding,
prelude::*,
};
use serde::Deserialize;
use serde::{Deserialize, Serialize};
use signatory::{
ed25519,
encoding::{Decode, Encode},
Expand Down Expand Up @@ -37,8 +37,20 @@ pub struct ValidatorConfig {
pub max_height: Option<tendermint::block::Height>,

/// Use Tendermint v0.33 handshake
#[serde(default = "handshake_default")]
pub v0_33_handshake: bool,
#[serde(default = "protocol_default")]
pub protocol_version: TendermintVersion,
}

/// Tendermint secure connection protocol version
#[derive(Deserialize, Serialize, Clone, Debug)]
pub enum TendermintVersion {
/// Legacy V1 SecretConnection Handshake
#[serde(rename = "legacy")]
Legacy,

/// Tendermint v0.33+ SecretConnection Handshake
#[serde(rename = "v0.33")]
V0_33,
}

impl ValidatorConfig {
Expand Down Expand Up @@ -81,6 +93,6 @@ fn reconnect_default() -> bool {
}

/// Default value for the `ValidatorConfig` reconnect field
fn handshake_default() -> bool {
false
fn protocol_default() -> TendermintVersion {
TendermintVersion::Legacy
}
9 changes: 7 additions & 2 deletions src/session.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

use crate::{
chain::{self, state::StateErrorKind},
config::ValidatorConfig,
config::{TendermintVersion, ValidatorConfig},
connection::{tcp, unix::UnixConnection, Connection},
error::{Error, ErrorKind::*},
prelude::*,
Expand Down Expand Up @@ -39,13 +39,18 @@ impl Session {
debug!("{}: Connecting to {}...", &config.chain_id, &config.addr);

let seed = config.load_secret_key()?;
let v0_33_handshake = match config.protocol_version {
TendermintVersion::V0_33 => true,
TendermintVersion::Legacy => false,
};

let conn = tcp::open_secret_connection(
host,
*port,
&seed,
peer_id,
config.timeout,
config.v0_33_handshake,
v0_33_handshake,
)?;

info!(
Expand Down
2 changes: 1 addition & 1 deletion tmkms.toml.example
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ chain_id = "cosmoshub-1"
reconnect = true # true is the default
secret_key = "path/to/secret_connection.key"
# max_height = "500000"
v0_33_handshake = false # false is the default
protocol_version = "v0.33" # "legacy" is the default

## Signing provider configuration

Expand Down