* Start cosmos-sdk v0.47 integration (#1136) * Upgrade to sdk v0.47 branch * More integration work * SDK version upgrade; fixes * More fixes * Fixes * Deactivate failing tests * SDK + ibc-go version upgrades * limix gas fix (cherry picked from commit f7f841768e5051d96d243b42ce4f231a33020326) * with valset in bench (cherry picked from commit 35b2a8fd2c23d6160fca540771fd348913f7f143) * Revert staking query handler; fix tests * Minor cleanup * Rebased * Address linter issues * Set legacy router proper * Deactivate failing test. Race condition needs to handled in SDK * Address some code smells * Bump sdk version * Use gov v1 internally for votes * Activate test after sdk fix * Add group test * Add config template for wasm fields * Add Rust backtrace flag for more debug output on simulations * Set unique node folder for tests * Revert "Add Rust backtrace flag for more debug output on simulations" This reverts commit 218c3c6ce137dc02f7bc38391408d3460fb27e6f. * Simulations * Run also im/export + deterministic sims * Add package prefix to interfaces * Add signer annotation (https://github.com/cosmos/cosmos-sdk/issues/10933), minor cleanup * Bump sdk version * Review comments Co-authored-by: vuong <nguyenvuong1122000@gmail.com> * Bump bufbuild/buf-setup-action from 1.11.0 to 1.12.0 Bumps [bufbuild/buf-setup-action](https://github.com/bufbuild/buf-setup-action) from 1.11.0 to 1.12.0. - [Release notes](https://github.com/bufbuild/buf-setup-action/releases) - [Commits](https://github.com/bufbuild/buf-setup-action/compare/v1.11.0...v1.12.0) --- updated-dependencies: - dependency-name: bufbuild/buf-setup-action dependency-type: direct:production update-type: version-update:semver-minor ... Signed-off-by: dependabot[bot] <support@github.com> (cherry picked from commitf4905955b5) * Remove intertx for vanilla ICA * fix msg format in EVENTS.md (cherry picked from commit38d466adfd) * Better to sdk coin convertion (#1164) * Better to sdk coin convertion * Review feedback (cherry picked from commita925a9ed61) * Disallow only address permission (#1163) * Remove AccessTypeOnlyAddress for store msg * Remove AccessTypeOnlyAddress for update config msg * Review feedback Co-authored-by: Simon Warta <2603011+webmaster128@users.noreply.github.com> Co-authored-by: Simon Warta <2603011+webmaster128@users.noreply.github.com> (cherry picked from commit8991633de2) * Integrate wasmvm v1.2.0 (backport #1161) (#1175) * Integrate wasmvm v1.2.0 (#1161) * Bump wasmvm version * Bump wasm test contracts * Encode weighted votes * Encode instantiate2 * Handle code info query; better wasmvm errors * Fix readme * Make linter happy * add non cgo build * Review comments * Bump wasmvm to release version Co-authored-by: jhernandezb <contact@jhernandez.me> (cherry picked from commit957b38e0a5) # Conflicts: # x/wasm/keeper/handler_plugin_encoders.go # x/wasm/keeper/handler_plugin_encoders_test.go # x/wasm/keeper/keeper.go # x/wasm/keeper/keeper_test.go * Adress merge conflicts Co-authored-by: Alexander Peters <alpe@users.noreply.github.com> * Bump bufbuild/buf-setup-action from 1.12.0 to 1.13.0 Bumps [bufbuild/buf-setup-action](https://github.com/bufbuild/buf-setup-action) from 1.12.0 to 1.13.0. - [Release notes](https://github.com/bufbuild/buf-setup-action/releases) - [Commits](https://github.com/bufbuild/buf-setup-action/compare/v1.12.0...v1.13.0) --- updated-dependencies: - dependency-name: bufbuild/buf-setup-action dependency-type: direct:production update-type: version-update:semver-minor ... Signed-off-by: dependabot[bot] <support@github.com> (cherry picked from commitffa0e5e5e1) * Emit events for setContractAdmin + setAccessConfig (#1179) (cherry picked from commitc9e7830ac1) * Dependency upgrades (#1172) * Bump sdk version to lastest * Bump ibc-go version to lastest * Remove channel hack * Update to ibc-go v7 + protoVer=0.11.5 * Bump bufbuild/buf-setup-action from 1.13.0 to 1.13.1 Bumps [bufbuild/buf-setup-action](https://github.com/bufbuild/buf-setup-action) from 1.13.0 to 1.13.1. - [Release notes](https://github.com/bufbuild/buf-setup-action/releases) - [Commits](https://github.com/bufbuild/buf-setup-action/compare/v1.13.0...v1.13.1) --- updated-dependencies: - dependency-name: bufbuild/buf-setup-action dependency-type: direct:production update-type: version-update:semver-patch ... Signed-off-by: dependabot[bot] <support@github.com> (cherry picked from commitde27e7f82f) * Fix typos (backport #1185) (#1194) * Fix typos (cherry picked from commitc88b8194cb) # Conflicts: # proto/cosmwasm/wasm/v1/tx.proto * Fix merge conflict --------- Co-authored-by: Alex Peters <alpe@users.noreply.github.com> * Bump bufbuild/buf-setup-action from 1.13.1 to 1.14.0 (#1200) Bumps [bufbuild/buf-setup-action](https://github.com/bufbuild/buf-setup-action) from 1.13.1 to 1.14.0. - [Release notes](https://github.com/bufbuild/buf-setup-action/releases) - [Commits](https://github.com/bufbuild/buf-setup-action/compare/v1.13.1...v1.14.0) --- updated-dependencies: - dependency-name: bufbuild/buf-setup-action dependency-type: direct:production update-type: version-update:semver-minor ... Signed-off-by: dependabot[bot] <support@github.com> Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> (cherry picked from commitf3fc31c386) * list-contract-by-code bugfix (cherry picked from commit2ccffed778) * fix: stargate querier does not reset the state (cherry picked from commitfd0323541d) * test: add unit test (cherry picked from commit6d8018ac59) * Add Windows client support (#1197) * Add Windows client support * Separate server and windows client --------- Co-authored-by: Alex Peters <alpe@users.noreply.github.com> (cherry picked from commit8a20779518) * Bump bufbuild/buf-setup-action from 1.14.0 to 1.15.0 Bumps [bufbuild/buf-setup-action](https://github.com/bufbuild/buf-setup-action) from 1.14.0 to 1.15.0. - [Release notes](https://github.com/bufbuild/buf-setup-action/releases) - [Commits](https://github.com/bufbuild/buf-setup-action/compare/v1.14.0...v1.15.0) --- updated-dependencies: - dependency-name: bufbuild/buf-setup-action dependency-type: direct:production update-type: version-update:semver-minor ... Signed-off-by: dependabot[bot] <support@github.com> (cherry picked from commite5fab3da5a) * Rename windows client binary (cherry picked from commitde09c7fe2b) * Return IBC packet sequence number (backport #1225) (#1233) * Return IBC packet sequence number (#1225) * Return IBC packet sequence number * Fix review feedbacks * Remove names to return values in DispatchMsg method * Fix comments (cherry picked from commit4f1c57fc12) # Conflicts: # x/wasm/keeper/handler_plugin.go * Fix merge conflict --------- Co-authored-by: pinosu <95283998+pinosu@users.noreply.github.com> Co-authored-by: Alex Peters <alpe@users.noreply.github.com> * Test rust panic for regression (cherry picked from commita52e604966) * Fix client checksum verification (#1234) * Fix client checksum verification * Review comments (cherry picked from commit1a8019b380) # Conflicts: # x/wasm/client/cli/gov_tx.go * Fix merge conflict * Fix linters * Configure sonarcloud analysis (cherry picked from commit85cf1614fb) * Bump bufbuild/buf-setup-action from 1.15.0 to 1.15.1 Bumps [bufbuild/buf-setup-action](https://github.com/bufbuild/buf-setup-action) from 1.15.0 to 1.15.1. - [Release notes](https://github.com/bufbuild/buf-setup-action/releases) - [Commits](https://github.com/bufbuild/buf-setup-action/compare/v1.15.0...v1.15.1) --- updated-dependencies: - dependency-name: bufbuild/buf-setup-action dependency-type: direct:production update-type: version-update:semver-patch ... Signed-off-by: dependabot[bot] <support@github.com> (cherry picked from commit730ea5a1cf) * Make `CaptureIbcEvents` in ibctesting public. Before this change, it wasn't possible to implement the `chain.SendMsgs` method without [copying](https://github.com/public-awesome/ics721/blob/main/e2e/suite_helpers.go#L81-L98) them over. (cherry picked from commitb64fa078a3) * Upgrade to wasmvm 1.2.1 (backport #1245) (#1254) * Upgrade to wasmvm 1.2.1 (#1245) * Use wasmvm store adapter * Bump wasmvm to v1.2.1 (cherry picked from commit850f901b2e) # Conflicts: # go.mod # go.sum # x/wasm/keeper/keeper.go * Resolve conflicts --------- Co-authored-by: Alexander Peters <alpe@users.noreply.github.com> * WIP All cometbft (#1244) * Dep upgrade; use CometBft * Remove duplicte message events * Add changelog for v0.31.0 (#1188) * Start changelog for v0.31.0 * Add ICA upgrade * Add proto version link to buf.build * Update changelog (#1239) * Update changelog * Update changelog with latest changes * Set release date --------- Co-authored-by: pinosu <95283998+pinosu@users.noreply.github.com> (cherry picked from commitbc0e817912) * Remove new message type event * Support msg update params gov proposal (#1247) * Add MsgUpdateParams support * Implement UpdateParams msg * Fix test UpdateParams * Add migration test * Fix * Fix lint issues * Revert changes according to review feedback * Remove more x/params dependencies * Remove x/params from genesis test * Formatting * Restore old changes * fix lint * Fix tests and restructure migrations * Rename alias for convention --------- Co-authored-by: Alex Peters <alpe@users.noreply.github.com> * Fix test data generator (#1263) * linting 47 pr (#1261) * lint cosmwasm for sdk 47 * fix * remove setGenesis * remove additional unused functions * pass tests * use SDK's errors module * unecessary conversions * unnecessary conversions * remove unneeded event manager * complete linting of tests for 47 * add test for reimportation * check errors * Update x/wasm/keeper/proposal_integration_test.go Co-authored-by: Alexander Peters <alpe@users.noreply.github.com> * apply suggestion * suggestions * lints * don't return error in when making new transactions * no todo's in the code * Fix test data generator * Update x/wasm/types/genesis_test.go Co-authored-by: Alexander Peters <alpe@users.noreply.github.com> * use the full string invalid address (2 words) always --------- Co-authored-by: Alexander Peters <alpe@users.noreply.github.com> * Regenerate from proto; remove dead code; polish code * Set SDK version to v0.47x.0 (#1262) * Set SDK version to v0.47x.0 * Set chainID * Minor updates * Set chainID for simulations * Buf mod update * Use sdk tag instead of hash in buf * Bump ibc-go to v7.0.0 * faddat/re merge main (#1274) undefined --------- Co-authored-by: vuong <nguyenvuong1122000@gmail.com> Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> Co-authored-by: llllllluc <58892938+llllllluc@users.noreply.github.com> Co-authored-by: mergify[bot] <37929162+mergify[bot]@users.noreply.github.com> Co-authored-by: Gjermund Garaba <gjermund@garaba.net> Co-authored-by: Nikhil Suri <nikhilsuri@comcast.net> Co-authored-by: Paul <p22626262@gmail.com> Co-authored-by: pinosu <95283998+pinosu@users.noreply.github.com> Co-authored-by: ekez <zekemedley@gmail.com> Co-authored-by: Jacob Gadikian <jacobgadikian@gmail.com>
12 KiB
Integration
If you want to use Wasm in your own app, here is how you can get this working
quickly and easily.
First start with This article
in the "CosmWasm for CTOs" series that gives you a high level view.
Then check to make sure you fit the pre-requisites,
then integrate the x/wasm module as described below, and finally, you
can add custom messages and queries to your custom Go/SDK modules, exposing
them to any chain-specific contract.
Prerequisites
The pre-requisites of integrating x/wasm into your custom app is to be using
a compatible version of the Cosmos SDK, and to accept some limits to the
hardware it runs on.
| wasmd | Cosmos SDK |
|---|---|
| v0.40 | v0.47.0 |
| v0.31 | v0.45.14 |
| v0.30 | v0.45.11 |
| v0.29 | v0.45.8 |
| v0.28 | v0.45.5 |
| v0.27 | v0.45.4 |
| v0.26 | v0.45.1 |
| v0.25 | v0.45.1 |
| v0.24 | v0.45.0 |
| v0.23 | v0.45.0 |
| v0.22 | v0.45.0 |
| v0.21 | v0.42.x |
We currently only support Intel/AMD64 CPUs and OSX or Linux. For Linux, the standard build
commands work for glibc systems (Ubuntu, Debian, CentOS, etc). If you wish to compile
for a muslc based system (like alpine), you need to compile a static library wasmvm locally
and compile go with the muslc build tag. Or just use the Dockerfile,
which builds a static go binary in an alpine system.
This limit comes from the Rust dll we use to run the wasm code, which comes
from wasmvm. There are open issues
for adding ARM support, and
adding Windows support.
However, these issues are not high on the roadmap and unless you are championing
them, please count on the current limits for the near future.
Quick Trial
The simplest way to try out CosmWasm is simply to run wasmd out of the box,
and focus on writing, uploading, and using your custom contracts. There is
plenty that can be done there, and lots to learn.
Once you are happy with it and want to use a custom Cosmos SDK app,
you may consider simply forking wasmd. I highly advise against this.
You should try one of the methods below.
Integrating wasmd
As external module
The simplest way to use wasmd is just to import x/wasm and wire it up
in app.go. You now have access to the whole module and you custom modules
running side by side. (But the CosmWasm contracts will only have access
to bank and staking... more below on customization).
The requirement here is that you have imported the standard sdk modules
from the Cosmos SDK, and enabled them in app.go. If so, you can just look
at wasmd/app/app.go
for how to do so (just search there for lines with wasm).
wasmd also comes with 2 custom ante handlers:
CountTXDecoratoradds the TX position in the block into the context and passes it to the contractsLimitSimulationGasDecoratorprevents an "infinite gas" query
In order to support these features you would need to add our custom
ante handlers into the ante handler chain as in: app/ante.go
Copied into your app
Sometimes, however, you will need to copy x/wasm into your app. This should
be in limited cases, and makes upgrading more difficult, so please take the
above path if possible. This is required if you have either disabled some key
SDK modules in your app (eg. using PoA not staking and need to disable those
callbacks and feature support), or if you have copied in the core x/* modules
from the Cosmos SDK into your application and customized them somehow.
In either case, your best approach is to copy the x/wasm module from the
latest release into your application. Your goal is to make minimal changes
in this module, and rather add your customizations in a separate module.
This is due to the fact that you will have to copy and customize x/wasm
from upstream on all future wasmd releases, and this should be as simple
as possible.
If, for example, you have forked the standard SDK libs, you just want to
change the imports (from eg. github.com/cosmos/cosmos-sdk/x/bank to
github.com/YOUR/APP/x/bank), and adjust any calls if there are compiler
errors due to differing APIs (maybe you use Decimals not Ints for currencies?).
By the end of this, you should be able to run the standard CosmWasm contracts in your application, alongside all your custom logic.
Adding custom hooks
Once you have gotten this integration working and are happy with the flexibility it offers you, you will probably start wishing for deeper integration with your custom SDK modules. "It sure is nice to have custom tokens with a bonding curve from my native token, but I would love to trade them on the exchange I wrote as a Go module. Or maybe use them to add options to the exchange."
At this point, you need to dig down deeper and see how you can add this
power without forking either CosmWasm or wasmd.
Calling contracts from native code
This is perhaps the easiest part. Let's say your native exchange module
wants to call into a token that lives as a CosmWasm module. You need to
pass the wasm.Keeper into your exchange.Keeper. If you know the format
for sending messages and querying the contract (exported as json schema
from each contract), and have a way of configuring addresses of supported
token contracts, your exchange code can simply call wasm.Keeper.Execute
with a properly formatted message to move funds, or wasm.Keeper.SmartQuery
to check balances.
If you look at the unit tests in x/wasm/internal/keeper,
it should be pretty straight forward.
Extending the Contract Interface
If you want to let the contracts access your native modules, the first
step is to define a set of Messages and Queries that you want to expose,
and then add them as CosmosMsg::Custom and QueryRequest::Custom
variants. You can see an example of the bindings for Terra.
Once you have those bindings, use them to build a simple contact using much of the API. Don't worry too much about the details, this should be usable, but mainly you will want to upload it to your chain and use for integration tests with your native Cosmos SDK modules. Once that is solid, then add more and more complex contracts.
You will then likely want to add a mocks package so you can provide
mocks for the functionality of your native modules when unit testing
the contracts (provide static data for exchange rates when your contracts
query it). You can see an example of mocks for Terra contracts.
What these three steps provide is basically a chain-specific extension to the CosmWasm contract SDK. Any CosmWasm contract can import you library (bindings and mocks) and easily get started using your custom, chain-specific extensions just as easily as using the standard CosmWasm interfaces. What is left is actually wiring them up in your chain so they work as desired.
Note, in order to ensure that no one tries to run the contracts on an unsupported chain,
you will want to include a requires_XYZ directive in your bindings library, this will
mean that only blockchain apps that explicitly declare their support for the XYZ extensions
(please rename XYZ to your project name) will allow the contract to be uploaded, and others
get error messages upon upload, not while running a critical feature later on.
You just need to add a line like this
to your binding library to add the requirement to any contract that imports your bindings lib.
Calling into the SDK
Before I show how this works, I want to remind you, if you have copied x/wasm,
please do not make these changes to x/wasm.
We will add a new module, eg. x/contracts, that will contain custom
bindings between CosmWasm contracts and your native modules. There are two entry points
for you to use. The first is
CustomQuerier,
which allows you to handle your custom queries. The second is
CustomEncoder
which allows you to convert the CosmosMsg::Custom(YourMessage) types to []sdk.Msg to be dispatched.
Writing stubs for these is rather simple. You can look at the reflect_test.go file to see this in action.
In particular, here we define a CustomQuerier,
and here we define a CustomHandler.
This code is responsible to take json.RawMessage from the raw bytes serialized from your custom types in rust and parse it into
Go structs. Then take these go structs and properly convert them for your custom SDK modules.
You can look at the implementations for the staking module to see how to build these for non-trivial
cases, including passing in the Keeper via a closure. Here we
encode staking messages.
Note that withdraw returns 2 messages, which is an option you can use if needed to translate into native messages.
When we handle staking queries
we take in a Keeper in the closure and dispatch the custom QueryRequest from the contract to the native Keeper interface,
then encodes a response. When defining the return types, note that for proper parsing in the Rust contract, you
should properly name the JSON fields and use the omitempty keyword if Rust expects Option<T>. You must also use
omitempty and pointers for all fields that correspond to a Rust enum, so exactly one field is serialized.
Wiring it all together
Once you have writen and tested these custom callbacks for your module, you need to enable it in your application.
The first step is to write an integration test with a contract compiled with your custom SDK to ensure it works properly,
then you need to configure this in app.go.
For the test cases, you must
define the supported feature set
to include your custom name (remember requires_XYZ above?). Then, when creating TestInput,
you can pass in your custom encoder and querier.
Run a few tests with your compiled contract, ideally exercising the majority of the interfaces to ensure that all parsing between the contract and
the SDK is implemented properly.
Once you have tested this and are happy with the results, you can wire it up in app.go.
Just edit the default NewKeeper constructor
to have the proper availableCapabilities and pass in the CustomEncoder and CustomQuerier as the last two arguments to NewKeeper.
Now you can compile your chain and upload your custom contracts on it.