Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/feature/wasm-lightclient-ibc-cha…
Browse files Browse the repository at this point in the history
…nges' into 810-verify-trust-level-to-be-larger-than-13-on-tendermint-client-creation
  • Loading branch information
AntonAndell committed Apr 2, 2024
2 parents ad5c712 + 68daa8c commit 0c0c791
Show file tree
Hide file tree
Showing 26 changed files with 1,724 additions and 54 deletions.
7 changes: 6 additions & 1 deletion .github/workflows/check-pr-label.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,11 @@ on:
- reopened
- labeled
- unlabeled
workflow_run:
workflows:
- auto-label
types:
- completed

jobs:

Expand All @@ -16,5 +21,5 @@ jobs:
steps:
- uses: docker://agilepathway/pull-request-label-checker:latest
with:
any_of: documentation,enhancement,bug,cicd,test,breaking-change,feature,scripts
any_of: documentation,enhancement,bug,cicd,test,breaking-change,feature,scripts,dependencies
repo_token: ${{ secrets.GITHUB_TOKEN }}
7 changes: 7 additions & 0 deletions contracts/cosmwasm-vm/cw-common/src/xcall_connection_msg.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,13 @@ pub enum ExecuteMsg {
client_id: String,
timeout_height: u64,
},
OverrideConnection {
connection_id: String,
counterparty_port_id: String,
counterparty_nid: NetId,
client_id: String,
timeout_height: u64,
},
ClaimFees {
nid: NetId,
address: String,
Expand Down
6 changes: 3 additions & 3 deletions contracts/cosmwasm-vm/cw-ibc-core/tests/test_client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -198,7 +198,7 @@ fn create_misbehaviour_event_test() {
}

#[test]
fn store_client_type_sucess() {
fn store_client_type_success() {
let mut deps = deps();
let contract = CwIbcCoreContext::default();
let client_type = ClientType::new("icon_client".to_string());
Expand Down Expand Up @@ -1169,7 +1169,7 @@ fn fails_on_storing_already_registered_client_into_registry() {
}

#[test]
fn sucess_on_getting_client() {
fn success_on_getting_client() {
let mut mock_deps = deps();
let contract = CwIbcCoreContext::default();
let client_type = ClientType::new("new_client_type".to_string());
Expand Down Expand Up @@ -1290,7 +1290,7 @@ fn fails_on_getting_client_state() {
}

#[test]
fn sucess_on_misbehaviour_validate() {
fn success_on_misbehaviour_validate() {
let mut deps = deps();
let contract = CwIbcCoreContext::default();
let info = create_mock_info("alice", "umlg", 2000);
Expand Down
2 changes: 1 addition & 1 deletion contracts/cosmwasm-vm/cw-xcall-ibc-connection/src/ack.rs
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ pub fn make_ack_fail(err: String) -> Binary {
/// Returns:
///
/// a `Result` with either an `IbcBasicResponse` or a `ContractError`.
pub fn on_ack_sucess(_packet: CwPacket) -> Result<CwBasicResponse, ContractError> {
pub fn on_ack_success(_packet: CwPacket) -> Result<CwBasicResponse, ContractError> {
let attributes = vec![attr("action", "acknowledge"), attr("success", "true")];

Ok(CwBasicResponse::new().add_attributes(attributes))
Expand Down
77 changes: 66 additions & 11 deletions contracts/cosmwasm-vm/cw-xcall-ibc-connection/src/contract.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use common::{
ibc::Height,
ibc::{core::ics04_channel::channel::State, Height},
rlp::{self},
};
use cosmwasm_std::{coins, BankMsg, IbcChannel};
Expand Down Expand Up @@ -120,6 +120,24 @@ impl<'a> CwIbcConnection<'a> {
} => {
self.ensure_admin(deps.as_ref().storage, info.sender)?;
self.configure_connection(
deps,
connection_id,
counterparty_port_id,
counterparty_nid,
client_id,
timeout_height,
)?;
Ok(Response::new())
}
ExecuteMsg::OverrideConnection {
connection_id,
counterparty_port_id,
counterparty_nid,
client_id,
timeout_height,
} => {
self.ensure_owner(deps.as_ref().storage, &info)?;
self.override_connection(
deps.storage,
connection_id,
counterparty_port_id,
Expand Down Expand Up @@ -684,23 +702,60 @@ impl<'a> CwIbcConnection<'a> {

pub fn configure_connection(
&self,
store: &mut dyn Storage,
deps: DepsMut,
connection_id: String,
counterparty_port_id: String,
counterparty_nid: NetId,
client_id: String,
timeout_height: u64,
) -> Result<(), ContractError> {
if self.get_connection_config(store, &connection_id).is_ok()
&& self
.get_counterparty_nid(store, &connection_id, &counterparty_port_id)
.is_ok()
{
return Err(ContractError::ConnectionAlreadyConfigured {
connection_id,
port_id: counterparty_port_id,
});
let cfg_res = self.get_ibc_config(deps.storage, &counterparty_nid);
if let Ok(cfg) = cfg_res {
let state_res = self.query_channel_state(
deps.as_ref(),
cfg.src_endpoint().port_id.clone(),
cfg.src_endpoint().channel_id.clone(),
);
if let Ok(state) = state_res {
if State::from_i32(state).map_or(false, |s| s.is_open()) {
return Err(ContractError::ConnectionAlreadyConfigured {
connection_id,
port_id: counterparty_port_id,
});
}
}

self.clear_ibc_config(deps.storage, &counterparty_nid)
}

self.store_counterparty_nid(
deps.storage,
&connection_id,
&counterparty_port_id,
&counterparty_nid,
)?;

self.store_connection_config(
deps.storage,
&connection_id,
&ConnectionConfig {
timeout_height,
client_id,
},
)?;

Ok(())
}
pub fn override_connection(
&self,
store: &mut dyn Storage,
connection_id: String,
counterparty_port_id: String,
counterparty_nid: NetId,
client_id: String,
timeout_height: u64,
) -> Result<(), ContractError> {
self.clear_ibc_config(store, &counterparty_nid);
self.store_counterparty_nid(
store,
&connection_id,
Expand Down
19 changes: 19 additions & 0 deletions contracts/cosmwasm-vm/cw-xcall-ibc-connection/src/ibc_host.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ use common::ibc::Height;
use cosmwasm_std::{to_binary, CosmosMsg, Deps, DepsMut, Storage, SubMsg, WasmMsg};
use cw_common::cw_types::CwPacket;
use cw_common::query_helpers::build_smart_query;
use cw_common::raw_types::channel::RawChannel;
use cw_common::{hex_string::HexString, raw_types::channel::RawPacket, ProstMessage};

use cw_common::cw_println;
Expand Down Expand Up @@ -82,6 +83,24 @@ impl<'a> CwIbcConnection<'a> {
Ok(Height::new(0, timeout_height).unwrap())
}

pub fn query_channel_state(
&self,
deps: Deps,
port: String,
channel: String,
) -> Result<i32, ContractError> {
let ibc_host = self.get_ibc_host(deps.storage)?;
let message = to_binary(&cw_common::core_msg::QueryMsg::GetChannel {
port_id: port,
channel_id: channel,
})
.unwrap();
let query = build_smart_query(ibc_host.to_string(), message);
let encoded_channel: String = deps.querier.query(&query).map_err(ContractError::Std)?;
let channel = RawChannel::decode(hex::decode(encoded_channel).unwrap().as_slice()).unwrap();
Ok(channel.state)
}

pub fn query_host_sequence_no(
&self,
deps: Deps,
Expand Down
4 changes: 4 additions & 0 deletions contracts/cosmwasm-vm/cw-xcall-ibc-connection/src/state.rs
Original file line number Diff line number Diff line change
Expand Up @@ -196,6 +196,10 @@ impl<'a> CwIbcConnection<'a> {
.save(store, nid.to_owned(), config)
.map_err(ContractError::Std)
}

pub fn clear_ibc_config(&self, store: &mut dyn Storage, nid: &NetId) {
self.ibc_config.remove(store, nid.to_owned());
}
pub fn set_ibc_host(
&self,
store: &mut dyn Storage,
Expand Down
Loading

0 comments on commit 0c0c791

Please sign in to comment.