Skip to content

Commit ddcb0f1

Browse files
committed
feat(lightclients): use new client state type in state lens light clients
1 parent d73c9c0 commit ddcb0f1

File tree

22 files changed

+284
-417
lines changed

22 files changed

+284
-417
lines changed

Cargo.lock

+3
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

+1
Original file line numberDiff line numberDiff line change
@@ -280,6 +280,7 @@ tendermint-rpc = { git = "https://github.com/unionlabs/tendermint-rs", branch =
280280

281281
alloy = { version = "0.6", default-features = false }
282282
alloy-primitives = { version = "0.8.16", default-features = false }
283+
alloy-sol-types = { version = "0.8.12", default-features = true }
283284

284285
# https://github.com/aptos-labs/aptos-core/pull/12636
285286
aptos-crypto = { git = "https://github.com/unionlabs/aptos-core" }

cosmwasm/ibc-union/light-clients/state-lens-ics23-mpt/src/client.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -133,17 +133,17 @@ impl IbcClient for StateLensIcs23MptLightClient {
133133

134134
let l2_timestamp = extract_uint64(
135135
&header.l2_consensus_state,
136-
client_state.timestamp_offset as usize,
136+
client_state.extra.timestamp_offset as usize,
137137
);
138138

139139
let l2_state_root = extract_bytes32(
140140
&header.l2_consensus_state,
141-
client_state.state_root_offset as usize,
141+
client_state.extra.state_root_offset as usize,
142142
);
143143

144144
let l2_storage_root = extract_bytes32(
145145
&header.l2_consensus_state,
146-
client_state.storage_root_offset as usize,
146+
client_state.extra.storage_root_offset as usize,
147147
);
148148

149149
if client_state.l2_latest_height < header.l2_height.height() {

lib/create3/Cargo.toml

+1-1
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ version = "0.1.0"
77

88
[dependencies]
99
alloy-primitives = { workspace = true }
10-
alloy-sol-types = "0.8.12"
10+
alloy-sol-types = { workspace = true }
1111
sha3.workspace = true
1212

1313
[lints]

lib/macros/src/lib.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1154,7 +1154,7 @@ fn derive_as_tuple(
11541154
impl #impl_generics ::unionlabs::tuple::AsTuple for #ident #ty_generics #where_clause {
11551155
type Tuple = (#(#field_types,)*);
11561156

1157-
fn as_tuple(&self) -> <Self::Tuple as Tuple>::Ref<'_> {
1157+
fn as_tuple(&self) -> <Self::Tuple as ::unionlabs::tuple::Tuple>::Ref<'_> {
11581158
(
11591159
#(
11601160
&self.#as_tuple_fields,

lib/state-lens-ics23-ics23-light-client-types/Cargo.toml

+9-7
Original file line numberDiff line numberDiff line change
@@ -4,16 +4,18 @@ name = "state-lens-ics23-ics23-light-client-types"
44
version = "0.1.0"
55

66
[dependencies]
7-
alloy = { workspace = true, features = ["sol-types"], optional = true }
8-
protos = { workspace = true, optional = true, features = ["proto_full", "serde"] }
9-
serde = { workspace = true, optional = true, features = ["derive"] }
10-
thiserror = { workspace = true }
11-
unionlabs = { workspace = true, features = ["ethabi", "proto"] }
7+
alloy = { workspace = true, optional = true, features = ["sol-types"] }
8+
protos = { workspace = true, optional = true, features = ["proto_full", "serde"] }
9+
serde = { workspace = true, optional = true, features = ["derive"] }
10+
state-lens-light-client-types = { workspace = true }
11+
thiserror = { workspace = true }
12+
unionlabs = { workspace = true }
1213

1314
[dev-dependencies]
1415
hex-literal = { workspace = true }
1516

1617
[features]
1718
default = []
18-
ethabi = ["unionlabs/ethabi", "dep:alloy", "dep:protos"]
19-
serde = ["dep:serde"]
19+
20+
ethabi = ["unionlabs/ethabi", "dep:alloy", "dep:protos", "state-lens-light-client-types/ethabi"]
21+
serde = ["dep:serde", "state-lens-light-client-types/serde"]
Original file line numberDiff line numberDiff line change
@@ -1,89 +1,10 @@
1-
use unionlabs::primitives::H256;
1+
use unionlabs::{primitives::H256, tuple::AsTuple};
22

3-
#[derive(Debug, Clone, PartialEq)]
3+
pub type ClientState = state_lens_light_client_types::ClientState<Extra>;
4+
5+
#[derive(Debug, Clone, PartialEq, AsTuple)]
46
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
5-
pub struct ClientState {
6-
/// l2 chain id
7-
pub l2_chain_id: String,
8-
/// l1 client id used to check the l2 inclusion proof against
9-
pub l1_client_id: u32,
10-
/// l2 client id
11-
pub l2_client_id: u32,
12-
/// l2 latest height
13-
pub l2_latest_height: u64,
7+
pub struct Extra {
148
/// ibc contract that is running on l2
159
pub contract_address: H256,
1610
}
17-
18-
#[cfg(feature = "ethabi")]
19-
pub mod ethabi {
20-
use core::str;
21-
use std::string::FromUtf8Error;
22-
23-
use alloy::sol_types::SolValue;
24-
use unionlabs::{
25-
encoding::{Decode, Encode, EthAbi},
26-
TryFromEthAbiBytesErrorAlloy,
27-
};
28-
29-
use crate::ClientState;
30-
31-
alloy::sol! {
32-
struct SolClientState {
33-
string l2ChainId;
34-
uint32 l1ClientId;
35-
uint32 l2ClientId;
36-
uint64 l2LatestHeight;
37-
bytes32 contractAddress;
38-
}
39-
}
40-
41-
impl Encode<EthAbi> for ClientState {
42-
fn encode(self) -> Vec<u8> {
43-
SolClientState {
44-
l2ChainId: self.l2_chain_id,
45-
l1ClientId: self.l1_client_id,
46-
l2ClientId: self.l2_client_id,
47-
l2LatestHeight: self.l2_latest_height,
48-
contractAddress: self.contract_address.into(),
49-
}
50-
.abi_encode_params()
51-
}
52-
}
53-
54-
impl Decode<EthAbi> for ClientState {
55-
type Error = TryFromEthAbiBytesErrorAlloy<Error>;
56-
57-
fn decode(bytes: &[u8]) -> Result<Self, Self::Error> {
58-
let client_state = SolClientState::abi_decode_params(bytes, true)?;
59-
60-
Ok(Self {
61-
l2_chain_id: String::from_utf8(client_state.l2ChainId.into_bytes())
62-
.map_err(|err| TryFromEthAbiBytesErrorAlloy::Convert(Error::ChainId(err)))?,
63-
l1_client_id: client_state.l1ClientId,
64-
l2_client_id: client_state.l2ClientId,
65-
l2_latest_height: client_state.l2LatestHeight,
66-
contract_address: client_state.contractAddress.into(),
67-
})
68-
}
69-
}
70-
71-
#[derive(Debug, Clone, PartialEq, thiserror::Error)]
72-
pub enum Error {
73-
#[error("invalid chain_id")]
74-
ChainId(#[from] FromUtf8Error),
75-
}
76-
77-
#[cfg(test)]
78-
mod test {
79-
#[test]
80-
fn test_decode() {
81-
// TODO(aeryz): impl
82-
}
83-
84-
#[test]
85-
fn test_encode() {
86-
// TODO(aeryz): impl
87-
}
88-
}
89-
}

lib/state-lens-ics23-ics23-light-client-types/src/header.rs

-125
This file was deleted.
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
pub mod client_state;
22
pub mod consensus_state;
3-
pub mod header;
43

5-
pub use crate::{client_state::ClientState, consensus_state::ConsensusState, header::Header};
4+
pub use state_lens_light_client_types::Header;
5+
6+
pub use crate::{client_state::ClientState, consensus_state::ConsensusState};

lib/state-lens-ics23-mpt-light-client-types/Cargo.toml

+11-9
Original file line numberDiff line numberDiff line change
@@ -4,18 +4,20 @@ name = "state-lens-ics23-mpt-light-client-types"
44
version = "0.1.0"
55

66
[dependencies]
7-
alloy = { workspace = true, features = ["sol-types"], optional = true }
8-
bincode = { workspace = true, features = ["alloc", "derive"], optional = true }
9-
protos = { workspace = true, optional = true, features = ["proto_full", "serde"] }
10-
serde = { workspace = true, optional = true, features = ["derive"] }
11-
thiserror = { workspace = true }
12-
unionlabs = { workspace = true, features = ["ethabi", "proto"] }
7+
alloy = { workspace = true, optional = true, features = ["sol-types"] }
8+
bincode = { workspace = true, optional = true, features = ["alloc", "derive"] }
9+
protos = { workspace = true, optional = true, features = ["proto_full", "serde"] }
10+
serde = { workspace = true, optional = true, features = ["derive"] }
11+
state-lens-light-client-types = { workspace = true }
12+
thiserror = { workspace = true }
13+
unionlabs = { workspace = true, features = ["ethabi", "proto"] }
1314

1415
[dev-dependencies]
1516
hex-literal = { workspace = true }
1617

1718
[features]
18-
bincode = ["dep:bincode", "unionlabs/bincode"]
1919
default = []
20-
ethabi = ["unionlabs/ethabi", "dep:alloy", "dep:protos"]
21-
serde = ["dep:serde"]
20+
21+
bincode = ["dep:bincode", "unionlabs/bincode", "state-lens-light-client-types/bincode"]
22+
ethabi = ["unionlabs/ethabi", "dep:alloy", "dep:protos", "state-lens-light-client-types/ethabi"]
23+
serde = ["dep:serde", "state-lens-light-client-types/serde"]

0 commit comments

Comments
 (0)