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

feat: wasm lightclient ibc changes javascore #859

Draft
wants to merge 15 commits into
base: main
Choose a base branch
from
Draft
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
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
1,449 changes: 757 additions & 692 deletions Cargo.lock

Large diffs are not rendered by default.

34 changes: 21 additions & 13 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ members = [
"libraries/rust/common",
]

exclude = ["contracts/cosmwasm-vm/archway"]
exclude = ["contracts/cosmwasm-vm/archway","contracts/cosmwasm-vm/cw-integration"]


[workspace.package]
Expand All @@ -13,29 +13,37 @@ repository = "https://github.com/icon-project/ibc-integration.git"
version="0.1.1"

[workspace.dependencies]
cosmwasm-std = {version="1.2.2",default-features = false,features = ["iterator", "ibc3","staking"]}
cosmwasm-storage = "1.2.2"
cosmwasm-schema = "1.2.2"
schemars = "0.8.12"
cosmwasm-schema = {version="1.4.0",default-features = false}
cosmwasm-std = {version="1.4.0",default-features = false, features = ["ibc3"]}
schemars = {version="0.8.10",default-features = false}
serde = { version = "1.0.145", default-features = false, features = ["derive"] }
thiserror = { version = "1.0.31" }

cw-storage-plus = {git="https://github.com/icon-project/cw-storage-plus.git", branch="fix-raw"}
cw-xcall-lib={package="cw-xcall-lib", git="https://github.com/icon-project/xCall.git", tag="v0.1.0-alpha.5"}
cw-xcall = {package="cw-xcall", git="https://github.com/icon-project/xCall.git", tag="v0.1.0-alpha.5"}
cw-mock-dapp = { git="https://github.com/icon-project/xCall.git", tag="v0.1.0-alpha.5" }
cw-mock-dapp-multi = { git="https://github.com/icon-project/xCall.git", tag="v0.1.0-alpha.5" }
cw2 = "1.0.1"

common = { path="./libraries/rust/common" }
cw-common = { path="./contracts/cosmwasm-vm/cw-common" }
cw-light-client-common= {path="./contracts/cosmwasm-vm/cw-light-client-common"}


cw-xcall-lib={package="cw-xcall-lib", git="https://github.com/icon-project/xCall.git", branch="main"}
cw-xcall = {package="cw-xcall", git="https://github.com/icon-project/xCall.git", branch="main"}
cw-mock-dapp = { git="https://github.com/icon-project/xCall.git", branch="main" }
cw-mock-dapp-multi = { git="https://github.com/icon-project/xCall.git", branch="main" }
cw2 = {version="1.0.1",default-features = false}

ibc-proto = { version = "0.26.0", default-features = false}

prost = { version = "0.11.8", default-features = false,features=["prost-derive"]}

serde-json-wasm = {version="0.5.0", default-features = false}
serde_json = "1.0.96"
serde = { version = "1.0.154", default-features = false, features = ["derive"] }

bytes = { version = "1.4.0", default-features = false }
thiserror = { version = "1.0.39" }
hex ={ version = "0.4.3", default-features = false }
hex-literal={version ="*"}
debug_print = "1.0.0"


[profile.release]
opt-level = 'z'
debug = false
Expand Down
4 changes: 4 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,10 @@ e2e:
@echo "Running e2e tests..."
go test -v ./test/e2e -testify.m TestE2E_all

e2e-hopchain:
@echo "Running hopchain e2e tests..."
go test -v ./test/e2e-hopchain -testify.m TestE2E_hopchain

e2e-demo-setup:
@echo "Configuring e2e demo..."
export PRESERVE_DOCKER=true && \
Expand Down
4 changes: 2 additions & 2 deletions contracts/cosmwasm-vm/cw-common/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,14 @@ crate-type = ["cdylib", "rlib"]

[dependencies]
cosmwasm-schema = {workspace=true}
cosmwasm-std = {workspace=true, features=["ibc3"]}
cosmwasm-std = { workspace=true}
serde = { workspace=true}
cw-storage-plus = {workspace=true}
serde_json = {workspace=true}
hex-buffer-serde = "0.4.0"
schemars = {workspace=true}
hex = { workspace=true}
common = { path="../../../libraries/rust/common" }
common = { workspace=true }
ibc-proto = { workspace=true}
prost = { workspace=true}
serde-json-wasm = {workspace=true}
Expand Down
4 changes: 2 additions & 2 deletions contracts/cosmwasm-vm/cw-common/src/utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ macro_rules! cw_println {
use cosmwasm_std::Api;
let res = std::fmt::format(format_args!($($arg)*));
debug_print::debug_println!("{}",res);
$f.api.debug(&res);
$f.debug(&res);
}};
}

Expand All @@ -16,6 +16,6 @@ mod tests {
fn test_print_macro() {
let q = 10;
let mut deps = mock_dependencies();
cw_println!(deps.as_mut(), "hello {}", q);
cw_println!(deps.as_mut().api, "hello {}", q);
}
}
6 changes: 3 additions & 3 deletions contracts/cosmwasm-vm/cw-ibc-core/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -41,16 +41,16 @@ sha2 = { version = "0.10.6", default-features = false }
hex ={workspace=true }
sha3 = { version = "0.10.6", default-features = false }
bytes = { workspace=true }
common = { path="../../../libraries/rust/common", default-features = false }
cw-common = { path="../cw-common",default-features = false }
common = { workspace=true, default-features = false }
cw-common = { workspace=true,default-features = false }
prost = { workspace=true}
serde-json-wasm = {workspace=true}
debug_print = {workspace=true}


[dev-dependencies]
getrandom = {version = "0.2", default-features = false, features = ["custom"]}
cw-multi-test = "0.16.4"
#cw-multi-test = "0.15.1"
cw-icon-light-client = { path="../cw-icon-light-client",default-features = false }
anyhow="1.0.71"
test-utils={path="../../../libraries/rust/test-utils"}
Expand Down
42 changes: 21 additions & 21 deletions contracts/cosmwasm-vm/cw-ibc-core/src/contract.rs
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ impl<'a> CwIbcCoreContext<'a> {
self.init_client_counter(deps.storage, u64::default())?;
self.init_connection_counter(deps.storage, u64::default())?;
self.set_owner(deps.storage, info.sender)?;
cw_println!(deps, "{:?}", info.funds);
cw_println!(deps.api, "{:?}", info.funds);

Ok(Response::new().add_attribute("method", "instantiate"))
}
Expand Down Expand Up @@ -106,12 +106,12 @@ impl<'a> CwIbcCoreContext<'a> {
self.register_client(deps, client_type, client_address)
}
CoreExecuteMsg::CreateClient { msg } => {
cw_println!(deps, "[IBCCore] CreateClient Called");
cw_println!(deps.api, "[IBCCore] CreateClient Called");
let message: RawMsgCreateClient = Self::raw_from_hex(&msg)?;
self.create_client(deps, info, env, message)
}
CoreExecuteMsg::UpdateClient { msg } => {
cw_println!(deps, "[IBCCore] UpdateClient Called");
cw_println!(deps.api, "[IBCCore] UpdateClient Called");
let message: RawMsgUpdateClient = Self::raw_from_hex(&msg)?;
self.update_client(deps, info, message)
}
Expand All @@ -122,77 +122,77 @@ impl<'a> CwIbcCoreContext<'a> {
unimplemented!()
}
CoreExecuteMsg::ConnectionOpenInit { msg } => {
cw_println!(deps, "[IBCCore] Connection Open Init Called");
cw_println!(deps.api, "[IBCCore] Connection Open Init Called");
let message: RawMsgConnectionOpenInit = Self::raw_from_hex(&msg)?;
self.connection_open_init(deps, message)
}
CoreExecuteMsg::ConnectionOpenTry { msg } => {
cw_println!(deps, "[IBCCore] Connection Open Try Called");
cw_println!(deps.api, "[IBCCore] Connection Open Try Called");
let message: RawMsgConnectionOpenTry = Self::raw_from_hex(&msg)?;
self.connection_open_try(deps, info, env, message)
}
CoreExecuteMsg::ConnectionOpenAck { msg } => {
cw_println!(deps, "[IBCCore] Connection Open Ack Called");
cw_println!(deps.api, "[IBCCore] Connection Open Ack Called");
let message: RawMsgConnectionOpenAck = Self::raw_from_hex(&msg)?;
self.connection_open_ack(deps, info, env, message)
}
CoreExecuteMsg::ConnectionOpenConfirm { msg } => {
cw_println!(deps, "[IBCCore] Connection Open Confirm Called");
cw_println!(deps.api, "[IBCCore] Connection Open Confirm Called");
let message: RawMsgConnectionOpenConfirm = Self::raw_from_hex(&msg)?;
self.connection_open_confirm(deps, env, info, message)
}
CoreExecuteMsg::ChannelOpenInit { msg } => {
cw_println!(deps, "[IBCCore] Channel Open Init Called");
cw_println!(deps.api, "[IBCCore] Channel Open Init Called");
let message = Self::raw_from_hex::<RawMsgChannelOpenInit>(&msg)?;

self.validate_channel_open_init(deps, info, &message)
}
CoreExecuteMsg::ChannelOpenTry { msg } => {
cw_println!(deps, "[IBCCore] Channel Open Try Called");
cw_println!(deps.api, "[IBCCore] Channel Open Try Called");
let message: RawMsgChannelOpenTry = Self::raw_from_hex(&msg)?;
self.validate_channel_open_try(deps, info, &message)
}
CoreExecuteMsg::ChannelOpenAck { msg } => {
cw_println!(deps, "[IBCCore] Channel Open Ack Called");
cw_println!(deps.api, "[IBCCore] Channel Open Ack Called");
let message: RawMsgChannelOpenAck = Self::raw_from_hex(&msg)?;
self.validate_channel_open_ack(deps, info, &message)
}
CoreExecuteMsg::ChannelOpenConfirm { msg } => {
cw_println!(deps, "[IBCCore] Channel Open Confirm Called");
cw_println!(deps.api, "[IBCCore] Channel Open Confirm Called");
let message: RawMsgChannelOpenConfirm = Self::raw_from_hex(&msg)?;
self.validate_channel_open_confirm(deps, info, &message)
}
CoreExecuteMsg::ChannelCloseInit { msg } => {
cw_println!(deps, "[IBCCore] Channel Close Init Called");
cw_println!(deps.api, "[IBCCore] Channel Close Init Called");
let message: RawMsgChannelCloseInit = Self::raw_from_hex(&msg)?;
self.validate_channel_close_init(deps, info, &message)
}
CoreExecuteMsg::ChannelCloseConfirm { msg } => {
cw_println!(deps, "[IBCCore] Channel Close Confirm Called");
cw_println!(deps.api, "[IBCCore] Channel Close Confirm Called");
let message: RawMsgChannelCloseConfirm = Self::raw_from_hex(&msg)?;
self.validate_channel_close_confirm(deps, info, &message)
}
CoreExecuteMsg::SendPacket { packet } => {
cw_println!(deps, "[IBCCore] Send Packet Called");
cw_println!(deps.api, "[IBCCore] Send Packet Called");
let packet_bytes = packet.to_bytes().map_err(Into::<ContractError>::into)?;
let packet: RawPacket = Message::decode(packet_bytes.as_slice())
.map_err(|error| ContractError::IbcDecodeError { error })?;

self.send_packet(deps, &env, info, packet)
}
CoreExecuteMsg::ReceivePacket { msg } => {
cw_println!(deps, "[IBCCore] Receive Packet Called");
cw_println!(deps.api, "[IBCCore] Receive Packet Called");
let message = Self::raw_from_hex::<RawMessageRecvPacket>(&msg)?;

self.validate_receive_packet(deps, info, env, &message)
}
CoreExecuteMsg::AcknowledgementPacket { msg } => {
cw_println!(deps, "[IBCCore] Acknowledgement Packet Called");
cw_println!(deps.api, "[IBCCore] Acknowledgement Packet Called");
let message = Self::raw_from_hex::<RawMessageAcknowledgement>(&msg)?;
self.acknowledgement_packet_validate(deps, info, env, &message)
}
CoreExecuteMsg::TimeoutPacket { msg } => {
cw_println!(deps, "[IBCCore] Timeout Packet Called");
cw_println!(deps.api, "[IBCCore] Timeout Packet Called");
let message = Self::raw_from_hex::<RawMessageTimeout>(&msg)?;
self.timeout_packet_validate(
deps,
Expand All @@ -202,7 +202,7 @@ impl<'a> CwIbcCoreContext<'a> {
)
}
CoreExecuteMsg::TimeoutOnClose { msg } => {
cw_println!(deps, "[IBCCore] Timeout On Close Called");
cw_println!(deps.api, "[IBCCore] Timeout On Close Called");
let message = Self::raw_from_hex::<RawMessageTimeoutOnclose>(&msg)?;
self.timeout_packet_validate(
deps,
Expand All @@ -212,7 +212,7 @@ impl<'a> CwIbcCoreContext<'a> {
)
}
CoreExecuteMsg::BindPort { port_id, address } => {
cw_println!(deps, "[IBCCore] Bind Port Called");
cw_println!(deps.api, "[IBCCore] Bind Port Called");
let port_id = IbcPortId::from_str(&port_id).map_err(|error| {
ContractError::IbcDecodeError {
error: DecodeError::new(error.to_string()),
Expand All @@ -232,7 +232,7 @@ impl<'a> CwIbcCoreContext<'a> {
packet,
acknowledgement,
} => {
cw_println!(deps, "[IBCCore] Write Acknowledgement Called");
cw_println!(deps.api, "[IBCCore] Write Acknowledgement Called");
let ack = acknowledgement.to_bytes()?;
self.write_acknowledgement(deps, info, &env, packet, ack)
}
Expand Down Expand Up @@ -279,7 +279,7 @@ impl<'a> CwIbcCoreContext<'a> {
let res = self
.consensus_state_any(deps, &IbcClientId::from_str(&client_id).unwrap())
.map_err(|_e| {
cw_println!(deps, "{_e:?}");
cw_println!(deps.api, "{_e:?}");
ContractError::InvalidClientId { client_id }
})
.unwrap();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,7 @@ impl<'a> IbcClient for CwIbcCoreContext<'a> {

let sub_msg: SubMsg = client.update_client(&client_id, &header)?;
cw_println!(
deps,
deps.api,
"Called Update Client On Lightclient for client id:{}",
&message.client_id
);
Expand Down Expand Up @@ -325,7 +325,7 @@ impl<'a> IbcClient for CwIbcCoreContext<'a> {
cosmwasm_std::SubMsgResult::Ok(result) => match result.data {
Some(data) => {
let update_client_response: UpdateClientResponse = from_binary_response(&data)?;
cw_println!(deps, "Received Client Update Callback with data");
cw_println!(deps.api, "Received Client Update Callback with data");
let client_id: ClientId =
self.get_callback_data(deps.as_ref().storage, EXECUTE_UPDATE_CLIENT)?;
self.clear_callback_data(deps.storage, EXECUTE_UPDATE_CLIENT);
Expand Down Expand Up @@ -468,7 +468,7 @@ impl<'a> IbcClient for CwIbcCoreContext<'a> {

let clinet_message = LightClientMessage::Misbehaviour {
client_id: client_id.to_string(),
misbehaviour: to_vec(&message.misbehaviour)?,
misbehaviour: message.misbehaviour.unwrap().encode_to_vec(),
};

let wasm_exec_message: CosmosMsg = CosmosMsg::Wasm(cosmwasm_std::WasmMsg::Execute {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,12 +27,8 @@ impl<'a> CwIbcCoreContext<'a> {
conn_id: &ConnectionId,
conn_end: &ConnectionEnd,
) -> Result<(), ContractError> {
let data = conn_end
.encode_vec()
.map_err(|error| ConnectionError::Other {
description: error.to_string(),
})
.map_err(Into::<ContractError>::into)?;
let data = conn_end.encode_vec().unwrap();

match self.ibc_store().connections().save(store, conn_id, &data) {
Ok(_) => Ok(()),
Err(error) => Err(ContractError::Std(error)),
Expand Down Expand Up @@ -287,14 +283,7 @@ impl<'a> CwIbcCoreContext<'a> {
) -> Result<(), ContractError> {
let connection_commit_key = commitment::connection_commitment_key(connection_id);

let connection_end_bytes =
connection_end
.encode_vec()
.map_err(|error| ContractError::IbcConnectionError {
error: ConnectionError::Other {
description: error.to_string(),
},
})?;
let connection_end_bytes = connection_end.encode_vec().unwrap();

let commitment_bytes = keccak256(&connection_end_bytes).to_vec();

Expand Down
Loading
Loading