Closed KamiD closed 4 years ago
We will release 0.9 with cosmwasm_vm_version_2 later this week. It has quite a few breaking changes and I would wait for that to begin work on this issue
I would also say that this demo doesn't need storage or anything else. For an mvp, it should just parse the input message (json) , do some math on it and return a result (json).
This ensures we can call into it and that dynamic data is properly transfered
Hi ethan, : ) that's great news, so that means we have a stable version of api ?
Yeah, I agree that just for an MVP. so, my progress : now, the poc can be loaded and initialized by cosmwasm-vm correctly .
but also, some problem occurred during building, I just do some changes in my local repo of cosmwasm-vm :
init
to initialize
(as you know, init
is a default initialize func in go language)parse_wasm_opcode
for testwasi_unstable
during building, when cosmwasm-vm try to compile target byte-code to instance, it failed. so i add code in function from_module
as follow:
import_obj.extend(imports! {
"wasi_unstable" => {
// just fake a fd_write function to pass import check
"fd_write" => Func::new(move |fa: i32, fb: i32, fc: i32, fd: i32| -> i32 {
return 0;
}),
},
});
Of cause, there have some other perfect way to fix that problem, But for an mvp, that is rough but useful. Anyway, poc can be loaded, I am trying to test contract interface(init\handle\query) now, and got some problem:
malloc/free
to allocate memory for vm, the following go code is allocate
body:
//export allocate
func allocate(size C.uint) unsafe.Pointer{
ptr := C.malloc(C.ulong(size))
return ptr
}
get_region
return an empty result, I am working on fix that problem now. maybe i can't use C.malloc in this case? need more debuggingNice update.
Can you post your code here?
I will see about renaming init->initialize. Time is now or never
As to the extra imports and such, I looked at tiny go and I think the approach is to change the defaults imports they compile with. This was some months ago, but I can take a look again
in default, tinyGo to wasm will add import_table which named
wasi_unstable
during building, when cosmwasm-vm try to compile target byte-code to instance, it failed. so i add code in functionfrom_module
as follow:
There must be a way to disable WASI in TinyGo. If this is not the case, then this is a show stopper. Unfortunately I did not find any kind of flag for that and https://github.com/tinygo-org/tinygo/blob/master/targets/wasm.json does not look good as well.
This is doable, but adding a custom compile option to tinygo.
I did this some months ago.... need to look for the code
Okay, first of all the wasmi stuff....
I hacked around with tinygo some months ago to strip out excess exports. You can see what I did here: https://github.com/confio/tinygo/commit/95a4707853f8c8522f6a51db14c8306727a3776f
(Also trimming down the docker file for faster wasm builds)
Neither should be committed, but show some techniques. We can maintain a separate trimmed docker file rather than editing the master one. Also, we could add a separate runtime for cosmwasm, I would copy runtime_wasm and then edit.
Okay, I have some code up on https://github.com/ethanfrey/tinygo-demo which shows my build process and getting a simple code exporting init
(using go:exports
to rename it). This is not a contract, just a test of the build tooling.
I have now patched https://github.com/confio/tinygo/tree/cosmwasm-v2
It is up to the most recent release (0.13.1) with a smaller wasm-only Dockerfile (for quick test turnaround) and a special cosmwasm
mode for wasm code that doesn't require any imports
Please check out the README in https://github.com/ethanfrey/tinygo-demo (which includes building Dockerfile.wasm
from the linked repo and compiling a sample contract). You can see how we:
init
, handle
query
and migrate
(even with other go names)I would suggest using that image for all CosmWasm-related go contracts and making a PR there if necessary. When we are happy with it, I would like to upstream this.
I have also pushed cosmwasm/tinygo:latest
to DockerHub, so no need to build locally, if you have docker installed, just try make build-cosmwasm
@KamiD can you push your code to this repo so I can review/debug it?
This is still a private repo (open to your team, Simon and I) so it is not like publishing to the world, and I think I can help get a few key pieces working.
Great !, I will try it now~ The code will uploaded in a few hours
Hi Ethan ~ I used your code and docker image to test my code, every thing looks good, so I roll back local cosmwasm-vm repo to v0.8.0
Also i fixed get_region
failure, very powerful support~~, I will upload my code sooner , thanks for your help !
Hi Ethan, I upload my test code in this repo~, its working imperfect, only testing on init
, next working are in progress~
I took a look. Interesting stuff there with all the mallocs. I made a simple update to the makefile so I can view the generated wasm better.
I also noted that go test
doesn't run (only the tinygo compile). Not a problem at this stage, but odd. (And I modified the paths with go mod and saw tinygo complained... I'm sure you spent some time debugging this).
$ go test ./src/
src/lib.go:5:2: local import "../std" in non-local package
If you could make a (draft) PR with future work on this, it is easier to comment on the code.
This is a good start to have a demo on master, but I am happy to review PRs as they come in. Also, it would be cool if you added step-by-step testing procedures with cosmwasm-simulate in the readme. I already see the power of such tool :smile:
If you could make a (draft) PR with future work on this, it is easier to comment on the code.
This is a good start to have a demo on master, but I am happy to review PRs as they come in. Also, it would be cool if you added step-by-step testing procedures with cosmwasm-simulate in the readme. I already see the power of such tool 😄
Sure, I will update Readme later~ also, the next update will pushing by PR for more easier to review~
:+1:
Summary
we must build a poc of contract which dev on go language, it need accord with required exports :
make sure that Demo can be loaded and compiled without any errors
Proposal
For Admin Use