Skip to content

Commit

Permalink
Fix/optimizer (#72)
Browse files Browse the repository at this point in the history
#65 small fix / follow-up.

Gates `library` feature included code not to be in the final wasm
  • Loading branch information
maurolacy authored Sep 27, 2024
1 parent f73fb6a commit a7cd058
Show file tree
Hide file tree
Showing 20 changed files with 805 additions and 214 deletions.
920 changes: 743 additions & 177 deletions Cargo.lock

Large diffs are not rendered by default.

8 changes: 4 additions & 4 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -36,9 +36,9 @@ blst = "0.3.11"
cosmos-sdk-proto = { version = "0.19.0", default-features = false, features = [
"cosmwasm",
] }
cosmwasm-derive = "2.0.4"
cosmwasm-schema = "2.0.4"
cosmwasm-std = { version = "2.0.4", default-features = false, features = [
cosmwasm-derive = "2.1.4"
cosmwasm-schema = "2.1.4"
cosmwasm-std = { version = "2.1.4", default-features = false, features = [
"std",
"abort",
"staking",
Expand Down Expand Up @@ -67,7 +67,7 @@ rust_decimal = "1.35"
k256 = { version = "0.13.1", default-features = false, features = ["schnorr"] }

# dev deps
cosmwasm-vm = { version = "2.0.4", default-features = false, features = [
cosmwasm-vm = { version = "2.1.4", default-features = false, features = [
"iterator",
"stargate",
] }
Expand Down
5 changes: 3 additions & 2 deletions contracts/babylon/schema/babylon-contract.json
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,7 @@
],
"properties": {
"headers": {
"description": "`headers` is a list of BTC headers. Typically: - A given delta of headers a user wants to add to the tip of, or fork the BTC chain.",
"description": "`headers` is a list of BTC headers. Typically: - A given delta of headers a user wants to add to the tip or fork of the BTC chain.",
"type": "array",
"items": {
"$ref": "#/definitions/BtcHeader"
Expand Down Expand Up @@ -540,7 +540,8 @@
"$schema": "http://json-schema.org/draft-07/schema#",
"title": "MigrateMsg",
"description": "An empty struct that serves as a placeholder in different places, such as contracts that don't set a custom message.\n\nIt is designed to be expressable in correct JSON and JSON Schema but contains no meaningful data. Previously we used enums without cases, but those cannot represented as valid JSON Schema (https://github.com/CosmWasm/cosmwasm/issues/451)",
"type": "object"
"type": "object",
"additionalProperties": false
},
"sudo": null,
"responses": {
Expand Down
2 changes: 1 addition & 1 deletion contracts/babylon/schema/raw/execute.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
],
"properties": {
"headers": {
"description": "`headers` is a list of BTC headers. Typically: - A given delta of headers a user wants to add to the tip of, or fork the BTC chain.",
"description": "`headers` is a list of BTC headers. Typically: - A given delta of headers a user wants to add to the tip or fork of the BTC chain.",
"type": "array",
"items": {
"$ref": "#/definitions/BtcHeader"
Expand Down
3 changes: 2 additions & 1 deletion contracts/babylon/schema/raw/migrate.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,6 @@
"$schema": "http://json-schema.org/draft-07/schema#",
"title": "MigrateMsg",
"description": "An empty struct that serves as a placeholder in different places, such as contracts that don't set a custom message.\n\nIt is designed to be expressable in correct JSON and JSON Schema but contains no meaningful data. Previously we used enums without cases, but those cannot represented as valid JSON Schema (https://github.com/CosmWasm/cosmwasm/issues/451)",
"type": "object"
"type": "object",
"additionalProperties": false
}
2 changes: 1 addition & 1 deletion contracts/babylon/src/contract.rs
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ pub fn instantiate(
let init_msg = SubMsg::reply_on_success(init_msg, REPLY_ID_INSTANTIATE_STAKING);

// Test code sets a channel, so that we can better approximate IBC in test code
#[cfg(any(test, feature = "library"))]
#[cfg(any(test, all(feature = "library", not(target_arch = "wasm32"))))]
{
let channel = cosmwasm_std::testing::mock_ibc_channel(
"channel-123",
Expand Down
20 changes: 13 additions & 7 deletions contracts/babylon/src/msg/contract.rs
Original file line number Diff line number Diff line change
@@ -1,14 +1,20 @@
use crate::msg::btc_header::{BtcHeader, BtcHeaderResponse, BtcHeadersResponse};
use crate::msg::cz_header::CzHeaderResponse;
use crate::msg::epoch::EpochResponse;
use crate::state::config::Config;
use babylon_apis::finality_api::Evidence;
use cosmwasm_schema::{cw_serde, QueryResponses};
use cosmwasm_std::{Binary, StdError, StdResult};

use babylon_apis::finality_api::Evidence;

use crate::msg::btc_header::BtcHeader;
#[cfg(not(target_arch = "wasm32"))]
use {
crate::msg::btc_header::{BtcHeaderResponse, BtcHeadersResponse},
crate::msg::cz_header::CzHeaderResponse,
crate::msg::epoch::EpochResponse,
crate::state::config::Config,
};

const BABYLON_TAG_BYTES: usize = 4;

// common functions for contract msgs
// Common functions for contract messages
pub trait ContractMsg {
fn validate(&self) -> StdResult<()>;
fn babylon_tag_to_bytes(&self) -> StdResult<Vec<u8>>;
Expand Down Expand Up @@ -94,7 +100,7 @@ impl ContractMsg for InstantiateMsg {
pub enum ExecuteMsg {
BtcHeaders {
/// `headers` is a list of BTC headers. Typically:
/// - A given delta of headers a user wants to add to the tip of, or fork the BTC chain.
/// - A given delta of headers a user wants to add to the tip or fork of the BTC chain.
headers: Vec<BtcHeader>,
},
/// `slashing` is a slashing event from the BTC staking contract.
Expand Down
3 changes: 2 additions & 1 deletion contracts/btc-finality/schema/btc-finality.json
Original file line number Diff line number Diff line change
Expand Up @@ -841,7 +841,8 @@
"$schema": "http://json-schema.org/draft-07/schema#",
"title": "MigrateMsg",
"description": "An empty struct that serves as a placeholder in different places, such as contracts that don't set a custom message.\n\nIt is designed to be expressable in correct JSON and JSON Schema but contains no meaningful data. Previously we used enums without cases, but those cannot represented as valid JSON Schema (https://github.com/CosmWasm/cosmwasm/issues/451)",
"type": "object"
"type": "object",
"additionalProperties": false
},
"sudo": null,
"responses": {
Expand Down
3 changes: 2 additions & 1 deletion contracts/btc-finality/schema/raw/migrate.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,6 @@
"$schema": "http://json-schema.org/draft-07/schema#",
"title": "MigrateMsg",
"description": "An empty struct that serves as a placeholder in different places, such as contracts that don't set a custom message.\n\nIt is designed to be expressable in correct JSON and JSON Schema but contains no meaningful data. Previously we used enums without cases, but those cannot represented as valid JSON Schema (https://github.com/CosmWasm/cosmwasm/issues/451)",
"type": "object"
"type": "object",
"additionalProperties": false
}
10 changes: 7 additions & 3 deletions contracts/btc-finality/src/msg.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,13 @@
use cosmwasm_schema::{cw_serde, QueryResponses};
use cw_controllers::AdminResponse;
#[cfg(not(target_arch = "wasm32"))]
use {
crate::state::config::Config, babylon_apis::finality_api::PubRandCommit,
cw_controllers::AdminResponse,
};

use babylon_apis::finality_api::{Evidence, IndexedBlock, PubRandCommit};
use babylon_apis::finality_api::{Evidence, IndexedBlock};

use crate::state::config::{Config, Params};
use crate::state::config::Params;

#[cw_serde]
#[derive(Default)]
Expand Down
3 changes: 2 additions & 1 deletion contracts/btc-staking/schema/btc-staking.json
Original file line number Diff line number Diff line change
Expand Up @@ -841,7 +841,8 @@
"$schema": "http://json-schema.org/draft-07/schema#",
"title": "MigrateMsg",
"description": "An empty struct that serves as a placeholder in different places, such as contracts that don't set a custom message.\n\nIt is designed to be expressable in correct JSON and JSON Schema but contains no meaningful data. Previously we used enums without cases, but those cannot represented as valid JSON Schema (https://github.com/CosmWasm/cosmwasm/issues/451)",
"type": "object"
"type": "object",
"additionalProperties": false
},
"sudo": null,
"responses": {
Expand Down
3 changes: 2 additions & 1 deletion contracts/btc-staking/schema/raw/migrate.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,6 @@
"$schema": "http://json-schema.org/draft-07/schema#",
"title": "MigrateMsg",
"description": "An empty struct that serves as a placeholder in different places, such as contracts that don't set a custom message.\n\nIt is designed to be expressable in correct JSON and JSON Schema but contains no meaningful data. Previously we used enums without cases, but those cannot represented as valid JSON Schema (https://github.com/CosmWasm/cosmwasm/issues/451)",
"type": "object"
"type": "object",
"additionalProperties": false
}
10 changes: 7 additions & 3 deletions contracts/btc-staking/src/msg.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,13 @@
use cosmwasm_schema::{cw_serde, QueryResponses};
use cw_controllers::AdminResponse;
#[cfg(not(target_arch = "wasm32"))]
use {
crate::state::config::Config, babylon_apis::btc_staking_api::ActiveBtcDelegation,
cw_controllers::AdminResponse,
};

use babylon_apis::btc_staking_api::{ActiveBtcDelegation, FinalityProvider};
use babylon_apis::btc_staking_api::FinalityProvider;

use crate::state::config::{Config, Params};
use crate::state::config::Params;
use crate::state::staking::BtcDelegation;

#[cw_serde]
Expand Down
3 changes: 2 additions & 1 deletion contracts/op-finality-gadget/schema/op-finality-gadget.json
Original file line number Diff line number Diff line change
Expand Up @@ -336,7 +336,8 @@
"$schema": "http://json-schema.org/draft-07/schema#",
"title": "MigrateMsg",
"description": "An empty struct that serves as a placeholder in different places, such as contracts that don't set a custom message.\n\nIt is designed to be expressable in correct JSON and JSON Schema but contains no meaningful data. Previously we used enums without cases, but those cannot represented as valid JSON Schema (https://github.com/CosmWasm/cosmwasm/issues/451)",
"type": "object"
"type": "object",
"additionalProperties": false
},
"sudo": null,
"responses": {
Expand Down
3 changes: 2 additions & 1 deletion contracts/op-finality-gadget/schema/raw/migrate.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,6 @@
"$schema": "http://json-schema.org/draft-07/schema#",
"title": "MigrateMsg",
"description": "An empty struct that serves as a placeholder in different places, such as contracts that don't set a custom message.\n\nIt is designed to be expressable in correct JSON and JSON Schema but contains no meaningful data. Previously we used enums without cases, but those cannot represented as valid JSON Schema (https://github.com/CosmWasm/cosmwasm/issues/451)",
"type": "object"
"type": "object",
"additionalProperties": false
}
13 changes: 8 additions & 5 deletions contracts/op-finality-gadget/src/msg.rs
Original file line number Diff line number Diff line change
@@ -1,10 +1,13 @@
use crate::state::config::Config;
use babylon_apis::finality_api::PubRandCommit;
use babylon_merkle::Proof;
#[cfg(not(target_arch = "wasm32"))]
use {
crate::state::config::Config, babylon_apis::finality_api::PubRandCommit,
cw_controllers::AdminResponse, std::collections::HashSet,
};

use cosmwasm_schema::{cw_serde, QueryResponses};
use cosmwasm_std::Binary;
use cw_controllers::AdminResponse;
use std::collections::HashSet;

use babylon_merkle::Proof;

#[cw_serde]
pub struct InstantiateMsg {
Expand Down
2 changes: 1 addition & 1 deletion docker/Dockerfile-arm64
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
FROM cosmwasm/rust-optimizer-arm64:0.16.0 AS rust-optimizer
FROM cosmwasm/optimizer-arm64:0.16.0 AS rust-optimizer

# clang and llvm are required for compiling rust-secp256k1 in rust-bitcoin
RUN apk update && \
Expand Down
2 changes: 1 addition & 1 deletion docker/Dockerfile-ci
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
FROM cosmwasm/rust-optimizer:0.16.0 AS rust-optimizer
FROM cosmwasm/optimizer:0.16.0 AS rust-optimizer

# clang and llvm are required for compiling rust-secp256k1 in rust-bitcoin
RUN apk update && \
Expand Down
2 changes: 1 addition & 1 deletion docker/Dockerfile-x86_64
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
FROM cosmwasm/rust-optimizer:0.16.0 AS rust-optimizer
FROM cosmwasm/optimizer:0.16.0 AS rust-optimizer

# clang and llvm are required for compiling rust-secp256k1 in rust-bitcoin
RUN apk update && \
Expand Down
2 changes: 1 addition & 1 deletion packages/test-utils/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -341,4 +341,4 @@ pub fn get_public_randomness_commitment() -> (String, PubRandCommit, Vec<u8>) {
},
pub_rand_commitment_msg.sig.to_vec(),
)
}
}

0 comments on commit a7cd058

Please sign in to comment.