Skip to content

Commit

Permalink
imp: remove ibc from basecoin-store (#149)
Browse files Browse the repository at this point in the history
* imp: decouple basecoin-store from ibc

* nit

* fix: remove infallable path tests

* fix: remove redundant deps

* perform clippy suggestion

* impl Debug for NullCodec

* add minimal unit tests

---------

Co-authored-by: Ranadeep Biswas <mail@rnbguy.at>
  • Loading branch information
Farhad-Shabani and rnbguy committed Jan 22, 2024
1 parent 25d86e6 commit dc3b43a
Show file tree
Hide file tree
Showing 18 changed files with 83 additions and 351 deletions.
117 changes: 0 additions & 117 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 @@ -12,7 +12,7 @@ base64 = { version = "0.21", default-features = false, features = ["alloc"] }
displaydoc = { version = "0.2", default-features = false }
derive_more = { version = "0.99.17", default-features = false, features = ["from", "into", "display"] }
ed25519 = { version = "2.1.0", default-features = false }
ibc = { version = "0.49.1", default-features = false }
ibc = { version = "0.49.1", default-features = false, features = ["serde"] }
ibc-query = { version = "0.49.1", default-features = false }
ibc-proto = { version = "0.39.1", default-features = false }
ics23 = { version = "0.11", default-features = false }
Expand Down
2 changes: 1 addition & 1 deletion crates/app/src/abci/v0_37/impls.rs
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ pub fn query<S: Default + ProvableStore>(
) -> ResponseQuery {
debug!("Got query request: {:?}", request);

let path: Option<Path> = request.path.try_into().ok();
let path: Option<Path> = Some(request.path.into());
let modules = app.modules.read_access();
let height = Height::from(request.height as u64);
for IdentifiedModule { id, module } in modules.iter() {
Expand Down
2 changes: 1 addition & 1 deletion crates/app/src/modules/auth/account.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ use std::convert::{TryFrom, TryInto};
pub const RELAYER_ACCOUNT: &str = "cosmos12xpmzmfpf7tn57xg93rne2hc2q26lcfql5efws";
pub const ACCOUNT_PREFIX: &str = "cosmos";

#[derive(Clone)]
#[derive(Clone, derive_more::Display)]
pub struct AccountsPath(pub AccountId);

impl From<AccountsPath> for Path {
Expand Down
2 changes: 1 addition & 1 deletion crates/app/src/modules/bank/util.rs
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ impl From<&MsgCoin> for Coin {
#[serde(transparent)]
pub struct Balances(pub Vec<Coin>);

#[derive(Clone, Debug)]
#[derive(Clone, Debug, derive_more::Display)]
pub(super) struct BalancesPath(pub AccountId);

impl From<BalancesPath> for Path {
Expand Down
2 changes: 1 addition & 1 deletion crates/app/src/modules/gov/path.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,6 @@ impl ProposalPath {

impl From<ProposalPath> for Path {
fn from(value: ProposalPath) -> Self {
Self::try_from(value.to_string()).unwrap()
Self::from(value.to_string())
}
}
8 changes: 3 additions & 5 deletions crates/app/src/modules/ibc/client_contexts.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
use super::impls::{AnyConsensusState, IbcContext};

use basecoin_store::context::Store;
use basecoin_store::types::Height;

use ibc::clients::tendermint::client_state::ClientState as TmClientState;
use ibc::clients::tendermint::consensus_state::ConsensusState as TmConsensusState;
use ibc::clients::tendermint::context::{CommonContext, ValidationContext as TmValidationContext};
Expand Down Expand Up @@ -224,7 +222,7 @@ where

let keys = self.store.get_keys(&path);
let found_path = keys.into_iter().find_map(|path| {
if let Ok(Path::ClientConsensusState(path)) = Path::try_from(path) {
if let Ok(Path::ClientConsensusState(path)) = path.try_into() {
if height > &IbcHeight::new(path.revision_number, path.revision_height).unwrap() {
return Some(path);
}
Expand Down Expand Up @@ -258,7 +256,7 @@ where

let keys = self.store.get_keys(&path);
let pos = keys.iter().position(|path| {
if let Ok(Path::ClientConsensusState(path)) = Path::try_from(path.clone()) {
if let Ok(Path::ClientConsensusState(path)) = path.clone().try_into() {
height >= &IbcHeight::new(path.revision_number, path.revision_height).unwrap()
} else {
false
Expand All @@ -267,7 +265,7 @@ where

if let Some(pos) = pos {
if pos > 0 {
let prev_path = match Path::try_from(keys[pos - 1].clone()) {
let prev_path = match keys[pos - 1].clone().try_into() {
Ok(Path::ClientConsensusState(p)) => p,
_ => unreachable!(), // safety - path retrieved from store
};
Expand Down
30 changes: 6 additions & 24 deletions crates/app/src/modules/ibc/impls.rs
Original file line number Diff line number Diff line change
Expand Up @@ -229,12 +229,9 @@ where
.map_err(|_| AppError::Custom {
reason: "Invalid domain path".to_string(),
})?
.try_into()
.map_err(|_| AppError::Custom {
reason: "Invalid IBC path".to_string(),
})?;
.into();

let _ = IbcPath::try_from(path.clone()).map_err(|_| AppError::Custom {
let _: IbcPath = path.clone().try_into().map_err(|_| AppError::Custom {
reason: "Invalid IBC path".to_string(),
})?;

Expand Down Expand Up @@ -612,7 +609,7 @@ where
/// Returns the proof for the given [`IbcHeight`] and [`Path`]
fn get_proof(&self, height: IbcHeight, path: &IbcPath) -> Option<Vec<u8>> {
self.store
.get_proof(height.revision_height().into(), &path.clone().into())
.get_proof(height.revision_height().into(), &path.to_string().into())
.map(|p| p.encode_to_vec())
}
}
Expand All @@ -624,12 +621,7 @@ where
{
/// Returns the list of all client states.
fn client_states(&self) -> Result<Vec<(ClientId, Self::AnyClientState)>, ContextError> {
let path = "clients"
.to_owned()
.try_into()
.map_err(|_| ClientError::Other {
description: "Invalid client state path: clients".into(),
})?;
let path = "clients".to_owned().into();

self.client_state_store
.get_keys(&path)
Expand Down Expand Up @@ -725,12 +717,7 @@ where

/// Connections queries all the IBC connections of a chain.
fn connection_ends(&self) -> Result<Vec<IdentifiedConnectionEnd>, ContextError> {
let path = "connections"
.to_owned()
.try_into()
.map_err(|_| ConnectionError::Other {
description: "Invalid connection path: connections".into(),
})?;
let path = "connections".to_owned().into();

self.connection_end_store
.get_keys(&path)
Expand Down Expand Up @@ -772,12 +759,7 @@ where

/// Channels queries all the IBC channels of a chain.
fn channel_ends(&self) -> Result<Vec<IdentifiedChannelEnd>, ContextError> {
let path = "channelEnds"
.to_owned()
.try_into()
.map_err(|_| ChannelError::Other {
description: "Invalid channel path: channels".into(),
})?;
let path = "channelEnds".to_owned().into();

self.channel_end_store
.get_keys(&path)
Expand Down
2 changes: 1 addition & 1 deletion crates/app/src/modules/ibc/router.rs
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ where
.ok_or(RouterError::UnknownPort {
port_id: port_id.clone(),
})
.map(Clone::clone)
.cloned()
.ok()
}
}
5 changes: 1 addition & 4 deletions crates/app/src/modules/upgrade/impls.rs
Original file line number Diff line number Diff line change
Expand Up @@ -94,10 +94,7 @@ where
.map_err(|_| AppError::Custom {
reason: "Invalid path".to_string(),
})?
.try_into()
.map_err(|_| AppError::Custom {
reason: "Failed to parse path".to_string(),
})?;
.into();

debug!(
"Querying for path ({}) at height {:?}",
Expand Down
2 changes: 1 addition & 1 deletion crates/app/src/modules/upgrade/path.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,6 @@ impl UpgradePlanPath {

impl From<UpgradePlanPath> for Path {
fn from(value: UpgradePlanPath) -> Self {
Self::try_from(value.to_string()).unwrap()
Self::from(value.to_string())
}
}
Loading

0 comments on commit dc3b43a

Please sign in to comment.