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: implement execute and query handlers #16

Merged
merged 9 commits into from
Apr 11, 2024
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
43 changes: 0 additions & 43 deletions .github/workflows/lint.yml

This file was deleted.

37 changes: 0 additions & 37 deletions .github/workflows/test.yml

This file was deleted.

29 changes: 11 additions & 18 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -28,12 +28,6 @@ panic = 'abort'
incremental = false
overflow-checks = true

[features]
# for more explicit tests, cargo test --features=backtraces
backtraces = ["cosmwasm-std/backtraces"]
# use library feature to disable all instantiate/execute/query exports
library = []

[package.metadata.scripts]
optimize = """docker run --rm -v "$(pwd)":/code \
--mount type=volume,source="$(basename "$(pwd)")_cache",target=/target \
Expand All @@ -43,24 +37,23 @@ optimize = """docker run --rm -v "$(pwd)":/code \

[dependencies]
base64 = "0.22.0"
cosmwasm-schema = "1.5.0"
cosmwasm-std = { version = "1.5.0", features = [
"cosmwasm_1_3",
# Enable this if you only deploy to chains that have CosmWasm 1.4 or higher
# "cosmwasm_1_4",
] }
cw-storage-plus = "1.1.0"
cw2 = "1.1.1"
cosmwasm-schema = "2.0.1"
cosmwasm-std = "2.0.1"
cw-storage-plus = "2.0.0"
cw2 = "2.0.0"
derive_more = "0.99.17"
ibc-core = { git = "https://github.com/cosmos/ibc-rs", rev = "1410bb03fdba930abd31c0941a5fd7f43d13ec96", default-features = false, features = ["schema"] } # "0.50.0"
ibc-clients = { git = "https://github.com/cosmos/ibc-rs", rev = "1410bb03fdba930abd31c0941a5fd7f43d13ec96", default-features = false, features = ["schema"] } # "0.50.0"
ibc-proto = { git = "https://github.com/cosmos/ibc-proto-rs.git", rev = "6cbe4c7ace5a688bc98831fa9c1cc2dabf3b2976", default-features = false } # "0.42.0"
ibc-core = { version = "0.51.0", default-features = false, features = ["schema"] }
ibc-clients = { version = "0.51.0", default-features = false, features = ["schema"] }
ibc-proto = { version = "0.42.2", default-features = false }
prost = "0.12.3"
schemars = "0.8.15"
serde = { version = "1.0", features = ["derive", "rc"] }
tendermint = "0.34.1"
tendermint-light-client-verifier = "0.34.1"
thiserror = { version = "1.0.49" }

[patch.crates-io]
ibc-proto = { git = "https://github.com/cosmos/ibc-proto-rs.git", rev = "6cbe4c7ace5a688bc98831fa9c1cc2dabf3b2976", default-features = false } # "0.42.2"

[dev-dependencies]
cw-multi-test = "0.17.0"
cw-multi-test = "2.0.0"
15 changes: 6 additions & 9 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,9 @@
help: ## Display this help message
@awk 'BEGIN {FS = ":.*?## "} /^[a-zA-Z_-]+:.*?## / {printf "\033[36m%-30s\033[0m %s\n", $$1, $$2}' $(MAKEFILE_LIST)

clean: ## Cleans compiled
@cargo clean

install-dev-tools: ## Installs all necessary cargo helpers
cargo install wasm-opt

Expand All @@ -11,7 +14,7 @@ build: ## Build the the entire project

build-cw: ## Build the WASM file for the rollkit light client
@echo "Building the WASM file for the rollkit light client"
@RUSTFLAGS='-C link-arg=-s' cargo build --target wasm32-unknown-unknown --release --lib --locked
@RUSTFLAGS='-C link-arg=-s' cargo build --target wasm32-unknown-unknown --release --lib
@mkdir -p contracts
@cp target/wasm32-unknown-unknown/release/rollkit_ibc.wasm contracts/

Expand All @@ -22,9 +25,6 @@ optimize-contracts: ## Optimize WASM files in contracts directory
wasm-opt "$$wasm_file" -o "$$optimized_file" -Os; \
done

clean: ## Cleans compiled
@cargo clean

lint: ## cargo check and clippy. Skip clippy on guest code since it's not supported by risc0
## fmt first, because it's the cheapest
cargo +nightly fmt --all --check
Expand All @@ -42,11 +42,8 @@ find-unused-deps: ## Prints unused dependencies for project. Note: requires nigh
check-features: ## Checks that project compiles with all combinations of features. default is not needed because we never check `cfg(default)`, we only use it as an alias.
cargo hack check --workspace --feature-powerset --exclude-features default

test-legacy: ## Runs test suite with output from tests printed
@cargo test -- --nocapture -Zunstable-options --report-time

test: ## Runs test suite using next test
@cargo nextest run --workspace --all-features
test: ## Run tests with all features and without default features.
@cargo test --all-targets --no-default-features

docs: ## Generates documentation locally
cargo doc --all-features --no-deps --release --open
21 changes: 14 additions & 7 deletions src/contract.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#[cfg(not(feature = "library"))]
use cosmwasm_std::entry_point;
use cosmwasm_std::{Binary, Deps, DepsMut, Env, MessageInfo, Response, StdResult};
use cosmwasm_std::{Binary, Deps, DepsMut, Env, MessageInfo, Response, StdError, StdResult};

// use cw2::set_contract_version;

Expand Down Expand Up @@ -33,17 +33,24 @@ pub fn instantiate(

#[cfg_attr(not(feature = "library"), entry_point)]
pub fn execute(
_deps: DepsMut<'_>,
_env: Env,
deps: DepsMut<'_>,
env: Env,
_info: MessageInfo,
_msg: SudoMsg,
msg: SudoMsg,
) -> Result<Response, ContractError> {
unimplemented!()
let mut ctx = RollkitContext::new_mut(deps, env)?;

let data = ctx.sudo(msg)?;

Ok(Response::default().set_data(data))
}

#[cfg_attr(not(feature = "library"), entry_point)]
pub fn query(_deps: Deps<'_>, _env: Env, _msg: QueryMsg) -> StdResult<Binary> {
unimplemented!()
pub fn query(deps: Deps<'_>, env: Env, msg: QueryMsg) -> StdResult<Binary> {
let ctx = RollkitContext::new_ref(deps, env)?;

ctx.query(msg)
.map_err(|e| StdError::generic_err(e.to_string()))
}

#[cfg(test)]
Expand Down
16 changes: 14 additions & 2 deletions src/handlers.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,9 @@ use crate::{

impl<'a, C: ClientType<'a>> Context<'a, C> {
pub fn instantiate(&mut self, msg: InstantiateMsg) -> Result<Binary, ContractError> {
let any = Any::decode(&mut msg.client_state.as_slice())?;
let any_client_state = Any::decode(&mut msg.client_state.as_slice())?;

let client_state = C::ClientState::try_from(any)?;
let client_state = C::ClientState::try_from(any_client_state)?;

let any_consensus_state = Any::decode(&mut msg.consensus_state.as_slice())?;

Expand Down Expand Up @@ -58,9 +58,14 @@ impl<'a, C: ClientType<'a>> Context<'a, C> {

client_state.update_state_on_misbehaviour(self, &client_id, any_client_msg)?;

// TODO: delete consensus state at misbehaviour height

ContractResult::success()
}
SudoMsg::VerifyMembership(msg) => {
// TODO: check DA light client is active
// TODO: assert(processedTime + clientState.fraudPeriod > currentTimestamp())

let msg = VerifyMembershipMsg::try_from(msg)?;

let client_cons_state_path = ClientConsensusStatePath::new(
Expand All @@ -82,6 +87,9 @@ impl<'a, C: ClientType<'a>> Context<'a, C> {
ContractResult::success()
}
SudoMsg::VerifyNonMembership(msg) => {
// TODO: check DA light client is active
// TODO: assert(processedTime + clientState.fraudPeriod > currentTimestamp())

let msg = VerifyNonMembershipMsg::try_from(msg)?;

let client_cons_state_path = ClientConsensusStatePath::new(
Expand Down Expand Up @@ -172,6 +180,8 @@ impl<'a, C: ClientType<'a>> Context<'a, C> {

client_state.verify_client_message(self, &client_id, any_client_msg)?;

// TODO: in case client message is a header, verify header proof and block data proof on the DA light client

QueryResponse::success()
}
QueryMsg::CheckForMisbehaviour(msg) => {
Expand All @@ -185,6 +195,8 @@ impl<'a, C: ClientType<'a>> Context<'a, C> {
let result =
client_state.check_for_misbehaviour(self, &client_id, any_client_msg)?;

// TODO: handle fraud proofs

QueryResponse::success().misbehaviour(result)
}
};
Expand Down
2 changes: 0 additions & 2 deletions src/msg.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,6 @@ use cosmwasm_schema::cw_serde;
use serde::de::Error;
use serde::{Deserialize, Deserializer, Serialize, Serializer};

//use ibc_clients::wasm_types::client_message::ClientMessage;

use ibc_core::client::types::error::ClientError;
use ibc_core::client::types::proto::v1::Height as RawHeight;
use ibc_core::client::types::Height;
Expand Down
Loading