From f8a77ad28cde510f893586226af05a79f11b3918 Mon Sep 17 00:00:00 2001 From: benluelo Date: Thu, 5 Dec 2024 23:47:46 +0000 Subject: [PATCH] feat: cleanup and remove unused code --- .../tendermint/create_client_tracker.rs | 120 ++-- lib/chain-utils/src/cosmos_sdk.rs | 20 +- lib/unionlabs/src/cometbls/types.rs | 1 - .../src/cometbls/types/canonical_vote.rs | 1 - lib/unionlabs/src/cosmwasm/mod.rs | 1 - lib/unionlabs/src/cosmwasm/wasm/mod.rs | 1 - .../src/cosmwasm/wasm/msg_execute_contract.rs | 29 - lib/unionlabs/src/lib.rs | 35 +- voyager/modules/proof/cosmos-sdk/src/main.rs | 625 ++---------------- .../state/cosmos-sdk-union/src/main.rs | 48 -- voyager/modules/state/cosmos-sdk/src/main.rs | 7 - 11 files changed, 117 insertions(+), 771 deletions(-) delete mode 100644 lib/unionlabs/src/cometbls/types.rs delete mode 100644 lib/unionlabs/src/cometbls/types/canonical_vote.rs delete mode 100644 lib/unionlabs/src/cosmwasm/mod.rs delete mode 100644 lib/unionlabs/src/cosmwasm/wasm/mod.rs delete mode 100644 lib/unionlabs/src/cosmwasm/wasm/msg_execute_contract.rs diff --git a/hubble/src/indexer/tendermint/create_client_tracker.rs b/hubble/src/indexer/tendermint/create_client_tracker.rs index 3c6c7ad438..d8c37fdef3 100644 --- a/hubble/src/indexer/tendermint/create_client_tracker.rs +++ b/hubble/src/indexer/tendermint/create_client_tracker.rs @@ -76,17 +76,17 @@ pub fn schedule_create_client_checker( let client_type = parse_wasm_client_type(wasm_blob).unwrap(); let counterparty_chain_id = match client_type.unwrap() { - WasmClientType::Ethereum => { - let cs = match ethereum_light_client_types::ClientState::decode_as::(&cs.data) { - Ok(cs) => cs, - // We changed the format of berachain client states, but union-testnet-8 still contains an old configuration which we need to ignore. - Err(err) => { - warn!("error while decoding client {client_id}: {:?}. Most likely due to a client state upgrade. This can then be safely ignored", err); - continue; - } - }; - cs.chain_id.to_string() - } + // WasmClientType::Ethereum => { + // let cs = match ethereum_light_client_types::ClientState::decode_as::(&cs.data) { + // Ok(cs) => cs, + // // We changed the format of berachain client states, but union-testnet-8 still contains an old configuration which we need to ignore. + // Err(err) => { + // warn!("error while decoding client {client_id}: {:?}. Most likely due to a client state upgrade. This can then be safely ignored", err); + // continue; + // } + // }; + // cs.chain_id.to_string() + // } WasmClientType::Cometbls => { let cs = match cometbls_light_client_types::ClientState::decode_as::(&cs.data) { Ok(cs) => cs, @@ -109,55 +109,55 @@ pub fn schedule_create_client_checker( cs.chain_id } - WasmClientType::Scroll => { - let cs = match scroll_light_client_types::ClientState::decode_as::(&cs.data) { - Ok(cs) => cs, - Err(err) => { - warn!("error while decoding client {client_id}: {:?}. Most likely due to a client state upgrade. This can then be safely ignored", err); - continue - } - }; - - cs.chain_id.to_string() - } - WasmClientType::Arbitrum => { - let cs = match arbitrum_light_client_types::ClientState::decode_as::(&cs.data) { - Ok(cs) => cs, - Err(err) => { - warn!("error while decoding client {client_id}: {:?}. Most likely due to a client state upgrade. This can then be safely ignored", err); - continue - } - }; - - cs.chain_id.to_string() - } - WasmClientType::Linea => todo!("We still need to add linea"), - WasmClientType::Berachain => { - let cs = match berachain_light_client_types::ClientState::decode_as::(&cs.data) { - Ok(cs) => cs, - // We changed the format of berachain client states, but union-testnet-8 still contains an old configuration which we need to ignore. - Err(err) => { - warn!("error while decoding client {client_id}: {:?}. Most likely due to a client state upgrade. This can then be safely ignored", err); - continue; - } - }; - - cs.execution_chain_id.to_string() - } - WasmClientType::EvmInCosmos => { - todo!("We still need to add evm-in-cosmos") - } - WasmClientType::Movement => { - let cs = match movement_light_client_types::ClientState::decode_as::(&cs.data) { - Ok(cs) => cs, - Err(err) => { - warn!("error while decoding client {client_id}: {:?}. Most likely due to a client state upgrade. This can then be safely ignored", err); - continue; - } - }; - - cs.chain_id.to_string() - } + // WasmClientType::Scroll => { + // let cs = match scroll_light_client_types::ClientState::decode_as::(&cs.data) { + // Ok(cs) => cs, + // Err(err) => { + // warn!("error while decoding client {client_id}: {:?}. Most likely due to a client state upgrade. This can then be safely ignored", err); + // continue + // } + // }; + + // cs.chain_id.to_string() + // } + // WasmClientType::Arbitrum => { + // let cs = match arbitrum_light_client_types::ClientState::decode_as::(&cs.data) { + // Ok(cs) => cs, + // Err(err) => { + // warn!("error while decoding client {client_id}: {:?}. Most likely due to a client state upgrade. This can then be safely ignored", err); + // continue + // } + // }; + + // cs.chain_id.to_string() + // } + // WasmClientType::Linea => todo!("We still need to add linea"), + // WasmClientType::Berachain => { + // let cs = match berachain_light_client_types::ClientState::decode_as::(&cs.data) { + // Ok(cs) => cs, + // // We changed the format of berachain client states, but union-testnet-8 still contains an old configuration which we need to ignore. + // Err(err) => { + // warn!("error while decoding client {client_id}: {:?}. Most likely due to a client state upgrade. This can then be safely ignored", err); + // continue; + // } + // }; + + // cs.execution_chain_id.to_string() + // } + // WasmClientType::EvmInCosmos => { + // todo!("We still need to add evm-in-cosmos") + // } + // WasmClientType::Movement => { + // let cs = match movement_light_client_types::ClientState::decode_as::(&cs.data) { + // Ok(cs) => cs, + // Err(err) => { + // warn!("error while decoding client {client_id}: {:?}. Most likely due to a client state upgrade. This can then be safely ignored", err); + // continue; + // } + // }; + + // cs.chain_id.to_string() + // } }; info!("{}: add mapping {} => {} (ibc.lightclients.wasm.v1.ClientState)", internal_chain_id, client_id, counterparty_chain_id); diff --git a/lib/chain-utils/src/cosmos_sdk.rs b/lib/chain-utils/src/cosmos_sdk.rs index b980ee13da..8810516ed2 100644 --- a/lib/chain-utils/src/cosmos_sdk.rs +++ b/lib/chain-utils/src/cosmos_sdk.rs @@ -22,7 +22,7 @@ use unionlabs::{ id::{ClientId, ConnectionId}, parse_wasm_client_type, signer::CosmosSigner, - ErrorReporter, MaybeRecoverableError, WasmClientType, + ErrorReporter, WasmClientType, }; use crate::{ @@ -531,24 +531,6 @@ pub enum BroadcastTxCommitError { OutOfGas, } -impl MaybeRecoverableError for BroadcastTxCommitError { - fn is_recoverable(&self) -> bool { - match self { - // tx wasn't included, retry unconditionally - Self::Inclusion(_) => true, - Self::Tx(code) => matches!( - code, - CosmosSdkError::SdkError(SdkError::ErrTxInMempoolCache) - | CosmosSdkError::SdkError(SdkError::ErrMempoolIsFull) - | CosmosSdkError::SdkError(SdkError::ErrTxTimeoutHeight) - | CosmosSdkError::SdkError(SdkError::ErrWrongSequence) - ), - Self::SimulateTx(_) => false, - _ => false, - } - } -} - #[allow(non_upper_case_globals)] // TODO: Report this upstream to num_enum pub mod cosmos_sdk_error { macro_rules! cosmos_sdk_errors { diff --git a/lib/unionlabs/src/cometbls/types.rs b/lib/unionlabs/src/cometbls/types.rs deleted file mode 100644 index b177eeb308..0000000000 --- a/lib/unionlabs/src/cometbls/types.rs +++ /dev/null @@ -1 +0,0 @@ -pub mod canonical_vote; diff --git a/lib/unionlabs/src/cometbls/types/canonical_vote.rs b/lib/unionlabs/src/cometbls/types/canonical_vote.rs deleted file mode 100644 index 8b13789179..0000000000 --- a/lib/unionlabs/src/cometbls/types/canonical_vote.rs +++ /dev/null @@ -1 +0,0 @@ - diff --git a/lib/unionlabs/src/cosmwasm/mod.rs b/lib/unionlabs/src/cosmwasm/mod.rs deleted file mode 100644 index ce1d9f82ec..0000000000 --- a/lib/unionlabs/src/cosmwasm/mod.rs +++ /dev/null @@ -1 +0,0 @@ -pub mod wasm; diff --git a/lib/unionlabs/src/cosmwasm/wasm/mod.rs b/lib/unionlabs/src/cosmwasm/wasm/mod.rs deleted file mode 100644 index 12932ffea2..0000000000 --- a/lib/unionlabs/src/cosmwasm/wasm/mod.rs +++ /dev/null @@ -1 +0,0 @@ -pub mod msg_execute_contract; diff --git a/lib/unionlabs/src/cosmwasm/wasm/msg_execute_contract.rs b/lib/unionlabs/src/cosmwasm/wasm/msg_execute_contract.rs deleted file mode 100644 index b0d2525343..0000000000 --- a/lib/unionlabs/src/cosmwasm/wasm/msg_execute_contract.rs +++ /dev/null @@ -1,29 +0,0 @@ -use macros::model; - -use crate::cosmos::base::coin::Coin; - -/// `MsgExecuteContract` submits the given message data to a smart contract -#[model(proto(raw(protos::cosmwasm::wasm::v1::MsgExecuteContract), from))] -pub struct MsgExecuteContract { - /// Sender is the that actor that signed the messages - // TODO: bech32 encoded address - pub sender: String, - /// Contract is the address of the smart contract - // TODO: bech32 encoded address - pub contract: String, - /// Msg json encoded message to be passed to the contract - pub msg: Vec, - /// Funds coins that are transferred to the contract on execution - pub funds: Vec, -} - -impl From for protos::cosmwasm::wasm::v1::MsgExecuteContract { - fn from(value: MsgExecuteContract) -> Self { - Self { - sender: value.sender, - contract: value.contract, - msg: value.msg, - funds: value.funds.into_iter().map(Into::into).collect(), - } - } -} diff --git a/lib/unionlabs/src/lib.rs b/lib/unionlabs/src/lib.rs index 5a744e8001..3a2856264c 100644 --- a/lib/unionlabs/src/lib.rs +++ b/lib/unionlabs/src/lib.rs @@ -34,17 +34,12 @@ pub const DELAY_PERIOD: u64 = 0; /// Wrapper types around protos defined in , matching the proto module structure. pub mod google; -pub mod cosmwasm; - #[cfg(feature = "near")] pub mod near; /// Defines types that wrap the IBC specification, matching the proto module structure. This also includes `union` extensions to ibc (i.e. types defined in `union.ibc`). pub mod ibc; -/// Defines types that are extended from tendermint in cometbls -pub mod cometbls; - /// Defines types that wrap the cosmos specification, matching the proto module structure. pub mod cosmos; @@ -73,6 +68,7 @@ pub mod bounded; pub mod constants; +// TODO: Remove (only used in ucs01-relay-api currently) pub mod validated; pub mod bytes; @@ -170,16 +166,8 @@ macro_rules! export_wasm_client_type { #[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize)] #[serde(rename_all = "snake_case")] pub enum WasmClientType { - Ethereum, Cometbls, Tendermint, - Scroll, - Arbitrum, - Linea, - // TODO: Rename to beacon-kit - Berachain, - EvmInCosmos, - Movement, } #[derive(Debug, Clone, PartialEq, Serialize, Deserialize)] @@ -208,15 +196,8 @@ impl FromStr for WasmClientType { fn from_str(s: &str) -> Result { match s { - "Ethereum" => Ok(WasmClientType::Ethereum), "Cometbls" => Ok(WasmClientType::Cometbls), "Tendermint" => Ok(WasmClientType::Tendermint), - "Scroll" => Ok(WasmClientType::Scroll), - "Arbitrum" => Ok(WasmClientType::Arbitrum), - "Linea" => Ok(WasmClientType::Linea), - "Berachain" => Ok(WasmClientType::Berachain), - "EvmInCosmos" => Ok(WasmClientType::EvmInCosmos), - "Movement" => Ok(WasmClientType::Movement), _ => Err(WasmClientTypeParseError::UnknownType(s.to_string())), } } @@ -225,15 +206,8 @@ impl FromStr for WasmClientType { impl Display for WasmClientType { fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { match self { - Self::Ethereum => write!(f, "Ethereum"), Self::Cometbls => write!(f, "Cometbls"), Self::Tendermint => write!(f, "Tendermint"), - Self::Scroll => write!(f, "Scroll"), - Self::Arbitrum => write!(f, "Arbitrum"), - Self::Linea => write!(f, "Linea"), - Self::Berachain => write!(f, "Berachain"), - Self::EvmInCosmos => write!(f, "EvmInCosmos"), - Self::Movement => write!(f, "Movement"), } } } @@ -267,13 +241,6 @@ pub fn parse_wasm_client_type( .transpose() } -// TODO: remove this as it is unused -pub trait MaybeRecoverableError: core::error::Error { - fn is_recoverable(&self) -> bool; -} - -fn _is_object_safe(_: &dyn MaybeRecoverableError) {} - pub fn ensure(expr: bool, err: E) -> Result<(), E> { expr.then_some(()).ok_or(err) } diff --git a/voyager/modules/proof/cosmos-sdk/src/main.rs b/voyager/modules/proof/cosmos-sdk/src/main.rs index b72aa0f657..a6afe56dae 100644 --- a/voyager/modules/proof/cosmos-sdk/src/main.rs +++ b/voyager/modules/proof/cosmos-sdk/src/main.rs @@ -3,17 +3,12 @@ use std::{ error::Error, fmt::{Debug, Display}, - num::{NonZeroU64, ParseIntError}, + num::ParseIntError, sync::Arc, }; -use cometbft_rpc::types::abci::response_query::QueryResponse; use dashmap::DashMap; -use ibc_classic_spec::{ - AcknowledgementPath, ChannelEndPath, ClientConsensusStatePath, ClientStatePath, CommitmentPath, - ConnectionPath, IbcClassic, NextClientSequencePath, NextConnectionSequencePath, - NextSequenceAckPath, NextSequenceRecvPath, NextSequenceSendPath, ReceiptPath, StorePath, -}; +use ibc_classic_spec::{IbcClassic, StorePath}; use jsonrpsee::{ core::{async_trait, RpcResult}, types::{ErrorObject, ErrorObjectOwned}, @@ -21,31 +16,23 @@ use jsonrpsee::{ }; use serde::{Deserialize, Serialize}; use serde_json::{json, Value}; -use tracing::{debug, error, info, instrument, warn}; +use tracing::{error, instrument}; use unionlabs::{ - bytes::Bytes, - encoding::{DecodeAs, Proto}, - hash::{hash_v2::HexUnprefixed, H256, H64}, - ibc::core::{ - channel::channel::Channel, client::height::Height, - connection::connection_end::ConnectionEnd, - }, - id::{ChannelId, ClientId, ConnectionId, PortId}, - parse_wasm_client_type, ErrorReporter, WasmClientType, + hash::H256, + ibc::core::{client::height::Height, commitment::merkle_proof::MerkleProof}, + ErrorReporter, WasmClientType, }; use voyager_message::{ - core::{ChainId, ClientInfo, ClientType, IbcGo08WasmClientMetadata, IbcInterface}, + core::ChainId, into_value, - module::{StateModuleInfo, StateModuleServer}, - StateModule, FATAL_JSONRPC_ERROR_CODE, + module::{ProofModuleInfo, ProofModuleServer}, + ProofModule, }; use voyager_vm::BoxDynError; -const IBC_STORE_PATH: &str = "store/ibc/key"; - #[tokio::main(flavor = "multi_thread")] async fn main() { - >::run().await; + >::run().await; } #[derive(clap::Subcommand)] @@ -72,10 +59,10 @@ pub struct Config { pub grpc_url: String, } -impl StateModule for Module { +impl ProofModule for Module { type Config = Config; - async fn new(config: Self::Config, info: StateModuleInfo) -> Result { + async fn new(config: Self::Config, info: ProofModuleInfo) -> Result { let tm_client = cometbft_rpc::Client::new(config.ws_url).await?; let chain_id = tm_client.status().await?.node_info.network; @@ -110,389 +97,6 @@ impl Module { pub fn make_height(&self, height: u64) -> Height { 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 })), - )) - } - - async fn abci_query(&self, path_string: &str, height: Height) -> RpcResult { - self.tm_client - .abci_query( - IBC_STORE_PATH, - &path_string, - Some( - i64::try_from(height.height()) - .expect("should be fine") - .try_into() - .expect("invalid height"), - ), - false, - ) - .await - .map_err(rpc_error( - format_args!("error fetching abci query"), - Some(json!({ "height": height, "path": path_string })), - )) - .map(|response| response.response) - } - - #[instrument(skip_all, fields(chain_id = %self.chain_id, %height, %client_id))] - async fn query_client_state(&self, height: Height, client_id: ClientId) -> RpcResult { - let path_string = ClientStatePath { client_id }.to_string(); - - let query_result = self.abci_query(&path_string, height).await?; - - Ok(query_result.value.unwrap().into_encoding()) - } - - #[instrument(skip_all, fields(chain_id = %self.chain_id, %height, %client_id, %trusted_height))] - async fn query_client_consensus_state( - &self, - height: Height, - client_id: ClientId, - trusted_height: Height, - ) -> RpcResult { - let path_string = ClientConsensusStatePath { - client_id, - height: trusted_height, - } - .to_string(); - - let query_result = self.abci_query(&path_string, height).await?; - - Ok(query_result.value.unwrap().into_encoding()) - } - - #[instrument(skip_all, fields(chain_id = %self.chain_id, %height, %connection_id))] - async fn query_connection( - &self, - height: Height, - connection_id: ConnectionId, - ) -> RpcResult> { - let path_string = ConnectionPath { connection_id }.to_string(); - - let query_result = self.abci_query(&path_string, height).await?; - - Ok(match query_result.value { - Some(value) => Some( - ConnectionEnd::decode_as::(&value) - .map_err(fatal_rpc_error("error decoding connection end", None))?, - ), - None => None, - }) - } - - #[instrument(skip_all, fields(chain_id = %self.chain_id, %height, %port_id, %channel_id))] - async fn query_channel( - &self, - height: Height, - port_id: PortId, - channel_id: ChannelId, - ) -> RpcResult> { - let path_string = ChannelEndPath { - channel_id, - port_id, - } - .to_string(); - - let query_result = self.abci_query(&path_string, height).await?; - - Ok(match query_result.value { - Some(value) => Some( - Channel::decode_as::(&value) - .map_err(fatal_rpc_error("error decoding channel end", None))?, - ), - None => None, - }) - } - - #[instrument(skip_all, fields(chain_id = %self.chain_id, %height, %port_id, %channel_id, %sequence))] - async fn query_commitment( - &self, - height: Height, - port_id: PortId, - channel_id: ChannelId, - sequence: NonZeroU64, - ) -> RpcResult> { - let path_string = CommitmentPath { - port_id, - channel_id, - sequence, - } - .to_string(); - - let query_result = self.abci_query(&path_string, height).await?; - - Ok(match query_result.value { - Some(value) => Some( - H256::try_from(value) - .map_err(fatal_rpc_error("error decoding commitment", None))?, - ), - None => None, - }) - } - - #[instrument(skip_all, fields(chain_id = %self.chain_id, %height, %port_id, %channel_id, %sequence))] - async fn query_acknowledgement( - &self, - height: Height, - port_id: PortId, - channel_id: ChannelId, - sequence: NonZeroU64, - ) -> RpcResult> { - let path_string = AcknowledgementPath { - port_id, - channel_id, - sequence, - } - .to_string(); - - let query_result = self.abci_query(&path_string, height).await?; - - Ok(match query_result.value { - Some(value) => Some(H256::try_from(value).map_err(fatal_rpc_error( - "error decoding acknowledgement commitment", - None, - ))?), - None => None, - }) - } - - #[instrument(skip_all, fields(chain_id = %self.chain_id, %height, %port_id, %channel_id, %sequence))] - async fn query_receipt( - &self, - height: Height, - port_id: PortId, - channel_id: ChannelId, - sequence: NonZeroU64, - ) -> RpcResult { - let path_string = ReceiptPath { - port_id, - channel_id, - sequence, - } - .to_string(); - - let query_result = self.abci_query(&path_string, height).await?; - - Ok(match query_result.value { - None => false, - Some(b) if b == [1] => true, - Some(invalid) => { - return Err(fatal_rpc_error("error decoding receipt", None)(format!( - "value is neither empty nor the single byte 0x01, found {}", - serde_utils::to_hex(invalid) - ))) - } - }) - } - - #[instrument(skip_all, fields(chain_id = %self.chain_id, %height, %port_id, %channel_id))] - async fn query_next_sequence_send( - &self, - height: Height, - port_id: PortId, - channel_id: ChannelId, - ) -> RpcResult { - let path_string = NextSequenceSendPath { - port_id, - channel_id, - } - .to_string(); - - let query_result = self.abci_query(&path_string, height).await?; - - Ok(u64::from_be_bytes( - *::try_from(query_result.value.unwrap()) - .map_err(fatal_rpc_error("error decoding next_sequence_send", None))? - .get(), - )) - } - - #[instrument(skip_all, fields(chain_id = %self.chain_id, %height, %port_id, %channel_id))] - async fn query_next_sequence_recv( - &self, - height: Height, - port_id: PortId, - channel_id: ChannelId, - ) -> RpcResult { - let path_string = NextSequenceRecvPath { - port_id, - channel_id, - } - .to_string(); - - let query_result = self.abci_query(&path_string, height).await?; - - Ok(u64::from_be_bytes( - *::try_from(query_result.value.unwrap()) - .map_err(fatal_rpc_error("error decoding next_sequence_recv", None))? - .get(), - )) - } - - #[instrument(skip_all, fields(chain_id = %self.chain_id, %height, %port_id, %channel_id))] - async fn query_next_sequence_ack( - &self, - height: Height, - port_id: PortId, - channel_id: ChannelId, - ) -> RpcResult { - let path_string = NextSequenceAckPath { - port_id, - channel_id, - } - .to_string(); - - let query_result = self.abci_query(&path_string, height).await?; - - Ok(u64::from_be_bytes( - *::try_from(query_result.value.unwrap()) - .map_err(fatal_rpc_error("error decoding next_sequence_ack", None))? - .get(), - )) - } - - #[instrument(skip_all, fields(chain_id = %self.chain_id, %height))] - async fn query_next_connection_sequence(&self, height: Height) -> RpcResult { - let path_string = NextConnectionSequencePath {}.to_string(); - - let query_result = self.abci_query(&path_string, height).await?; - - Ok(u64::from_be_bytes( - *::try_from(query_result.value.unwrap()) - .map_err(fatal_rpc_error( - "error decoding next_connection_sequence", - None, - ))? - .get(), - )) - } - - #[instrument(skip_all, fields(chain_id = %self.chain_id, %height))] - async fn query_next_client_sequence(&self, height: Height) -> RpcResult { - let path_string = NextClientSequencePath {}.to_string(); - - let query_result = self.abci_query(&path_string, height).await?; - - Ok(u64::from_be_bytes( - *::try_from(query_result.value.unwrap()) - .map_err(fatal_rpc_error("error decoding next_client_sequence", None))? - .get(), - )) - } } #[derive(Debug, thiserror::Error)] @@ -504,164 +108,57 @@ pub struct ChainIdParseError { } #[async_trait] -impl StateModuleServer for Module { - #[instrument(skip_all, fields(chain_id = %self.chain_id))] - async fn client_info(&self, _: &Extensions, client_id: ClientId) -> RpcResult { - match client_id.to_string().rsplit_once('-') { - Some(("07-tendermint", _)) => Ok(ClientInfo { - client_type: ClientType::new(ClientType::TENDERMINT), - ibc_interface: IbcInterface::new(IbcInterface::IBC_GO_V8_NATIVE), - metadata: Default::default(), - }), - Some(("08-wasm", _)) => { - let checksum = self.checksum_of_client_id(client_id.clone()).await?; - - Ok(ClientInfo { - client_type: match self.client_type_of_checksum(checksum).await? { - Some(ty) => match ty { - WasmClientType::Ethereum => ClientType::new(ClientType::ETHEREUM), - WasmClientType::Cometbls => { - ClientType::new(ClientType::COMETBLS_GROTH16) - } - WasmClientType::Tendermint => ClientType::new(ClientType::TENDERMINT), - WasmClientType::Scroll => ClientType::new(ClientType::SCROLL), - WasmClientType::Arbitrum => ClientType::new(ClientType::ARBITRUM), - WasmClientType::Linea => todo!(), - WasmClientType::Berachain => ClientType::new(ClientType::BEACON_KIT), - WasmClientType::Movement => ClientType::new(ClientType::MOVEMENT), - WasmClientType::EvmInCosmos => todo!(), - }, - None => { - warn!(%client_id, "unknown client type for 08-wasm client"); - // this early return is kind of dirty but it works - return Err(ErrorObject::owned( - FATAL_JSONRPC_ERROR_CODE, - "unknown client type for 08-wasm client", - Some(json!({ - "client_id": client_id.to_string() - })), - )); - } - }, - ibc_interface: IbcInterface::new(IbcInterface::IBC_GO_V8_08_WASM), - metadata: into_value(IbcGo08WasmClientMetadata { checksum }), - }) - } - _ => Err(ErrorObject::owned( - -1, - format!("unknown client type (client id `{client_id}`)"), - Some(json!({ - "client_id": client_id.to_string() - })), - )), - } - } - +impl ProofModuleServer for Module { #[instrument(skip_all, fields(chain_id = %self.chain_id))] - async fn query_ibc_state( + async fn query_ibc_proof( &self, _: &Extensions, at: Height, path: StorePath, ) -> RpcResult { - match path { - StorePath::ClientState(path) => self - .query_client_state(at, path.client_id) - .await - .map(into_value), - StorePath::ClientConsensusState(path) => self - .query_client_consensus_state(at, path.client_id, path.height) - .await - .map(into_value), - StorePath::Connection(path) => self - .query_connection(at, path.connection_id) - .await - .map(into_value), - StorePath::ChannelEnd(path) => self - .query_channel(at, path.port_id, path.channel_id) - .await - .map(into_value), - StorePath::Commitment(path) => self - .query_commitment(at, path.port_id, path.channel_id, path.sequence) - .await - .map(into_value), - StorePath::Acknowledgement(path) => self - .query_acknowledgement(at, path.port_id, path.channel_id, path.sequence) - .await - .map(into_value), - StorePath::Receipt(path) => self - .query_receipt(at, path.port_id, path.channel_id, path.sequence) - .await - .map(into_value), - StorePath::NextSequenceSend(path) => self - .query_next_sequence_send(at, path.port_id, path.channel_id) - .await - .map(into_value), - StorePath::NextSequenceRecv(path) => self - .query_next_sequence_recv(at, path.port_id, path.channel_id) - .await - .map(into_value), - StorePath::NextSequenceAck(path) => self - .query_next_sequence_ack(at, path.port_id, path.channel_id) - .await - .map(into_value), - StorePath::NextConnectionSequence(_path) => self - .query_next_connection_sequence(at) - .await - .map(into_value), - StorePath::NextClientSequence(_path) => { - self.query_next_client_sequence(at).await.map(into_value) - } - } - } + const IBC_STORE_PATH: &str = "store/ibc/key"; - // #[instrument(skip_all, fields(chain_id = %self.chain_id))] - // async fn query_ibc_proof(&self, _: &Extensions, at: Height, path: Path) -> RpcResult { - // // TODO: This is also in the fn above, move this to somewhere more appropriate (chain-utils perhaps?) + let path_string = path.to_string(); - // const IBC_STORE_PATH: &str = "store/ibc/key"; - - // let path_string = path.to_string(); - - // let query_result = self - // .tm_client - // .abci_query( - // IBC_STORE_PATH, - // &path_string, - // // a proof at height H is provable at height H + 1 - // // we assume that the height passed in to this function is the intended height to prove against, thus we have to query the height - 1 - // Some( - // (i64::try_from(at.height()).expect("should be fine") - 1) - // .try_into() - // .expect("invalid height"), - // ), - // true, - // ) - // .await - // .map_err(rpc_error( - // format_args!("error fetching abci query"), - // Some(json!({ "height": at, "path": path })), - // ))?; - - // Ok(into_value( - // MerkleProof::try_from(protos::ibc::core::commitment::v1::MerkleProof { - // proofs: query_result - // .response - // .proof_ops - // .unwrap() - // .ops - // .into_iter() - // .map(|op| { - // ::decode( - // op.data.as_slice(), - // ) - // .unwrap() - // }) - // .collect::>(), - // }) - // .unwrap(), - // )) - // } + let query_result = self + .tm_client + .abci_query( + IBC_STORE_PATH, + &path_string, + // a proof at height H is provable at height H + 1 + // we assume that the height passed in to this function is the intended height to prove against, thus we have to query the height - 1 + Some( + (i64::try_from(at.height()).expect("should be fine") - 1) + .try_into() + .expect("invalid height"), + ), + true, + ) + .await + .map_err(rpc_error( + format_args!("error fetching abci query"), + Some(json!({ "height": at, "path": path })), + ))?; + + Ok(into_value( + MerkleProof::try_from(protos::ibc::core::commitment::v1::MerkleProof { + proofs: query_result + .response + .proof_ops + .unwrap() + .ops + .into_iter() + .map(|op| { + ::decode( + &*op.data, + ) + .unwrap() + }) + .collect::>(), + }) + .unwrap(), + )) + } } // NOTE: For both of the below functions, `message` as a field will override any actual message put in (i.e. `error!("foo", message = "bar")` will print as "bar", not "foo" with an extra field `message = "bar"`. @@ -676,15 +173,3 @@ fn rpc_error( ErrorObject::owned(-1, message, data) } } - -fn fatal_rpc_error>>( - message: impl Display, - data: Option, -) -> impl FnOnce(E) -> ErrorObjectOwned { - move |e| { - let e = e.into(); - let message = format!("{message}: {}", ErrorReporter(&*e)); - error!(%message, data = %data.as_ref().unwrap_or(&serde_json::Value::Null)); - ErrorObject::owned(FATAL_JSONRPC_ERROR_CODE, message, data) - } -} diff --git a/voyager/modules/state/cosmos-sdk-union/src/main.rs b/voyager/modules/state/cosmos-sdk-union/src/main.rs index 6dadea42e7..12fd224181 100644 --- a/voyager/modules/state/cosmos-sdk-union/src/main.rs +++ b/voyager/modules/state/cosmos-sdk-union/src/main.rs @@ -328,54 +328,6 @@ impl StateModuleServer for Module { .map(into_value), } } - - // #[instrument(skip_all, fields(chain_id = %self.chain_id))] - // async fn query_ibc_proof(&self, _: &Extensions, at: Height, path: Path) -> RpcResult { - // // TODO: This is also in the fn above, move this to somewhere more appropriate (chain-utils perhaps?) - - // const IBC_STORE_PATH: &str = "store/ibc/key"; - - // let path_string = path.to_string(); - - // let query_result = self - // .tm_client - // .abci_query( - // IBC_STORE_PATH, - // &path_string, - // // a proof at height H is provable at height H + 1 - // // we assume that the height passed in to this function is the intended height to prove against, thus we have to query the height - 1 - // Some( - // (i64::try_from(at.height()).expect("should be fine") - 1) - // .try_into() - // .expect("invalid height"), - // ), - // true, - // ) - // .await - // .map_err(rpc_error( - // format_args!("error fetching abci query"), - // Some(json!({ "height": at, "path": path })), - // ))?; - - // Ok(into_value( - // MerkleProof::try_from(protos::ibc::core::commitment::v1::MerkleProof { - // proofs: query_result - // .response - // .proof_ops - // .unwrap() - // .ops - // .into_iter() - // .map(|op| { - // ::decode( - // op.data.as_slice(), - // ) - // .unwrap() - // }) - // .collect::>(), - // }) - // .unwrap(), - // )) - // } } // NOTE: For both of the below functions, `message` as a field will override any actual message put in (i.e. `error!("foo", message = "bar")` will print as "bar", not "foo" with an extra field `message = "bar"`. diff --git a/voyager/modules/state/cosmos-sdk/src/main.rs b/voyager/modules/state/cosmos-sdk/src/main.rs index b72aa0f657..1ddb167a3e 100644 --- a/voyager/modules/state/cosmos-sdk/src/main.rs +++ b/voyager/modules/state/cosmos-sdk/src/main.rs @@ -519,17 +519,10 @@ impl StateModuleServer for Module { Ok(ClientInfo { client_type: match self.client_type_of_checksum(checksum).await? { Some(ty) => match ty { - WasmClientType::Ethereum => ClientType::new(ClientType::ETHEREUM), WasmClientType::Cometbls => { ClientType::new(ClientType::COMETBLS_GROTH16) } WasmClientType::Tendermint => ClientType::new(ClientType::TENDERMINT), - WasmClientType::Scroll => ClientType::new(ClientType::SCROLL), - WasmClientType::Arbitrum => ClientType::new(ClientType::ARBITRUM), - WasmClientType::Linea => todo!(), - WasmClientType::Berachain => ClientType::new(ClientType::BEACON_KIT), - WasmClientType::Movement => ClientType::new(ClientType::MOVEMENT), - WasmClientType::EvmInCosmos => todo!(), }, None => { warn!(%client_id, "unknown client type for 08-wasm client");