Skip to content

Commit

Permalink
ibc: fix build
Browse files Browse the repository at this point in the history
  • Loading branch information
tzemanovic committed Jan 3, 2024
1 parent 80cf5ea commit 982ab0d
Show file tree
Hide file tree
Showing 15 changed files with 215 additions and 166 deletions.
18 changes: 17 additions & 1 deletion Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions core/src/types/address.rs
Original file line number Diff line number Diff line change
Expand Up @@ -33,10 +33,10 @@ pub const ADDRESS_LEN: usize =
string_encoding::hrp_len::<Address>() + 1 + HASH_HEX_LEN;

/// Length of a hash of an address as a hexadecimal string
pub(crate) const HASH_HEX_LEN: usize = 40;
pub const HASH_HEX_LEN: usize = 40;

/// Length of a trimmed hash of an address.
pub(crate) const HASH_LEN: usize = 20;
pub const HASH_LEN: usize = 20;

/// SHA-256 hash len
///
Expand Down
32 changes: 29 additions & 3 deletions ibc/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,8 +1,34 @@
[package]
name = "namada_ibc"
version = "0.1.0"
edition = "2021"
description = "Namada IBC"
resolver = "2"
authors.workspace = true
edition.workspace = true
documentation.workspace = true
homepage.workspace = true
keywords.workspace = true
license.workspace = true
readme.workspace = true
repository.workspace = true
version.workspace = true

# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
[features]
default = []
testing = ["namada_core/testing"]

[dependencies]
namada_core = { path = "../core", default-features = false }
namada_parameters = { path = "../parameters" }
namada_state = { path = "../state" }
namada_storage = { path = "../storage" }
namada_trans_token = { path = "../trans_token" }

borsh.workspace = true
ibc-derive.workspace = true
ibc.workspace = true
ics23.workspace = true
primitive-types.workspace = true
prost.workspace = true
sha2.workspace = true
thiserror.workspace = true
tracing.workspace = true
27 changes: 13 additions & 14 deletions ibc/src/context/client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,29 +7,28 @@ use ibc_testkit::testapp::ibc::clients::mock::client_state::MockClientContext;
use ibc_testkit::testapp::ibc::clients::mock::client_state::MockClientState;
#[cfg(feature = "testing")]
use ibc_testkit::testapp::ibc::clients::mock::consensus_state::MockConsensusState;
use prost::Message;

use crate::ibc::clients::tendermint::client_state::ClientState as TmClientState;
use crate::ibc::clients::tendermint::consensus_state::ConsensusState as TmConsensusState;
use crate::ibc::clients::tendermint::context::{
use namada_core::ibc::clients::tendermint::client_state::ClientState as TmClientState;
use namada_core::ibc::clients::tendermint::consensus_state::ConsensusState as TmConsensusState;
use namada_core::ibc::clients::tendermint::context::{
CommonContext, ExecutionContext as TmExecutionContext,
ValidationContext as TmValidationContext,
};
use crate::ibc::core::client::context::client_state::{
use namada_core::ibc::core::client::context::client_state::{
ClientStateCommon, ClientStateExecution, ClientStateValidation,
};
use crate::ibc::core::client::context::{
use namada_core::ibc::core::client::context::{
ClientExecutionContext, ClientValidationContext,
};
use crate::ibc::core::client::types::error::ClientError;
use crate::ibc::core::client::types::{Height, Status, UpdateKind};
use crate::ibc::core::commitment_types::commitment::{
use namada_core::ibc::core::client::types::error::ClientError;
use namada_core::ibc::core::client::types::{Height, Status, UpdateKind};
use namada_core::ibc::core::commitment_types::commitment::{
CommitmentPrefix, CommitmentProofBytes, CommitmentRoot,
};
use crate::ibc::core::host::types::identifiers::{ClientId, ClientType};
use crate::ibc::core::host::types::path::Path;
use crate::ibc::core::host::ExecutionContext;
use crate::ibc::primitives::proto::Any;
use namada_core::ibc::core::host::types::identifiers::{ClientId, ClientType};
use namada_core::ibc::core::host::types::path::Path;
use namada_core::ibc::core::host::ExecutionContext;
use namada_core::ibc::primitives::proto::Any;
use prost::Message;

// TODO: #[derive(ClientState)] doesn't support contexts with contexts generic
// for now
Expand Down
65 changes: 27 additions & 38 deletions ibc/src/context/common.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,37 +2,38 @@

use core::time::Duration;

use namada_core::ibc::clients::tendermint::consensus_state::ConsensusState as TmConsensusState;
use namada_core::ibc::clients::tendermint::types::ConsensusState as TmConsensusStateType;
use namada_core::ibc::core::channel::types::channel::ChannelEnd;
use namada_core::ibc::core::channel::types::commitment::{
AcknowledgementCommitment, PacketCommitment,
};
use namada_core::ibc::core::channel::types::error::{
ChannelError, PacketError,
};
use namada_core::ibc::core::channel::types::packet::Receipt;
use namada_core::ibc::core::channel::types::timeout::TimeoutHeight;
use namada_core::ibc::core::client::context::consensus_state::ConsensusState;
use namada_core::ibc::core::client::types::error::ClientError;
use namada_core::ibc::core::client::types::Height;
use namada_core::ibc::core::connection::types::error::ConnectionError;
use namada_core::ibc::core::connection::types::ConnectionEnd;
use namada_core::ibc::core::handler::types::error::ContextError;
use namada_core::ibc::core::host::types::identifiers::{
ChannelId, ClientId, ConnectionId, PortId, Sequence,
};
use namada_core::ibc::primitives::proto::{Any, Protobuf};
use namada_core::ibc::primitives::Timestamp;
use namada_core::tendermint::Time as TmTime;
use namada_core::types::storage::{BlockHeight, Key};
use namada_core::types::time::DurationSecs;
use namada_parameters::storage::get_max_expected_time_per_block_key;
use prost::Message;
use sha2::Digest;

use super::client::{AnyClientState, AnyConsensusState};
use super::storage::IbcStorageContext;
use crate::ibc::clients::tendermint::consensus_state::ConsensusState as TmConsensusState;
use crate::ibc::clients::tendermint::types::ConsensusState as TmConsensusStateType;
use crate::ibc::core::channel::types::channel::ChannelEnd;
use crate::ibc::core::channel::types::commitment::{
AcknowledgementCommitment, PacketCommitment,
};
use crate::ibc::core::channel::types::error::{ChannelError, PacketError};
use crate::ibc::core::channel::types::packet::Receipt;
use crate::ibc::core::channel::types::timeout::TimeoutHeight;
use crate::ibc::core::client::context::consensus_state::ConsensusState;
use crate::ibc::core::client::types::error::ClientError;
use crate::ibc::core::client::types::Height;
use crate::ibc::core::connection::types::error::ConnectionError;
use crate::ibc::core::connection::types::ConnectionEnd;
use crate::ibc::core::handler::types::error::ContextError;
use crate::ibc::core::host::types::identifiers::{
ChannelId, ClientId, ConnectionId, PortId, Sequence,
};
use crate::ibc::primitives::proto::{Any, Protobuf};
use crate::ibc::primitives::Timestamp;
use crate::ledger::ibc::storage;
use crate::ledger::parameters::storage::get_max_expected_time_per_block_key;
use crate::ledger::storage_api;
use crate::tendermint::Time as TmTime;
use crate::types::storage::{BlockHeight, Key};
use crate::types::time::DurationSecs;
use crate::storage;

/// Result of IBC common function call
pub type Result<T> = std::result::Result<T, ContextError>;
Expand Down Expand Up @@ -668,15 +669,3 @@ pub trait IbcCommonContext: IbcStorageContext {
Ok(())
}
}

/// Convert `storage_api::Error` into `ContextError`.
/// It always returns `ClientError::Other` though the storage error could happen
/// in any storage access.
impl From<storage_api::Error> for ContextError {
fn from(error: storage_api::Error) -> Self {
ClientError::Other {
description: format!("Storage error: {error}"),
}
.into()
}
}
33 changes: 17 additions & 16 deletions ibc/src/context/execution.rs
Original file line number Diff line number Diff line change
@@ -1,29 +1,30 @@
//! ExecutionContext implementation for IBC

use super::client::{AnyClientState, AnyConsensusState};
use super::common::IbcCommonContext;
use super::IbcContext;
use crate::ibc::core::channel::types::channel::ChannelEnd;
use crate::ibc::core::channel::types::commitment::{
use namada_core::ibc::core::channel::types::channel::ChannelEnd;
use namada_core::ibc::core::channel::types::commitment::{
AcknowledgementCommitment, PacketCommitment,
};
use crate::ibc::core::channel::types::packet::Receipt;
use crate::ibc::core::client::context::ClientExecutionContext;
use crate::ibc::core::client::types::Height;
use crate::ibc::core::connection::types::ConnectionEnd;
use crate::ibc::core::handler::types::error::ContextError;
use crate::ibc::core::handler::types::events::IbcEvent;
use crate::ibc::core::host::types::identifiers::{
use namada_core::ibc::core::channel::types::packet::Receipt;
use namada_core::ibc::core::client::context::ClientExecutionContext;
use namada_core::ibc::core::client::types::Height;
use namada_core::ibc::core::connection::types::ConnectionEnd;
use namada_core::ibc::core::handler::types::error::ContextError;
use namada_core::ibc::core::handler::types::events::IbcEvent;
use namada_core::ibc::core::host::types::identifiers::{
ClientId, ConnectionId, Sequence,
};
use crate::ibc::core::host::types::path::{
use namada_core::ibc::core::host::types::path::{
AckPath, ChannelEndPath, ClientConnectionPath, ClientConsensusStatePath,
ClientStatePath, CommitmentPath, ConnectionPath, ReceiptPath, SeqAckPath,
SeqRecvPath, SeqSendPath,
};
use crate::ibc::core::host::ExecutionContext;
use crate::ibc::primitives::Timestamp;
use crate::ledger::ibc::storage;
use namada_core::ibc::core::host::ExecutionContext;
use namada_core::ibc::primitives::Timestamp;

use super::client::{AnyClientState, AnyConsensusState};
use super::common::IbcCommonContext;
use super::IbcContext;
use crate::storage;

impl<C> ClientExecutionContext for IbcContext<C>
where
Expand Down
4 changes: 2 additions & 2 deletions ibc/src/context/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@ use std::fmt::Debug;
use std::rc::Rc;
use std::time::Duration;

use crate::ibc::core::commitment_types::specs::ProofSpecs;
use crate::ibc::core::host::types::identifiers::ChainId as IbcChainId;
use namada_core::ibc::core::commitment_types::specs::ProofSpecs;
use namada_core::ibc::core::host::types::identifiers::ChainId as IbcChainId;

/// IBC context to handle IBC-related data
#[derive(Debug)]
Expand Down
9 changes: 5 additions & 4 deletions ibc/src/context/router.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,12 @@
use std::collections::HashMap;
use std::rc::Rc;

use namada_core::ibc::core::host::types::identifiers::PortId;
use namada_core::ibc::core::router::module::Module;
use namada_core::ibc::core::router::router::Router;
use namada_core::ibc::core::router::types::module::ModuleId;

use super::super::ModuleWrapper;
use crate::ibc::core::host::types::identifiers::PortId;
use crate::ibc::core::router::module::Module;
use crate::ibc::core::router::router::Router;
use crate::ibc::core::router::types::module::ModuleId;

/// IBC router
#[derive(Debug, Default)]
Expand Down
9 changes: 4 additions & 5 deletions ibc/src/context/storage.rs
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
//! IBC storage context

pub use ics23::ProofSpec;

use crate::ledger::storage_api::{Error, StorageRead, StorageWrite};
use crate::types::address::Address;
use crate::types::ibc::{IbcEvent, IbcShieldedTransfer};
use crate::types::token::DenominatedAmount;
use namada_core::types::address::Address;
use namada_core::types::ibc::{IbcEvent, IbcShieldedTransfer};
use namada_core::types::token::DenominatedAmount;
use namada_storage::{Error, StorageRead, StorageWrite};

/// IBC context trait to be implemented in integration that can read and write
pub trait IbcStorageContext: StorageRead + StorageWrite {
Expand Down
25 changes: 13 additions & 12 deletions ibc/src/context/token_transfer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,20 +3,21 @@
use std::cell::RefCell;
use std::rc::Rc;

use super::common::IbcCommonContext;
use crate::ibc::apps::transfer::context::{
use namada_core::ibc::apps::transfer::context::{
TokenTransferExecutionContext, TokenTransferValidationContext,
};
use crate::ibc::apps::transfer::types::error::TokenTransferError;
use crate::ibc::apps::transfer::types::{PrefixedCoin, PrefixedDenom};
use crate::ibc::core::channel::types::error::ChannelError;
use crate::ibc::core::handler::types::error::ContextError;
use crate::ibc::core::host::types::identifiers::{ChannelId, PortId};
use crate::ledger::ibc::storage;
use crate::ledger::storage_api::token::read_denom;
use crate::types::address::{Address, InternalAddress};
use crate::types::token;
use crate::types::uint::Uint;
use namada_core::ibc::apps::transfer::types::error::TokenTransferError;
use namada_core::ibc::apps::transfer::types::{PrefixedCoin, PrefixedDenom};
use namada_core::ibc::core::channel::types::error::ChannelError;
use namada_core::ibc::core::handler::types::error::ContextError;
use namada_core::ibc::core::host::types::identifiers::{ChannelId, PortId};
use namada_core::types::address::{Address, InternalAddress};
use namada_core::types::token;
use namada_core::types::uint::Uint;
use namada_trans_token::read_denom;

use super::common::IbcCommonContext;
use crate::storage;

/// Token transfer context to handle tokens
#[derive(Debug)]
Expand Down
36 changes: 20 additions & 16 deletions ibc/src/context/transfer_mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,7 @@ use std::cell::RefCell;
use std::fmt::Debug;
use std::rc::Rc;

use super::common::IbcCommonContext;
use super::token_transfer::TokenTransferContext;
use crate::ibc::apps::transfer::module::{
use namada_core::ibc::apps::transfer::module::{
on_acknowledgement_packet_execute, on_acknowledgement_packet_validate,
on_chan_close_confirm_execute, on_chan_close_confirm_validate,
on_chan_close_init_execute, on_chan_close_init_validate,
Expand All @@ -17,19 +15,24 @@ use crate::ibc::apps::transfer::module::{
on_recv_packet_execute, on_timeout_packet_execute,
on_timeout_packet_validate,
};
use crate::ibc::apps::transfer::types::error::TokenTransferError;
use crate::ibc::apps::transfer::types::MODULE_ID_STR;
use crate::ibc::core::channel::types::acknowledgement::Acknowledgement;
use crate::ibc::core::channel::types::channel::{Counterparty, Order};
use crate::ibc::core::channel::types::error::{ChannelError, PacketError};
use crate::ibc::core::channel::types::packet::Packet;
use crate::ibc::core::channel::types::Version;
use crate::ibc::core::host::types::identifiers::{
use namada_core::ibc::apps::transfer::types::error::TokenTransferError;
use namada_core::ibc::apps::transfer::types::MODULE_ID_STR;
use namada_core::ibc::core::channel::types::acknowledgement::Acknowledgement;
use namada_core::ibc::core::channel::types::channel::{Counterparty, Order};
use namada_core::ibc::core::channel::types::error::{
ChannelError, PacketError,
};
use namada_core::ibc::core::channel::types::packet::Packet;
use namada_core::ibc::core::channel::types::Version;
use namada_core::ibc::core::host::types::identifiers::{
ChannelId, ConnectionId, PortId,
};
use crate::ibc::core::router::module::Module;
use crate::ibc::core::router::types::module::{ModuleExtras, ModuleId};
use crate::ibc::primitives::Signer;
use namada_core::ibc::core::router::module::Module;
use namada_core::ibc::core::router::types::module::{ModuleExtras, ModuleId};
use namada_core::ibc::primitives::Signer;

use super::common::IbcCommonContext;
use super::token_transfer::TokenTransferContext;

/// IBC module wrapper for getting the reference of the module
pub trait ModuleWrapper: Module {
Expand Down Expand Up @@ -331,9 +334,10 @@ fn into_packet_error(error: TokenTransferError) -> PacketError {
/// Helpers for testing
#[cfg(any(test, feature = "testing"))]
pub mod testing {
use namada_core::ibc::apps::transfer::types::ack_success_b64;
use namada_core::ibc::core::channel::types::acknowledgement::AcknowledgementStatus;

use super::*;
use crate::ibc::apps::transfer::types::ack_success_b64;
use crate::ibc::core::channel::types::acknowledgement::AcknowledgementStatus;

/// Dummy IBC module for token transfer
#[derive(Debug)]
Expand Down
Loading

0 comments on commit 982ab0d

Please sign in to comment.