diff --git a/.changelog/v0.15.0/bug-fixes/ibc/2104-fix-commitment-computation.md b/.changelog/v0.15.0/bug-fixes/ibc/2104-fix-commitment-computation.md index 570c1b3338..da0b858a75 100644 --- a/.changelog/v0.15.0/bug-fixes/ibc/2104-fix-commitment-computation.md +++ b/.changelog/v0.15.0/bug-fixes/ibc/2104-fix-commitment-computation.md @@ -1,2 +1,2 @@ -- Fix packet commitment calculation to match IBC-Go - ([#2104](https://github.com/informalsystems/ibc-rs/issues/2104)) +- Fix packet commitment calculation to match ibc-go ([#2104](https://github.com/informalsystems/ibc- + rs/issues/2104)) diff --git a/.changelog/v0.15.0/bug-fixes/ibc/2114-fix-ack-verification.md b/.changelog/v0.15.0/bug-fixes/ibc/2114-fix-ack-verification.md index 0987d40b6f..cbe6399a16 100644 --- a/.changelog/v0.15.0/bug-fixes/ibc/2114-fix-ack-verification.md +++ b/.changelog/v0.15.0/bug-fixes/ibc/2114-fix-ack-verification.md @@ -1,2 +1,2 @@ -- Fix incorrect acknowledgement verification - ([#2114](https://github.com/informalsystems/ibc-rs/issues/2114)) +- Fix incorrect acknowledgement verification ([#2114](https://github.com/informalsystems/ibc- + rs/issues/2114)) diff --git a/.changelog/v0.15.0/bug-fixes/ibc/2178-conn-ack-bug-fix.md b/.changelog/v0.15.0/bug-fixes/ibc/2178-conn-ack-bug-fix.md index af72298e4b..054fb34968 100644 --- a/.changelog/v0.15.0/bug-fixes/ibc/2178-conn-ack-bug-fix.md +++ b/.changelog/v0.15.0/bug-fixes/ibc/2178-conn-ack-bug-fix.md @@ -1,2 +1,2 @@ -- Fix connection identifier mix-up in connection acknowledgement processing - ([#2178](https://github.com/informalsystems/ibc-rs/issues/2178)) +- fix connection id mix-up in connection acknowledgement processing + ([#2178](https://github.com/informalsystems/ibc-rs/issues/2178)) \ No newline at end of file diff --git a/modules/Cargo.toml b/modules/Cargo.toml index 024c306d94..ab11162874 100644 --- a/modules/Cargo.toml +++ b/modules/Cargo.toml @@ -21,6 +21,7 @@ std = [ "flex-error/std", "flex-error/eyre_tracer", "ibc-proto/std", + "ics23/std", "clock", "beefy-client/std", "sp-runtime/std", @@ -39,7 +40,7 @@ mocks = ["tendermint-testgen", "clock", "std", "sp-io", "sp-io/std"] [dependencies] # Proto definitions for all IBC-related interfaces, e.g., connections or channels. borsh = { version = "0.9.3", default-features = false } -ibc-proto = { version = "0.17.1", path = "../proto", default-features = false } +ibc-proto = { version = "0.18.0", path = "../proto", default-features = false } ics23 = { version = "=0.8.0-alpha", default-features = false } time = { version = "0.3", default-features = false } serde_derive = { version = "1.0.104", default-features = false } @@ -53,8 +54,8 @@ safe-regex = { version = "0.2.5", default-features = false } subtle-encoding = { version = "0.5", default-features = false } sha2 = { version = "0.10.2", default-features = false } flex-error = { version = "0.4.4", default-features = false } -num-traits = { version = "0.2.14", default-features = false } -derive_more = { version = "0.99.17", default-features = false, features = ["from", "display"] } +num-traits = { version = "0.2.15", default-features = false } +derive_more = { version = "0.99.17", default-features = false, features = ["from", "into", "display"] } uint = { version = "0.9", default-features = false } beefy-client = { package = "beefy-generic-client", git = "https://github.com/ComposableFi/beefy-client", branch = "master", default-features = false } sp-runtime = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.22", default-features = false } diff --git a/modules/src/applications/ics20_fungible_token_transfer/relay_application_logic/send_transfer.rs b/modules/src/applications/ics20_fungible_token_transfer/relay_application_logic/send_transfer.rs deleted file mode 100644 index aae23629a2..0000000000 --- a/modules/src/applications/ics20_fungible_token_transfer/relay_application_logic/send_transfer.rs +++ /dev/null @@ -1,52 +0,0 @@ -use crate::applications::ics20_fungible_token_transfer::error::Error; -use crate::applications::ics20_fungible_token_transfer::msgs::transfer::MsgTransfer; -use crate::clients::host_functions::HostFunctionsProvider; -use crate::core::ics04_channel::handler::send_packet::send_packet; -use crate::core::ics04_channel::packet::Packet; -use crate::core::ics04_channel::packet::PacketResult; -use crate::core::ics26_routing::context::LightClientContext; -use crate::handler::HandlerOutput; -use crate::prelude::*; - -pub(crate) fn send_transfer( - ctx: &Ctx, - msg: MsgTransfer, -) -> Result, Error> -where - Ctx: LightClientContext, -{ - let source_channel_end = ctx - .channel_end(&(msg.source_port.clone(), msg.source_channel)) - .map_err(Error::ics04_channel)?; - - let destination_port = source_channel_end.counterparty().port_id().clone(); - let destination_channel = source_channel_end - .counterparty() - .channel_id() - .ok_or_else(|| { - Error::destination_channel_not_found(msg.source_port.clone(), msg.source_channel) - })?; - - // get the next sequence - let sequence = ctx - .get_next_sequence_send(&(msg.source_port.clone(), msg.source_channel)) - .map_err(Error::ics04_channel)?; - - //TODO: Application LOGIC. - - let packet = Packet { - sequence, - source_port: msg.source_port, - source_channel: msg.source_channel, - destination_port, - destination_channel: *destination_channel, - data: vec![0], - timeout_height: msg.timeout_height, - timeout_timestamp: msg.timeout_timestamp, - }; - - let handler_output = send_packet(ctx, packet).map_err(Error::ics04_channel)?; - - //TODO: add event/atributes and writes to the store issued by the application logic for packet sending. - Ok(handler_output) -} diff --git a/modules/src/applications/transfer/context.rs b/modules/src/applications/transfer/context.rs index 13220ca87b..ab9c1afdb8 100644 --- a/modules/src/applications/transfer/context.rs +++ b/modules/src/applications/transfer/context.rs @@ -1,4 +1,3 @@ -use sha2::{Digest, Sha256}; use subtle_encoding::hex; use super::error::Error as Ics20Error; @@ -16,7 +15,7 @@ use crate::core::ics04_channel::packet::Packet; use crate::core::ics04_channel::Version; use crate::core::ics05_port::context::PortReader; use crate::core::ics24_host::identifier::{ChannelId, ConnectionId, PortId}; -use crate::core::ics26_routing::context::{ModuleOutputBuilder, OnRecvPacketAck}; +use crate::core::ics26_routing::context::{ModuleOutputBuilder, OnRecvPacketAck, ReaderContext}; use crate::prelude::*; use crate::signer::Signer; @@ -26,7 +25,10 @@ pub trait Ics20Keeper: type AccountId; } -pub trait Ics20Reader: ChannelReader + PortReader { +pub trait Ics20Reader: ChannelReader + PortReader +where + Self: Sized, +{ type AccountId: TryFrom; /// get_port returns the portID for the transfer module. @@ -38,7 +40,8 @@ pub trait Ics20Reader: ChannelReader + PortReader { port_id: &PortId, channel_id: ChannelId, ) -> Result<::AccountId, Ics20Error> { - let hash = cosmos_adr028_escrow_address(port_id, channel_id); + let hash = cosmos_adr028_escrow_address(self, port_id, channel_id); + String::from_utf8(hex::encode_upper(hash)) .expect("hex encoded bytes are not valid UTF8") .parse::() @@ -61,15 +64,17 @@ pub trait Ics20Reader: ChannelReader + PortReader { } // https://github.com/cosmos/cosmos-sdk/blob/master/docs/architecture/adr-028-public-key-addresses.md -fn cosmos_adr028_escrow_address(port_id: &PortId, channel_id: ChannelId) -> Vec { +fn cosmos_adr028_escrow_address( + ctx: &dyn ChannelReader, + port_id: &PortId, + channel_id: ChannelId, +) -> Vec { let contents = format!("{}/{}", port_id, channel_id); + let mut data = VERSION.as_bytes().to_vec(); + data.extend_from_slice(&[0]); + data.extend_from_slice(contents.as_bytes()); - let mut hasher = Sha256::new(); - hasher.update(VERSION.as_bytes()); - hasher.update([0]); - hasher.update(contents.as_bytes()); - - let mut hash = hasher.finalize().to_vec(); + let mut hash = ctx.hash(data); hash.truncate(20); hash } @@ -105,6 +110,7 @@ pub trait BankKeeper { pub trait Ics20Context: Ics20Keeper::AccountId> + Ics20Reader::AccountId> + + ReaderContext { type AccountId: TryFrom; } @@ -296,6 +302,9 @@ pub fn on_timeout_packet( #[cfg(test)] pub(crate) mod test { + use std::sync::Mutex; + + use std::sync::Arc; use subtle_encoding::bech32; use crate::applications::transfer::context::cosmos_adr028_escrow_address; @@ -305,6 +314,7 @@ pub(crate) mod test { use crate::applications::transfer::PrefixedCoin; use crate::core::ics04_channel::error::Error; use crate::handler::HandlerOutputBuilder; + use crate::mock::context::MockIbcStore; use crate::prelude::*; use crate::test_utils::DummyTransferModule; @@ -322,7 +332,9 @@ pub(crate) mod test { let port_id = port_id.parse().unwrap(); let channel_id = channel_id.parse().unwrap(); let gen_address = { - let addr = cosmos_adr028_escrow_address(&port_id, channel_id); + let ibc_store = MockIbcStore::default(); + let ctx = DummyTransferModule::new(Arc::new(Mutex::new(ibc_store))); + let addr = cosmos_adr028_escrow_address(&ctx, &port_id, channel_id); bech32::encode("cosmos", addr) }; assert_eq!(gen_address, address.to_owned()) diff --git a/modules/src/clients/ics07_tendermint/client_def.rs b/modules/src/clients/ics07_tendermint/client_def.rs index 8311d361af..8f3250d57f 100644 --- a/modules/src/clients/ics07_tendermint/client_def.rs +++ b/modules/src/clients/ics07_tendermint/client_def.rs @@ -31,7 +31,7 @@ use crate::core::ics24_host::path::{ ConnectionsPath, ReceiptsPath, SeqRecvsPath, }; use crate::core::ics24_host::Path; -use crate::core::ics26_routing::context::LightClientContext; +use crate::core::ics26_routing::context::ReaderContext; use crate::downcast; use crate::prelude::*; use crate::Height; @@ -48,7 +48,7 @@ impl ClientDef for TendermintClient { fn verify_header( &self, - ctx: &dyn LightClientContext, + ctx: &dyn ReaderContext, client_id: ClientId, client_state: Self::ClientState, header: Self::Header, @@ -137,7 +137,7 @@ impl ClientDef for TendermintClient { fn update_state( &self, - _ctx: &dyn LightClientContext, + _ctx: &dyn ReaderContext, _client_id: ClientId, client_state: Self::ClientState, header: Self::Header, @@ -161,7 +161,7 @@ impl ClientDef for TendermintClient { fn check_for_misbehaviour( &self, - ctx: &dyn LightClientContext, + ctx: &dyn ReaderContext, client_id: ClientId, client_state: Self::ClientState, header: Self::Header, @@ -242,7 +242,7 @@ impl ClientDef for TendermintClient { fn verify_client_consensus_state( &self, - _ctx: &dyn LightClientContext, + _ctx: &dyn ReaderContext, client_state: &Self::ClientState, height: Height, prefix: &CommitmentPrefix, @@ -267,7 +267,7 @@ impl ClientDef for TendermintClient { fn verify_connection_state( &self, - _ctx: &dyn LightClientContext, + _ctx: &dyn ReaderContext, _client_id: &ClientId, client_state: &Self::ClientState, height: Height, @@ -288,7 +288,7 @@ impl ClientDef for TendermintClient { fn verify_channel_state( &self, - _ctx: &dyn LightClientContext, + _ctx: &dyn ReaderContext, _client_id: &ClientId, client_state: &Self::ClientState, height: Height, @@ -310,7 +310,7 @@ impl ClientDef for TendermintClient { fn verify_client_full_state( &self, - _ctx: &dyn LightClientContext, + _ctx: &dyn ReaderContext, client_state: &Self::ClientState, height: Height, prefix: &CommitmentPrefix, @@ -330,7 +330,7 @@ impl ClientDef for TendermintClient { fn verify_packet_data( &self, - ctx: &dyn LightClientContext, + ctx: &dyn ReaderContext, _client_id: &ClientId, client_state: &Self::ClientState, height: Height, @@ -363,7 +363,7 @@ impl ClientDef for TendermintClient { fn verify_packet_acknowledgement( &self, - ctx: &dyn LightClientContext, + ctx: &dyn ReaderContext, _client_id: &ClientId, client_state: &Self::ClientState, height: Height, @@ -396,7 +396,7 @@ impl ClientDef for TendermintClient { fn verify_next_sequence_recv( &self, - ctx: &dyn LightClientContext, + ctx: &dyn ReaderContext, _client_id: &ClientId, client_state: &Self::ClientState, height: Height, @@ -428,7 +428,7 @@ impl ClientDef for TendermintClient { fn verify_packet_receipt_absence( &self, - ctx: &dyn LightClientContext, + ctx: &dyn ReaderContext, _client_id: &ClientId, client_state: &Self::ClientState, height: Height, @@ -512,7 +512,7 @@ fn verify_non_membership( } fn verify_delay_passed( - ctx: &dyn LightClientContext, + ctx: &dyn ReaderContext, height: Height, connection_end: &ConnectionEnd, ) -> Result<(), Ics02Error> { diff --git a/modules/src/clients/ics11_beefy/client_def.rs b/modules/src/clients/ics11_beefy/client_def.rs index 8f1d948a1e..d734b1cf3b 100644 --- a/modules/src/clients/ics11_beefy/client_def.rs +++ b/modules/src/clients/ics11_beefy/client_def.rs @@ -29,7 +29,7 @@ use crate::core::ics23_commitment::commitment::{ use crate::core::ics24_host::identifier::ConnectionId; use crate::core::ics24_host::identifier::{ChannelId, ClientId, PortId}; use crate::core::ics24_host::Path; -use crate::core::ics26_routing::context::LightClientContext; +use crate::core::ics26_routing::context::ReaderContext; use crate::prelude::*; use crate::Height; use core::marker::PhantomData; @@ -56,7 +56,7 @@ impl ClientDef for BeefyClient ClientDef for BeefyClient ClientDef for BeefyClient ClientDef for BeefyClient ClientDef for BeefyClient ClientDef for BeefyClient ClientDef for BeefyClient ClientDef for BeefyClient ClientDef for BeefyClient ClientDef for BeefyClient ClientDef for BeefyClient>( } fn verify_delay_passed( - ctx: &dyn LightClientContext, + ctx: &dyn ReaderContext, height: Height, connection_end: &ConnectionEnd, ) -> Result<(), Error> { diff --git a/modules/src/clients/ics13_near/client_def.rs b/modules/src/clients/ics13_near/client_def.rs index b8523d6450..a59f8e93bf 100644 --- a/modules/src/clients/ics13_near/client_def.rs +++ b/modules/src/clients/ics13_near/client_def.rs @@ -10,7 +10,7 @@ use crate::core::ics23_commitment::commitment::{ CommitmentPrefix, CommitmentProofBytes, CommitmentRoot, }; use crate::core::ics24_host::identifier::{ChannelId, ClientId, ConnectionId, PortId}; -use crate::core::ics26_routing::context::LightClientContext; +use crate::core::ics26_routing::context::ReaderContext; use crate::Height; use core::marker::PhantomData; @@ -54,7 +54,7 @@ impl ClientDef for NearClient { // rehydrate client from its own storage, then call this function fn verify_header( &self, - _ctx: &dyn LightClientContext, + _ctx: &dyn ReaderContext, _client_id: ClientId, client_state: Self::ClientState, header: Self::Header, @@ -65,7 +65,7 @@ impl ClientDef for NearClient { fn update_state( &self, - _ctx: &dyn LightClientContext, + _ctx: &dyn ReaderContext, _client_id: ClientId, _client_state: Self::ClientState, _header: Self::Header, @@ -93,7 +93,7 @@ impl ClientDef for NearClient { fn check_for_misbehaviour( &self, - _ctx: &dyn LightClientContext, + _ctx: &dyn ReaderContext, _client_id: ClientId, _client_state: Self::ClientState, _header: Self::Header, @@ -113,7 +113,7 @@ impl ClientDef for NearClient { fn verify_client_consensus_state( &self, - _ctx: &dyn LightClientContext, + _ctx: &dyn ReaderContext, _client_state: &Self::ClientState, _height: Height, _prefix: &CommitmentPrefix, @@ -129,7 +129,7 @@ impl ClientDef for NearClient { // Consensus state will be verified in the verification functions before these are called fn verify_connection_state( &self, - _ctx: &dyn LightClientContext, + _ctx: &dyn ReaderContext, _client_id: &ClientId, _client_state: &Self::ClientState, _height: Height, @@ -144,7 +144,7 @@ impl ClientDef for NearClient { fn verify_channel_state( &self, - _ctx: &dyn LightClientContext, + _ctx: &dyn ReaderContext, _client_id: &ClientId, _client_state: &Self::ClientState, _height: Height, @@ -160,7 +160,7 @@ impl ClientDef for NearClient { fn verify_client_full_state( &self, - _ctx: &dyn LightClientContext, + _ctx: &dyn ReaderContext, _client_state: &Self::ClientState, _height: Height, _prefix: &CommitmentPrefix, @@ -174,7 +174,7 @@ impl ClientDef for NearClient { fn verify_packet_data( &self, - _ctx: &dyn LightClientContext, + _ctx: &dyn ReaderContext, _client_id: &ClientId, _client_state: &Self::ClientState, _height: Height, @@ -191,7 +191,7 @@ impl ClientDef for NearClient { fn verify_packet_acknowledgement( &self, - _ctx: &dyn LightClientContext, + _ctx: &dyn ReaderContext, _client_id: &ClientId, _client_state: &Self::ClientState, _height: Height, @@ -208,7 +208,7 @@ impl ClientDef for NearClient { fn verify_next_sequence_recv( &self, - _ctx: &dyn LightClientContext, + _ctx: &dyn ReaderContext, _client_id: &ClientId, _client_state: &Self::ClientState, _height: Height, @@ -224,7 +224,7 @@ impl ClientDef for NearClient { fn verify_packet_receipt_absence( &self, - _ctx: &dyn LightClientContext, + _ctx: &dyn ReaderContext, _client_id: &ClientId, _client_state: &Self::ClientState, _height: Height, diff --git a/modules/src/core/ics02_client/client_def.rs b/modules/src/core/ics02_client/client_def.rs index ffe6c067ec..08470e7a29 100644 --- a/modules/src/core/ics02_client/client_def.rs +++ b/modules/src/core/ics02_client/client_def.rs @@ -14,7 +14,7 @@ use crate::core::ics23_commitment::commitment::{ CommitmentPrefix, CommitmentProofBytes, CommitmentRoot, }; use crate::core::ics24_host::identifier::{ChannelId, ClientId, ConnectionId, PortId}; -use crate::core::ics26_routing::context::LightClientContext; +use crate::core::ics26_routing::context::ReaderContext; use crate::downcast; use crate::prelude::*; use crate::Height; @@ -36,7 +36,7 @@ pub trait ClientDef: Clone { fn verify_header( &self, - ctx: &dyn LightClientContext, + ctx: &dyn ReaderContext, client_id: ClientId, client_state: Self::ClientState, header: Self::Header, @@ -44,7 +44,7 @@ pub trait ClientDef: Clone { fn update_state( &self, - ctx: &dyn LightClientContext, + ctx: &dyn ReaderContext, client_id: ClientId, client_state: Self::ClientState, header: Self::Header, @@ -58,7 +58,7 @@ pub trait ClientDef: Clone { fn check_for_misbehaviour( &self, - ctx: &dyn LightClientContext, + ctx: &dyn ReaderContext, client_id: ClientId, client_state: Self::ClientState, header: Self::Header, @@ -83,7 +83,7 @@ pub trait ClientDef: Clone { #[allow(clippy::too_many_arguments)] fn verify_client_consensus_state( &self, - ctx: &dyn LightClientContext, + ctx: &dyn ReaderContext, client_state: &Self::ClientState, height: Height, prefix: &CommitmentPrefix, @@ -98,7 +98,7 @@ pub trait ClientDef: Clone { #[allow(clippy::too_many_arguments)] fn verify_connection_state( &self, - ctx: &dyn LightClientContext, + ctx: &dyn ReaderContext, client_id: &ClientId, client_state: &Self::ClientState, height: Height, @@ -113,7 +113,7 @@ pub trait ClientDef: Clone { #[allow(clippy::too_many_arguments)] fn verify_channel_state( &self, - ctx: &dyn LightClientContext, + ctx: &dyn ReaderContext, client_id: &ClientId, client_state: &Self::ClientState, height: Height, @@ -129,7 +129,7 @@ pub trait ClientDef: Clone { #[allow(clippy::too_many_arguments)] fn verify_client_full_state( &self, - ctx: &dyn LightClientContext, + ctx: &dyn ReaderContext, client_state: &Self::ClientState, height: Height, prefix: &CommitmentPrefix, @@ -143,7 +143,7 @@ pub trait ClientDef: Clone { #[allow(clippy::too_many_arguments)] fn verify_packet_data( &self, - ctx: &dyn LightClientContext, + ctx: &dyn ReaderContext, client_id: &ClientId, client_state: &Self::ClientState, height: Height, @@ -160,7 +160,7 @@ pub trait ClientDef: Clone { #[allow(clippy::too_many_arguments)] fn verify_packet_acknowledgement( &self, - ctx: &dyn LightClientContext, + ctx: &dyn ReaderContext, client_id: &ClientId, client_state: &Self::ClientState, height: Height, @@ -177,7 +177,7 @@ pub trait ClientDef: Clone { #[allow(clippy::too_many_arguments)] fn verify_next_sequence_recv( &self, - ctx: &dyn LightClientContext, + ctx: &dyn ReaderContext, client_id: &ClientId, client_state: &Self::ClientState, height: Height, @@ -193,7 +193,7 @@ pub trait ClientDef: Clone { #[allow(clippy::too_many_arguments)] fn verify_packet_receipt_absence( &self, - ctx: &dyn LightClientContext, + ctx: &dyn ReaderContext, client_id: &ClientId, client_state: &Self::ClientState, height: Height, @@ -236,7 +236,7 @@ impl ClientDef for AnyClient ClientDef for AnyClient ClientDef for AnyClient ClientDef for AnyClient ClientDef for AnyClient ClientDef for AnyClient ClientDef for AnyClient ClientDef for AnyClient ClientDef for AnyClient ClientDef for AnyClient ClientDef for AnyClient( msg: ClientMsg, ) -> Result, Error> where - Ctx: LightClientContext, + Ctx: ReaderContext, HostFunctions: HostFunctionsProvider, { match msg { diff --git a/modules/src/core/ics02_client/handler/create_client.rs b/modules/src/core/ics02_client/handler/create_client.rs index 169864be05..41cb2bf136 100644 --- a/modules/src/core/ics02_client/handler/create_client.rs +++ b/modules/src/core/ics02_client/handler/create_client.rs @@ -1,6 +1,6 @@ //! Protocol logic specific to processing ICS2 messages of type `MsgCreateAnyClient`. -use crate::core::ics26_routing::context::LightClientContext; +use crate::core::ics26_routing::context::ReaderContext; use crate::prelude::*; use core::fmt::Debug; @@ -30,7 +30,7 @@ pub struct Result { } pub fn process( - ctx: &dyn LightClientContext, + ctx: &dyn ReaderContext, msg: MsgCreateAnyClient, ) -> HandlerResult { let mut output = HandlerOutput::builder(); diff --git a/modules/src/core/ics02_client/handler/update_client.rs b/modules/src/core/ics02_client/handler/update_client.rs index b3f3a57c48..472ebc9054 100644 --- a/modules/src/core/ics02_client/handler/update_client.rs +++ b/modules/src/core/ics02_client/handler/update_client.rs @@ -12,7 +12,7 @@ use crate::core::ics02_client::handler::ClientResult; use crate::core::ics02_client::height::Height; use crate::core::ics02_client::msgs::update_client::MsgUpdateAnyClient; use crate::core::ics24_host::identifier::ClientId; -use crate::core::ics26_routing::context::LightClientContext; +use crate::core::ics26_routing::context::ReaderContext; use crate::events::IbcEvent; use crate::handler::{HandlerOutput, HandlerResult}; use crate::prelude::*; @@ -30,7 +30,7 @@ pub struct Result { } pub fn process( - ctx: &dyn LightClientContext, + ctx: &dyn ReaderContext, msg: MsgUpdateAnyClient, ) -> HandlerResult { let mut output = HandlerOutput::builder(); diff --git a/modules/src/core/ics02_client/handler/upgrade_client.rs b/modules/src/core/ics02_client/handler/upgrade_client.rs index 3cc7722c43..0ef3738593 100644 --- a/modules/src/core/ics02_client/handler/upgrade_client.rs +++ b/modules/src/core/ics02_client/handler/upgrade_client.rs @@ -8,7 +8,7 @@ use crate::core::ics02_client::events::Attributes; use crate::core::ics02_client::handler::ClientResult; use crate::core::ics02_client::msgs::upgrade_client::MsgUpgradeAnyClient; use crate::core::ics24_host::identifier::ClientId; -use crate::core::ics26_routing::context::LightClientContext; +use crate::core::ics26_routing::context::ReaderContext; use crate::events::IbcEvent; use crate::handler::{HandlerOutput, HandlerResult}; use crate::prelude::*; @@ -24,7 +24,7 @@ pub struct Result { } pub fn process( - ctx: &dyn LightClientContext, + ctx: &dyn ReaderContext, msg: MsgUpgradeAnyClient, ) -> HandlerResult { let mut output = HandlerOutput::builder(); diff --git a/modules/src/core/ics02_client/msgs/create_client.rs b/modules/src/core/ics02_client/msgs/create_client.rs index effd6bec72..c3018f4e47 100644 --- a/modules/src/core/ics02_client/msgs/create_client.rs +++ b/modules/src/core/ics02_client/msgs/create_client.rs @@ -78,7 +78,7 @@ impl TryFrom for MsgCreateAnyClient { MsgCreateAnyClient::new( AnyClientState::try_from(raw_client_state)?, consensus_state, - raw.signer.into(), + raw.signer.parse().map_err(Error::signer)?, ) } } diff --git a/modules/src/core/ics02_client/msgs/upgrade_client.rs b/modules/src/core/ics02_client/msgs/upgrade_client.rs index db7907dfed..fe5b94347c 100644 --- a/modules/src/core/ics02_client/msgs/upgrade_client.rs +++ b/modules/src/core/ics02_client/msgs/upgrade_client.rs @@ -93,7 +93,7 @@ impl TryFrom for MsgUpgradeAnyClient { consensus_state: AnyConsensusState::try_from(raw_consensus_state)?, proof_upgrade_client: proto_msg.proof_upgrade_client, proof_upgrade_consensus_state: proto_msg.proof_upgrade_consensus_state, - signer: proto_msg.signer.into(), + signer: Signer::from_str(proto_msg.signer.as_str()).map_err(Error::signer)?, }) } } diff --git a/modules/src/core/ics03_connection/handler.rs b/modules/src/core/ics03_connection/handler.rs index e3d596b3c7..154c1a3e6f 100644 --- a/modules/src/core/ics03_connection/handler.rs +++ b/modules/src/core/ics03_connection/handler.rs @@ -4,7 +4,7 @@ use crate::core::ics03_connection::connection::ConnectionEnd; use crate::core::ics03_connection::error::Error; use crate::core::ics03_connection::msgs::ConnectionMsg; use crate::core::ics24_host::identifier::ConnectionId; -use crate::core::ics26_routing::context::LightClientContext; +use crate::core::ics26_routing::context::ReaderContext; use crate::handler::HandlerOutput; use core::fmt::Debug; @@ -47,7 +47,7 @@ pub fn dispatch( msg: ConnectionMsg, ) -> Result, Error> where - Ctx: LightClientContext, + Ctx: ReaderContext, HostFunctions: HostFunctionsProvider, { match msg { diff --git a/modules/src/core/ics03_connection/handler/conn_open_ack.rs b/modules/src/core/ics03_connection/handler/conn_open_ack.rs index 1fd4fca6bd..7f1dd4a9da 100644 --- a/modules/src/core/ics03_connection/handler/conn_open_ack.rs +++ b/modules/src/core/ics03_connection/handler/conn_open_ack.rs @@ -9,13 +9,13 @@ use crate::core::ics03_connection::handler::verify::{ }; use crate::core::ics03_connection::handler::{ConnectionIdState, ConnectionResult}; use crate::core::ics03_connection::msgs::conn_open_ack::MsgConnectionOpenAck; -use crate::core::ics26_routing::context::LightClientContext; +use crate::core::ics26_routing::context::ReaderContext; use crate::events::IbcEvent; use crate::handler::{HandlerOutput, HandlerResult}; use crate::prelude::*; pub(crate) fn process( - ctx: &dyn LightClientContext, + ctx: &dyn ReaderContext, msg: MsgConnectionOpenAck, ) -> HandlerResult { let mut output = HandlerOutput::builder(); diff --git a/modules/src/core/ics03_connection/handler/conn_open_confirm.rs b/modules/src/core/ics03_connection/handler/conn_open_confirm.rs index aa196d60a5..d331820a37 100644 --- a/modules/src/core/ics03_connection/handler/conn_open_confirm.rs +++ b/modules/src/core/ics03_connection/handler/conn_open_confirm.rs @@ -7,13 +7,13 @@ use crate::core::ics03_connection::events::Attributes; use crate::core::ics03_connection::handler::verify::verify_proofs; use crate::core::ics03_connection::handler::{ConnectionIdState, ConnectionResult}; use crate::core::ics03_connection::msgs::conn_open_confirm::MsgConnectionOpenConfirm; -use crate::core::ics26_routing::context::LightClientContext; +use crate::core::ics26_routing::context::ReaderContext; use crate::events::IbcEvent; use crate::handler::{HandlerOutput, HandlerResult}; use crate::prelude::*; pub(crate) fn process( - ctx: &dyn LightClientContext, + ctx: &dyn ReaderContext, msg: MsgConnectionOpenConfirm, ) -> HandlerResult { let mut output = HandlerOutput::builder(); diff --git a/modules/src/core/ics03_connection/handler/conn_open_init.rs b/modules/src/core/ics03_connection/handler/conn_open_init.rs index 89b8efbb68..f2c2f386d7 100644 --- a/modules/src/core/ics03_connection/handler/conn_open_init.rs +++ b/modules/src/core/ics03_connection/handler/conn_open_init.rs @@ -6,13 +6,13 @@ use crate::core::ics03_connection::events::Attributes; use crate::core::ics03_connection::handler::{ConnectionIdState, ConnectionResult}; use crate::core::ics03_connection::msgs::conn_open_init::MsgConnectionOpenInit; use crate::core::ics24_host::identifier::ConnectionId; -use crate::core::ics26_routing::context::LightClientContext; +use crate::core::ics26_routing::context::ReaderContext; use crate::events::IbcEvent; use crate::handler::{HandlerOutput, HandlerResult}; use crate::prelude::*; pub(crate) fn process( - ctx: &dyn LightClientContext, + ctx: &dyn ReaderContext, msg: MsgConnectionOpenInit, ) -> HandlerResult { let mut output = HandlerOutput::builder(); diff --git a/modules/src/core/ics03_connection/handler/conn_open_try.rs b/modules/src/core/ics03_connection/handler/conn_open_try.rs index dfc0c9301a..e5f556c780 100644 --- a/modules/src/core/ics03_connection/handler/conn_open_try.rs +++ b/modules/src/core/ics03_connection/handler/conn_open_try.rs @@ -10,13 +10,13 @@ use crate::core::ics03_connection::handler::verify::{ use crate::core::ics03_connection::handler::{ConnectionIdState, ConnectionResult}; use crate::core::ics03_connection::msgs::conn_open_try::MsgConnectionOpenTry; use crate::core::ics24_host::identifier::ConnectionId; -use crate::core::ics26_routing::context::LightClientContext; +use crate::core::ics26_routing::context::ReaderContext; use crate::events::IbcEvent; use crate::handler::{HandlerOutput, HandlerResult}; use crate::prelude::*; pub(crate) fn process( - ctx: &dyn LightClientContext, + ctx: &dyn ReaderContext, msg: MsgConnectionOpenTry, ) -> HandlerResult { let mut output = HandlerOutput::builder(); diff --git a/modules/src/core/ics03_connection/handler/verify.rs b/modules/src/core/ics03_connection/handler/verify.rs index 2acc9544e3..66f9404f70 100644 --- a/modules/src/core/ics03_connection/handler/verify.rs +++ b/modules/src/core/ics03_connection/handler/verify.rs @@ -6,13 +6,13 @@ use crate::core::ics02_client::{client_def::AnyClient, client_def::ClientDef}; use crate::core::ics03_connection::connection::ConnectionEnd; use crate::core::ics03_connection::error::Error; use crate::core::ics23_commitment::commitment::CommitmentProofBytes; -use crate::core::ics26_routing::context::LightClientContext; +use crate::core::ics26_routing::context::ReaderContext; use crate::proofs::{ConsensusProof, Proofs}; use crate::Height; /// Entry point for verifying all proofs bundled in any ICS3 message. pub fn verify_proofs( - ctx: &dyn LightClientContext, + ctx: &dyn ReaderContext, client_state: Option, height: Height, connection_end: &ConnectionEnd, @@ -60,7 +60,7 @@ pub fn verify_proofs( /// claims to prove that an object of type connection exists on the source chain (i.e., the chain /// which created this proof). This object must match the state of `expected_conn`. pub fn verify_connection_proof( - ctx: &dyn LightClientContext, + ctx: &dyn ReaderContext, height: Height, connection_end: &ConnectionEnd, expected_conn: &ConnectionEnd, @@ -115,7 +115,7 @@ pub fn verify_connection_proof( /// at the same revision as the current chain, with matching chain identifiers, etc) and that the /// `proof` is correct. pub fn verify_client_proof( - ctx: &dyn LightClientContext, + ctx: &dyn ReaderContext, height: Height, connection_end: &ConnectionEnd, expected_client_state: AnyClientState, @@ -154,7 +154,7 @@ pub fn verify_client_proof( } pub fn verify_consensus_proof( - ctx: &dyn LightClientContext, + ctx: &dyn ReaderContext, height: Height, connection_end: &ConnectionEnd, proof: &ConsensusProof, @@ -197,7 +197,7 @@ pub fn verify_consensus_proof( /// Checks that `claimed_height` is within normal bounds, i.e., fresh enough so that the chain has /// not pruned it yet, but not newer than the current (actual) height of the local chain. pub fn check_client_consensus_height( - ctx: &dyn LightClientContext, + ctx: &dyn ReaderContext, claimed_height: Height, ) -> Result<(), Error> { if claimed_height > ctx.host_height() { diff --git a/modules/src/core/ics04_channel/context.rs b/modules/src/core/ics04_channel/context.rs index 13f2df1ffc..0cd1aff12f 100644 --- a/modules/src/core/ics04_channel/context.rs +++ b/modules/src/core/ics04_channel/context.rs @@ -15,7 +15,7 @@ use crate::prelude::*; use crate::timestamp::Timestamp; use crate::Height; -use super::packet::{PacketResult, Sequence}; +use super::packet::{Packet, PacketResult, Sequence}; /// A context supplying all the necessary read-only dependencies for processing any `ChannelMsg`. pub trait ChannelReader { @@ -71,7 +71,7 @@ pub trait ChannelReader { self.hash(ack.into_bytes()).into() } - /// A hashing function for packet commitments + /// A Sha2_256 hashing function fn hash(&self, value: Vec) -> Vec; /// Returns the time when the client state for the given [`ClientId`] was updated with a header for the given [`Height`] @@ -137,6 +137,8 @@ pub trait ChannelKeeper { (res.port_id.clone(), res.channel_id, res.seq), res.commitment, )?; + + self.store_packet((res.port_id.clone(), res.channel_id, res.seq), res.packet)?; } PacketResult::Recv(res) => { let res = match res { @@ -199,6 +201,13 @@ pub trait ChannelKeeper { commitment: PacketCommitment, ) -> Result<(), Error>; + /// Allow implementers to optionally store packet in storage + fn store_packet( + &mut self, + key: (PortId, ChannelId, Sequence), + packet: Packet, + ) -> Result<(), Error>; + fn delete_packet_commitment(&mut self, key: (PortId, ChannelId, Sequence)) -> Result<(), Error>; diff --git a/modules/src/core/ics04_channel/error.rs b/modules/src/core/ics04_channel/error.rs index 61f77a28e3..b4473966e3 100644 --- a/modules/src/core/ics04_channel/error.rs +++ b/modules/src/core/ics04_channel/error.rs @@ -344,6 +344,14 @@ define_error! { ImplementationSpecific { reason: String } | e | { format_args!("implementation specific error: {}", e.reason) }, + + AppModule + { description: String } + | e | { + format_args!( + "application module error: {0}", + e.description) + }, } } diff --git a/modules/src/core/ics04_channel/handler.rs b/modules/src/core/ics04_channel/handler.rs index cbdba24490..bb0a789a23 100644 --- a/modules/src/core/ics04_channel/handler.rs +++ b/modules/src/core/ics04_channel/handler.rs @@ -7,7 +7,7 @@ use crate::core::ics04_channel::msgs::ChannelMsg; use crate::core::ics04_channel::{msgs::PacketMsg, packet::PacketResult}; use crate::core::ics24_host::identifier::{ChannelId, PortId}; use crate::core::ics26_routing::context::{ - Ics26Context, LightClientContext, ModuleId, ModuleOutput, OnRecvPacketAck, Router, + Ics26Context, ModuleId, ModuleOutputBuilder, OnRecvPacketAck, ReaderContext, Router, }; use crate::handler::{HandlerOutput, HandlerOutputBuilder}; use core::fmt::Debug; @@ -64,7 +64,7 @@ pub fn channel_dispatch( msg: &ChannelMsg, ) -> Result<(HandlerOutputBuilder<()>, ChannelResult), Error> where - Ctx: LightClientContext, + Ctx: ReaderContext, HostFunctions: HostFunctionsProvider, { let output = match msg { @@ -177,7 +177,7 @@ pub fn packet_dispatch( msg: &PacketMsg, ) -> Result<(HandlerOutputBuilder<()>, PacketResult), Error> where - Ctx: LightClientContext, + Ctx: ReaderContext, HostFunctions: HostFunctionsProvider, { let output = match msg { diff --git a/modules/src/core/ics04_channel/handler/acknowledgement.rs b/modules/src/core/ics04_channel/handler/acknowledgement.rs index d316e2a703..ccdc305a55 100644 --- a/modules/src/core/ics04_channel/handler/acknowledgement.rs +++ b/modules/src/core/ics04_channel/handler/acknowledgement.rs @@ -8,7 +8,7 @@ use crate::core::ics04_channel::handler::verify::verify_packet_acknowledgement_p use crate::core::ics04_channel::msgs::acknowledgement::MsgAcknowledgement; use crate::core::ics04_channel::packet::{PacketResult, Sequence}; use crate::core::ics24_host::identifier::{ChannelId, PortId}; -use crate::core::ics26_routing::context::LightClientContext; +use crate::core::ics26_routing::context::ReaderContext; use crate::events::IbcEvent; use crate::handler::{HandlerOutput, HandlerResult}; use crate::prelude::*; @@ -23,7 +23,7 @@ pub struct AckPacketResult { } pub fn process( - ctx: &dyn LightClientContext, + ctx: &dyn ReaderContext, msg: &MsgAcknowledgement, ) -> HandlerResult { let mut output = HandlerOutput::builder(); diff --git a/modules/src/core/ics04_channel/handler/chan_close_confirm.rs b/modules/src/core/ics04_channel/handler/chan_close_confirm.rs index 308d1e90bb..54bdcbef43 100644 --- a/modules/src/core/ics04_channel/handler/chan_close_confirm.rs +++ b/modules/src/core/ics04_channel/handler/chan_close_confirm.rs @@ -8,13 +8,13 @@ use crate::core::ics04_channel::events::Attributes; use crate::core::ics04_channel::handler::verify::verify_channel_proofs; use crate::core::ics04_channel::handler::{ChannelIdState, ChannelResult}; use crate::core::ics04_channel::msgs::chan_close_confirm::MsgChannelCloseConfirm; -use crate::core::ics26_routing::context::LightClientContext; +use crate::core::ics26_routing::context::ReaderContext; use crate::events::IbcEvent; use crate::handler::{HandlerOutput, HandlerResult}; use crate::prelude::*; pub(crate) fn process( - ctx: &dyn LightClientContext, + ctx: &dyn ReaderContext, msg: &MsgChannelCloseConfirm, ) -> HandlerResult { let mut output = HandlerOutput::builder(); diff --git a/modules/src/core/ics04_channel/handler/chan_close_init.rs b/modules/src/core/ics04_channel/handler/chan_close_init.rs index 1cfd416536..8abfd0e339 100644 --- a/modules/src/core/ics04_channel/handler/chan_close_init.rs +++ b/modules/src/core/ics04_channel/handler/chan_close_init.rs @@ -6,12 +6,12 @@ use crate::core::ics04_channel::error::Error; use crate::core::ics04_channel::events::Attributes; use crate::core::ics04_channel::handler::{ChannelIdState, ChannelResult}; use crate::core::ics04_channel::msgs::chan_close_init::MsgChannelCloseInit; -use crate::core::ics26_routing::context::LightClientContext; +use crate::core::ics26_routing::context::ReaderContext; use crate::events::IbcEvent; use crate::handler::{HandlerOutput, HandlerResult}; pub(crate) fn process( - ctx: &dyn LightClientContext, + ctx: &dyn ReaderContext, msg: &MsgChannelCloseInit, ) -> HandlerResult { let mut output = HandlerOutput::builder(); diff --git a/modules/src/core/ics04_channel/handler/chan_open_ack.rs b/modules/src/core/ics04_channel/handler/chan_open_ack.rs index d98316303a..7138a55a66 100644 --- a/modules/src/core/ics04_channel/handler/chan_open_ack.rs +++ b/modules/src/core/ics04_channel/handler/chan_open_ack.rs @@ -7,13 +7,13 @@ use crate::core::ics04_channel::events::Attributes; use crate::core::ics04_channel::handler::verify::verify_channel_proofs; use crate::core::ics04_channel::handler::{ChannelIdState, ChannelResult}; use crate::core::ics04_channel::msgs::chan_open_ack::MsgChannelOpenAck; -use crate::core::ics26_routing::context::LightClientContext; +use crate::core::ics26_routing::context::ReaderContext; use crate::events::IbcEvent; use crate::handler::{HandlerOutput, HandlerResult}; use crate::prelude::*; pub(crate) fn process( - ctx: &dyn LightClientContext, + ctx: &dyn ReaderContext, msg: &MsgChannelOpenAck, ) -> HandlerResult { let mut output = HandlerOutput::builder(); diff --git a/modules/src/core/ics04_channel/handler/chan_open_confirm.rs b/modules/src/core/ics04_channel/handler/chan_open_confirm.rs index 7704959d67..f605500d50 100644 --- a/modules/src/core/ics04_channel/handler/chan_open_confirm.rs +++ b/modules/src/core/ics04_channel/handler/chan_open_confirm.rs @@ -7,13 +7,13 @@ use crate::core::ics04_channel::events::Attributes; use crate::core::ics04_channel::handler::verify::verify_channel_proofs; use crate::core::ics04_channel::handler::{ChannelIdState, ChannelResult}; use crate::core::ics04_channel::msgs::chan_open_confirm::MsgChannelOpenConfirm; -use crate::core::ics26_routing::context::LightClientContext; +use crate::core::ics26_routing::context::ReaderContext; use crate::events::IbcEvent; use crate::handler::{HandlerOutput, HandlerResult}; use crate::prelude::*; pub(crate) fn process( - ctx: &dyn LightClientContext, + ctx: &dyn ReaderContext, msg: &MsgChannelOpenConfirm, ) -> HandlerResult { let mut output = HandlerOutput::builder(); diff --git a/modules/src/core/ics04_channel/handler/chan_open_init.rs b/modules/src/core/ics04_channel/handler/chan_open_init.rs index 4a1e9ecc7a..4c7af9e743 100644 --- a/modules/src/core/ics04_channel/handler/chan_open_init.rs +++ b/modules/src/core/ics04_channel/handler/chan_open_init.rs @@ -6,13 +6,13 @@ use crate::core::ics04_channel::events::Attributes; use crate::core::ics04_channel::handler::{ChannelIdState, ChannelResult}; use crate::core::ics04_channel::msgs::chan_open_init::MsgChannelOpenInit; use crate::core::ics24_host::identifier::ChannelId; -use crate::core::ics26_routing::context::LightClientContext; +use crate::core::ics26_routing::context::ReaderContext; use crate::events::IbcEvent; use crate::handler::{HandlerOutput, HandlerResult}; use crate::prelude::*; pub(crate) fn process( - ctx: &dyn LightClientContext, + ctx: &dyn ReaderContext, msg: &MsgChannelOpenInit, ) -> HandlerResult { let mut output = HandlerOutput::builder(); diff --git a/modules/src/core/ics04_channel/handler/chan_open_try.rs b/modules/src/core/ics04_channel/handler/chan_open_try.rs index 810cc4c3bc..2564486364 100644 --- a/modules/src/core/ics04_channel/handler/chan_open_try.rs +++ b/modules/src/core/ics04_channel/handler/chan_open_try.rs @@ -9,13 +9,13 @@ use crate::core::ics04_channel::handler::verify::verify_channel_proofs; use crate::core::ics04_channel::handler::{ChannelIdState, ChannelResult}; use crate::core::ics04_channel::msgs::chan_open_try::MsgChannelOpenTry; use crate::core::ics24_host::identifier::ChannelId; -use crate::core::ics26_routing::context::LightClientContext; +use crate::core::ics26_routing::context::ReaderContext; use crate::events::IbcEvent; use crate::handler::{HandlerOutput, HandlerResult}; use crate::prelude::*; pub(crate) fn process( - ctx: &dyn LightClientContext, + ctx: &dyn ReaderContext, msg: &MsgChannelOpenTry, ) -> HandlerResult { let mut output = HandlerOutput::builder(); diff --git a/modules/src/core/ics04_channel/handler/recv_packet.rs b/modules/src/core/ics04_channel/handler/recv_packet.rs index 8d04445504..8ac7ae0c71 100644 --- a/modules/src/core/ics04_channel/handler/recv_packet.rs +++ b/modules/src/core/ics04_channel/handler/recv_packet.rs @@ -7,7 +7,7 @@ use crate::core::ics04_channel::handler::verify::verify_packet_recv_proofs; use crate::core::ics04_channel::msgs::recv_packet::MsgRecvPacket; use crate::core::ics04_channel::packet::{PacketResult, Receipt, Sequence}; use crate::core::ics24_host::identifier::{ChannelId, PortId}; -use crate::core::ics26_routing::context::LightClientContext; +use crate::core::ics26_routing::context::ReaderContext; use crate::events::IbcEvent; use crate::handler::{HandlerOutput, HandlerResult}; use crate::prelude::*; @@ -31,7 +31,7 @@ pub enum RecvPacketResult { } pub fn process( - ctx: &dyn LightClientContext, + ctx: &dyn ReaderContext, msg: &MsgRecvPacket, ) -> HandlerResult { let mut output = HandlerOutput::builder(); diff --git a/modules/src/core/ics04_channel/handler/send_packet.rs b/modules/src/core/ics04_channel/handler/send_packet.rs index bf0b34436d..ca484371f8 100644 --- a/modules/src/core/ics04_channel/handler/send_packet.rs +++ b/modules/src/core/ics04_channel/handler/send_packet.rs @@ -6,7 +6,7 @@ use crate::core::ics04_channel::events::SendPacket; use crate::core::ics04_channel::packet::{PacketResult, Sequence}; use crate::core::ics04_channel::{error::Error, packet::Packet}; use crate::core::ics24_host::identifier::{ChannelId, PortId}; -use crate::core::ics26_routing::context::LightClientContext; +use crate::core::ics26_routing::context::ReaderContext; use crate::events::IbcEvent; use crate::handler::{HandlerOutput, HandlerResult}; use crate::prelude::*; @@ -19,12 +19,10 @@ pub struct SendPacketResult { pub seq: Sequence, pub seq_number: Sequence, pub commitment: PacketCommitment, + pub packet: Packet, } -pub fn send_packet( - ctx: &dyn LightClientContext, - packet: Packet, -) -> HandlerResult { +pub fn send_packet(ctx: &dyn ReaderContext, packet: Packet) -> HandlerResult { let mut output = HandlerOutput::builder(); let source_channel_end = @@ -96,6 +94,7 @@ pub fn send_packet( channel_id: packet.source_channel, seq: packet.sequence, seq_number: next_seq_send.increment(), + packet: packet.clone(), commitment: ctx.packet_commitment( packet.data.clone(), packet.timeout_height, diff --git a/modules/src/core/ics04_channel/handler/timeout.rs b/modules/src/core/ics04_channel/handler/timeout.rs index cf7c08b015..5f2e7b4480 100644 --- a/modules/src/core/ics04_channel/handler/timeout.rs +++ b/modules/src/core/ics04_channel/handler/timeout.rs @@ -9,7 +9,7 @@ use crate::core::ics04_channel::handler::verify::{ use crate::core::ics04_channel::msgs::timeout::MsgTimeout; use crate::core::ics04_channel::packet::{PacketResult, Sequence}; use crate::core::ics24_host::identifier::{ChannelId, PortId}; -use crate::core::ics26_routing::context::LightClientContext; +use crate::core::ics26_routing::context::ReaderContext; use crate::events::IbcEvent; use crate::handler::{HandlerOutput, HandlerResult}; use crate::prelude::*; @@ -25,7 +25,7 @@ pub struct TimeoutPacketResult { } pub fn process( - ctx: &dyn LightClientContext, + ctx: &dyn ReaderContext, msg: &MsgTimeout, ) -> HandlerResult { let mut output = HandlerOutput::builder(); diff --git a/modules/src/core/ics04_channel/handler/timeout_on_close.rs b/modules/src/core/ics04_channel/handler/timeout_on_close.rs index 2be21ade6c..3b194a395f 100644 --- a/modules/src/core/ics04_channel/handler/timeout_on_close.rs +++ b/modules/src/core/ics04_channel/handler/timeout_on_close.rs @@ -9,13 +9,13 @@ use crate::core::ics04_channel::handler::verify::{ use crate::core::ics04_channel::msgs::timeout_on_close::MsgTimeoutOnClose; use crate::core::ics04_channel::packet::PacketResult; use crate::core::ics04_channel::{error::Error, handler::timeout::TimeoutPacketResult}; -use crate::core::ics26_routing::context::LightClientContext; +use crate::core::ics26_routing::context::ReaderContext; use crate::events::IbcEvent; use crate::handler::{HandlerOutput, HandlerResult}; use crate::prelude::*; pub fn process( - ctx: &dyn LightClientContext, + ctx: &dyn ReaderContext, msg: &MsgTimeoutOnClose, ) -> HandlerResult { let mut output = HandlerOutput::builder(); diff --git a/modules/src/core/ics04_channel/handler/verify.rs b/modules/src/core/ics04_channel/handler/verify.rs index 086cf591c8..7e2f2e9ea9 100644 --- a/modules/src/core/ics04_channel/handler/verify.rs +++ b/modules/src/core/ics04_channel/handler/verify.rs @@ -7,14 +7,14 @@ use crate::core::ics04_channel::channel::ChannelEnd; use crate::core::ics04_channel::error::Error; use crate::core::ics04_channel::msgs::acknowledgement::Acknowledgement; use crate::core::ics04_channel::packet::{Packet, Sequence}; -use crate::core::ics26_routing::context::LightClientContext; +use crate::core::ics26_routing::context::ReaderContext; use crate::prelude::*; use crate::proofs::Proofs; use crate::Height; /// Entry point for verifying all proofs bundled in any ICS4 message for channel protocols. pub fn verify_channel_proofs( - ctx: &dyn LightClientContext, + ctx: &dyn ReaderContext, height: Height, channel_end: &ChannelEnd, connection_end: &ConnectionEnd, @@ -57,7 +57,7 @@ pub fn verify_channel_proofs( /// Entry point for verifying all proofs bundled in a ICS4 packet recv. message. pub fn verify_packet_recv_proofs( - ctx: &dyn LightClientContext, + ctx: &dyn ReaderContext, height: Height, packet: &Packet, connection_end: &ConnectionEnd, @@ -105,7 +105,7 @@ pub fn verify_packet_recv_proofs( /// Entry point for verifying all proofs bundled in an ICS4 packet ack message. pub fn verify_packet_acknowledgement_proofs( - ctx: &dyn LightClientContext, + ctx: &dyn ReaderContext, height: Height, packet: &Packet, acknowledgement: Acknowledgement, @@ -150,7 +150,7 @@ pub fn verify_packet_acknowledgement_proofs( - ctx: &dyn LightClientContext, + ctx: &dyn ReaderContext, height: Height, connection_end: &ConnectionEnd, packet: Packet, @@ -191,7 +191,7 @@ pub fn verify_next_sequence_recv( } pub fn verify_packet_receipt_absence( - ctx: &dyn LightClientContext, + ctx: &dyn ReaderContext, height: Height, connection_end: &ConnectionEnd, packet: Packet, diff --git a/modules/src/core/ics04_channel/handler/write_acknowledgement.rs b/modules/src/core/ics04_channel/handler/write_acknowledgement.rs index e86f1f5821..299bd68f9d 100644 --- a/modules/src/core/ics04_channel/handler/write_acknowledgement.rs +++ b/modules/src/core/ics04_channel/handler/write_acknowledgement.rs @@ -4,7 +4,7 @@ use crate::core::ics04_channel::error::Error; use crate::core::ics04_channel::events::WriteAcknowledgement; use crate::core::ics04_channel::packet::{Packet, PacketResult, Sequence}; use crate::core::ics24_host::identifier::{ChannelId, PortId}; -use crate::core::ics26_routing::context::LightClientContext; +use crate::core::ics26_routing::context::ReaderContext; use crate::prelude::*; use crate::{ events::IbcEvent, @@ -20,7 +20,7 @@ pub struct WriteAckPacketResult { } pub fn process( - ctx: &dyn LightClientContext, + ctx: &dyn ReaderContext, packet: Packet, ack: Vec, ) -> HandlerResult { diff --git a/modules/src/core/ics26_routing/context.rs b/modules/src/core/ics26_routing/context.rs index aac61fb214..0582bd9673 100644 --- a/modules/src/core/ics26_routing/context.rs +++ b/modules/src/core/ics26_routing/context.rs @@ -22,7 +22,7 @@ use crate::handler::HandlerOutputBuilder; use crate::signer::Signer; /// This trait captures all the functional dependencies of needed in light client implementations -pub trait LightClientContext: ClientReader + ConnectionReader + ChannelReader {} +pub trait ReaderContext: ClientReader + ConnectionReader + ChannelReader {} /// This trait captures all the functional dependencies (i.e., context) which the ICS26 module /// requires to be able to dispatch and process IBC messages. In other words, this is the @@ -35,8 +35,7 @@ pub trait Ics26Context: + ChannelKeeper + ChannelReader + PortReader - + Ics20Context - + LightClientContext + + ReaderContext { type Router: Router; diff --git a/modules/src/core/ics26_routing/handler.rs b/modules/src/core/ics26_routing/handler.rs index b0cd942218..c2f0765b88 100644 --- a/modules/src/core/ics26_routing/handler.rs +++ b/modules/src/core/ics26_routing/handler.rs @@ -3,7 +3,6 @@ use crate::prelude::*; use ibc_proto::google::protobuf::Any; -use crate::applications::ics20_fungible_token_transfer::relay_application_logic::send_transfer::send_transfer as ics20_msg_dispatcher; use crate::core::ics02_client::handler::dispatch as ics2_msg_dispatcher; use crate::core::ics03_connection::handler::dispatch as ics3_msg_dispatcher; use crate::core::ics04_channel::handler::{ @@ -32,10 +31,7 @@ pub struct MsgReceipt { /// Mimics the DeliverTx ABCI interface, but for a single message and at a slightly lower level. /// No need for authentication info or signature checks here. /// Returns a vector of all events that got generated as a byproduct of processing `message`. -pub fn deliver( - ctx: &mut Ctx, - message: Any, -) -> Result<(Vec, Vec), Error> +pub fn deliver(ctx: &mut Ctx, message: Any) -> Result where Ctx: Ics26Context, HostFunctions: HostFunctionsProvider, @@ -44,7 +40,7 @@ where let envelope = decode(message)?; // Process the envelope, and accumulate any events that were generated. - let output = dispatch::<_, HostFunctions>(ctx, envelope)?; + let HandlerOutput { log, events, .. } = dispatch::<_, HostFunctions>(ctx, envelope)?; Ok(MsgReceipt { events, log }) } @@ -114,20 +110,6 @@ where handler_builder.with_result(()) } - Ics20Msg(msg) => { - let handler_output = ics20_msg_dispatcher::<_, HostFunctions>(ctx, msg) - .map_err(Error::ics20_fungible_token_transfer)?; - - // Apply any results to the host chain store. - ctx.store_packet_result(handler_output.result) - .map_err(Error::ics04_channel)?; - - HandlerOutput::builder() - .with_log(handler_output.log) - .with_events(handler_output.events) - .with_result(()) - } - Ics4PacketMsg(msg) => { let module_id = get_module_for_packet_msg(ctx, &msg).map_err(Error::ics04_channel)?; let (mut handler_builder, packet_result) = @@ -160,12 +142,10 @@ mod tests { use test_log::test; - use crate::applications::ics20_fungible_token_transfer::msgs::transfer::test_util::get_dummy_msg_transfer; + use crate::applications::transfer::context::test::deliver as ics20_deliver; + use crate::applications::transfer::PrefixedCoin; use crate::core::ics02_client::client_consensus::AnyConsensusState; use crate::core::ics02_client::client_state::AnyClientState; - use crate::events::IbcEvent; - use crate::test_utils::Crypto; - use crate::core::ics02_client::msgs::{ create_client::MsgCreateAnyClient, update_client::MsgUpdateAnyClient, upgrade_client::MsgUpgradeAnyClient, ClientMsg, @@ -188,8 +168,8 @@ mod tests { timeout_on_close::{test_util::get_dummy_raw_msg_timeout_on_close, MsgTimeoutOnClose}, ChannelMsg, PacketMsg, }; - use crate::core::ics23_commitment::commitment::test_util::get_dummy_merkle_proof; use crate::events::IbcEvent; + use crate::test_utils::Crypto; use crate::{ applications::transfer::msgs::transfer::test_util::get_dummy_msg_transfer, applications::transfer::msgs::transfer::MsgTransfer, @@ -236,7 +216,7 @@ mod tests { // Test parameters struct Test { name: String, - msg: Ics26Envelope, + msg: TestMsg, want_pass: bool, } let default_signer = get_dummy_account_id(); @@ -561,7 +541,23 @@ mod tests { .collect(); for test in tests { - let res = dispatch::<_, Crypto>(&mut ctx, test.msg.clone()); + let res = match test.msg.clone() { + TestMsg::Ics26(msg) => dispatch::<_, Crypto>(&mut ctx, msg).map(|_| ()), + TestMsg::Ics20(msg) => { + let transfer_module = + ctx.router_mut().get_route_mut(&transfer_module_id).unwrap(); + ics20_deliver( + transfer_module + .as_any_mut() + .downcast_mut::() + .unwrap(), + &mut HandlerOutputBuilder::new(), + msg, + ) + .map(|_| ()) + .map_err(Error::ics04_channel) + } + }; assert_eq!( test.want_pass, diff --git a/modules/src/mock/client_def.rs b/modules/src/mock/client_def.rs index 155666847e..728d5be17a 100644 --- a/modules/src/mock/client_def.rs +++ b/modules/src/mock/client_def.rs @@ -13,7 +13,7 @@ use crate::core::ics23_commitment::merkle::apply_prefix; use crate::core::ics24_host::identifier::{ChannelId, ClientId, ConnectionId, PortId}; use crate::core::ics24_host::path::ClientConsensusStatePath; use crate::core::ics24_host::Path; -use crate::core::ics26_routing::context::LightClientContext; +use crate::core::ics26_routing::context::ReaderContext; use crate::mock::client_state::{MockClientState, MockConsensusState}; use crate::mock::header::MockHeader; use crate::prelude::*; @@ -30,7 +30,7 @@ impl ClientDef for MockClient { fn update_state( &self, - _ctx: &dyn LightClientContext, + _ctx: &dyn ReaderContext, _client_id: ClientId, client_state: Self::ClientState, header: Self::Header, @@ -50,7 +50,7 @@ impl ClientDef for MockClient { fn verify_client_consensus_state( &self, - _ctx: &dyn LightClientContext, + _ctx: &dyn ReaderContext, _client_state: &Self::ClientState, _height: Height, prefix: &CommitmentPrefix, @@ -74,7 +74,7 @@ impl ClientDef for MockClient { fn verify_connection_state( &self, - _ctx: &dyn LightClientContext, + _ctx: &dyn ReaderContext, _client_id: &ClientId, _client_state: &Self::ClientState, _height: Height, @@ -89,7 +89,7 @@ impl ClientDef for MockClient { fn verify_channel_state( &self, - _ctx: &dyn LightClientContext, + _ctx: &dyn ReaderContext, _client_id: &ClientId, _client_state: &Self::ClientState, _height: Height, @@ -105,7 +105,7 @@ impl ClientDef for MockClient { fn verify_client_full_state( &self, - _ctx: &dyn LightClientContext, + _ctx: &dyn ReaderContext, _client_state: &Self::ClientState, _height: Height, _prefix: &CommitmentPrefix, @@ -119,7 +119,7 @@ impl ClientDef for MockClient { fn verify_packet_data( &self, - _ctx: &dyn LightClientContext, + _ctx: &dyn ReaderContext, _client_id: &ClientId, _client_state: &Self::ClientState, _height: Height, @@ -136,7 +136,7 @@ impl ClientDef for MockClient { fn verify_packet_acknowledgement( &self, - _ctx: &dyn LightClientContext, + _ctx: &dyn ReaderContext, _client_id: &ClientId, _client_state: &Self::ClientState, _height: Height, @@ -153,7 +153,7 @@ impl ClientDef for MockClient { fn verify_next_sequence_recv( &self, - _ctx: &dyn LightClientContext, + _ctx: &dyn ReaderContext, _client_id: &ClientId, _client_state: &Self::ClientState, _height: Height, @@ -169,7 +169,7 @@ impl ClientDef for MockClient { fn verify_packet_receipt_absence( &self, - _ctx: &dyn LightClientContext, + _ctx: &dyn ReaderContext, _client_id: &ClientId, _client_state: &Self::ClientState, _height: Height, @@ -198,7 +198,7 @@ impl ClientDef for MockClient { fn verify_header( &self, - _ctx: &dyn LightClientContext, + _ctx: &dyn ReaderContext, _client_id: ClientId, _client_state: Self::ClientState, _header: Self::Header, @@ -216,7 +216,7 @@ impl ClientDef for MockClient { fn check_for_misbehaviour( &self, - _ctx: &dyn LightClientContext, + _ctx: &dyn ReaderContext, _client_id: ClientId, _client_state: Self::ClientState, _header: Self::Header, diff --git a/modules/src/mock/context.rs b/modules/src/mock/context.rs index eec73176b5..777aaa7c7b 100644 --- a/modules/src/mock/context.rs +++ b/modules/src/mock/context.rs @@ -37,7 +37,7 @@ use crate::core::ics05_port::error::Error; use crate::core::ics23_commitment::commitment::CommitmentPrefix; use crate::core::ics24_host::identifier::{ChainId, ChannelId, ClientId, ConnectionId, PortId}; use crate::core::ics26_routing::context::{ - Ics26Context, LightClientContext, Module, ModuleId, Router, RouterBuilder, + Ics26Context, Module, ModuleId, ReaderContext, Router, RouterBuilder, }; use crate::core::ics26_routing::handler::{deliver, dispatch, MsgReceipt}; use crate::core::ics26_routing::msgs::Ics26Envelope; @@ -513,7 +513,7 @@ impl MockContext { } pub fn consensus_states(&self, client_id: &ClientId) -> Vec { - self.clients[client_id] + self.ibc_store.lock().unwrap().clients[client_id] .consensus_states .iter() .map(|(k, v)| AnyConsensusStateWithHeight { @@ -535,8 +535,8 @@ impl MockContext { &self, client_id: &ClientId, height: &Height, - ) -> &AnyConsensusState { - self.clients[client_id] + ) -> AnyConsensusState { + self.ibc_store.lock().unwrap().clients[client_id] .consensus_states .get(height) .unwrap() @@ -642,7 +642,7 @@ impl Router for MockRouter { } } -impl LightClientContext for MockContext {} +impl ReaderContext for MockContext {} impl Ics26Context for MockContext { type Router = MockRouter; @@ -954,6 +954,14 @@ impl ChannelKeeper for MockContext { .insert(key, receipt); Ok(()) } + + fn store_packet( + &mut self, + _key: (PortId, ChannelId, Sequence), + _packet: crate::core::ics04_channel::packet::Packet, + ) -> Result<(), Ics04Error> { + Ok(()) + } } impl ConnectionReader for MockContext { @@ -1033,7 +1041,7 @@ impl ClientReader for MockContext { client_id: &ClientId, height: Height, ) -> Result { - match self.clients.get(client_id) { + match self.ibc_store.lock().unwrap().clients.get(client_id) { Some(client_record) => match client_record.consensus_states.get(&height) { Some(consensus_state) => Ok(consensus_state.clone()), None => Err(Ics02Error::consensus_state_not_found( @@ -1054,7 +1062,8 @@ impl ClientReader for MockContext { client_id: &ClientId, height: Height, ) -> Result, Ics02Error> { - let client_record = self + let ibc_store = self.ibc_store.lock().unwrap(); + let client_record = ibc_store .clients .get(client_id) .ok_or_else(|| Ics02Error::client_not_found(client_id.clone()))?; @@ -1081,7 +1090,8 @@ impl ClientReader for MockContext { client_id: &ClientId, height: Height, ) -> Result, Ics02Error> { - let client_record = self + let ibc_store = self.ibc_store.lock().unwrap(); + let client_record = ibc_store .clients .get(client_id) .ok_or_else(|| Ics02Error::client_not_found(client_id.clone()))?; @@ -1242,7 +1252,7 @@ impl Ics18Context for MockContext { // Forward call to Ics26 delivery method. let mut all_events = vec![]; for msg in msgs { - let (mut events, _) = + let MsgReceipt { mut events, .. } = deliver::<_, Crypto>(self, msg).map_err(Ics18Error::transaction_failed)?; all_events.append(&mut events); } diff --git a/modules/src/test_utils.rs b/modules/src/test_utils.rs index 04fb47b3ac..23bc3df164 100644 --- a/modules/src/test_utils.rs +++ b/modules/src/test_utils.rs @@ -2,6 +2,8 @@ use std::sync::{Arc, Mutex}; use std::time::Duration; use crate::clients::host_functions::HostFunctionsProvider; +use crate::core::ics02_client::context::ClientReader; +use crate::core::ics03_connection::context::ConnectionReader; use crate::prelude::*; use sp_core::keccak_256; use sp_trie::LayoutV0; @@ -9,16 +11,24 @@ use tendermint::{block, consensus, evidence, public_key::Algorithm}; use crate::clients::ics11_beefy::error::Error as BeefyError; use crate::core::ics02_client::error::Error as Ics02Error; -use crate::core::ics04_channel::channel::{Counterparty, Order}; + +use crate::applications::transfer::context::{BankKeeper, Ics20Context, Ics20Keeper, Ics20Reader}; +use crate::applications::transfer::{error::Error as Ics20Error, PrefixedCoin}; +use crate::core::ics02_client::client_consensus::AnyConsensusState; +use crate::core::ics02_client::client_state::AnyClientState; +use crate::core::ics03_connection::connection::ConnectionEnd; +use crate::core::ics03_connection::error::Error as Ics03Error; +use crate::core::ics04_channel::channel::{ChannelEnd, Counterparty, Order}; +use crate::core::ics04_channel::commitment::{AcknowledgementCommitment, PacketCommitment}; +use crate::core::ics04_channel::context::{ChannelKeeper, ChannelReader}; use crate::core::ics04_channel::error::Error; use crate::core::ics04_channel::packet::{Receipt, Sequence}; use crate::core::ics04_channel::Version; use crate::core::ics05_port::context::PortReader; use crate::core::ics05_port::error::Error as PortError; use crate::core::ics24_host::identifier::{ChannelId, ClientId, ConnectionId, PortId}; -use crate::core::ics26_routing::context::{Module, ModuleId, ModuleOutputBuilder}; +use crate::core::ics26_routing::context::{Module, ModuleId, ModuleOutputBuilder, ReaderContext}; use crate::mock::context::MockIbcStore; -use crate::prelude::*; use crate::signer::Signer; use crate::timestamp::Timestamp; use crate::Height; @@ -101,7 +111,7 @@ impl HostFunctionsProvider for Crypto { .map(|val| val.to_vec()) } - fn ed25519_verify(_signature: &[u8; 64], _value: &[u8; 32], public_key: &[u8; 32]) -> bool { + fn ed25519_verify(_signature: &[u8; 64], _value: &[u8; 32], _public_key: &[u8]) -> bool { true } @@ -134,3 +144,349 @@ impl HostFunctionsProvider for Crypto { sp_io::hashing::sha2_256(data) } } + +impl Ics20Keeper for DummyTransferModule { + type AccountId = Signer; +} + +impl ChannelKeeper for DummyTransferModule { + fn store_packet_commitment( + &mut self, + key: (PortId, ChannelId, Sequence), + commitment: PacketCommitment, + ) -> Result<(), Error> { + self.ibc_store + .lock() + .unwrap() + .packet_commitment + .insert(key, commitment); + Ok(()) + } + + fn delete_packet_commitment( + &mut self, + _key: (PortId, ChannelId, Sequence), + ) -> Result<(), Error> { + unimplemented!() + } + + fn store_packet_receipt( + &mut self, + _key: (PortId, ChannelId, Sequence), + _receipt: Receipt, + ) -> Result<(), Error> { + unimplemented!() + } + + fn store_packet_acknowledgement( + &mut self, + _key: (PortId, ChannelId, Sequence), + _ack: AcknowledgementCommitment, + ) -> Result<(), Error> { + unimplemented!() + } + + fn delete_packet_acknowledgement( + &mut self, + _key: (PortId, ChannelId, Sequence), + ) -> Result<(), Error> { + unimplemented!() + } + + fn store_connection_channels( + &mut self, + _conn_id: ConnectionId, + _port_channel_id: &(PortId, ChannelId), + ) -> Result<(), Error> { + unimplemented!() + } + + fn store_channel( + &mut self, + _port_channel_id: (PortId, ChannelId), + _channel_end: &ChannelEnd, + ) -> Result<(), Error> { + unimplemented!() + } + + fn store_next_sequence_send( + &mut self, + port_channel_id: (PortId, ChannelId), + seq: Sequence, + ) -> Result<(), Error> { + self.ibc_store + .lock() + .unwrap() + .next_sequence_send + .insert(port_channel_id, seq); + Ok(()) + } + + fn store_next_sequence_recv( + &mut self, + _port_channel_id: (PortId, ChannelId), + _seq: Sequence, + ) -> Result<(), Error> { + unimplemented!() + } + + fn store_next_sequence_ack( + &mut self, + _port_channel_id: (PortId, ChannelId), + _seq: Sequence, + ) -> Result<(), Error> { + unimplemented!() + } + + fn increase_channel_counter(&mut self) { + unimplemented!() + } + + fn store_packet( + &mut self, + _key: (PortId, ChannelId, Sequence), + _packet: crate::core::ics04_channel::packet::Packet, + ) -> Result<(), Error> { + Ok(()) + } +} + +impl PortReader for DummyTransferModule { + fn lookup_module_by_port(&self, _port_id: &PortId) -> Result { + unimplemented!() + } +} + +impl BankKeeper for DummyTransferModule { + type AccountId = Signer; + + fn send_coins( + &mut self, + _from: &Self::AccountId, + _to: &Self::AccountId, + _amt: &PrefixedCoin, + ) -> Result<(), Ics20Error> { + Ok(()) + } + + fn mint_coins( + &mut self, + _account: &Self::AccountId, + _amt: &PrefixedCoin, + ) -> Result<(), Ics20Error> { + Ok(()) + } + + fn burn_coins( + &mut self, + _account: &Self::AccountId, + _amt: &PrefixedCoin, + ) -> Result<(), Ics20Error> { + Ok(()) + } +} + +impl Ics20Reader for DummyTransferModule { + type AccountId = Signer; + + fn get_port(&self) -> Result { + Ok(PortId::transfer()) + } + + fn is_send_enabled(&self) -> bool { + true + } + + fn is_receive_enabled(&self) -> bool { + true + } +} + +impl ConnectionReader for DummyTransferModule { + fn connection_end(&self, cid: &ConnectionId) -> Result { + match self.ibc_store.lock().unwrap().connections.get(cid) { + Some(connection_end) => Ok(connection_end.clone()), + None => Err(Ics03Error::connection_not_found(cid.clone())), + } + } + + fn host_oldest_height(&self) -> Height { + todo!() + } + + fn commitment_prefix(&self) -> crate::core::ics23_commitment::commitment::CommitmentPrefix { + todo!() + } + + fn connection_counter(&self) -> Result { + todo!() + } +} + +impl ClientReader for DummyTransferModule { + fn client_state(&self, client_id: &ClientId) -> Result { + match self.ibc_store.lock().unwrap().clients.get(client_id) { + Some(client_record) => client_record + .client_state + .clone() + .ok_or_else(|| Ics02Error::client_not_found(client_id.clone())), + None => Err(Ics02Error::client_not_found(client_id.clone())), + } + } + + fn host_height(&self) -> Height { + Height::zero() + } + + fn host_consensus_state(&self, _height: Height) -> Result { + unimplemented!() + } + + fn consensus_state( + &self, + client_id: &ClientId, + height: Height, + ) -> Result { + match self.ibc_store.lock().unwrap().clients.get(client_id) { + Some(client_record) => match client_record.consensus_states.get(&height) { + Some(consensus_state) => Ok(consensus_state.clone()), + None => Err(Ics02Error::consensus_state_not_found( + client_id.clone(), + height, + )), + }, + None => Err(Ics02Error::consensus_state_not_found( + client_id.clone(), + height, + )), + } + } + + fn client_type( + &self, + _client_id: &ClientId, + ) -> Result { + todo!() + } + + fn next_consensus_state( + &self, + _client_id: &ClientId, + _height: Height, + ) -> Result, Ics02Error> { + todo!() + } + + fn prev_consensus_state( + &self, + _client_id: &ClientId, + _height: Height, + ) -> Result, Ics02Error> { + todo!() + } + + fn host_timestamp(&self) -> Timestamp { + todo!() + } + + fn client_counter(&self) -> Result { + todo!() + } +} + +impl ChannelReader for DummyTransferModule { + fn channel_end(&self, pcid: &(PortId, ChannelId)) -> Result { + match self.ibc_store.lock().unwrap().channels.get(pcid) { + Some(channel_end) => Ok(channel_end.clone()), + None => Err(Error::channel_not_found(pcid.0.clone(), pcid.1)), + } + } + + fn connection_channels(&self, _cid: &ConnectionId) -> Result, Error> { + unimplemented!() + } + + fn get_next_sequence_send( + &self, + port_channel_id: &(PortId, ChannelId), + ) -> Result { + match self + .ibc_store + .lock() + .unwrap() + .next_sequence_send + .get(port_channel_id) + { + Some(sequence) => Ok(*sequence), + None => Err(Error::missing_next_send_seq(port_channel_id.clone())), + } + } + + fn get_next_sequence_recv( + &self, + _port_channel_id: &(PortId, ChannelId), + ) -> Result { + unimplemented!() + } + + fn get_next_sequence_ack( + &self, + _port_channel_id: &(PortId, ChannelId), + ) -> Result { + unimplemented!() + } + + fn get_packet_commitment( + &self, + _key: &(PortId, ChannelId, Sequence), + ) -> Result { + unimplemented!() + } + + fn get_packet_receipt(&self, _key: &(PortId, ChannelId, Sequence)) -> Result { + unimplemented!() + } + + fn get_packet_acknowledgement( + &self, + _key: &(PortId, ChannelId, Sequence), + ) -> Result { + unimplemented!() + } + + fn hash(&self, value: Vec) -> Vec { + use sha2::Digest; + + sha2::Sha256::digest(value).to_vec() + } + + fn client_update_time( + &self, + _client_id: &ClientId, + _height: Height, + ) -> Result { + unimplemented!() + } + + fn client_update_height( + &self, + _client_id: &ClientId, + _height: Height, + ) -> Result { + unimplemented!() + } + + fn channel_counter(&self) -> Result { + unimplemented!() + } + + fn max_expected_time_per_block(&self) -> Duration { + unimplemented!() + } +} + +impl Ics20Context for DummyTransferModule { + type AccountId = Signer; +} + +impl ReaderContext for DummyTransferModule {} diff --git a/proto-compiler/Cargo.lock b/proto-compiler/Cargo.lock index 759acf3513..3b69bae13d 100644 --- a/proto-compiler/Cargo.lock +++ b/proto-compiler/Cargo.lock @@ -350,7 +350,7 @@ checksum = "c4a1e36c821dbe04574f602848a19f742f4fb3c98d40449f11bcad18d6b17421" [[package]] name = "hyper" -version = "0.14.19" +version = "0.15.04" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "42dc3c131584288d375f2d07f822b0cb012d8c6fb899a5b9fdb3cb7eb9b6004f" dependencies = [