Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

clean up light clients #3457

Merged
merged 11 commits into from
Jan 8, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
63 changes: 31 additions & 32 deletions Cargo.lock

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

11 changes: 6 additions & 5 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -77,16 +77,17 @@ members = [
"lib/tendermint-light-client-types",
"lib/linea-light-client-types",
"lib/movement-light-client-types",
"lib/state-lens/evm-light-client-types",
"lib/state-lens/cosmos-light-client-types",
"lib/state-lens-ics23-mpt-light-client-types",
"lib/state-lens-ics23-mpt-light-client-types",
"lib/state-lens-ics23-ics23-light-client-types",

# these will all be re enabled and updated once ethereum-light-client is updated

"cosmwasm/ibc-union/light-clients/ethereum",
"cosmwasm/ibc-union/light-clients/arbitrum",
"cosmwasm/ibc-union/light-clients/berachain",
"cosmwasm/ibc-union/light-clients/cometbls",
"cosmwasm/ibc-union/light-clients/evm-in-cosmos",
"cosmwasm/ibc-union/light-clients/state-lens-ics23-mpt",
# "cosmwasm/ibc-union/light-clients/scroll",
"cosmwasm/ibc-union/light-clients/tendermint",
# "cosmwasm/ibc-union/light-clients/linea",
Expand Down Expand Up @@ -218,8 +219,8 @@ scroll-api = { path = "lib/scroll-api", default-features = fal
scroll-codec = { path = "lib/scroll-codec", default-features = false }
scroll-rpc = { path = "lib/scroll-rpc", default-features = false }

cosmos-state-lens-light-client-types = { path = "lib/state-lens/cosmos-light-client-types", default-features = false }
evm-state-lens-light-client-types = { path = "lib/state-lens/evm-light-client-types", default-features = false }
state-lens-ics23-ics23-light-client-types = { path = "lib/state-lens-ics23-ics23-light-client-types", default-features = false }
state-lens-ics23-mpt-light-client-types = { path = "lib/state-lens-ics23-mpt-light-client-types", default-features = false }

tendermint-light-client = { path = "cosmwasm/ibc-union/light-clients/tendermint", default-features = false }
tendermint-light-client-types = { path = "lib/tendermint-light-client-types", default-features = false }
Expand Down
65 changes: 6 additions & 59 deletions cosmwasm/ibc-union/light-clients/ethereum/src/contract.rs
Original file line number Diff line number Diff line change
@@ -1,21 +1,11 @@
#[cfg(not(feature = "library"))]
use cosmwasm_std::entry_point;
use cosmwasm_std::{
from_json, to_json_binary, Binary, CosmosMsg, Deps, DepsMut, Env, MessageInfo, Response,
StdResult, SubMsg,
};
use ethereum_light_client_types::ClientState;
use cosmwasm_std::{Binary, Deps, DepsMut, Env, MessageInfo, Response, StdResult};
use ibc_union_light_client::{
msg::{InstantiateMsg, QueryMsg},
read_consensus_state,
state::IBC_HOST,
IbcClientError, CLIENT_STATES,
IbcClientError,
};
use serde::{Deserialize, Serialize};
use unionlabs::{
encoding::{Bincode, EncodeAs, EthAbi},
primitives::{encoding::Base64, Bytes},
};

use crate::client::EthereumLightClient;

Expand All @@ -35,56 +25,13 @@ pub fn query(deps: Deps, env: Env, msg: QueryMsg) -> StdResult<Binary> {
}

#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct MigrateMsg {
client_ids: Vec<u32>,
}
pub struct MigrateMsg {}

#[cfg_attr(not(feature = "library"), entry_point)]
pub fn migrate(
deps: DepsMut,
_deps: DepsMut,
_env: Env,
msg: MigrateMsg,
_msg: MigrateMsg,
) -> Result<Response, IbcClientError<EthereumLightClient>> {
let ibc_host = IBC_HOST.load(deps.storage)?;

let mut msgs = vec![];

for client_id in msg.client_ids {
let client_state_bytes = from_json::<Bytes<Base64>>(
deps.querier
.query_wasm_raw(ibc_host.to_string(), CLIENT_STATES.key(client_id).to_vec())?
.ok_or_else(|| {
IbcClientError::Std(cosmwasm_std::StdError::generic_err(format!(
"unable to read client state of client {client_id}"
)))
})?,
)?;

let client_state: ClientState = bincode_1::deserialize(&client_state_bytes).unwrap();

let consensus_state = read_consensus_state::<EthereumLightClient>(
deps.querier,
&ibc_host,
client_id,
client_state.latest_height,
)?;

msgs.push(SubMsg::new(CosmosMsg::Wasm(
cosmwasm_std::WasmMsg::Execute {
contract_addr: ibc_host.to_string(),
msg: to_json_binary(&ibc_union_msg::msg::ExecuteMsg::MigrateState(
ibc_union_msg::msg::MsgMigrateState {
client_id,
height: client_state.latest_height,
client_state: client_state.encode_as::<Bincode>().into(),
consensus_state: consensus_state.encode_as::<EthAbi>().into(),
},
))
.unwrap(),
funds: vec![],
},
)))
}

Ok(Response::new().add_submessages(msgs))
Ok(Response::new())
}
33 changes: 0 additions & 33 deletions cosmwasm/ibc-union/light-clients/evm-in-cosmos/Cargo.toml

This file was deleted.

33 changes: 33 additions & 0 deletions cosmwasm/ibc-union/light-clients/state-lens-ics23-mpt/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
[package]
authors = ["Union Labs"]
edition = "2021"
license-file = { workspace = true }
name = "evm-in-cosmos-light-client"
publish = false
version = "0.1.0"

[lints]
workspace = true

[lib]
crate-type = ["cdylib", "rlib"]

[dependencies]
cometbls-light-client = { workspace = true, features = ["library"] }
cosmwasm-std = { workspace = true, features = ["abort"] }
ethereum-light-client-types = { workspace = true, features = ["serde", "ethabi", "bincode"] }
evm-storage-verifier = { workspace = true }
ibc-union-light-client = { workspace = true }
ibc-union-msg = { workspace = true }
ibc-union-spec = { workspace = true }
ics23 = { workspace = true }
rlp = { workspace = true }
serde = { workspace = true, features = ["derive"] }
state-lens-ics23-mpt-light-client-types = { workspace = true, features = ["serde", "ethabi", "bincode"] }
thiserror = { workspace = true }
unionlabs = { workspace = true, features = ["ethabi", "stargate", "bincode"] }

[features]
default = []
# enabling this feature disables exposing the entrypoints and setting `#[global_allocator]`
library = []
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
use cometbls_light_client::client::CometblsLightClient;
use cosmwasm_std::Empty;
use ethereum_light_client_types::StorageProof;
use evm_state_lens_light_client_types::{ClientState, ConsensusState, Header};
use ibc_union_light_client::IbcClient;
use ibc_union_msg::lightclient::Status;
use ibc_union_spec::ConsensusStatePath;
use state_lens_ics23_mpt_light_client_types::{ClientState, ConsensusState, Header};
use unionlabs::{
encoding::Bincode,
ethereum::{ibc_commitment_key, keccak256},
Expand All @@ -14,9 +14,9 @@ use unionlabs::{

use crate::errors::Error;

pub struct EvmInCosmosLightClient;
pub struct StateLensIcs23MptLightClient;

impl IbcClient for EvmInCosmosLightClient {
impl IbcClient for StateLensIcs23MptLightClient {
type Error = Error;

type CustomQuery = Empty;
Expand Down
Loading
Loading