Skip to content

Commit

Permalink
Bump tendermint-rs crates to v0.26; MSRV 1.59
Browse files Browse the repository at this point in the history
This release removes the need to pin to specific versions, allowing the
requirements to shift to `^`.

It includes some changes related to the elimination of
`tendermint::abci`, namely `Gas` is now aliased to `u64`, `Data` is
aliased to `Vec<u8>`, and `Hash` uses `tendermint::Hash`.
  • Loading branch information
tony-iqlusion committed Nov 1, 2022
1 parent 3f8535a commit 70a02d0
Show file tree
Hide file tree
Showing 17 changed files with 60 additions and 42 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/cosmos-sdk-proto.yml
Expand Up @@ -22,7 +22,7 @@ jobs:
strategy:
matrix:
rust:
- 1.57.0 # MSRV
- 1.59.0 # MSRV
- stable
target:
- x86_64-unknown-linux-gnu
Expand All @@ -43,7 +43,7 @@ jobs:
strategy:
matrix:
rust:
- 1.57.0 # MSRV
- 1.59.0 # MSRV
- stable
steps:
- uses: actions/checkout@v1
Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/cosmrs.yml
Expand Up @@ -24,7 +24,7 @@ jobs:
strategy:
matrix:
rust:
- 1.57.0 # MSRV
- 1.59.0 # MSRV
- stable
target:
- x86_64-unknown-linux-gnu
Expand All @@ -44,7 +44,7 @@ jobs:
strategy:
matrix:
rust:
- 1.57.0 # MSRV
- 1.59.0 # MSRV
- stable
steps:
- uses: actions/checkout@v1
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/rebuild-protos.yml
Expand Up @@ -13,7 +13,7 @@ jobs:
- uses: actions/checkout@v2
- uses: actions-rs/toolchain@v1
with:
toolchain: 1.57.0 # MSRV
toolchain: 1.59.0 # MSRV
components: rustfmt
override: true
profile: minimal
Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/workspace.yml
Expand Up @@ -20,7 +20,7 @@ jobs:
- uses: actions/checkout@v2
- uses: actions-rs/toolchain@v1
with:
toolchain: 1.57.0 # MSRV
toolchain: stable
components: rustfmt
override: true
profile: minimal
Expand All @@ -35,7 +35,7 @@ jobs:
- uses: actions/checkout@v2
- uses: actions-rs/toolchain@v1
with:
toolchain: 1.57.0 # MSRV
toolchain: 1.59.0
components: clippy
override: true
profile: minimal
Expand Down
2 changes: 1 addition & 1 deletion README.md
Expand Up @@ -34,7 +34,7 @@ all other crates, simply make the required edits in [main.rs](proto-build/main.r

## Minimum Supported Rust Version

Rust **1.57**
Rust **1.59**

[//]: # "crates"

Expand Down
6 changes: 3 additions & 3 deletions cosmos-sdk-proto/Cargo.toml
@@ -1,6 +1,6 @@
[package]
name = "cosmos-sdk-proto"
version = "0.14.0"
version = "0.15.0-pre"
authors = [
"Justin Kilpatrick <justin@althea.net>",
"Greg Szabo <greg@informal.systems>",
Expand All @@ -13,12 +13,12 @@ readme = "README.md"
categories = ["cryptography", "cryptography::cryptocurrencies", "database"]
keywords = ["blockchain", "cosmos", "tendermint", "proto"]
edition = "2021"
rust-version = "1.56"
rust-version = "1.59"

[dependencies]
prost = "0.11"
prost-types = "0.11"
tendermint-proto = "=0.23.9"
tendermint-proto = "0.26"

# Optional dependencies
tonic = { version = "0.8", optional = true, default-features = false, features = ["codegen", "prost"] }
Expand Down
4 changes: 2 additions & 2 deletions cosmos-sdk-proto/README.md
Expand Up @@ -20,7 +20,7 @@ Pull requests to expand coverage are welcome.

## Minimum Supported Rust Version

This crate is supported on Rust **1.57** or newer.
This crate is supported on Rust **1.59** or newer.

[//]: # "badges"
[crate-image]: https://buildstats.info/crate/cosmos-sdk-proto
Expand All @@ -31,7 +31,7 @@ This crate is supported on Rust **1.57** or newer.
[build-link]: https://github.com/cosmos/cosmos-rust/actions/workflows/cosmos-sdk-proto.yml
[license-image]: https://img.shields.io/badge/license-Apache2.0-blue.svg
[license-link]: https://github.com/cosmos/cosmos-rust/blob/master/LICENSE
[rustc-image]: https://img.shields.io/badge/rustc-1.57+-blue.svg
[rustc-image]: https://img.shields.io/badge/rustc-1.59+-blue.svg

[//]: # "links"
[Protobufs]: (https://github.com/cosmos/cosmos-sdk/tree/master/proto/)
Expand Down
10 changes: 5 additions & 5 deletions cosmrs/Cargo.toml
@@ -1,6 +1,6 @@
[package]
name = "cosmrs"
version = "0.9.0"
version = "0.10.0-pre"
authors = ["Tony Arcieri <tony@iqlusion.io>"]
license = "Apache-2.0"
repository = "https://github.com/cosmos/cosmos-rust/tree/main/cosmrs"
Expand All @@ -9,23 +9,23 @@ readme = "README.md"
categories = ["cryptography", "cryptography::cryptocurrencies", "encoding"]
keywords = ["blockchain", "cosmos", "tendermint", "transaction"]
edition = "2021"
rust-version = "1.57"
rust-version = "1.59"

[dependencies]
cosmos-sdk-proto = { version = "0.14", default-features = false, path = "../cosmos-sdk-proto" }
cosmos-sdk-proto = { version = "=0.15.0-pre", default-features = false, path = "../cosmos-sdk-proto" }
ecdsa = { version = "0.14", features = ["std"] }
eyre = "0.6"
k256 = { version = "0.11", features = ["ecdsa", "sha256"] }
rand_core = { version = "0.6", features = ["std"] }
serde = { version = "1", features = ["serde_derive"] }
serde_json = "1"
subtle-encoding = { version = "0.5", features = ["bech32-preview"] }
tendermint = { version = "=0.23.9", features = ["secp256k1"] }
tendermint = { version = "0.26", features = ["secp256k1"] }
thiserror = "1"

# optional dependencies
bip32 = { version = "0.4", optional = true }
tendermint-rpc = { version = "=0.23.9", optional = true, features = ["http-client"] }
tendermint-rpc = { version = "0.26", optional = true, features = ["http-client"] }
tokio = { version = "1", optional = true }

[target.'cfg(target_arch = "wasm32")'.dependencies]
Expand Down
4 changes: 2 additions & 2 deletions cosmrs/README.md
Expand Up @@ -30,7 +30,7 @@ and message passing.

## Minimum Supported Rust Version

This crate is supported on Rust **1.57** or newer.
This crate is supported on Rust **1.59** or newer.

[//]: # "badges"
[crate-image]: https://buildstats.info/crate/cosmrs
Expand All @@ -41,7 +41,7 @@ This crate is supported on Rust **1.57** or newer.
[build-link]: https://github.com/cosmos/cosmos-rust/actions/workflows/cosmrs.yml
[license-image]: https://img.shields.io/badge/license-Apache2.0-blue.svg
[license-link]: https://github.com/cosmos/cosmos-rust/blob/master/LICENSE
[rustc-image]: https://img.shields.io/badge/rustc-1.57+-blue.svg
[rustc-image]: https://img.shields.io/badge/rustc-1.59+-blue.svg

[//]: # "general links"
[Cosmos]: https://cosmos.network/
Expand Down
23 changes: 12 additions & 11 deletions cosmrs/src/abci.rs
@@ -1,12 +1,14 @@
//! Abci-related functionality

use crate::tx::Msg;
use crate::{
proto::{self, traits::Message},
ErrorReport, Result,
tx::Msg,
ErrorReport, Gas, Result,
};
use serde::{Deserialize, Serialize};
use tendermint::abci::Gas;

/// Transaction data.
pub type Data = Vec<u8>;

/// MsgData defines the data returned in a Result object during message execution.
#[derive(Clone, Debug, Eq, PartialEq, PartialOrd, Ord)]
Expand Down Expand Up @@ -61,12 +63,11 @@ pub struct TxMsgData {
pub data: Vec<MsgData>,
}

impl TryFrom<tendermint::abci::Data> for TxMsgData {
impl TryFrom<Data> for TxMsgData {
type Error = ErrorReport;

fn try_from(data: tendermint::abci::Data) -> Result<TxMsgData> {
let proto = proto::cosmos::base::abci::v1beta1::TxMsgData::decode(data.value().as_ref())?;
proto.try_into()
fn try_from(data: Data) -> Result<TxMsgData> {
proto::cosmos::base::abci::v1beta1::TxMsgData::decode(data.as_ref())?.try_into()
}
}

Expand Down Expand Up @@ -111,17 +112,17 @@ impl TryFrom<proto::cosmos::base::abci::v1beta1::GasInfo> for GasInfo {

fn try_from(proto: proto::cosmos::base::abci::v1beta1::GasInfo) -> Result<GasInfo> {
Ok(GasInfo {
gas_wanted: Gas::from(proto.gas_wanted),
gas_used: Gas::from(proto.gas_used),
gas_wanted: proto.gas_wanted,
gas_used: proto.gas_used,
})
}
}

impl From<GasInfo> for proto::cosmos::base::abci::v1beta1::GasInfo {
fn from(info: GasInfo) -> Self {
proto::cosmos::base::abci::v1beta1::GasInfo {
gas_wanted: info.gas_wanted.value(),
gas_used: info.gas_wanted.value(),
gas_wanted: info.gas_wanted,
gas_used: info.gas_wanted,
}
}
}
10 changes: 8 additions & 2 deletions cosmrs/src/base.rs
Expand Up @@ -126,19 +126,22 @@ impl Serialize for AccountId {
}
}

/// Amounts.
pub type Amount = u128;

/// Coin defines a token with a denomination and an amount.
#[derive(Serialize, Deserialize, Clone, Debug, Eq, PartialEq, PartialOrd, Ord)]
pub struct Coin {
/// Denomination
pub denom: Denom,

/// Amount
pub amount: u128,
pub amount: Amount,
}

impl Coin {
/// Constructor
pub fn new(amount: u128, denom: &str) -> Result<Self> {
pub fn new(amount: Amount, denom: &str) -> Result<Self> {
Ok(Coin {
amount,
denom: denom.parse()?,
Expand Down Expand Up @@ -232,6 +235,9 @@ impl Serialize for Denom {
}
}

/// Gas cost.
pub type Gas = u64;

#[cfg(test)]
mod tests {
use super::{AccountId, Coin, Denom};
Expand Down
7 changes: 6 additions & 1 deletion cosmrs/src/dev.rs
Expand Up @@ -10,6 +10,7 @@ use crate::{
tx::{self, Tx},
};
use std::{ffi::OsStr, panic, process, str, time::Duration};
use tendermint_rpc::abci::transaction::Hash;
use tokio::time;

/// Docker image (on Docker Hub) containing a single-node test environment for
Expand Down Expand Up @@ -101,9 +102,13 @@ pub async fn poll_for_first_block(rpc_client: &rpc::HttpClient) {
}

/// Wait for a transaction with the given hash to appear in the blockchain
pub async fn poll_for_tx(rpc_client: &rpc::HttpClient, tx_hash: tx::Hash) -> Tx {
pub async fn poll_for_tx(rpc_client: &rpc::HttpClient, tx_hash: Hash) -> Tx {
let attempts = 5;

// TODO(tarcieri): better conversion or unified `Hash` type, see tendermint-rs#1221
#[allow(clippy::unwrap_used)]
let tx_hash = tx::Hash::Sha256(tx_hash.as_ref().try_into().unwrap());

for _ in 0..attempts {
// TODO(tarcieri): handle not found errors
if let Ok(tx) = Tx::find_by_hash(rpc_client, tx_hash).await {
Expand Down
2 changes: 1 addition & 1 deletion cosmrs/src/lib.rs
Expand Up @@ -47,7 +47,7 @@ mod base;
mod error;

pub use crate::{
base::{AccountId, Coin, Denom},
base::{AccountId, Amount, Coin, Denom, Gas},
error::{Error, Result},
tx::Tx,
};
Expand Down
12 changes: 9 additions & 3 deletions cosmrs/src/tx.rs
Expand Up @@ -63,7 +63,7 @@
//! let chain_id = "cosmoshub-4".parse()?;
//! let account_number = 1;
//! let sequence_number = 0;
//! let gas = 100_000;
//! let gas = 100_000u64;
//! let timeout_height = 9001u16;
//! let memo = "example memo";
//!
Expand Down Expand Up @@ -128,11 +128,11 @@ pub use crate::{
proto::{cosmos::tx::signing::v1beta1::SignMode, traits::MessageExt},
ErrorReport,
};
pub use tendermint::abci::{transaction::Hash, Gas};
pub use tendermint::Hash;

use crate::{
proto::{self, traits::Message},
Error, Result,
Error, Gas, Result,
};

#[cfg(feature = "rpc")]
Expand Down Expand Up @@ -178,6 +178,12 @@ impl Tx {
where
C: rpc::Client + Send + Sync,
{
// TODO(tarcieri): better conversion or unified `Hash` type, see tendermint-rs#1221
let tx_hash = match tx_hash {
Hash::Sha256(bytes) => tendermint_rpc::abci::transaction::Hash::new(bytes),
_ => return Err(Error::Crypto.into()),
};

let response = rpc_client.tx(tx_hash, false).await?;
Tx::from_bytes(response.tx.as_bytes())
}
Expand Down
4 changes: 2 additions & 2 deletions cosmrs/src/tx/fee.rs
Expand Up @@ -72,7 +72,7 @@ impl TryFrom<&proto::cosmos::tx::v1beta1::Fee> for Fee {

Ok(Fee {
amount,
gas_limit: proto.gas_limit.into(),
gas_limit: proto.gas_limit,
payer: proto.payer.parse_optional()?,
granter: proto.granter.parse_optional()?,
})
Expand All @@ -89,7 +89,7 @@ impl From<&Fee> for proto::cosmos::tx::v1beta1::Fee {
fn from(fee: &Fee) -> proto::cosmos::tx::v1beta1::Fee {
proto::cosmos::tx::v1beta1::Fee {
amount: fee.amount.iter().map(Into::into).collect(),
gas_limit: fee.gas_limit.value(),
gas_limit: fee.gas_limit,
payer: fee
.payer
.as_ref()
Expand Down
2 changes: 1 addition & 1 deletion cosmrs/tests/integration.rs
Expand Up @@ -58,7 +58,7 @@ fn msg_send() {

let chain_id = CHAIN_ID.parse().unwrap();
let sequence_number = 0;
let gas = 100_000;
let gas = 100_000u64;
let fee = Fee::from_amount_and_gas(amount, gas);

let tx_body = tx::BodyBuilder::new().msg(msg_send).memo(MEMO).finish();
Expand Down
2 changes: 1 addition & 1 deletion rust-toolchain
@@ -1 +1 @@
1.57.0
1.59.0

0 comments on commit 70a02d0

Please sign in to comment.