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

Prepare for Prost v0.8+ upgrade #978

Closed
wants to merge 10 commits into from
Closed
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
5 changes: 5 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -21,3 +21,8 @@ exclude = [
[profile.release.package.tendermint-light-client-js]
# Tell `rustc` to optimize for small code size.
opt-level = "s"

[patch.crates-io]
prost = { git = "https://github.com/tokio-rs/prost", rev = "859f2438d955f8613bb7ca37c83bc990f55d6658" }
prost-derive = { git = "https://github.com/tokio-rs/prost", rev = "859f2438d955f8613bb7ca37c83bc990f55d6658" }
prost-types = { git = "https://github.com/tokio-rs/prost", rev = "859f2438d955f8613bb7ca37c83bc990f55d6658" }
2 changes: 1 addition & 1 deletion abci/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ std = [

[dependencies]
bytes = "1.0"
prost = "0.7"
prost = "0.8"
tendermint-proto = { version = "0.21.0", path = "../proto" }
tracing = "0.1"
flex-error = { version = "0.4.1", default-features = false }
Expand Down
4 changes: 2 additions & 2 deletions p2p/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ eyre = "0.6"
flume = "0.10.7"
hkdf = "0.10.0"
merlin = "2"
prost = "0.7"
prost = "0.8"
rand_core = { version = "0.5", features = ["std"] }
sha2 = "0.9"
subtle = "2"
Expand All @@ -53,4 +53,4 @@ tendermint-proto = { path = "../proto", version = "0.21.0" }
tendermint-std-ext = { path = "../std-ext", version = "0.21.0" }

# optional dependencies
prost-derive = { version = "0.7", optional = true }
prost-derive = { version = "0.8", optional = true }
4 changes: 2 additions & 2 deletions proto/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@ description = """
all-features = true

[dependencies]
prost = "0.7"
prost-types = "0.7"
prost = "0.8"
prost-types = "0.8"
bytes = "1.0"
serde = { version = "1.0", features = ["derive"] }
subtle-encoding = "0.5"
Expand Down
4 changes: 2 additions & 2 deletions tendermint/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,8 @@ ed25519-dalek = { version = "1", features = ["serde"] }
futures = "0.3"
num-traits = "0.2"
once_cell = "1.3"
prost = "0.7"
prost-types = "0.7"
prost = "0.8"
prost-types = "0.8"
serde = { version = "1", features = ["derive"] }
serde_json = "1"
serde_bytes = "0.11"
Expand Down
10 changes: 8 additions & 2 deletions tendermint/src/block/commit_sig.rs
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,10 @@ impl TryFrom<RawCommitSig> for CommitSig {
return Err(Error::invalid_validator_address());
}

let timestamp = value.timestamp.ok_or_else(Error::missing_timestamp)?.into();
let timestamp = value
.timestamp
.ok_or_else(Error::missing_timestamp)?
.try_into()?;

return Ok(CommitSig::BlockIdFlagCommit {
validator_address: value.validator_address.try_into()?,
Expand All @@ -119,7 +122,10 @@ impl TryFrom<RawCommitSig> for CommitSig {
}
return Ok(CommitSig::BlockIdFlagNil {
validator_address: value.validator_address.try_into()?,
timestamp: value.timestamp.ok_or_else(Error::missing_timestamp)?.into(),
timestamp: value
.timestamp
.ok_or_else(Error::missing_timestamp)?
.try_into()?,
signature: Signature::new(value.signature)?,
});
}
Expand Down
5 changes: 4 additions & 1 deletion tendermint/src/block/header.rs
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,10 @@ impl TryFrom<RawHeader> for Header {
version: value.version.ok_or_else(Error::missing_version)?.into(),
chain_id: value.chain_id.try_into()?,
height,
time: value.time.ok_or_else(Error::missing_timestamp)?.into(),
time: value
.time
.ok_or_else(Error::missing_timestamp)?
.try_into()?,
last_block_id,
last_commit_hash,
data_hash: if value.data_hash.is_empty() {
Expand Down
5 changes: 4 additions & 1 deletion tendermint/src/evidence.rs
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,10 @@ impl TryFrom<RawDuplicateVoteEvidence> for DuplicateVoteEvidence {
.try_into()?,
total_voting_power: value.total_voting_power.try_into()?,
validator_power: value.validator_power.try_into()?,
timestamp: value.timestamp.ok_or_else(Error::missing_timestamp)?.into(),
timestamp: value
.timestamp
.ok_or_else(Error::missing_timestamp)?
.try_into()?,
})
}
}
Expand Down
2 changes: 1 addition & 1 deletion tendermint/src/proposal.rs
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ impl TryFrom<RawProposal> for Proposal {
round: value.round.try_into()?,
pol_round,
block_id: value.block_id.map(TryInto::try_into).transpose()?,
timestamp: value.timestamp.map(|t| t.into()),
timestamp: value.timestamp.map(TryInto::try_into).transpose()?,
signature: Signature::new(value.signature)?,
})
}
Expand Down
2 changes: 1 addition & 1 deletion tendermint/src/proposal/canonical_proposal.rs
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ impl TryFrom<RawCanonicalProposal> for CanonicalProposal {
round,
pol_round,
block_id: block_id.map(TryInto::try_into).transpose()?,
timestamp: value.timestamp.map(|t| t.into()),
timestamp: value.timestamp.map(TryInto::try_into).transpose()?,
chain_id: ChainId::try_from(value.chain_id).unwrap(),
})
}
Expand Down
11 changes: 8 additions & 3 deletions tendermint/src/time.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
use chrono::{DateTime, Utc};
use serde::{Deserialize, Serialize};

use std::convert::TryFrom;
use std::fmt;
use std::ops::{Add, Sub};
use std::str::FromStr;
Expand All @@ -21,16 +22,20 @@ pub struct Time(DateTime<Utc>);

impl Protobuf<Timestamp> for Time {}

impl From<Timestamp> for Time {
fn from(value: Timestamp) -> Self {
impl TryFrom<Timestamp> for Time {
type Error = Error;

fn try_from(value: Timestamp) -> Result<Self, Self::Error> {
// prost_types::Timestamp has a SystemTime converter but
// tendermint_proto::Timestamp can be JSON-encoded
let prost_value = prost_types::Timestamp {
seconds: value.seconds,
nanos: value.nanos,
};

SystemTime::from(prost_value).into()
SystemTime::try_from(prost_value)
.map(Into::into)
.map_err(|e| Error::invalid_timestamp(e.to_string()))
}
}

Expand Down
2 changes: 1 addition & 1 deletion tendermint/src/vote.rs
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ impl TryFrom<RawVote> for Vote {
.map(TryInto::try_into)
.transpose()?
.filter(|i| i != &block::Id::default()),
timestamp: value.timestamp.map(|t| t.into()),
timestamp: value.timestamp.map(TryFrom::try_from).transpose()?,
validator_address: value.validator_address.try_into()?,
validator_index: value.validator_index.try_into()?,
signature: Signature::new(value.signature)?,
Expand Down
4 changes: 2 additions & 2 deletions tendermint/src/vote/canonical_vote.rs
Original file line number Diff line number Diff line change
Expand Up @@ -48,8 +48,8 @@ impl TryFrom<RawCanonicalVote> for CanonicalVote {
vote_type: value.r#type.try_into()?,
height: value.height.try_into()?,
round: (value.round as i32).try_into()?,
block_id: block_id.map(|b| b.try_into()).transpose()?,
timestamp: value.timestamp.map(|t| t.into()),
block_id: block_id.map(TryInto::try_into).transpose()?,
timestamp: value.timestamp.map(TryInto::try_into).transpose()?,
chain_id: ChainId::try_from(value.chain_id)?,
})
}
Expand Down
5 changes: 5 additions & 0 deletions tools/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,8 @@ members = [
"proto-compiler",
"rpc-probe"
]

[patch.crates-io]
prost = { git = "https://github.com/tokio-rs/prost", rev = "859f2438d955f8613bb7ca37c83bc990f55d6658" }
prost-build = { git = "https://github.com/tokio-rs/prost", rev = "859f2438d955f8613bb7ca37c83bc990f55d6658" }
prost-types = { git = "https://github.com/tokio-rs/prost", rev = "859f2438d955f8613bb7ca37c83bc990f55d6658" }
2 changes: 1 addition & 1 deletion tools/proto-compiler/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ publish = false

[dependencies]
walkdir = { version = "2.3" }
prost-build = { version = "0.7" }
prost-build = { version = "0.8" }
git2 = { version = "0.13" }
tempfile = { version = "3.2.0" }
subtle-encoding = { version = "0.5" }
16 changes: 8 additions & 8 deletions tools/proto-compiler/src/functions.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,13 @@ use git2::build::{CheckoutBuilder, RepoBuilder};
use git2::{AutotagOption, Commit, FetchOptions, Oid, Reference, Repository};
use std::fs::{copy, create_dir_all, remove_dir_all, File};
use std::io::Write;
use std::path::PathBuf;
use std::path::{Path, PathBuf};
use subtle_encoding::hex;
use walkdir::WalkDir;

/// Clone or open+fetch a repository and check out a specific commitish
/// In case of an existing repository, the origin remote will be set to `url`.
pub fn get_commitish(dir: &PathBuf, url: &str, commitish: &str) {
pub fn get_commitish(dir: &Path, url: &str, commitish: &str) {
let repo = if dir.exists() {
fetch_existing(dir, url)
} else {
Expand All @@ -17,7 +17,7 @@ pub fn get_commitish(dir: &PathBuf, url: &str, commitish: &str) {
checkout_commitish(&repo, commitish)
}

fn clone_new(dir: &PathBuf, url: &str) -> Repository {
fn clone_new(dir: &Path, url: &str) -> Repository {
println!(
" [info] => Cloning {} into {} folder",
url,
Expand All @@ -34,7 +34,7 @@ fn clone_new(dir: &PathBuf, url: &str) -> Repository {
builder.clone(url, dir).unwrap()
}

fn fetch_existing(dir: &PathBuf, url: &str) -> Repository {
fn fetch_existing(dir: &Path, url: &str) -> Repository {
println!(
" [info] => Fetching from {} into existing {} folder",
url,
Expand Down Expand Up @@ -115,7 +115,7 @@ fn find_reference_or_commit<'a>(
) -> (Option<Reference<'a>>, Commit<'a>) {
let mut tried_origin = false; // we tried adding 'origin/' to the commitish

let mut try_reference = repo.resolve_reference_from_short_name(&commitish);
let mut try_reference = repo.resolve_reference_from_short_name(commitish);
if try_reference.is_err() {
// Local branch might be missing, try the remote branch
try_reference = repo.resolve_reference_from_short_name(&format!("origin/{}", commitish));
Expand Down Expand Up @@ -151,7 +151,7 @@ fn find_reference_or_commit<'a>(
}

/// Copy generated files to target folder
pub fn copy_files(src_dir: &PathBuf, target_dir: &PathBuf) {
pub fn copy_files(src_dir: &Path, target_dir: &Path) {
// Remove old compiled files
remove_dir_all(target_dir).unwrap_or_default();
create_dir_all(target_dir).unwrap();
Expand Down Expand Up @@ -203,7 +203,7 @@ pub fn find_proto_files(proto_paths: Vec<PathBuf>) -> Vec<PathBuf> {
}

/// Create tendermint.rs with library information
pub fn generate_tendermint_lib(prost_dir: &PathBuf, tendermint_lib_target: &PathBuf) {
pub fn generate_tendermint_lib(prost_dir: &Path, tendermint_lib_target: &Path) {
let file_names = WalkDir::new(prost_dir)
.into_iter()
.filter_map(|e| e.ok())
Expand Down Expand Up @@ -238,7 +238,7 @@ pub fn generate_tendermint_lib(prost_dir: &PathBuf, tendermint_lib_target: &Path
);

for part in parts {
tab_count = tab_count - 1;
tab_count -= 1;
let tabs = tab.repeat(tab_count);
//{tabs} pub mod {part} {
//{inner_content}
Expand Down
12 changes: 6 additions & 6 deletions tools/rpc-probe/src/client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ impl Client {
})
.await?;
response_rx.recv().await.ok_or_else(|| {
Error::InternalError("internal channel communication problem".to_string())
Error::Internal("internal channel communication problem".to_string())
})?
}

Expand All @@ -59,7 +59,7 @@ impl Client {
})
.await?;
let response = response_rx.recv().await.ok_or_else(|| {
Error::InternalError("internal channel communication problem".to_string())
Error::Internal("internal channel communication problem".to_string())
})??;
Ok((subscription_rx, response))
}
Expand Down Expand Up @@ -93,7 +93,7 @@ impl Client {
return Ok(());
}
}
Err(Error::InternalError(format!(
Err(Error::Internal(format!(
"subscription terminated before we could reach target height of {}",
h
)))
Expand All @@ -105,7 +105,7 @@ impl Client {

async fn send_cmd(&mut self, cmd: DriverCommand) -> Result<()> {
self.cmd_tx.send(cmd).map_err(|e| {
Error::InternalError(format!(
Error::Internal(format!(
"WebSocket driver channel receiving end closed unexpectedly: {}",
e.to_string()
))
Expand Down Expand Up @@ -155,7 +155,7 @@ impl ClientDriver {
Some(res) = self.stream.next() => match res {
Ok(msg) => self.handle_incoming_msg(msg).await?,
Err(e) => return Err(
Error::WebSocketError(
Error::WebSocket(
format!("failed to read from WebSocket connection: {}", e),
),
),
Expand All @@ -179,7 +179,7 @@ impl ClientDriver {

async fn send_msg(&mut self, msg: Message) -> Result<()> {
self.stream.send(msg).await.map_err(|e| {
Error::WebSocketError(format!("failed to write to WebSocket connection: {}", e))
Error::WebSocket(format!("failed to write to WebSocket connection: {}", e))
})
}

Expand Down
18 changes: 9 additions & 9 deletions tools/rpc-probe/src/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,10 @@ pub type Result<T> = std::result::Result<T, Error>;
#[derive(Debug, Clone, Error)]
pub enum Error {
#[error("an internal error occurred: {0}")]
InternalError(String),
Internal(String),

#[error("WebSocket connection error: {0}")]
WebSocketError(String),
WebSocket(String),

#[error("timed out: {0}")]
Timeout(String),
Expand All @@ -25,18 +25,18 @@ pub enum Error {
InvalidParamValue(String),

#[error("I/O error: {0}")]
IoError(String),
Io(String),

#[error("unexpected success response")]
UnexpectedSuccess,
UnexpectedSuccessResponse,

#[error("unexpected error response: {0}")]
UnexpectedError(String),
UnexpectedErrorResponse(String),
}

impl From<async_tungstenite::tungstenite::Error> for Error {
fn from(e: async_tungstenite::tungstenite::Error) -> Self {
Self::WebSocketError(e.to_string())
Self::WebSocket(e.to_string())
}
}

Expand All @@ -54,13 +54,13 @@ impl From<serde_json::Error> for Error {

impl<T> From<tokio::sync::mpsc::error::SendError<T>> for Error {
fn from(e: tokio::sync::mpsc::error::SendError<T>) -> Self {
Self::InternalError(format!("failed to send to channel: {}", e))
Self::Internal(format!("failed to send to channel: {}", e))
}
}

impl From<tokio::task::JoinError> for Error {
fn from(e: tokio::task::JoinError) -> Self {
Self::InternalError(format!(
Self::Internal(format!(
"failed while waiting for async task to join: {}",
e
))
Expand All @@ -69,6 +69,6 @@ impl From<tokio::task::JoinError> for Error {

impl From<std::io::Error> for Error {
fn from(e: std::io::Error) -> Self {
Self::IoError(e.to_string())
Self::Io(e.to_string())
}
}
Loading