From 132dc08bc691a8e5a6fa1a577636163090a6d0c8 Mon Sep 17 00:00:00 2001 From: benluelo Date: Wed, 22 Jan 2025 09:36:02 +0000 Subject: [PATCH 1/2] fix(voyager): tx simulation errors are fatal errors actually --- lib/unionlabs/src/ibc/core/client/height.rs | 24 + .../event-source/cosmos-sdk/src/main.rs | 505 +++++++----------- .../transaction/cosmos-sdk/src/main.rs | 24 +- 3 files changed, 236 insertions(+), 317 deletions(-) diff --git a/lib/unionlabs/src/ibc/core/client/height.rs b/lib/unionlabs/src/ibc/core/client/height.rs index 6957e147a6..31e2ffdcfa 100644 --- a/lib/unionlabs/src/ibc/core/client/height.rs +++ b/lib/unionlabs/src/ibc/core/client/height.rs @@ -99,6 +99,30 @@ impl Height { } } +// Implement once this is stabilized: https://github.com/rust-lang/rust/issues/42168 +// impl Step for Height { +// fn steps_between(start: &Self, end: &Self) -> Option { +// start +// .revision_matches(end) +// .then(|| ::steps_between(&start.height(), &end.height())) +// .flatten() +// } + +// fn forward_checked(start: Self, count: usize) -> Option { +// start +// .revision_matches(end) +// .then(|| ::forward_checked(&start.height(), &end.height())) +// .flatten() +// } + +// fn backward_checked(start: Self, count: usize) -> Option { +// start +// .revision_matches(end) +// .then(|| ::backward_checked(&start.height(), &end.height())) +// .flatten() +// } +// } + impl FromStr for Height { type Err = HeightFromStrError; diff --git a/voyager/plugins/event-source/cosmos-sdk/src/main.rs b/voyager/plugins/event-source/cosmos-sdk/src/main.rs index 9768bd5865..d2a9348e0d 100644 --- a/voyager/plugins/event-source/cosmos-sdk/src/main.rs +++ b/voyager/plugins/event-source/cosmos-sdk/src/main.rs @@ -20,16 +20,16 @@ use jsonrpsee::{ }; use serde::{Deserialize, Serialize}; use serde_json::{json, Value}; -use tracing::{debug, error, info, instrument}; +use tracing::{debug, error, info, instrument, trace, warn}; use unionlabs::{ bech32::Bech32, ibc::core::{ channel::{self}, client::height::Height, }, - id::{ChannelId, ClientId, ConnectionId, PortId}, - option_unwrap, parse_wasm_client_type, - primitives::{encoding::HexUnprefixed, H256}, + id::{ChannelId, ConnectionId, PortId}, + option_unwrap, + primitives::H256, ErrorReporter, WasmClientType, }; use voyager_message::{ @@ -39,7 +39,8 @@ use voyager_message::{ into_value, module::{PluginInfo, PluginServer}, rpc::missing_state, - ExtensionsExt, Plugin, PluginMessage, VoyagerClient, VoyagerMessage, + DefaultCmd, ExtensionsExt, Plugin, PluginMessage, VoyagerClient, VoyagerMessage, + FATAL_JSONRPC_ERROR_CODE, }; use voyager_vm::{call, conc, data, pass::PassResult, seq, BoxDynError, Op}; @@ -62,12 +63,6 @@ async fn main() { Module::run().await } -#[derive(clap::Subcommand)] -pub enum Cmd { - ChainId, - LatestHeight, -} - #[derive(Debug, Clone)] pub struct Module { pub chain_id: ChainId, @@ -105,7 +100,7 @@ impl Plugin for Module { type Callback = ModuleCallback; type Config = Config; - type Cmd = Cmd; + type Cmd = DefaultCmd; async fn new(config: Self::Config) -> Result { let tm_client = cometbft_rpc::Client::new(config.rpc_url).await?; @@ -147,13 +142,8 @@ impl Plugin for Module { } } - async fn cmd(config: Self::Config, cmd: Self::Cmd) { - let module = Self::new(config).await.unwrap(); - - match cmd { - Cmd::ChainId => println!("{}", module.chain_id), - Cmd::LatestHeight => println!("{}", module.latest_height().await.unwrap()), - } + async fn cmd(_config: Self::Config, cmd: Self::Cmd) { + match cmd {} } } @@ -173,144 +163,6 @@ impl Module { Height::new_with_revision(self.chain_revision, height) } - async fn client_type_of_checksum(&self, checksum: H256) -> RpcResult> { - if let Some(ty) = self.checksum_cache.get(&checksum) { - debug!( - %checksum, - ty = ?*ty, - "cache hit for checksum" - ); - - return Ok(Some(*ty)); - }; - - info!( - %checksum, - "cache miss for checksum" - ); - - let bz = protos::ibc::lightclients::wasm::v1::query_client::QueryClient::connect( - self.grpc_url.clone(), - ) - .await - .map_err(rpc_error( - "error connecting to grpc server", - Some(json!({ - "grpc_url": self.grpc_url - })), - ))? - .code(protos::ibc::lightclients::wasm::v1::QueryCodeRequest { - checksum: checksum.into_encoding::().to_string(), - }) - .await - .map_err(rpc_error( - "error querying wasm code", - Some(json!({ - "checksum": checksum, - "grpc_url": self.grpc_url - })), - ))? - .into_inner() - .data; - - match parse_wasm_client_type(bz) { - Ok(Some(ty)) => { - info!( - %checksum, - ?ty, - "parsed checksum" - ); - - self.checksum_cache.insert(checksum, ty); - - Ok(Some(ty)) - } - Ok(None) => Ok(None), - Err(err) => { - error!( - %checksum, - %err, - "unable to parse wasm client type" - ); - - Ok(None) - } - } - } - - #[instrument(skip_all, fields(%client_id))] - async fn checksum_of_client_id(&self, client_id: ClientId) -> RpcResult { - type WasmClientState = protos::ibc::lightclients::wasm::v1::ClientState; - - let client_state = protos::ibc::core::client::v1::query_client::QueryClient::connect( - self.grpc_url.clone(), - ) - .await - .map_err(rpc_error( - "error connecting to grpc server", - Some(json!({ "client_id": client_id })), - ))? - .client_state(protos::ibc::core::client::v1::QueryClientStateRequest { - client_id: client_id.to_string(), - }) - .await - .map_err(rpc_error( - "error querying client state", - Some(json!({ "client_id": client_id })), - ))? - .into_inner() - .client_state - .ok_or_else(|| { - // lol - rpc_error( - "error fetching client state", - Some(json!({ "client_id": client_id })), - )(&*Box::::from("client state field is empty")) - })?; - - assert!( - client_state.type_url == ::type_url(), - "attempted to get the wasm blob checksum of a non-wasm \ - light client. this is a bug, please report this at \ - `https://github.com/unionlabs/union`." - ); - - // NOTE: We only need the checksum, so we don't need to decode the inner state contained in .data - ::decode(&*client_state.value) - .map_err(rpc_error( - "error decoding client state", - Some(json!({ "client_id": client_id })), - ))? - .checksum - .try_into() - .map_err(rpc_error( - "invalid checksum", - Some(json!({ "client_id": client_id })), - )) - } - - // TODO: Remove - async fn latest_height(&self) -> Result { - let commit_response = self.cometbft_client.commit(None).await?; - - let mut height = commit_response - .signed_header - .header - .height - .inner() - .try_into() - .expect("value is >= 0; qed;"); - - if !commit_response.canonical { - debug!("commit is not canonical, latest finalized height is the previous block"); - height -= 1; - } - - debug!(height, "latest height"); - - Ok(self.make_height(height)) - } - #[allow(clippy::too_many_arguments)] // pls async fn make_packet_metadata( &self, @@ -461,152 +313,11 @@ impl PluginServer for Module { async fn call(&self, e: &Extensions, msg: ModuleCall) -> RpcResult> { match msg { ModuleCall::FetchTransactions(FetchTransactions { height, page }) => { - info!(%height, %page, "fetching events in block"); - - let response = self - .cometbft_client - .tx_search( - format!("tx.height={}", height.height()), - false, - page, - PER_PAGE_LIMIT, - cometbft_rpc::rpc_types::Order::Desc, - ) - .await - .map_err(rpc_error( - format_args!("error fetching transactions at height {height}"), - Some(json!({ "height": height })), - ))?; - - Ok(conc( - response - .txs - .into_iter() - .flat_map(|txr| { - txr.tx_result.events.into_iter().filter_map(move |event| { - debug!(%event.ty, "observed event"); - - let event = CosmosSdkEvent::::new(event.clone()) - .inspect_err(|e| match e { - cosmos_sdk_event::Error::Deserialize(error) => { - debug!("unable to parse event: {error}") - } - _ => { - error!("{e}"); - } - }) - .ok()?; - - match (&event.contract_address, &self.ibc_host_contract_address) { - (None, None) => Some((event, txr.hash)), - (None, Some(_)) => Some((event, txr.hash)), - (Some(_), None) => None, - (Some(a), Some(b)) => { - if a == b { - Some((event, txr.hash)) - } else { - None - } - } - } - }) - }) - // .collect::, _>>() - // .map_err(|err| { - // ErrorObject::owned( - // -1, - // ErrorReporter(err).to_string(), - // Some(json!({ - // "height": height, - // "page": page - // })), - // ) - // })? - // .into_iter() - .map(|(ibc_event, tx_hash)| { - debug!(event = %ibc_event.event.name(), "observed IBC event"); - call(PluginMessage::new( - self.plugin_name(), - ModuleCall::from(MakeChainEvent { - height, - tx_hash: tx_hash.into_encoding(), - event: ibc_event.event, - }), - )) - }) - .chain( - ((page.get() * PER_PAGE_LIMIT.get() as u32) < response.total_count) - .then(|| { - call(PluginMessage::new( - self.plugin_name(), - ModuleCall::from(FetchTransactions { - height, - page: page.checked_add(1).expect("too many pages?"), - }), - )) - }), - ), - )) + self.fetch_transaction(height, page).await } ModuleCall::FetchBlocks(FetchBlocks { height }) => { - let latest_height = e - .try_get::()? - .query_latest_height(self.chain_id.clone(), true) - .await?; - - let continuation = |next_height| { - seq([ - // TODO: Make this a config param - call(WaitForHeight { - chain_id: self.chain_id.clone(), - height: next_height, - finalized: true, - }), - call(PluginMessage::new( - self.plugin_name(), - ModuleCall::from(FetchBlocks { - height: next_height, - }), - )), - ]) - }; - - match height.height().cmp(&latest_height.height()) { - Ordering::Less => { - let next_height = (latest_height.height() - height.height()) - .clamp(1, self.chunk_block_fetch_size) - + height.height(); - - info!("batch fetching blocks in range {height}..{next_height}"); - - Ok(conc( - (height.height()..next_height) - .map(|h| { - call(PluginMessage::new( - self.plugin_name(), - ModuleCall::from(FetchTransactions { - height: Height::new_with_revision(height.revision(), h), - page: const { option_unwrap!(NonZeroU32::new(1_u32)) }, - }), - )) - }) - .chain([continuation(Height::new_with_revision( - height.revision(), - next_height, - ))]), - )) - } - Ordering::Equal | Ordering::Greater => Ok(conc([ - call(PluginMessage::new( - self.plugin_name(), - ModuleCall::from(FetchTransactions { - height: height.increment(), - page: const { option_unwrap!(NonZeroU32::new(1_u32)) }, - }), - )), - continuation(height.increment()), - ])), - } + self.fetch_blocks(e.try_get::()?, height) + .await } ModuleCall::MakeChainEvent(MakeChainEvent { height, @@ -1972,3 +1683,195 @@ fn rpc_error( ErrorObject::owned(-1, message, data) } } + +impl Module { + #[instrument(skip_all, fields(height))] + async fn fetch_blocks( + &self, + voyager_client: &VoyagerClient, + height: Height, + ) -> RpcResult> { + let latest_height = voyager_client + .query_latest_height(self.chain_id.clone(), true) + .await?; + + info!(%latest_height, %height, "fetching blocks"); + + if !height.revision_matches(&latest_height) { + return Err(ErrorObject::owned( + FATAL_JSONRPC_ERROR_CODE, + format!( + "revision number mismatch: fetching blocks from height \ + {height}, but the latest height is {latest_height}" + ), + None::<()>, + )); + } + + let continuation = |next_height| { + seq([ + // TODO: Make this a config param + call(WaitForHeight { + chain_id: self.chain_id.clone(), + height: next_height, + finalized: true, + }), + call(PluginMessage::new( + self.plugin_name(), + ModuleCall::from(FetchBlocks { + height: next_height, + }), + )), + ]) + }; + + match height.cmp(&latest_height) { + // height < latest_height + // fetch transactions on all blocks height..next_height (*exclusive* on the upper bound!) + // and then queue the continuation starting at next_height + Ordering::Less => { + let next_height = (latest_height.height() - height.height()) + .clamp(1, self.chunk_block_fetch_size) + + height.height(); + + info!("batch fetching blocks in range {height}..{next_height}"); + + Ok(conc( + (height.height()..next_height) + .map(|h| { + call(PluginMessage::new( + self.plugin_name(), + ModuleCall::from(FetchTransactions { + height: Height::new_with_revision(height.revision(), h), + page: const { option_unwrap!(NonZeroU32::new(1_u32)) }, + }), + )) + }) + .chain([continuation(Height::new_with_revision( + height.revision(), + next_height, + ))]), + )) + } + // height == latest_height + Ordering::Equal => { + info!("requested fetch height is lateset finalized height ({height})"); + + Ok(conc([ + call(PluginMessage::new( + self.plugin_name(), + ModuleCall::from(FetchTransactions { + height: height.increment(), + page: const { option_unwrap!(NonZeroU32::new(1_u32)) }, + }), + )), + continuation(height.increment()), + ])) + } + // height > latest_height + Ordering::Greater => { + warn!( + "the latest finalized height ({latest_height}) \ + is less than the requested height ({height})" + ); + + Ok(continuation(height)) + } + } + } + + #[instrument(skip_all, fields(height, page))] + async fn fetch_transaction( + &self, + height: Height, + page: NonZeroU32, + ) -> RpcResult> { + info!(%height, "fetching events in block"); + + let response = self + .cometbft_client + .tx_search( + format!("tx.height={}", height.height()), + false, + page, + PER_PAGE_LIMIT, + cometbft_rpc::rpc_types::Order::Desc, + ) + .await + .map_err(rpc_error( + format_args!("error fetching transactions at height {height}"), + Some(json!({ "height": height })), + ))?; + + Ok(conc( + response + .txs + .into_iter() + .flat_map(|txr| { + txr.tx_result.events.into_iter().filter_map(move |event| { + debug!(%event.ty, "observed event"); + + let event = CosmosSdkEvent::::new(event.clone()) + .inspect_err(|e| match e { + cosmos_sdk_event::Error::Deserialize(error) => { + trace!("unable to parse event: {error}") + } + _ => { + error!("{e}"); + } + }) + .ok()?; + + match (&event.contract_address, &self.ibc_host_contract_address) { + (None, None) => Some((event, txr.hash)), + (None, Some(_)) => Some((event, txr.hash)), + (Some(_), None) => None, + (Some(a), Some(b)) => { + if a == b { + Some((event, txr.hash)) + } else { + None + } + } + } + }) + }) + // .collect::, _>>() + // .map_err(|err| { + // ErrorObject::owned( + // -1, + // ErrorReporter(err).to_string(), + // Some(json!({ + // "height": height, + // "page": page + // })), + // ) + // })? + // .into_iter() + .map(|(ibc_event, tx_hash)| { + debug!(event = %ibc_event.event.name(), "observed IBC event"); + call(PluginMessage::new( + self.plugin_name(), + ModuleCall::from(MakeChainEvent { + height, + tx_hash: tx_hash.into_encoding(), + event: ibc_event.event, + }), + )) + }) + .chain( + ((page.get() * PER_PAGE_LIMIT.get() as u32) < response.total_count).then( + || { + call(PluginMessage::new( + self.plugin_name(), + ModuleCall::from(FetchTransactions { + height, + page: page.checked_add(1).expect("too many pages?"), + }), + )) + }, + ), + ), + )) + } +} diff --git a/voyager/plugins/transaction/cosmos-sdk/src/main.rs b/voyager/plugins/transaction/cosmos-sdk/src/main.rs index f00820197b..c1331cc942 100644 --- a/voyager/plugins/transaction/cosmos-sdk/src/main.rs +++ b/voyager/plugins/transaction/cosmos-sdk/src/main.rs @@ -289,14 +289,6 @@ impl Module { match res { Some(Err(BroadcastTxCommitError::AccountSequenceMismatch(_))) => Ok(call(rewrap_msg())), Some(Err(BroadcastTxCommitError::OutOfGas)) => Ok(call(rewrap_msg())), - Some(Err(BroadcastTxCommitError::SimulateTx(err))) => { - error!( - error = %ErrorReporter(err), - "transaction simulation failed, message will be requeued and retried" - ); - - Ok(call(rewrap_msg())) - } Some(Err(BroadcastTxCommitError::QueryLatestHeight(err))) => { error!(error = %ErrorReporter(err), "error querying latest height"); @@ -325,14 +317,9 @@ impl Module { Ok((tx_body, auth_info, simulation_gas_info)) => { (tx_body, auth_info, simulation_gas_info) } - Err((tx_body, auth_info, _err)) => ( - tx_body, - auth_info, - GasInfo { - gas_wanted: u64::MAX, - gas_used: u64::MAX, - }, - ), + Err((_tx_body, _auth_info, err)) => { + return Err(BroadcastTxCommitError::SimulateTx(err)) + } }; // .map_err(BroadcastTxCommitError::SimulateTx)?; @@ -686,6 +673,11 @@ impl PluginServer for Module { None::<()>, ), }, + BroadcastTxCommitError::SimulateTx(err) => ErrorObject::owned( + FATAL_JSONRPC_ERROR_CODE, + format!("tx simulation failed: {}", ErrorReporter(err)), + None::<()>, + ), BroadcastTxCommitError::IbcUnionError(_) => ErrorObject::owned( FATAL_JSONRPC_ERROR_CODE, ErrorReporter(err).to_string(), From da9e48faac9a0e1e2b379a486b0ad7c0f720f5c6 Mon Sep 17 00:00:00 2001 From: benluelo Date: Wed, 22 Jan 2025 09:54:46 +0000 Subject: [PATCH 2/2] feat(voyager): improve logging for cosmos sdk event sourcing --- .../event-source/cosmos-sdk/src/main.rs | 2663 ++++++++--------- 1 file changed, 1319 insertions(+), 1344 deletions(-) diff --git a/voyager/plugins/event-source/cosmos-sdk/src/main.rs b/voyager/plugins/event-source/cosmos-sdk/src/main.rs index d2a9348e0d..a2d75a68ff 100644 --- a/voyager/plugins/event-source/cosmos-sdk/src/main.rs +++ b/voyager/plugins/event-source/cosmos-sdk/src/main.rs @@ -324,1348 +324,8 @@ impl PluginServer for Module { tx_hash, event, }) => { - // events at height N are provable at height N+k where k<0 - let provable_height = height.increment(); - let voyager_client = e.try_get::()?; - - match event { - IbcEvent::CreateClient { ref client_id, .. } - | IbcEvent::UpdateClient { ref client_id, .. } - | IbcEvent::ClientMisbehaviour { ref client_id, .. } - | IbcEvent::ConnectionOpenInit { ref client_id, .. } - | IbcEvent::ConnectionOpenTry { ref client_id, .. } - | IbcEvent::ConnectionOpenAck { ref client_id, .. } - | IbcEvent::ConnectionOpenConfirm { ref client_id, .. } => { - let client_info = voyager_client - .client_info::(self.chain_id.clone(), client_id.clone()) - .await?; - - let client_meta = voyager_client - .client_meta::( - self.chain_id.clone(), - height.into(), - client_id.clone(), - ) - .await?; - - Ok(data(ChainEvent { - chain_id: self.chain_id.clone(), - client_info, - counterparty_chain_id: client_meta.chain_id, - tx_hash, - provable_height, - ibc_spec_id: IbcClassic::ID, - event: into_value::(match event { - IbcEvent::CreateClient { - client_id, - client_type, - consensus_height, - } => ibc_classic_spec::CreateClient { - client_id, - client_type: ClientType::new(client_type), - consensus_height, - } - .into(), - IbcEvent::UpdateClient { - client_id, - client_type, - consensus_heights, - } => ibc_classic_spec::UpdateClient { - client_id, - client_type: ClientType::new(client_type), - consensus_heights, - } - .into(), - IbcEvent::ConnectionOpenInit { - connection_id, - client_id, - counterparty_client_id, - } => { - ibc_classic_spec::ConnectionOpenInit { - client_id, - connection_id, - counterparty_client_id, - } - } - .into(), - IbcEvent::ConnectionOpenTry { - connection_id, - client_id, - counterparty_client_id, - counterparty_connection_id, - } => { - ibc_classic_spec::ConnectionOpenTry { - client_id, - connection_id, - counterparty_client_id, - counterparty_connection_id, - } - } - .into(), - IbcEvent::ConnectionOpenAck { - connection_id, - client_id, - counterparty_client_id, - counterparty_connection_id, - } => { - ibc_classic_spec::ConnectionOpenAck { - client_id, - connection_id, - counterparty_client_id, - counterparty_connection_id, - } - } - .into(), - IbcEvent::ConnectionOpenConfirm { - connection_id, - client_id, - counterparty_client_id, - counterparty_connection_id, - } => { - ibc_classic_spec::ConnectionOpenConfirm { - client_id, - connection_id, - counterparty_client_id, - counterparty_connection_id, - } - } - .into(), - _ => unreachable!("who needs flow typing"), - }), - })) - } - - IbcEvent::ChannelOpenInit { - ref connection_id, .. - } - | IbcEvent::ChannelOpenTry { - ref connection_id, .. - } => { - let connection = voyager_client - .query_ibc_state( - self.chain_id.clone(), - height.into(), - ibc_classic_spec::ConnectionPath { - connection_id: connection_id.clone(), - }, - ) - .await? - .state - .ok_or_else(missing_state("connection must exist", None))?; - - let client_info = voyager_client - .client_info::( - self.chain_id.clone(), - connection.client_id.clone(), - ) - .await?; - - let client_meta = voyager_client - .client_meta::( - self.chain_id.clone(), - height.into(), - connection.client_id.clone(), - ) - .await?; - - Ok(data(ChainEvent { - chain_id: self.chain_id.clone(), - client_info, - counterparty_chain_id: client_meta.chain_id, - tx_hash, - provable_height, - ibc_spec_id: IbcClassic::ID, - event: into_value::(match event { - IbcEvent::ChannelOpenInit { - port_id, - channel_id, - counterparty_port_id, - version, - .. - } => { - ibc_classic_spec::ChannelOpenInit { - port_id, - channel_id, - counterparty_port_id, - connection, - version, - } - } - .into(), - IbcEvent::ChannelOpenTry { - port_id, - channel_id, - counterparty_port_id, - counterparty_channel_id, - version, - .. - } => ibc_classic_spec::ChannelOpenTry { - port_id, - channel_id, - counterparty_port_id, - counterparty_channel_id, - connection, - version, - } - .into(), - _ => unreachable!("who needs flow typing"), - }), - })) - } - - IbcEvent::ChannelOpenAck { - ref connection_id, - ref port_id, - ref channel_id, - .. - } - | IbcEvent::ChannelOpenConfirm { - ref connection_id, - ref port_id, - ref channel_id, - .. - } => { - let connection = voyager_client - .query_ibc_state( - self.chain_id.clone(), - height.into(), - ibc_classic_spec::ConnectionPath { - connection_id: connection_id.clone(), - }, - ) - .await? - .state - .ok_or_else(missing_state("connection must exist", None))?; - - let client_info = voyager_client - .client_info::( - self.chain_id.clone(), - connection.client_id.clone(), - ) - .await?; - - let client_meta = voyager_client - .client_meta::( - self.chain_id.clone(), - height.into(), - connection.client_id.clone(), - ) - .await?; - - let channel = voyager_client - .query_ibc_state( - self.chain_id.clone(), - height.into(), - ibc_classic_spec::ChannelEndPath { - port_id: port_id.to_owned(), - channel_id: channel_id.to_owned(), - }, - ) - .await? - .state - .ok_or_else(missing_state("channel must exist", None))?; - - Ok(data(ChainEvent { - chain_id: self.chain_id.clone(), - client_info, - counterparty_chain_id: client_meta.chain_id, - tx_hash, - provable_height, - ibc_spec_id: IbcClassic::ID, - event: into_value::(match event { - IbcEvent::ChannelOpenAck { - port_id, - channel_id, - counterparty_port_id, - counterparty_channel_id, - connection_id: _, - } => { - ibc_classic_spec::ChannelOpenAck { - port_id, - channel_id, - counterparty_port_id, - counterparty_channel_id, - connection, - version: channel.version, - } - } - .into(), - IbcEvent::ChannelOpenConfirm { - port_id, - channel_id, - counterparty_port_id, - counterparty_channel_id, - connection_id: _, - } => ibc_classic_spec::ChannelOpenConfirm { - port_id, - channel_id, - counterparty_port_id, - counterparty_channel_id, - connection, - version: channel.version, - } - .into(), - _ => unreachable!("who needs flow typing"), - }), - })) - } - // packet origin is this chain - IbcEvent::SendPacket { - packet_data_hex, - packet_timeout_height, - packet_timeout_timestamp, - packet_sequence, - packet_src_port, - packet_src_channel, - packet_dst_port, - packet_dst_channel, - packet_channel_ordering: _, - connection_id, - } => { - let ( - counterparty_chain_id, - client_info, - source_channel, - destination_channel, - channel_ordering, - ) = self - .make_packet_metadata( - height, - connection_id.to_owned(), - packet_src_port.to_owned(), - packet_src_channel.to_owned(), - packet_dst_port.to_owned(), - packet_dst_channel.to_owned(), - voyager_client, - ) - .await?; - - Ok(data(ChainEvent { - chain_id: self.chain_id.clone(), - client_info, - counterparty_chain_id, - tx_hash, - provable_height, - ibc_spec_id: IbcClassic::ID, - event: into_value::( - ibc_classic_spec::SendPacket { - packet_data: packet_data_hex.into_encoding(), - packet: ibc_classic_spec::PacketMetadata { - sequence: packet_sequence, - source_channel, - destination_channel, - channel_ordering, - timeout_height: packet_timeout_height, - timeout_timestamp: packet_timeout_timestamp, - }, - } - .into(), - ), - })) - } - IbcEvent::TimeoutPacket { - packet_timeout_height, - packet_timeout_timestamp, - packet_sequence, - packet_src_port, - packet_src_channel, - packet_dst_port, - packet_dst_channel, - packet_channel_ordering: _, - connection_id, - } => { - let ( - counterparty_chain_id, - client_info, - source_channel, - destination_channel, - channel_ordering, - ) = self - .make_packet_metadata( - height, - connection_id.to_owned(), - packet_src_port.to_owned(), - packet_src_channel.to_owned(), - packet_dst_port.to_owned(), - packet_dst_channel.to_owned(), - voyager_client, - ) - .await?; - - Ok(data(ChainEvent { - chain_id: self.chain_id.clone(), - client_info, - counterparty_chain_id, - tx_hash, - provable_height, - ibc_spec_id: IbcClassic::ID, - event: into_value::( - ibc_classic_spec::TimeoutPacket { - packet: ibc_classic_spec::PacketMetadata { - sequence: packet_sequence, - source_channel, - destination_channel, - channel_ordering, - timeout_height: packet_timeout_height, - timeout_timestamp: packet_timeout_timestamp, - }, - } - .into(), - ), - })) - } - IbcEvent::AcknowledgePacket { - packet_timeout_height, - packet_timeout_timestamp, - packet_sequence, - packet_src_port, - packet_src_channel, - packet_dst_port, - packet_dst_channel, - packet_channel_ordering: _, - connection_id, - } => { - let ( - counterparty_chain_id, - client_info, - source_channel, - destination_channel, - channel_ordering, - ) = self - .make_packet_metadata( - height, - connection_id.to_owned(), - packet_src_port.to_owned(), - packet_src_channel.to_owned(), - packet_dst_port.to_owned(), - packet_dst_channel.to_owned(), - voyager_client, - ) - .await?; - - Ok(data(ChainEvent { - chain_id: self.chain_id.clone(), - client_info, - counterparty_chain_id, - tx_hash, - provable_height, - ibc_spec_id: IbcClassic::ID, - event: into_value::( - ibc_classic_spec::AcknowledgePacket { - packet: ibc_classic_spec::PacketMetadata { - sequence: packet_sequence, - source_channel, - destination_channel, - channel_ordering, - timeout_height: packet_timeout_height, - timeout_timestamp: packet_timeout_timestamp, - }, - } - .into(), - ), - })) - } - // packet origin is the counterparty chain (if i put this comment above this pattern rustfmt explodes) - IbcEvent::WriteAcknowledgement { - packet_data_hex, - packet_timeout_height, - packet_timeout_timestamp, - packet_sequence, - packet_src_port, - packet_src_channel, - packet_dst_port, - packet_dst_channel, - packet_ack_hex, - connection_id, - } => { - let ( - counterparty_chain_id, - client_info, - destination_channel, - source_channel, - channel_ordering, - ) = self - .make_packet_metadata( - height, - connection_id.to_owned(), - packet_dst_port.to_owned(), - packet_dst_channel.to_owned(), - packet_src_port.to_owned(), - packet_src_channel.to_owned(), - voyager_client, - ) - .await?; - - Ok(data(ChainEvent { - chain_id: self.chain_id.clone(), - client_info, - counterparty_chain_id, - tx_hash, - provable_height, - ibc_spec_id: IbcClassic::ID, - event: into_value::( - ibc_classic_spec::WriteAcknowledgement { - packet_data: packet_data_hex.into_encoding(), - packet_ack: packet_ack_hex.into_encoding(), - packet: ibc_classic_spec::PacketMetadata { - sequence: packet_sequence, - source_channel, - destination_channel, - channel_ordering, - timeout_height: packet_timeout_height, - timeout_timestamp: packet_timeout_timestamp, - }, - } - .into(), - ), - })) - } - IbcEvent::RecvPacket { - packet_data_hex, - packet_timeout_height, - packet_timeout_timestamp, - packet_sequence, - packet_src_port, - packet_src_channel, - packet_dst_port, - packet_dst_channel, - packet_channel_ordering: _, - connection_id, - } => { - let ( - counterparty_chain_id, - client_info, - destination_channel, - source_channel, - channel_ordering, - ) = self - .make_packet_metadata( - height, - connection_id.to_owned(), - packet_dst_port.to_owned(), - packet_dst_channel.to_owned(), - packet_src_port.to_owned(), - packet_src_channel.to_owned(), - voyager_client, - ) - .await?; - - Ok(data(ChainEvent { - chain_id: self.chain_id.clone(), - client_info, - counterparty_chain_id, - tx_hash, - provable_height, - ibc_spec_id: IbcClassic::ID, - event: into_value::( - ibc_classic_spec::RecvPacket { - packet_data: packet_data_hex.into_encoding(), - packet: ibc_classic_spec::PacketMetadata { - sequence: packet_sequence, - source_channel, - destination_channel, - channel_ordering, - timeout_height: packet_timeout_height, - timeout_timestamp: packet_timeout_timestamp, - }, - } - .into(), - ), - })) - } - IbcEvent::WasmCreateClient { - client_id, - client_type, - } => { - let client_info = voyager_client - .client_info::(self.chain_id.clone(), client_id) - .await?; - - let client_meta = voyager_client - .client_meta::( - self.chain_id.clone(), - height.into(), - client_id, - ) - .await?; - - let event = ibc_union_spec::event::CreateClient { - client_id, - client_type: ClientType::new(client_type), - } - .into(); - - ibc_union_spec::log_event(&event, &self.chain_id); - - Ok(data(ChainEvent { - chain_id: self.chain_id.clone(), - client_info, - counterparty_chain_id: client_meta.chain_id, - tx_hash, - provable_height, - ibc_spec_id: IbcUnion::ID, - event: into_value::(event), - })) - } - IbcEvent::WasmUpdateClient { - client_id, - counterparty_height, - } => { - let client_info = voyager_client - .client_info::(self.chain_id.clone(), client_id) - .await?; - - let client_meta = voyager_client - .client_meta::( - self.chain_id.clone(), - height.into(), - client_id, - ) - .await?; - - let event = ibc_union_spec::event::UpdateClient { - client_id, - client_type: client_info.client_type.clone(), - height: counterparty_height, - } - .into(); - - ibc_union_spec::log_event(&event, &self.chain_id); - - Ok(data(ChainEvent { - chain_id: self.chain_id.clone(), - client_info: client_info.clone(), - counterparty_chain_id: client_meta.chain_id, - tx_hash, - provable_height, - ibc_spec_id: IbcUnion::ID, - event: into_value::(event), - })) - } - IbcEvent::WasmConnectionOpenInit { - connection_id, - client_id, - counterparty_client_id, - } => { - let client_info = voyager_client - .client_info::(self.chain_id.clone(), client_id) - .await?; - - let client_meta = voyager_client - .client_meta::( - self.chain_id.clone(), - height.into(), - client_id, - ) - .await?; - - let event = ibc_union_spec::event::ConnectionOpenInit { - client_id, - connection_id, - counterparty_client_id, - } - .into(); - - ibc_union_spec::log_event(&event, &self.chain_id); - - Ok(data(ChainEvent { - chain_id: self.chain_id.clone(), - client_info, - counterparty_chain_id: client_meta.chain_id, - tx_hash, - provable_height, - ibc_spec_id: IbcUnion::ID, - event: into_value::(event), - })) - } - IbcEvent::WasmConnectionOpenTry { - connection_id, - client_id, - counterparty_client_id, - counterparty_connection_id, - } => { - let client_info = voyager_client - .client_info::(self.chain_id.clone(), client_id) - .await?; - - let client_meta = voyager_client - .client_meta::( - self.chain_id.clone(), - height.into(), - client_id, - ) - .await?; - - let event = ibc_union_spec::event::ConnectionOpenTry { - connection_id, - counterparty_connection_id, - client_id, - counterparty_client_id, - } - .into(); - - ibc_union_spec::log_event(&event, &self.chain_id); - - Ok(data(ChainEvent { - chain_id: self.chain_id.clone(), - client_info, - counterparty_chain_id: client_meta.chain_id, - tx_hash, - provable_height, - ibc_spec_id: IbcUnion::ID, - event: into_value::(event), - })) - } - IbcEvent::WasmConnectionOpenAck { - connection_id, - client_id, - counterparty_client_id, - counterparty_connection_id, - } => { - let client_info = voyager_client - .client_info::(self.chain_id.clone(), client_id) - .await?; - - let client_meta = voyager_client - .client_meta::( - self.chain_id.clone(), - height.into(), - client_id, - ) - .await?; - - let event = ibc_union_spec::event::ConnectionOpenAck { - connection_id, - counterparty_connection_id, - client_id, - counterparty_client_id, - } - .into(); - - ibc_union_spec::log_event(&event, &self.chain_id); - - Ok(data(ChainEvent { - chain_id: self.chain_id.clone(), - client_info, - counterparty_chain_id: client_meta.chain_id, - tx_hash, - provable_height, - ibc_spec_id: IbcUnion::ID, - event: into_value::(event), - })) - } - IbcEvent::WasmConnectionOpenConfirm { - connection_id, - client_id, - counterparty_client_id, - counterparty_connection_id, - } => { - let client_info = voyager_client - .client_info::(self.chain_id.clone(), client_id) - .await?; - - let client_meta = voyager_client - .client_meta::( - self.chain_id.clone(), - height.into(), - client_id, - ) - .await?; - - let event = ibc_union_spec::event::ConnectionOpenConfirm { - connection_id, - counterparty_connection_id, - client_id, - counterparty_client_id, - } - .into(); - - ibc_union_spec::log_event(&event, &self.chain_id); - - Ok(data(ChainEvent { - chain_id: self.chain_id.clone(), - client_info, - counterparty_chain_id: client_meta.chain_id, - tx_hash, - provable_height, - ibc_spec_id: IbcUnion::ID, - event: into_value::(event), - })) - } - IbcEvent::WasmChannelOpenInit { - port_id, - channel_id, - counterparty_port_id, - connection_id, - version, - } => { - let connection = voyager_client - .query_ibc_state( - self.chain_id.clone(), - QueryHeight::Specific(height), - ibc_union_spec::path::ConnectionPath { connection_id }, - ) - .await? - .state - .unwrap(); - - let client_info = voyager_client - .client_info::(self.chain_id.clone(), connection.client_id) - .await?; - - let client_meta = voyager_client - .client_meta::( - self.chain_id.clone(), - height.into(), - connection.client_id, - ) - .await?; - - let event = ibc_union_spec::event::ChannelOpenInit { - port_id: port_id.to_string().into_bytes().into(), - channel_id, - counterparty_port_id: counterparty_port_id.into_encoding(), - connection, - version, - } - .into(); - - ibc_union_spec::log_event(&event, &self.chain_id); - - Ok(data(ChainEvent { - chain_id: self.chain_id.clone(), - client_info, - counterparty_chain_id: client_meta.chain_id, - tx_hash, - provable_height, - ibc_spec_id: IbcUnion::ID, - event: into_value::(event), - })) - } - IbcEvent::WasmChannelOpenTry { - port_id, - channel_id, - counterparty_port_id, - counterparty_channel_id, - connection_id, - counterparty_version, - } => { - let connection = voyager_client - .query_ibc_state( - self.chain_id.clone(), - QueryHeight::Specific(height), - ibc_union_spec::path::ConnectionPath { connection_id }, - ) - .await? - .state - .unwrap(); - - let client_info = voyager_client - .client_info::(self.chain_id.clone(), connection.client_id) - .await?; - - let client_meta = voyager_client - .client_meta::( - self.chain_id.clone(), - height.into(), - connection.client_id, - ) - .await?; - - let event = ibc_union_spec::event::ChannelOpenTry { - port_id: port_id.to_string().into_bytes().into(), - channel_id, - counterparty_port_id: counterparty_port_id.into_encoding(), - counterparty_channel_id, - connection, - version: counterparty_version, - } - .into(); - - ibc_union_spec::log_event(&event, &self.chain_id); - - Ok(data(ChainEvent { - chain_id: self.chain_id.clone(), - client_info, - counterparty_chain_id: client_meta.chain_id, - tx_hash, - provable_height, - ibc_spec_id: IbcUnion::ID, - event: into_value::(event), - })) - } - IbcEvent::WasmChannelOpenAck { - port_id, - channel_id, - counterparty_port_id, - counterparty_channel_id, - connection_id, - } => { - let connection = voyager_client - .query_ibc_state( - self.chain_id.clone(), - QueryHeight::Specific(height), - ibc_union_spec::path::ConnectionPath { connection_id }, - ) - .await? - .state - .unwrap(); - - let client_info = voyager_client - .client_info::(self.chain_id.clone(), connection.client_id) - .await?; - - let client_meta = voyager_client - .client_meta::( - self.chain_id.clone(), - height.into(), - connection.client_id, - ) - .await?; - - let channel = voyager_client - .query_ibc_state( - self.chain_id.clone(), - height.into(), - ChannelPath { channel_id }, - ) - .await? - .state - .ok_or_else(missing_state("channel must exist", None))?; - - let event = ibc_union_spec::event::ChannelOpenAck { - port_id: port_id.to_string().into_bytes().into(), - channel_id, - counterparty_port_id: counterparty_port_id.into_encoding(), - counterparty_channel_id, - connection, - version: channel.version, - } - .into(); - - ibc_union_spec::log_event(&event, &self.chain_id); - - Ok(data(ChainEvent { - chain_id: self.chain_id.clone(), - client_info, - counterparty_chain_id: client_meta.chain_id, - tx_hash, - provable_height, - ibc_spec_id: IbcUnion::ID, - event: into_value::(event), - })) - } - - IbcEvent::WasmChannelOpenConfirm { - port_id, - channel_id, - counterparty_port_id, - counterparty_channel_id, - connection_id, - } => { - let channel = voyager_client - .query_ibc_state( - self.chain_id.clone(), - QueryHeight::Specific(height), - ibc_union_spec::path::ChannelPath { channel_id }, - ) - .await? - .state - .unwrap(); - - let connection = voyager_client - .query_ibc_state( - self.chain_id.clone(), - QueryHeight::Specific(height), - ibc_union_spec::path::ConnectionPath { connection_id }, - ) - .await? - .state - .unwrap(); - - let client_info = voyager_client - .client_info::(self.chain_id.clone(), connection.client_id) - .await?; - - let client_meta = voyager_client - .client_meta::( - self.chain_id.clone(), - height.into(), - connection.client_id, - ) - .await?; - - let event = ibc_union_spec::event::ChannelOpenConfirm { - port_id: port_id.to_string().into_bytes().into(), - channel_id, - counterparty_port_id: counterparty_port_id.into_encoding(), - counterparty_channel_id, - connection, - version: channel.version, - } - .into(); - - ibc_union_spec::log_event(&event, &self.chain_id); - - Ok(data(ChainEvent { - chain_id: self.chain_id.clone(), - client_info, - counterparty_chain_id: client_meta.chain_id, - tx_hash, - provable_height, - ibc_spec_id: IbcUnion::ID, - event: into_value::(event), - })) - } - IbcEvent::WasmPacketSend { packet } => { - let source_channel = voyager_client - .query_ibc_state( - self.chain_id.clone(), - QueryHeight::Specific(height), - ibc_union_spec::path::ChannelPath { - channel_id: packet.source_channel_id, - }, - ) - .await? - .state - .unwrap(); - - let source_connection = voyager_client - .query_ibc_state( - self.chain_id.clone(), - QueryHeight::Specific(height), - ibc_union_spec::path::ConnectionPath { - connection_id: source_channel.connection_id, - }, - ) - .await? - .state - .unwrap(); - - let client_info = voyager_client - .client_info::( - self.chain_id.clone(), - source_connection.client_id, - ) - .await?; - - let client_meta = voyager_client - .client_meta::( - self.chain_id.clone(), - height.into(), - source_connection.client_id, - ) - .await?; - - let event = ibc_union_spec::event::PacketSend { - packet_data: packet.data.into(), - packet: ibc_union_spec::event::PacketMetadata { - source_channel: ibc_union_spec::event::ChannelMetadata { - channel_id: packet.source_channel_id, - version: source_channel.version.clone(), - connection: ibc_union_spec::event::ConnectionMetadata { - client_id: source_connection.client_id, - connection_id: source_channel.connection_id, - }, - }, - destination_channel: ibc_union_spec::event::ChannelMetadata { - channel_id: packet.destination_channel_id, - version: source_channel.version, - connection: ibc_union_spec::event::ConnectionMetadata { - client_id: source_connection.counterparty_client_id, - connection_id: source_connection.counterparty_connection_id, - }, - }, - timeout_height: packet.timeout_height, - timeout_timestamp: packet.timeout_timestamp, - }, - } - .into(); - - ibc_union_spec::log_event(&event, &self.chain_id); - - Ok(data(ChainEvent { - chain_id: self.chain_id.clone(), - client_info, - counterparty_chain_id: client_meta.chain_id, - tx_hash, - provable_height, - ibc_spec_id: IbcUnion::ID, - event: into_value::(event), - })) - } - IbcEvent::WasmPacketAck { - packet, - acknowledgement, - } => { - let source_channel = voyager_client - .query_ibc_state( - self.chain_id.clone(), - QueryHeight::Specific(height), - ibc_union_spec::path::ChannelPath { - channel_id: packet.source_channel_id, - }, - ) - .await? - .state - .unwrap(); - - let source_connection = voyager_client - .query_ibc_state( - self.chain_id.clone(), - QueryHeight::Specific(height), - ibc_union_spec::path::ConnectionPath { - connection_id: source_channel.connection_id, - }, - ) - .await? - .state - .unwrap(); - - let client_info = voyager_client - .client_info::( - self.chain_id.clone(), - source_connection.client_id, - ) - .await?; - - let client_meta = voyager_client - .client_meta::( - self.chain_id.clone(), - height.into(), - source_connection.client_id, - ) - .await?; - - let event = ibc_union_spec::event::PacketAck { - packet_data: packet.data.into(), - packet: ibc_union_spec::event::PacketMetadata { - source_channel: ibc_union_spec::event::ChannelMetadata { - channel_id: packet.source_channel_id, - version: source_channel.version.clone(), - connection: ibc_union_spec::event::ConnectionMetadata { - client_id: source_connection.client_id, - connection_id: source_channel.connection_id, - }, - }, - destination_channel: ibc_union_spec::event::ChannelMetadata { - channel_id: packet.destination_channel_id, - version: source_channel.version, - connection: ibc_union_spec::event::ConnectionMetadata { - client_id: source_connection.counterparty_client_id, - connection_id: source_connection.counterparty_connection_id, - }, - }, - timeout_height: packet.timeout_height, - timeout_timestamp: packet.timeout_timestamp, - }, - acknowledgement: acknowledgement.into_encoding(), - } - .into(); - - ibc_union_spec::log_event(&event, &self.chain_id); - - Ok(data(ChainEvent { - chain_id: self.chain_id.clone(), - client_info, - counterparty_chain_id: client_meta.chain_id, - tx_hash, - provable_height, - ibc_spec_id: IbcUnion::ID, - event: into_value::(event), - })) - } - IbcEvent::WasmPacketRecv { - packet, - relayer_msg, - } => { - let destination_channel = voyager_client - .query_ibc_state( - self.chain_id.clone(), - QueryHeight::Specific(height), - ibc_union_spec::path::ChannelPath { - channel_id: packet.destination_channel_id, - }, - ) - .await? - .state - .unwrap(); - - let destination_connection = voyager_client - .query_ibc_state( - self.chain_id.clone(), - QueryHeight::Specific(height), - ibc_union_spec::path::ConnectionPath { - connection_id: destination_channel.connection_id, - }, - ) - .await? - .state - .unwrap(); - - let client_info = voyager_client - .client_info::( - self.chain_id.clone(), - destination_connection.client_id, - ) - .await?; - - let client_meta = voyager_client - .client_meta::( - self.chain_id.clone(), - height.into(), - destination_connection.client_id, - ) - .await?; - - let source_channel = voyager_client - .query_ibc_state( - client_meta.chain_id.clone(), - QueryHeight::Latest, - ibc_union_spec::path::ChannelPath { - channel_id: packet.source_channel_id, - }, - ) - .await? - .state - .unwrap(); - - let event = ibc_union_spec::event::PacketRecv { - packet_data: packet.data.into(), - packet: ibc_union_spec::event::PacketMetadata { - source_channel: ibc_union_spec::event::ChannelMetadata { - channel_id: packet.source_channel_id, - version: source_channel.version.clone(), - connection: ibc_union_spec::event::ConnectionMetadata { - client_id: destination_connection.counterparty_client_id, - connection_id: destination_connection - .counterparty_connection_id, - }, - }, - destination_channel: ibc_union_spec::event::ChannelMetadata { - channel_id: packet.destination_channel_id, - version: destination_channel.version.clone(), - - connection: ibc_union_spec::event::ConnectionMetadata { - client_id: destination_connection.client_id, - connection_id: destination_channel.connection_id, - }, - }, - timeout_height: packet.timeout_height, - timeout_timestamp: packet.timeout_timestamp, - }, - relayer_msg: relayer_msg.into_encoding(), - } - .into(); - - ibc_union_spec::log_event(&event, &self.chain_id); - - Ok(data(ChainEvent { - chain_id: self.chain_id.clone(), - client_info, - counterparty_chain_id: client_meta.chain_id, - tx_hash, - provable_height, - ibc_spec_id: IbcUnion::ID, - event: into_value::(event), - })) - } - IbcEvent::WasmWriteAck { - packet, - acknowledgement, - } => { - let destination_channel = voyager_client - .query_ibc_state( - self.chain_id.clone(), - QueryHeight::Specific(height), - ibc_union_spec::path::ChannelPath { - channel_id: packet.destination_channel_id, - }, - ) - .await? - .state - .unwrap(); - - let destination_connection = voyager_client - .query_ibc_state( - self.chain_id.clone(), - QueryHeight::Specific(height), - ibc_union_spec::path::ConnectionPath { - connection_id: destination_channel.connection_id, - }, - ) - .await? - .state - .unwrap(); - - let client_info = voyager_client - .client_info::( - self.chain_id.clone(), - destination_connection.client_id, - ) - .await?; - - let client_meta = voyager_client - .client_meta::( - self.chain_id.clone(), - height.into(), - destination_connection.client_id, - ) - .await?; - - let source_channel = voyager_client - .query_ibc_state( - client_meta.chain_id.clone(), - QueryHeight::Latest, - ibc_union_spec::path::ChannelPath { - channel_id: packet.source_channel_id, - }, - ) - .await? - .state - .unwrap(); - - let event = ibc_union_spec::event::WriteAck { - packet_data: packet.data.into(), - packet: ibc_union_spec::event::PacketMetadata { - source_channel: ibc_union_spec::event::ChannelMetadata { - channel_id: packet.source_channel_id, - version: source_channel.version.clone(), - connection: ibc_union_spec::event::ConnectionMetadata { - client_id: destination_connection.counterparty_client_id, - connection_id: destination_connection - .counterparty_connection_id, - }, - }, - destination_channel: ibc_union_spec::event::ChannelMetadata { - channel_id: packet.destination_channel_id, - version: destination_channel.version.clone(), - - connection: ibc_union_spec::event::ConnectionMetadata { - client_id: destination_connection.client_id, - connection_id: destination_channel.connection_id, - }, - }, - timeout_height: packet.timeout_height, - timeout_timestamp: packet.timeout_timestamp, - }, - acknowledgement: acknowledgement.into_encoding(), - } - .into(); - - ibc_union_spec::log_event(&event, &self.chain_id); - - Ok(data(ChainEvent { - chain_id: self.chain_id.clone(), - client_info, - counterparty_chain_id: client_meta.chain_id, - tx_hash, - provable_height, - ibc_spec_id: IbcUnion::ID, - event: into_value::(event), - })) - } - } + self.make_chain_event(e.try_get::()?, height, tx_hash, event) + .await } } } @@ -1685,7 +345,7 @@ fn rpc_error( } impl Module { - #[instrument(skip_all, fields(height))] + #[instrument(skip_all, fields(%height))] async fn fetch_blocks( &self, voyager_client: &VoyagerClient, @@ -1780,7 +440,7 @@ impl Module { } } - #[instrument(skip_all, fields(height, page))] + #[instrument(skip_all, fields(%height, %page))] async fn fetch_transaction( &self, height: Height, @@ -1874,4 +534,1319 @@ impl Module { ), )) } + + #[instrument(level = "info", skip_all, fields(%height, %tx_hash))] + async fn make_chain_event( + &self, + voyager_client: &VoyagerClient, + height: Height, + tx_hash: H256, + event: IbcEvent, + ) -> RpcResult> { + // events at height N are provable at height N+k where k<0 + let provable_height = height.increment(); + + debug!(?event, "raw event"); + + match event { + IbcEvent::CreateClient { ref client_id, .. } + | IbcEvent::UpdateClient { ref client_id, .. } + | IbcEvent::ClientMisbehaviour { ref client_id, .. } + | IbcEvent::ConnectionOpenInit { ref client_id, .. } + | IbcEvent::ConnectionOpenTry { ref client_id, .. } + | IbcEvent::ConnectionOpenAck { ref client_id, .. } + | IbcEvent::ConnectionOpenConfirm { ref client_id, .. } => { + let client_info = voyager_client + .client_info::(self.chain_id.clone(), client_id.clone()) + .await?; + + let client_meta = voyager_client + .client_meta::( + self.chain_id.clone(), + height.into(), + client_id.clone(), + ) + .await?; + + Ok(data(ChainEvent { + chain_id: self.chain_id.clone(), + client_info, + counterparty_chain_id: client_meta.chain_id, + tx_hash, + provable_height, + ibc_spec_id: IbcClassic::ID, + event: into_value::(match event { + IbcEvent::CreateClient { + client_id, + client_type, + consensus_height, + } => ibc_classic_spec::CreateClient { + client_id, + client_type: ClientType::new(client_type), + consensus_height, + } + .into(), + IbcEvent::UpdateClient { + client_id, + client_type, + consensus_heights, + } => ibc_classic_spec::UpdateClient { + client_id, + client_type: ClientType::new(client_type), + consensus_heights, + } + .into(), + IbcEvent::ConnectionOpenInit { + connection_id, + client_id, + counterparty_client_id, + } => { + ibc_classic_spec::ConnectionOpenInit { + client_id, + connection_id, + counterparty_client_id, + } + } + .into(), + IbcEvent::ConnectionOpenTry { + connection_id, + client_id, + counterparty_client_id, + counterparty_connection_id, + } => { + ibc_classic_spec::ConnectionOpenTry { + client_id, + connection_id, + counterparty_client_id, + counterparty_connection_id, + } + } + .into(), + IbcEvent::ConnectionOpenAck { + connection_id, + client_id, + counterparty_client_id, + counterparty_connection_id, + } => { + ibc_classic_spec::ConnectionOpenAck { + client_id, + connection_id, + counterparty_client_id, + counterparty_connection_id, + } + } + .into(), + IbcEvent::ConnectionOpenConfirm { + connection_id, + client_id, + counterparty_client_id, + counterparty_connection_id, + } => { + ibc_classic_spec::ConnectionOpenConfirm { + client_id, + connection_id, + counterparty_client_id, + counterparty_connection_id, + } + } + .into(), + _ => unreachable!("who needs flow typing"), + }), + })) + } + + IbcEvent::ChannelOpenInit { + ref connection_id, .. + } + | IbcEvent::ChannelOpenTry { + ref connection_id, .. + } => { + let connection = voyager_client + .query_ibc_state( + self.chain_id.clone(), + height.into(), + ibc_classic_spec::ConnectionPath { + connection_id: connection_id.clone(), + }, + ) + .await? + .state + .ok_or_else(missing_state("connection must exist", None))?; + + let client_info = voyager_client + .client_info::(self.chain_id.clone(), connection.client_id.clone()) + .await?; + + let client_meta = voyager_client + .client_meta::( + self.chain_id.clone(), + height.into(), + connection.client_id.clone(), + ) + .await?; + + Ok(data(ChainEvent { + chain_id: self.chain_id.clone(), + client_info, + counterparty_chain_id: client_meta.chain_id, + tx_hash, + provable_height, + ibc_spec_id: IbcClassic::ID, + event: into_value::(match event { + IbcEvent::ChannelOpenInit { + port_id, + channel_id, + counterparty_port_id, + version, + .. + } => { + ibc_classic_spec::ChannelOpenInit { + port_id, + channel_id, + counterparty_port_id, + connection, + version, + } + } + .into(), + IbcEvent::ChannelOpenTry { + port_id, + channel_id, + counterparty_port_id, + counterparty_channel_id, + version, + .. + } => ibc_classic_spec::ChannelOpenTry { + port_id, + channel_id, + counterparty_port_id, + counterparty_channel_id, + connection, + version, + } + .into(), + _ => unreachable!("who needs flow typing"), + }), + })) + } + + IbcEvent::ChannelOpenAck { + ref connection_id, + ref port_id, + ref channel_id, + .. + } + | IbcEvent::ChannelOpenConfirm { + ref connection_id, + ref port_id, + ref channel_id, + .. + } => { + let connection = voyager_client + .query_ibc_state( + self.chain_id.clone(), + height.into(), + ibc_classic_spec::ConnectionPath { + connection_id: connection_id.clone(), + }, + ) + .await? + .state + .ok_or_else(missing_state("connection must exist", None))?; + + let client_info = voyager_client + .client_info::(self.chain_id.clone(), connection.client_id.clone()) + .await?; + + let client_meta = voyager_client + .client_meta::( + self.chain_id.clone(), + height.into(), + connection.client_id.clone(), + ) + .await?; + + let channel = voyager_client + .query_ibc_state( + self.chain_id.clone(), + height.into(), + ibc_classic_spec::ChannelEndPath { + port_id: port_id.to_owned(), + channel_id: channel_id.to_owned(), + }, + ) + .await? + .state + .ok_or_else(missing_state("channel must exist", None))?; + + Ok(data(ChainEvent { + chain_id: self.chain_id.clone(), + client_info, + counterparty_chain_id: client_meta.chain_id, + tx_hash, + provable_height, + ibc_spec_id: IbcClassic::ID, + event: into_value::(match event { + IbcEvent::ChannelOpenAck { + port_id, + channel_id, + counterparty_port_id, + counterparty_channel_id, + connection_id: _, + } => { + ibc_classic_spec::ChannelOpenAck { + port_id, + channel_id, + counterparty_port_id, + counterparty_channel_id, + connection, + version: channel.version, + } + } + .into(), + IbcEvent::ChannelOpenConfirm { + port_id, + channel_id, + counterparty_port_id, + counterparty_channel_id, + connection_id: _, + } => ibc_classic_spec::ChannelOpenConfirm { + port_id, + channel_id, + counterparty_port_id, + counterparty_channel_id, + connection, + version: channel.version, + } + .into(), + _ => unreachable!("who needs flow typing"), + }), + })) + } + // packet origin is this chain + IbcEvent::SendPacket { + packet_data_hex, + packet_timeout_height, + packet_timeout_timestamp, + packet_sequence, + packet_src_port, + packet_src_channel, + packet_dst_port, + packet_dst_channel, + packet_channel_ordering: _, + connection_id, + } => { + let ( + counterparty_chain_id, + client_info, + source_channel, + destination_channel, + channel_ordering, + ) = self + .make_packet_metadata( + height, + connection_id.to_owned(), + packet_src_port.to_owned(), + packet_src_channel.to_owned(), + packet_dst_port.to_owned(), + packet_dst_channel.to_owned(), + voyager_client, + ) + .await?; + + Ok(data(ChainEvent { + chain_id: self.chain_id.clone(), + client_info, + counterparty_chain_id, + tx_hash, + provable_height, + ibc_spec_id: IbcClassic::ID, + event: into_value::( + ibc_classic_spec::SendPacket { + packet_data: packet_data_hex.into_encoding(), + packet: ibc_classic_spec::PacketMetadata { + sequence: packet_sequence, + source_channel, + destination_channel, + channel_ordering, + timeout_height: packet_timeout_height, + timeout_timestamp: packet_timeout_timestamp, + }, + } + .into(), + ), + })) + } + IbcEvent::TimeoutPacket { + packet_timeout_height, + packet_timeout_timestamp, + packet_sequence, + packet_src_port, + packet_src_channel, + packet_dst_port, + packet_dst_channel, + packet_channel_ordering: _, + connection_id, + } => { + let ( + counterparty_chain_id, + client_info, + source_channel, + destination_channel, + channel_ordering, + ) = self + .make_packet_metadata( + height, + connection_id.to_owned(), + packet_src_port.to_owned(), + packet_src_channel.to_owned(), + packet_dst_port.to_owned(), + packet_dst_channel.to_owned(), + voyager_client, + ) + .await?; + + Ok(data(ChainEvent { + chain_id: self.chain_id.clone(), + client_info, + counterparty_chain_id, + tx_hash, + provable_height, + ibc_spec_id: IbcClassic::ID, + event: into_value::( + ibc_classic_spec::TimeoutPacket { + packet: ibc_classic_spec::PacketMetadata { + sequence: packet_sequence, + source_channel, + destination_channel, + channel_ordering, + timeout_height: packet_timeout_height, + timeout_timestamp: packet_timeout_timestamp, + }, + } + .into(), + ), + })) + } + IbcEvent::AcknowledgePacket { + packet_timeout_height, + packet_timeout_timestamp, + packet_sequence, + packet_src_port, + packet_src_channel, + packet_dst_port, + packet_dst_channel, + packet_channel_ordering: _, + connection_id, + } => { + let ( + counterparty_chain_id, + client_info, + source_channel, + destination_channel, + channel_ordering, + ) = self + .make_packet_metadata( + height, + connection_id.to_owned(), + packet_src_port.to_owned(), + packet_src_channel.to_owned(), + packet_dst_port.to_owned(), + packet_dst_channel.to_owned(), + voyager_client, + ) + .await?; + + Ok(data(ChainEvent { + chain_id: self.chain_id.clone(), + client_info, + counterparty_chain_id, + tx_hash, + provable_height, + ibc_spec_id: IbcClassic::ID, + event: into_value::( + ibc_classic_spec::AcknowledgePacket { + packet: ibc_classic_spec::PacketMetadata { + sequence: packet_sequence, + source_channel, + destination_channel, + channel_ordering, + timeout_height: packet_timeout_height, + timeout_timestamp: packet_timeout_timestamp, + }, + } + .into(), + ), + })) + } + // packet origin is the counterparty chain (if i put this comment above this pattern rustfmt explodes) + IbcEvent::WriteAcknowledgement { + packet_data_hex, + packet_timeout_height, + packet_timeout_timestamp, + packet_sequence, + packet_src_port, + packet_src_channel, + packet_dst_port, + packet_dst_channel, + packet_ack_hex, + connection_id, + } => { + let ( + counterparty_chain_id, + client_info, + destination_channel, + source_channel, + channel_ordering, + ) = self + .make_packet_metadata( + height, + connection_id.to_owned(), + packet_dst_port.to_owned(), + packet_dst_channel.to_owned(), + packet_src_port.to_owned(), + packet_src_channel.to_owned(), + voyager_client, + ) + .await?; + + Ok(data(ChainEvent { + chain_id: self.chain_id.clone(), + client_info, + counterparty_chain_id, + tx_hash, + provable_height, + ibc_spec_id: IbcClassic::ID, + event: into_value::( + ibc_classic_spec::WriteAcknowledgement { + packet_data: packet_data_hex.into_encoding(), + packet_ack: packet_ack_hex.into_encoding(), + packet: ibc_classic_spec::PacketMetadata { + sequence: packet_sequence, + source_channel, + destination_channel, + channel_ordering, + timeout_height: packet_timeout_height, + timeout_timestamp: packet_timeout_timestamp, + }, + } + .into(), + ), + })) + } + IbcEvent::RecvPacket { + packet_data_hex, + packet_timeout_height, + packet_timeout_timestamp, + packet_sequence, + packet_src_port, + packet_src_channel, + packet_dst_port, + packet_dst_channel, + packet_channel_ordering: _, + connection_id, + } => { + let ( + counterparty_chain_id, + client_info, + destination_channel, + source_channel, + channel_ordering, + ) = self + .make_packet_metadata( + height, + connection_id.to_owned(), + packet_dst_port.to_owned(), + packet_dst_channel.to_owned(), + packet_src_port.to_owned(), + packet_src_channel.to_owned(), + voyager_client, + ) + .await?; + + Ok(data(ChainEvent { + chain_id: self.chain_id.clone(), + client_info, + counterparty_chain_id, + tx_hash, + provable_height, + ibc_spec_id: IbcClassic::ID, + event: into_value::( + ibc_classic_spec::RecvPacket { + packet_data: packet_data_hex.into_encoding(), + packet: ibc_classic_spec::PacketMetadata { + sequence: packet_sequence, + source_channel, + destination_channel, + channel_ordering, + timeout_height: packet_timeout_height, + timeout_timestamp: packet_timeout_timestamp, + }, + } + .into(), + ), + })) + } + IbcEvent::WasmCreateClient { + client_id, + client_type, + } => { + let client_info = voyager_client + .client_info::(self.chain_id.clone(), client_id) + .await?; + + let client_meta = voyager_client + .client_meta::(self.chain_id.clone(), height.into(), client_id) + .await?; + + let event = ibc_union_spec::event::CreateClient { + client_id, + client_type: ClientType::new(client_type), + } + .into(); + + ibc_union_spec::log_event(&event, &self.chain_id); + + Ok(data(ChainEvent { + chain_id: self.chain_id.clone(), + client_info, + counterparty_chain_id: client_meta.chain_id, + tx_hash, + provable_height, + ibc_spec_id: IbcUnion::ID, + event: into_value::(event), + })) + } + IbcEvent::WasmUpdateClient { + client_id, + counterparty_height, + } => { + let client_info = voyager_client + .client_info::(self.chain_id.clone(), client_id) + .await?; + + let client_meta = voyager_client + .client_meta::(self.chain_id.clone(), height.into(), client_id) + .await?; + + let event = ibc_union_spec::event::UpdateClient { + client_id, + client_type: client_info.client_type.clone(), + height: counterparty_height, + } + .into(); + + ibc_union_spec::log_event(&event, &self.chain_id); + + Ok(data(ChainEvent { + chain_id: self.chain_id.clone(), + client_info: client_info.clone(), + counterparty_chain_id: client_meta.chain_id, + tx_hash, + provable_height, + ibc_spec_id: IbcUnion::ID, + event: into_value::(event), + })) + } + IbcEvent::WasmConnectionOpenInit { + connection_id, + client_id, + counterparty_client_id, + } => { + let client_info = voyager_client + .client_info::(self.chain_id.clone(), client_id) + .await?; + + let client_meta = voyager_client + .client_meta::(self.chain_id.clone(), height.into(), client_id) + .await?; + + let event = ibc_union_spec::event::ConnectionOpenInit { + client_id, + connection_id, + counterparty_client_id, + } + .into(); + + ibc_union_spec::log_event(&event, &self.chain_id); + + Ok(data(ChainEvent { + chain_id: self.chain_id.clone(), + client_info, + counterparty_chain_id: client_meta.chain_id, + tx_hash, + provable_height, + ibc_spec_id: IbcUnion::ID, + event: into_value::(event), + })) + } + IbcEvent::WasmConnectionOpenTry { + connection_id, + client_id, + counterparty_client_id, + counterparty_connection_id, + } => { + let client_info = voyager_client + .client_info::(self.chain_id.clone(), client_id) + .await?; + + let client_meta = voyager_client + .client_meta::(self.chain_id.clone(), height.into(), client_id) + .await?; + + let event = ibc_union_spec::event::ConnectionOpenTry { + connection_id, + counterparty_connection_id, + client_id, + counterparty_client_id, + } + .into(); + + ibc_union_spec::log_event(&event, &self.chain_id); + + Ok(data(ChainEvent { + chain_id: self.chain_id.clone(), + client_info, + counterparty_chain_id: client_meta.chain_id, + tx_hash, + provable_height, + ibc_spec_id: IbcUnion::ID, + event: into_value::(event), + })) + } + IbcEvent::WasmConnectionOpenAck { + connection_id, + client_id, + counterparty_client_id, + counterparty_connection_id, + } => { + let client_info = voyager_client + .client_info::(self.chain_id.clone(), client_id) + .await?; + + let client_meta = voyager_client + .client_meta::(self.chain_id.clone(), height.into(), client_id) + .await?; + + let event = ibc_union_spec::event::ConnectionOpenAck { + connection_id, + counterparty_connection_id, + client_id, + counterparty_client_id, + } + .into(); + + ibc_union_spec::log_event(&event, &self.chain_id); + + Ok(data(ChainEvent { + chain_id: self.chain_id.clone(), + client_info, + counterparty_chain_id: client_meta.chain_id, + tx_hash, + provable_height, + ibc_spec_id: IbcUnion::ID, + event: into_value::(event), + })) + } + IbcEvent::WasmConnectionOpenConfirm { + connection_id, + client_id, + counterparty_client_id, + counterparty_connection_id, + } => { + let client_info = voyager_client + .client_info::(self.chain_id.clone(), client_id) + .await?; + + let client_meta = voyager_client + .client_meta::(self.chain_id.clone(), height.into(), client_id) + .await?; + + let event = ibc_union_spec::event::ConnectionOpenConfirm { + connection_id, + counterparty_connection_id, + client_id, + counterparty_client_id, + } + .into(); + + ibc_union_spec::log_event(&event, &self.chain_id); + + Ok(data(ChainEvent { + chain_id: self.chain_id.clone(), + client_info, + counterparty_chain_id: client_meta.chain_id, + tx_hash, + provable_height, + ibc_spec_id: IbcUnion::ID, + event: into_value::(event), + })) + } + IbcEvent::WasmChannelOpenInit { + port_id, + channel_id, + counterparty_port_id, + connection_id, + version, + } => { + let connection = voyager_client + .query_ibc_state( + self.chain_id.clone(), + QueryHeight::Specific(height), + ibc_union_spec::path::ConnectionPath { connection_id }, + ) + .await? + .state + .unwrap(); + + let client_info = voyager_client + .client_info::(self.chain_id.clone(), connection.client_id) + .await?; + + let client_meta = voyager_client + .client_meta::( + self.chain_id.clone(), + height.into(), + connection.client_id, + ) + .await?; + + let event = ibc_union_spec::event::ChannelOpenInit { + port_id: port_id.to_string().into_bytes().into(), + channel_id, + counterparty_port_id: counterparty_port_id.into_encoding(), + connection, + version, + } + .into(); + + ibc_union_spec::log_event(&event, &self.chain_id); + + Ok(data(ChainEvent { + chain_id: self.chain_id.clone(), + client_info, + counterparty_chain_id: client_meta.chain_id, + tx_hash, + provable_height, + ibc_spec_id: IbcUnion::ID, + event: into_value::(event), + })) + } + IbcEvent::WasmChannelOpenTry { + port_id, + channel_id, + counterparty_port_id, + counterparty_channel_id, + connection_id, + counterparty_version, + } => { + let connection = voyager_client + .query_ibc_state( + self.chain_id.clone(), + QueryHeight::Specific(height), + ibc_union_spec::path::ConnectionPath { connection_id }, + ) + .await? + .state + .unwrap(); + + let client_info = voyager_client + .client_info::(self.chain_id.clone(), connection.client_id) + .await?; + + let client_meta = voyager_client + .client_meta::( + self.chain_id.clone(), + height.into(), + connection.client_id, + ) + .await?; + + let event = ibc_union_spec::event::ChannelOpenTry { + port_id: port_id.to_string().into_bytes().into(), + channel_id, + counterparty_port_id: counterparty_port_id.into_encoding(), + counterparty_channel_id, + connection, + version: counterparty_version, + } + .into(); + + ibc_union_spec::log_event(&event, &self.chain_id); + + Ok(data(ChainEvent { + chain_id: self.chain_id.clone(), + client_info, + counterparty_chain_id: client_meta.chain_id, + tx_hash, + provable_height, + ibc_spec_id: IbcUnion::ID, + event: into_value::(event), + })) + } + IbcEvent::WasmChannelOpenAck { + port_id, + channel_id, + counterparty_port_id, + counterparty_channel_id, + connection_id, + } => { + let connection = voyager_client + .query_ibc_state( + self.chain_id.clone(), + QueryHeight::Specific(height), + ibc_union_spec::path::ConnectionPath { connection_id }, + ) + .await? + .state + .unwrap(); + + let client_info = voyager_client + .client_info::(self.chain_id.clone(), connection.client_id) + .await?; + + let client_meta = voyager_client + .client_meta::( + self.chain_id.clone(), + height.into(), + connection.client_id, + ) + .await?; + + let channel = voyager_client + .query_ibc_state( + self.chain_id.clone(), + height.into(), + ChannelPath { channel_id }, + ) + .await? + .state + .ok_or_else(missing_state("channel must exist", None))?; + + let event = ibc_union_spec::event::ChannelOpenAck { + port_id: port_id.to_string().into_bytes().into(), + channel_id, + counterparty_port_id: counterparty_port_id.into_encoding(), + counterparty_channel_id, + connection, + version: channel.version, + } + .into(); + + ibc_union_spec::log_event(&event, &self.chain_id); + + Ok(data(ChainEvent { + chain_id: self.chain_id.clone(), + client_info, + counterparty_chain_id: client_meta.chain_id, + tx_hash, + provable_height, + ibc_spec_id: IbcUnion::ID, + event: into_value::(event), + })) + } + + IbcEvent::WasmChannelOpenConfirm { + port_id, + channel_id, + counterparty_port_id, + counterparty_channel_id, + connection_id, + } => { + let channel = voyager_client + .query_ibc_state( + self.chain_id.clone(), + QueryHeight::Specific(height), + ibc_union_spec::path::ChannelPath { channel_id }, + ) + .await? + .state + .unwrap(); + + let connection = voyager_client + .query_ibc_state( + self.chain_id.clone(), + QueryHeight::Specific(height), + ibc_union_spec::path::ConnectionPath { connection_id }, + ) + .await? + .state + .unwrap(); + + let client_info = voyager_client + .client_info::(self.chain_id.clone(), connection.client_id) + .await?; + + let client_meta = voyager_client + .client_meta::( + self.chain_id.clone(), + height.into(), + connection.client_id, + ) + .await?; + + let event = ibc_union_spec::event::ChannelOpenConfirm { + port_id: port_id.to_string().into_bytes().into(), + channel_id, + counterparty_port_id: counterparty_port_id.into_encoding(), + counterparty_channel_id, + connection, + version: channel.version, + } + .into(); + + ibc_union_spec::log_event(&event, &self.chain_id); + + Ok(data(ChainEvent { + chain_id: self.chain_id.clone(), + client_info, + counterparty_chain_id: client_meta.chain_id, + tx_hash, + provable_height, + ibc_spec_id: IbcUnion::ID, + event: into_value::(event), + })) + } + IbcEvent::WasmPacketSend { packet } => { + let source_channel = voyager_client + .query_ibc_state( + self.chain_id.clone(), + QueryHeight::Specific(height), + ibc_union_spec::path::ChannelPath { + channel_id: packet.source_channel_id, + }, + ) + .await? + .state + .unwrap(); + + let source_connection = voyager_client + .query_ibc_state( + self.chain_id.clone(), + QueryHeight::Specific(height), + ibc_union_spec::path::ConnectionPath { + connection_id: source_channel.connection_id, + }, + ) + .await? + .state + .unwrap(); + + let client_info = voyager_client + .client_info::(self.chain_id.clone(), source_connection.client_id) + .await?; + + let client_meta = voyager_client + .client_meta::( + self.chain_id.clone(), + height.into(), + source_connection.client_id, + ) + .await?; + + let event = ibc_union_spec::event::PacketSend { + packet_data: packet.data.into(), + packet: ibc_union_spec::event::PacketMetadata { + source_channel: ibc_union_spec::event::ChannelMetadata { + channel_id: packet.source_channel_id, + version: source_channel.version.clone(), + connection: ibc_union_spec::event::ConnectionMetadata { + client_id: source_connection.client_id, + connection_id: source_channel.connection_id, + }, + }, + destination_channel: ibc_union_spec::event::ChannelMetadata { + channel_id: packet.destination_channel_id, + version: source_channel.version, + connection: ibc_union_spec::event::ConnectionMetadata { + client_id: source_connection.counterparty_client_id, + connection_id: source_connection.counterparty_connection_id, + }, + }, + timeout_height: packet.timeout_height, + timeout_timestamp: packet.timeout_timestamp, + }, + } + .into(); + + ibc_union_spec::log_event(&event, &self.chain_id); + + Ok(data(ChainEvent { + chain_id: self.chain_id.clone(), + client_info, + counterparty_chain_id: client_meta.chain_id, + tx_hash, + provable_height, + ibc_spec_id: IbcUnion::ID, + event: into_value::(event), + })) + } + IbcEvent::WasmPacketAck { + packet, + acknowledgement, + } => { + let source_channel = voyager_client + .query_ibc_state( + self.chain_id.clone(), + QueryHeight::Specific(height), + ibc_union_spec::path::ChannelPath { + channel_id: packet.source_channel_id, + }, + ) + .await? + .state + .unwrap(); + + let source_connection = voyager_client + .query_ibc_state( + self.chain_id.clone(), + QueryHeight::Specific(height), + ibc_union_spec::path::ConnectionPath { + connection_id: source_channel.connection_id, + }, + ) + .await? + .state + .unwrap(); + + let client_info = voyager_client + .client_info::(self.chain_id.clone(), source_connection.client_id) + .await?; + + let client_meta = voyager_client + .client_meta::( + self.chain_id.clone(), + height.into(), + source_connection.client_id, + ) + .await?; + + let event = ibc_union_spec::event::PacketAck { + packet_data: packet.data.into(), + packet: ibc_union_spec::event::PacketMetadata { + source_channel: ibc_union_spec::event::ChannelMetadata { + channel_id: packet.source_channel_id, + version: source_channel.version.clone(), + connection: ibc_union_spec::event::ConnectionMetadata { + client_id: source_connection.client_id, + connection_id: source_channel.connection_id, + }, + }, + destination_channel: ibc_union_spec::event::ChannelMetadata { + channel_id: packet.destination_channel_id, + version: source_channel.version, + connection: ibc_union_spec::event::ConnectionMetadata { + client_id: source_connection.counterparty_client_id, + connection_id: source_connection.counterparty_connection_id, + }, + }, + timeout_height: packet.timeout_height, + timeout_timestamp: packet.timeout_timestamp, + }, + acknowledgement: acknowledgement.into_encoding(), + } + .into(); + + ibc_union_spec::log_event(&event, &self.chain_id); + + Ok(data(ChainEvent { + chain_id: self.chain_id.clone(), + client_info, + counterparty_chain_id: client_meta.chain_id, + tx_hash, + provable_height, + ibc_spec_id: IbcUnion::ID, + event: into_value::(event), + })) + } + IbcEvent::WasmPacketRecv { + packet, + relayer_msg, + } => { + let destination_channel = voyager_client + .query_ibc_state( + self.chain_id.clone(), + QueryHeight::Specific(height), + ibc_union_spec::path::ChannelPath { + channel_id: packet.destination_channel_id, + }, + ) + .await? + .state + .unwrap(); + + let destination_connection = voyager_client + .query_ibc_state( + self.chain_id.clone(), + QueryHeight::Specific(height), + ibc_union_spec::path::ConnectionPath { + connection_id: destination_channel.connection_id, + }, + ) + .await? + .state + .unwrap(); + + let client_info = voyager_client + .client_info::( + self.chain_id.clone(), + destination_connection.client_id, + ) + .await?; + + let client_meta = voyager_client + .client_meta::( + self.chain_id.clone(), + height.into(), + destination_connection.client_id, + ) + .await?; + + let source_channel = voyager_client + .query_ibc_state( + client_meta.chain_id.clone(), + QueryHeight::Latest, + ibc_union_spec::path::ChannelPath { + channel_id: packet.source_channel_id, + }, + ) + .await? + .state + .unwrap(); + + let event = ibc_union_spec::event::PacketRecv { + packet_data: packet.data.into(), + packet: ibc_union_spec::event::PacketMetadata { + source_channel: ibc_union_spec::event::ChannelMetadata { + channel_id: packet.source_channel_id, + version: source_channel.version.clone(), + connection: ibc_union_spec::event::ConnectionMetadata { + client_id: destination_connection.counterparty_client_id, + connection_id: destination_connection.counterparty_connection_id, + }, + }, + destination_channel: ibc_union_spec::event::ChannelMetadata { + channel_id: packet.destination_channel_id, + version: destination_channel.version.clone(), + + connection: ibc_union_spec::event::ConnectionMetadata { + client_id: destination_connection.client_id, + connection_id: destination_channel.connection_id, + }, + }, + timeout_height: packet.timeout_height, + timeout_timestamp: packet.timeout_timestamp, + }, + relayer_msg: relayer_msg.into_encoding(), + } + .into(); + + ibc_union_spec::log_event(&event, &self.chain_id); + + Ok(data(ChainEvent { + chain_id: self.chain_id.clone(), + client_info, + counterparty_chain_id: client_meta.chain_id, + tx_hash, + provable_height, + ibc_spec_id: IbcUnion::ID, + event: into_value::(event), + })) + } + IbcEvent::WasmWriteAck { + packet, + acknowledgement, + } => { + let destination_channel = voyager_client + .query_ibc_state( + self.chain_id.clone(), + QueryHeight::Specific(height), + ibc_union_spec::path::ChannelPath { + channel_id: packet.destination_channel_id, + }, + ) + .await? + .state + .unwrap(); + + let destination_connection = voyager_client + .query_ibc_state( + self.chain_id.clone(), + QueryHeight::Specific(height), + ibc_union_spec::path::ConnectionPath { + connection_id: destination_channel.connection_id, + }, + ) + .await? + .state + .unwrap(); + + let client_info = voyager_client + .client_info::( + self.chain_id.clone(), + destination_connection.client_id, + ) + .await?; + + let client_meta = voyager_client + .client_meta::( + self.chain_id.clone(), + height.into(), + destination_connection.client_id, + ) + .await?; + + let source_channel = voyager_client + .query_ibc_state( + client_meta.chain_id.clone(), + QueryHeight::Latest, + ibc_union_spec::path::ChannelPath { + channel_id: packet.source_channel_id, + }, + ) + .await? + .state + .unwrap(); + + let event = ibc_union_spec::event::WriteAck { + packet_data: packet.data.into(), + packet: ibc_union_spec::event::PacketMetadata { + source_channel: ibc_union_spec::event::ChannelMetadata { + channel_id: packet.source_channel_id, + version: source_channel.version.clone(), + connection: ibc_union_spec::event::ConnectionMetadata { + client_id: destination_connection.counterparty_client_id, + connection_id: destination_connection.counterparty_connection_id, + }, + }, + destination_channel: ibc_union_spec::event::ChannelMetadata { + channel_id: packet.destination_channel_id, + version: destination_channel.version.clone(), + + connection: ibc_union_spec::event::ConnectionMetadata { + client_id: destination_connection.client_id, + connection_id: destination_channel.connection_id, + }, + }, + timeout_height: packet.timeout_height, + timeout_timestamp: packet.timeout_timestamp, + }, + acknowledgement: acknowledgement.into_encoding(), + } + .into(); + + ibc_union_spec::log_event(&event, &self.chain_id); + + Ok(data(ChainEvent { + chain_id: self.chain_id.clone(), + client_info, + counterparty_chain_id: client_meta.chain_id, + tx_hash, + provable_height, + ibc_spec_id: IbcUnion::ID, + event: into_value::(event), + })) + } + } + } }