Skip to content

Commit

Permalink
chore: sync with ibc-rs (#193)
Browse files Browse the repository at this point in the history
* update ibc-rs rev

* new error variant for Gov

* update AnyClientState and AnyConsensusState impls

* refactor for new ibc-rs error types

* fix deprecated warning

* fix use_self

* short first doc paragraph

* fix redundant_clone

* fix empty_line_after_outer_attr

* fix needless_collect

* update deps

* update msrv to 1.75 for derive_more

* update cargo lockfile

* fmt

* fix significant_drop_tightening

* fix equatable_if_let

* fix string_lit_as_bytes

* use ok_or

* fix: use missing_state everywhere storage call returns None

---------

Co-authored-by: Farhad Shabani <[email protected]>
  • Loading branch information
rnbguy and Farhad-Shabani authored Sep 26, 2024
1 parent 2787a8e commit 81f852c
Show file tree
Hide file tree
Showing 31 changed files with 700 additions and 624 deletions.
547 changes: 323 additions & 224 deletions Cargo.lock

Large diffs are not rendered by default.

19 changes: 10 additions & 9 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -8,31 +8,32 @@ members = [ "basecoin", "basecoin/app", "basecoin/modules", "basecoin/store" ]
version = "0.2.0"
license = "Apache-2.0"
edition = "2021"
rust-version = "1.64"
rust-version = "1.75"
readme = "README.md"
repository = "https://github.com/informalsystems/basecoin-rs"
authors = [ "Informal Systems <[email protected]>" ]

[workspace.dependencies]
# external dependencies
base64 = { version = "0.22.1", default-features = false, features = [ "alloc" ] }
cosmrs = { version = "0.18.0" }
cosmrs = { version = "0.20.0" }
displaydoc = { version = "0.2", default-features = false }
derive_more = { version = "0.99.18", default-features = false, features = [ "from", "into", "display" ] }
derive_more = { version = "1.0.0", default-features = false, features = [ "from", "into", "try_into", "display" ] }
ed25519 = { version = "2.2.3", default-features = false }
prost = { version = "0.13.1", default-features = false }
prost = { version = "0.13.3", default-features = false }
serde_derive = { version = "1.0", default-features = false }
serde = "1.0"
serde_json = "1.0"
sha2 = "0.10.8"
tonic = "0.12.1"
tonic-reflection = "0.12.1"
tonic = "0.12.2"
tonic-reflection = "0.12.2"
tracing = "0.1.40"
tracing-subscriber = "0.3.18"

# ibc dependencies
ibc = { version = "0.54.0", default-features = false, features = [ "serde" ] }
ibc-query = { version = "0.54.0", default-features = false }
ibc-proto = { version = "0.47.0", default-features = false }
ibc-proto = { version = "0.47.1", default-features = false }
ics23 = { version = "0.12", default-features = false }

# tendermint dependencies
Expand All @@ -45,8 +46,8 @@ tendermint-rpc = { version = "0.38", default-features = false }
tower-abci = { version = "0.16" }

[patch.crates-io]
ibc = { git = "https://github.com/cosmos/ibc-rs.git", rev = "474909d" }
ibc-query = { git = "https://github.com/cosmos/ibc-rs.git", rev = "474909d" }
ibc = { git = "https://github.com/cosmos/ibc-rs.git", rev = "cfb707e" }
ibc-query = { git = "https://github.com/cosmos/ibc-rs.git", rev = "cfb707e" }

# for tendermint 0.38
tower-abci = { git = "https://github.com/informalsystems/tower-abci", rev = "0992541" }
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ of the ibc-rs modules.

## Requirements
So far this app has been tested with:
* Rust > v1.64
* Rust > v1.75
* CometBFT v0.37

## How to integrate ibc-rs changes into basecoin
Expand Down
8 changes: 4 additions & 4 deletions basecoin/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -20,14 +20,14 @@ tiny-bip39 = { version = "1" }
digest = { version = "0.10.7" }
bitcoin = { version = "0.32.2" }
hdpath = { version = "0.6.3" }
clap = { version = "4.5.7", features = [ "derive", "wrap_help" ] }
clap = { version = "4.5", features = [ "derive", "wrap_help" ] }
prost = { workspace = true }
serde = { workspace = true }
serde_derive = { version = "1.0.203", default-features = false }
serde_derive = { workspace = true }
serde_json = { workspace = true }
secp256k1 = { version = "0.29.0", features = [ "serde", "rand-std" ] }
secp256k1 = { version = "0.29", features = [ "serde", "rand-std" ] }
sha2 = { workspace = true }
tokio = { version = "1.38", features = [ "macros", "rt-multi-thread" ] }
tokio = { version = "1.40", features = [ "macros", "rt-multi-thread" ] }
tonic = { workspace = true }
tonic-reflection = { workspace = true }
toml = { version = "0.8" }
Expand Down
2 changes: 1 addition & 1 deletion basecoin/app/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ prost = { workspace = true }
serde_json = { workspace = true }
tonic = { workspace = true }
tracing = { workspace = true }
tower = { version = "0.4", features = [ "full" ], optional = true }
tower = { version = "0.5", features = [ "full" ], optional = true }

# tedermint dependencies
tendermint = { workspace = true }
Expand Down
2 changes: 1 addition & 1 deletion basecoin/modules/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ derive_more = { workspace = true }
primitive-types = { version = "0.12.2", default-features = false, features = [ "serde_no_std" ] }
prost = { workspace = true }
serde = { workspace = true }
serde_derive = { version = "1.0.203", default-features = false }
serde_derive = { workspace = true }
serde_json = { workspace = true }
sha2 = { workspace = true }
tonic = { workspace = true }
Expand Down
6 changes: 3 additions & 3 deletions basecoin/modules/src/auth/account.rs
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ impl TryFrom<BaseAccount> for AuthAccount {
type Error = String;

fn try_from(account: BaseAccount) -> Result<Self, Self::Error> {
Ok(AuthAccount {
Ok(Self {
address: account
.address
.parse()
Expand All @@ -73,7 +73,7 @@ impl TryFrom<BaseAccount> for AuthAccount {

impl From<AuthAccount> for BaseAccount {
fn from(account: AuthAccount) -> Self {
BaseAccount {
Self {
address: account.address.to_string(),
pub_key: None,
account_number: account.number,
Expand All @@ -85,7 +85,7 @@ impl From<AuthAccount> for BaseAccount {
impl From<AuthAccount> for Any {
fn from(account: AuthAccount) -> Self {
let account = BaseAccount::from(account);
Any {
Self {
type_url: "/cosmos.auth.v1beta1.BaseAccount".to_string(),
value: account.encode_to_vec(),
}
Expand Down
2 changes: 1 addition & 1 deletion basecoin/modules/src/bank/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,6 @@ pub enum Error {

impl From<Error> for AppError {
fn from(e: Error) -> Self {
AppError::Bank(e)
Self::Bank(e)
}
}
8 changes: 1 addition & 7 deletions basecoin/modules/src/bank/impls.rs
Original file line number Diff line number Diff line change
Expand Up @@ -293,13 +293,7 @@ where

let account_id = AccountId::from_str(&account).unwrap();
self.balance_keeper
.mint_coins(
account_id,
balances
.into_iter()
.map(|b| b.into())
.collect::<Vec<Coin>>(),
)
.mint_coins(account_id, balances.into_iter().map(|b| b.into()))
.unwrap();
}
}
Expand Down
6 changes: 5 additions & 1 deletion basecoin/modules/src/gov/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,14 @@ pub use crate::error::Error as AppError;
pub enum Error {
/// invalid proposal: `{reason}`
InvalidProposal { reason: String },
/// failed to validate: `{reason}`
ValidationFailure { reason: String },
/// failed to execute: `{reason}`
ExecutionFailure { reason: String },
}

impl From<Error> for AppError {
fn from(e: Error) -> Self {
AppError::Gov(e)
Self::Gov(e)
}
}
29 changes: 19 additions & 10 deletions basecoin/modules/src/gov/impls.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ use ibc_proto::Protobuf;
use tendermint::abci::Event;
use tracing::debug;

use super::error::Error as GovError;
use super::path::ProposalPath;
use super::proposal::Proposal;
use super::service::GovernanceService;
Expand Down Expand Up @@ -78,13 +79,13 @@ where
let upgrade_proposal =
UpgradeProposal::decode_vec(message.content.value.as_slice()).unwrap();

let mut upgrade_ctx = self.upgrade_ctx.write_access();

let event =
execute_upgrade_client_proposal(upgrade_ctx.deref_mut(), upgrade_proposal)
.map_err(|e| AppError::Custom {
reason: format!("Error handling upgrade proposal: {:?}", e),
})?;
let event = execute_upgrade_client_proposal(
self.upgrade_ctx.write_access().deref_mut(),
upgrade_proposal,
)
.map_err(|e| AppError::Custom {
reason: format!("Error handling upgrade proposal: {:?}", e),
})?;

let proposal = message.proposal(self.proposal_counter);

Expand All @@ -104,8 +105,16 @@ where

let mut ibc_ctx = self.ibc_ctx.write_access();

recover_client::validate(&ibc_ctx.ctx, msg_recover_client.clone())?;
recover_client::execute(&mut ibc_ctx.ctx, msg_recover_client)?;
recover_client::validate(&ibc_ctx.ctx, msg_recover_client.clone()).map_err(
|e| GovError::ValidationFailure {
reason: format!("Error validating client recovery message: {:?}", e),
},
)?;
recover_client::execute(&mut ibc_ctx.ctx, msg_recover_client).map_err(|e| {
GovError::ValidationFailure {
reason: format!("Error executing client recovery message: {:?}", e),
}
})?;

// client recovery operation does not return an event
// https://github.com/cosmos/ibc-go/blob/4c1aae32/modules/light-clients/07-tendermint/light_client_module.go#L249
Expand Down Expand Up @@ -134,7 +143,7 @@ where
let data = self
.store
.get(Height::Pending, &Path::from(ProposalPath::sdk_path()))
.ok_or(AppError::Custom {
.ok_or_else(|| AppError::Custom {
reason: "Data not found".to_string(),
})?;

Expand Down
2 changes: 1 addition & 1 deletion basecoin/modules/src/gov/msg.rs
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ impl TryFrom<Any> for MsgSubmitProposal {

fn try_from(raw: Any) -> Result<Self, Self::Error> {
match raw.type_url.as_str() {
TYPE_URL => MsgSubmitProposal::decode_vec(&raw.value).map_err(|e| Error::Custom {
TYPE_URL => Self::decode_vec(&raw.value).map_err(|e| Error::Custom {
reason: e.to_string(),
}),
_ => Err(Error::Custom {
Expand Down
2 changes: 1 addition & 1 deletion basecoin/modules/src/gov/proposal.rs
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ impl TryFrom<RawProposal> for Proposal {
})
}
};
Ok(Proposal {
Ok(Self {
proposal_id: raw.proposal_id,
content: raw.content.unwrap(),
status,
Expand Down
Loading

0 comments on commit 81f852c

Please sign in to comment.