Skip to content

Commit 1992b51

Browse files
ibrizsabinsabinchitrakarredlarva
authored
fix: use consensus state and client state from lightclient 232 (#670)
* fix: make reply on success * fix: clear callback data * fix: chan open init remove reply * fix: remove reply chan open try * fix: remove reply from open confirm * fix: remove close init reply * fix: fix tests * fix: add unit tests * fix: add unit tests * fix: unit tests * fix: remove reply on ack * fix: fix format * fix: remove receive packet callback * chore: pass buils * fix: add tests * fix: refactor test setup * fix: cleanup test * fix: receive test * fix: refactor test * chore: pass build * fix: fix close init test * fix: add test for send packet * fix: test for close confirm * chore: pass build * fix: cargo fmt * fix: unit tests * fix: tests * fix: refactor test * fix: timeout packet reply never * fix: fix test * fix: cleanup * fix: pull * fix: refactor tests * fix: remove client and consensus state * chore: pass build * chore: pull main * fix: refactor test * fix: channel tests * chore: pass build * fix: Missing IBC core checks against timestamp #191 (#636) * fix: fix tests * chore: pass build * fix: validate packet expiry * fix: add unit test for timeout * chore: pass build * fix: add test for packet timeout * chore: pass build * chore: remove cmnts * fix: fix validate packet expired * fix: timeout test * chore: build pass * fix: fix unit test * chore: pass build * fix: resolve conversation * fix: fix test * fix: timeout test * chore: pass build --------- Co-authored-by: sabinchitrakar <immortal.infidel@gmail.com> * fix: Rust Light Client update reply #181 (#662) * fix: get client type from client state * fix: rm log * fix: remove reply from create client * fix: update create client * fix: remove sending root * chore: build check * fix: store client id on update * fix: rename client * chore: pass build * fix: build script * fix: fix build --------- Co-authored-by: sabinchitrakar <immortal.infidel@gmail.com> Co-authored-by: redlarva <91685111+redlarva@users.noreply.github.com> --------- Co-authored-by: sabinchitrakar <immortal.infidel@gmail.com> Co-authored-by: redlarva <91685111+redlarva@users.noreply.github.com>
1 parent b4b7701 commit 1992b51

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

43 files changed

+1743
-4132
lines changed

contracts/cosmwasm-vm/cw-common/src/client_msg.rs

+4-9
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,8 @@ pub enum QueryMsg {
2323
#[returns(Vec<u8>)]
2424
GetConsensusState { client_id: String, height: u64 },
2525
#[returns(Vec<u8>)]
26+
GetLatestConsensusState { client_id: String },
27+
#[returns(Vec<u8>)]
2628
GetClientState { client_id: String },
2729
#[returns(bool)]
2830
VerifyMembership {
@@ -79,6 +81,8 @@ pub enum QueryMsg {
7981
VerifyConnectionOpenAck(VerifyConnectionPayload),
8082
#[returns(Vec<u64>)]
8183
GetPreviousConsensusState { client_id: String, height: u64 },
84+
#[returns(u64)]
85+
GetTimestampAtHeight { client_id: String, height: u64 },
8286
}
8387

8488
#[cw_serde]
@@ -113,7 +117,6 @@ pub struct VerifyConnectionState {
113117
pub proof_height: String,
114118
pub counterparty_prefix: Vec<u8>,
115119
pub proof: Vec<u8>,
116-
pub root: Vec<u8>,
117120
pub counterparty_conn_end_path: Vec<u8>,
118121
pub expected_counterparty_connection_end: Vec<u8>,
119122
}
@@ -122,15 +125,13 @@ impl VerifyConnectionState {
122125
proof_height: String,
123126
counterparty_prefix: Vec<u8>,
124127
proof: Vec<u8>,
125-
root: Vec<u8>,
126128
counterparty_conn_end_path: Vec<u8>,
127129
expected_counterparty_connection_end: Vec<u8>,
128130
) -> Self {
129131
Self {
130132
proof_height,
131133
counterparty_prefix,
132134
proof,
133-
root,
134135
counterparty_conn_end_path,
135136
expected_counterparty_connection_end,
136137
}
@@ -142,7 +143,6 @@ pub struct VerifyClientFullState {
142143
pub proof_height: String,
143144
pub counterparty_prefix: Vec<u8>,
144145
pub client_state_proof: Vec<u8>,
145-
pub root: Vec<u8>,
146146
pub client_state_path: Vec<u8>,
147147
pub expected_client_state: Vec<u8>,
148148
}
@@ -151,15 +151,13 @@ impl VerifyClientFullState {
151151
proof_height: String,
152152
counterparty_prefix: Vec<u8>,
153153
client_state_proof: Vec<u8>,
154-
root: Vec<u8>,
155154
client_state_path: Vec<u8>,
156155
expected_client_state: Vec<u8>,
157156
) -> Self {
158157
Self {
159158
proof_height,
160159
counterparty_prefix,
161160
client_state_proof,
162-
root,
163161
client_state_path,
164162
expected_client_state,
165163
}
@@ -171,7 +169,6 @@ pub struct VerifyClientConsensusState {
171169
pub proof_height: String,
172170
pub counterparty_prefix: Vec<u8>,
173171
pub consensus_state_proof: Vec<u8>,
174-
pub root: Vec<u8>,
175172
pub conesenus_state_path: Vec<u8>,
176173
pub expected_conesenus_state: Vec<u8>,
177174
}
@@ -181,15 +178,13 @@ impl VerifyClientConsensusState {
181178
proof_height: String,
182179
counterparty_prefix: Vec<u8>,
183180
consensus_state_proof: Vec<u8>,
184-
root: Vec<u8>,
185181
conesenus_state_path: Vec<u8>,
186182
expected_conesenus_state: Vec<u8>,
187183
) -> Self {
188184
Self {
189185
proof_height,
190186
counterparty_prefix,
191187
consensus_state_proof,
192-
root,
193188
conesenus_state_path,
194189
expected_conesenus_state,
195190
}

contracts/cosmwasm-vm/cw-ibc-core/src/contract.rs

+8-55
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,7 @@ impl<'a> CwIbcCoreContext<'a> {
108108
CoreExecuteMsg::CreateClient { msg } => {
109109
cw_println!(deps, "[IBCCore] CreateClient Called");
110110
let message: RawMsgCreateClient = Self::raw_from_hex(&msg)?;
111-
self.create_client(deps, info, message)
111+
self.create_client(deps, info, env, message)
112112
}
113113
CoreExecuteMsg::UpdateClient { msg } => {
114114
cw_println!(deps, "[IBCCore] UpdateClient Called");
@@ -277,7 +277,7 @@ impl<'a> CwIbcCoreContext<'a> {
277277
}
278278
QueryMsg::GetConsensusState { client_id } => {
279279
let res = self
280-
.consensus_state_any(deps.storage, &IbcClientId::from_str(&client_id).unwrap())
280+
.consensus_state_any(deps, &IbcClientId::from_str(&client_id).unwrap())
281281
.map_err(|_e| {
282282
cw_println!(deps, "{_e:?}");
283283
ContractError::InvalidClientId { client_id }
@@ -288,15 +288,16 @@ impl<'a> CwIbcCoreContext<'a> {
288288
}
289289
QueryMsg::GetConsensusStateByHeight { client_id, height } => {
290290
let client_val = IbcClientId::from_str(&client_id).unwrap();
291-
let client = self.get_client(deps.storage, &client_val).unwrap();
291+
let client = self.get_light_client(deps.storage, &client_val).unwrap();
292292
let res = client
293293
.get_consensus_state(deps, &client_val, height)
294294
.unwrap();
295-
to_binary(&hex::encode(res))
295+
let state = res.as_bytes();
296+
to_binary(&hex::encode(state))
296297
}
297298
QueryMsg::GetClientState { client_id } => {
298299
let res = self
299-
.client_state_any(deps.storage, &IbcClientId::from_str(&client_id).unwrap())
300+
.client_state_any(deps, &IbcClientId::from_str(&client_id).unwrap())
300301
.map_err(|_| ContractError::InvalidClientId { client_id })
301302
.unwrap();
302303

@@ -497,7 +498,7 @@ impl<'a> CwIbcCoreContext<'a> {
497498
}
498499
QueryMsg::GetPreviousConsensusStateHeight { client_id, height } => {
499500
let client_val = IbcClientId::from_str(&client_id).unwrap();
500-
let client = self.get_client(deps.storage, &client_val).unwrap();
501+
let client = self.get_light_client(deps.storage, &client_val).unwrap();
501502
let res = client
502503
.get_previous_consensus_state(deps, &client_val, height)
503504
.unwrap();
@@ -529,7 +530,6 @@ impl<'a> CwIbcCoreContext<'a> {
529530
message: Reply,
530531
) -> Result<Response, ContractError> {
531532
match message.id {
532-
EXECUTE_CREATE_CLIENT => self.execute_create_client_reply(deps, env, message),
533533
EXECUTE_UPDATE_CLIENT => self.execute_update_client_reply(deps, env, message),
534534
EXECUTE_UPGRADE_CLIENT => self.execute_upgrade_client_reply(deps, env, message),
535535
MISBEHAVIOUR => self.execute_misbehaviour_reply(deps, env, message),
@@ -683,32 +683,22 @@ impl<'a> CwIbcCoreContext<'a> {
683683

684684
#[cfg(test)]
685685
mod tests {
686-
use std::str::FromStr;
687686

688687
use crate::context::CwIbcCoreContext;
689688
use crate::contract::{CONTRACT_NAME, CONTRACT_VERSION};
690-
use common::ibc::core::ics02_client::height::Height;
691-
use common::{
692-
constants::ICON_CONSENSUS_STATE_TYPE_URL,
693-
icon::icon::lightclient::v1::ConsensusState as RawConsensusState, traits::AnyTypes,
694-
};
695689

696690
use crate::msg::MigrateMsg;
697691
use cw2::{get_contract_version, ContractVersion};
698692
use cw_common::ibc_types::IbcClientType;
699693

700-
use cw_common::cw_println;
701-
use prost::Message;
702-
703694
use super::{instantiate, query, InstantiateMsg, QueryMsg};
704695

705696
use cosmwasm_std::{
706697
from_binary,
707698
testing::{mock_dependencies, mock_env, mock_info, MockApi, MockQuerier, MockStorage},
708699
Addr, OwnedDeps,
709700
};
710-
use cw_common::ibc_types::IbcClientId;
711-
use cw_common::raw_types::{Any, RawHeight};
701+
712702
const SENDER: &str = "sender";
713703

714704
fn setup() -> OwnedDeps<MockStorage, MockApi, MockQuerier> {
@@ -757,43 +747,6 @@ mod tests {
757747
assert_eq!(client, result_parsed.as_str());
758748
}
759749

760-
#[test]
761-
fn test_query_get_consensus_state() {
762-
let contract = CwIbcCoreContext::default();
763-
let client_id = "test_client_1".to_string();
764-
let mut deps = setup();
765-
let commitment_root =
766-
"0x7702db70e830e07b4ff46313456fc86d677c7eeca0c011d7e7dcdd48d5aacfe2".to_string();
767-
let consensus_state = RawConsensusState {
768-
message_root: commitment_root.encode_to_vec(),
769-
next_proof_context_hash: vec![1, 2, 3, 4],
770-
};
771-
772-
let height = Height::new(123, 456).unwrap();
773-
let _raw_height: RawHeight = RawHeight::from(height);
774-
contract
775-
.store_consensus_state(
776-
deps.as_mut().storage,
777-
&IbcClientId::from_str(&client_id).unwrap(),
778-
height,
779-
consensus_state.to_any().encode_to_vec(),
780-
consensus_state.get_keccak_hash().to_vec(),
781-
)
782-
.unwrap();
783-
784-
let msg = QueryMsg::GetConsensusState { client_id };
785-
let result = query(deps.as_ref(), mock_env(), msg).unwrap();
786-
let result_parsed: String = from_binary(&result).unwrap();
787-
let result_bytes = hex::decode(result_parsed).unwrap();
788-
789-
let result_decoded = Any::decode(result_bytes.as_ref()).unwrap();
790-
cw_println!(deps, "{result_decoded:?}");
791-
assert_eq!(
792-
ICON_CONSENSUS_STATE_TYPE_URL.to_string(),
793-
result_decoded.type_url
794-
);
795-
}
796-
797750
#[test]
798751
fn test_migrate() {
799752
let mut mock_deps = mock_dependencies();

contracts/cosmwasm-vm/cw-ibc-core/src/error.rs

+2
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,8 @@ pub enum ContractError {
7878
#[error("InvalidHeight")]
7979
InvalidHeight,
8080

81+
#[error("PacketNotExpired")]
82+
PacketNotExpired,
8183
#[error("CallAlreadyInProgress")]
8284
CallAlreadyInProgress,
8385
}

0 commit comments

Comments
 (0)