gnolang / gno

Gno: An interpreted, stack-based Go virtual machine to build succinct and composable apps + Gno.land: a blockchain for timeless code and fair open-source
https://gno.land/
Other
844 stars 344 forks source link

Added smart contract does not run #581

Closed tadvi closed 1 year ago

tadvi commented 1 year ago

Description

Commit# 469b97a8a02c71c3d700f4f19bda5177025fa673

Can not run added smart contract. Call does not execute.

build/gnokey maketx addpkg -deposit "1ugnot" -gas-fee "1ugnot" -gas-wanted "5000000" -remote "localhost:26657" -chainid "dev" -pkgdir "/home/tad/sage/gno/build" -pkgpath "gno.land/r/demo/hello" test1

addpkg appears to work. No errors reported.

build/gnokey maketx call -gas-fee "1ugnot" -gas-wanted "5000000" -remote "localhost:26657" -chainid "dev" -pkgpath "gno.land/r/demo/hello" -func Hello test1

Output

{"msg":[{"@type":"/vm.m_call","caller":"g1tm8a6g4ptpt823llnjnk096t6s7jclq3exlcjz","send":"","pkg_path":"gno.land/r/demo/hello","func":"Hello","args":null}],"fee":{"gas_wanted":"5000000","gas_fee":"1ugnot"},"signatures":null,"memo":""}

hello.gno source code:

// hello.gno

package hello

var root int

func Render(path string) string {
    root += 1
    return fmt.Sprintf("Hello: %d", root)
} 

func Hello() string {
    root += 1
    //panic(ufmt.Sprintf("worked: %d", root))
    return fmt.Sprintf("Hello: %d", root)
}

Uncommenting panic above does not produce panics.

grepsuzette commented 1 year ago

Try with -broadcast (or -broadcast true in old versions I think). The "signatures":null you get in the json answer means it has not been signed, omitting the broadcast flag is for example to sign messages on airgapped devices.

Have a look here for example: https://test3.gno.land/r/demo/foo20?help

tadvi commented 1 year ago

Added -broadcast and now getting different error.

unknown address error

These is test1 in the list

build/gnokey list
0. test1 (local) - addr: g1tm8a6g4ptpt823llnjnk096t6s7jclq3exlcjz pub: gpub1pgfj7ard9eg82cjtv4u4xetrwqer2dntxyfzxz3pqtesk5kgc4lkw9adtxr6uvf0qajnylc2x8yx3a24ytwwgl38rtkgzcdkaa8, path: <nil>
grepsuzette commented 1 year ago

Try using the address before the flags gnokey maketx call test1 <flags>.

Here is a typical command that I would use: 'gnokey maketx addpkg grepsuzette --deposit 1ugnot --gas-fee 1ugnot --gas-wanted 5000000 --broadcast true '.

tadvi commented 1 year ago

This worked before big-huge CLI refactor. Now order of parameters is different.

build/gnokey maketx call -h
USAGE
  call [flags] <key-name or address>

Keyname or address is the last argument.

tadvi commented 1 year ago

I have tried both keybase name and address. Same issue: unknown address error.

grepsuzette commented 1 year ago

With the new cli for me this works:

build/gnokey maketx call -gas-fee "1ugnot" -gas-wanted "5000000" -remote "localhost:26657" -chainid "dev" -broadcast -pkgpath "gno.land/r/demo/hello" -func Hello -args "foo" grepsuzette

I had to add `-args "foo". Could you indicate both the commandline and result? Someone can take a look.

zivkovicmilos commented 1 year ago

@grepsuzette is right.

Due to the CLI library we're using, it requires that command arguments be left at the end (after flags), there is really no way around this: https://github.com/gnolang/gno/issues/460#issuecomment-1437019293

I'm sorry this refactor is causing headaches now, especially when some guides are still using the old syntax, but it was a necessary step in standardizing the way people use gno, and write commands

tadvi commented 1 year ago

Hello function has no arguments.

tadvi commented 1 year ago

More details to this issue.

Address is in the list of all the other addresses reported via gnokey list

0. test1 (local) - addr: g1u4f3dj5psnjh4efywl4yhz4ah864wnww4eealw pub: gpub1pgfj7ard9eg82cjtv4u4xetrwqer2dntxyfzxz3pq06uzfr3r9p8exvssh6ntcn7ksrlg8xjkfg47kpc4gye7sre2pcrx0gr2rr, path: <nil>

First addpkg and then call is made for test1.

gnoland reports this:

.level 1 .msg Served RPC HTTP response [method POST url / status 200 duration 2 remoteAddr 127.0.0.1:36694 [module rpc-server]]
.level 1 .msg Rejected bad transaction [tx E6270583735EF0F8F3AC0CD46E086D4D53E4FE82A2E643B0C2323A7CAE881FD7 res {{unknown address error [] [] --= Error =--
Data: std.UnknownAddressError{abciError:std.abciError{}}
Msg Traces:
    0  /home/tad/sage/gno/pkgs/std/errors.go:86 - account g1u4f3dj5psnjh4efywl4yhz4ah864wnww4eealw does not exist
Stack Trace:
    0  /home/tad/sage/gno/pkgs/errors/errors.go:20
    1  /home/tad/sage/gno/pkgs/std/errors.go:86
    2  /home/tad/sage/gno/pkgs/sdk/auth/ante.go:176
    3  /home/tad/sage/gno/pkgs/sdk/auth/ante.go:121
    4  /home/tad/sage/gno/gnoland/app.go:63
    5  /home/tad/sage/gno/pkgs/sdk/baseapp.go:800
    6  /home/tad/sage/gno/pkgs/sdk/baseapp.go:564
    7  /home/tad/sage/gno/pkgs/bft/abci/client/local_client.go:90
    8  /home/tad/sage/gno/pkgs/bft/proxy/app_conn.go:114
    9  /home/tad/sage/gno/pkgs/bft/mempool/clist_mempool.go:283
   10  /home/tad/sage/gno/pkgs/bft/mempool/clist_mempool.go:211
   11  /home/tad/sage/gno/pkgs/bft/rpc/core/mempool.go:233
   12  /usr/local/go/src/reflect/value.go:587
   13  /usr/local/go/src/reflect/value.go:368
   14  /home/tad/sage/gno/pkgs/bft/rpc/lib/server/handlers.go:158
   15  /home/tad/sage/gno/pkgs/bft/rpc/lib/server/handlers.go:183
   16  /usr/local/go/src/net/http/server.go:2110
   17  /usr/local/go/src/net/http/server.go:2488
   18  /usr/local/go/src/net/http/request.go:1137
   19  /home/tad/sage/gno/pkgs/bft/rpc/lib/server/http_server.go:181
   20  /usr/local/go/src/net/http/server.go:2110
   21  /usr/local/go/src/net/http/server.go:2948
   22  /usr/local/go/src/net/http/server.go:1992
   23  /usr/local/go/src/runtime/asm_amd64.s:1595
--= /Error =--
 } 0 0} err unknown address error [module mempool]]
grepsuzette commented 1 year ago

Hello function has no arguments.

Sorry I tinkered a bit of everything on my localhost in the beginning, I should revert that.

I think your account is added into gnokey, but it was never credited on the blockchain, meaning it doesn't exist.

Easy way to check it:

gnokey query auth/accounts/g1jg8mtutu9khhfwc4nxmuhcpftf0pajdhfvsqf5 Faucet account

height: 0
data: {
  "BaseAccount": {
    "address": "g1jg8mtutu9khhfwc4nxmuhcpftf0pajdhfvsqf5",
    "coins": "9999964000000ugnot",
    "public_key": null,
    "account_number": "0",
    "sequence": "0"
  }
}

gnokey query auth/accounts/g1u4f3dj5psnjh4efywl4yhz4ah864wnww4eealw Your account I don't know but I suspect you'll get:

height: 0
data: null

If so, you must have reset the blockchain in some ways.

You can add yourself to the genesis file using this tuto https://github.com/grepsuzette/gnoland-tutorials/blob/restart-to-read-genesis/docs/environment-setup/restart-on-block-1-to-read-the-genesis-again.md. This requires you manually addpkg the modules you want.

Or use a faucet (it must be explained somewhere there https://github.com/onbloc/gnoland-tutorials). I think this will help you get back on track.

grepsuzette commented 1 year ago

BTW I also found this was the biggest obstacle to start working on GNO in the beginning (either getting GNOT on the testnet, or find how to do it on the localnet). Maybe we should do something about it.

tadvi commented 1 year ago

Thanks grepsuzette. I have made small progress by resetting /testdir . Now gnokey query produces coin output.

./gnokey query auth/accounts/g1u4f3dj5psnjh4efywl4yhz4ah864wnww4eealw
height: 0
data: {
  "BaseAccount": {
    "address": "g1u4f3dj5psnjh4efywl4yhz4ah864wnww4eealw",
    "coins": "10000000000ugnot",
    "public_key": null,
    "account_number": "53",
    "sequence": "0"
  }

I perform addpkg and then call added smart contract. I get internal error. There is no extra detail in gnoland output.

grepsuzette commented 1 year ago

It's a very good start. I recommend trying with --args "". If doesn't work, then be more precise regarding what you type and what you get.

tadvi commented 1 year ago

nope. Still same error. Tried few different variations including change to smart contract itself accept 1 parameter.

grepsuzette commented 1 year ago

Can you indicate the full line you type? Do other realms work?

tadvi commented 1 year ago
./gnokey maketx addpkg -deposit "1ugnot" -gas-fee "1ugnot" -gas-wanted "5000000" -remote "localhost:26657" -chainid "dev" -pkgdir "/home/tad/sage/gno/build" -pkgpath "gno.land/r/demo/hello" test1

./gnokey maketx call -gas-fee "1ugnot" -gas-wanted "5000000" -remote "localhost:26657" -chainid "dev" -pkgpath "gno.land/r/demo/hello" -broadcast -func Hello -args "" test1
package hello

var root int

func Render(path string) string {
    root += 1
    return fmt.Sprintf("Hello: %d", root)
} 

func Hello(path string) string {
    root += 1
    // panic(ufmt.Sprintf("worked: %d", root))
    return fmt.Sprintf("Hello: %d", root)
}

test1 exists with valid address.

gnoland does not produce any error in the output.

gnokey maketx call result: "internal error".

grepsuzette commented 1 year ago

Note the first call to addpkg doesn't have a -broadcast. If -broadcast is absent, it is not broadcasted to your node (it is not executed, it doesn't ask the password either, and instead produces some json).

When you add the -broadcast, the addpkg fails with "Internal error" in the console. The output of the node (the one launched with build/gnoland) gives: .level 0 .msg Invalid tx [error internal error log recovered: gno.land/r/demo/issue581/issue581.gno:11: name fmt not declared followed by a long stack trace (this is long stack trace is how you spot it in the long stream of messages).

grepsuzette commented 1 year ago

So there's no bug, so far it's expected behaviour.

To make your example work, I suggest to import "gno.land/p/demo/ufmt" and then replace fmt.Sprintf with ufmt.Sprintf.

tadvi commented 1 year ago

Added -broadcast option:

./gnokey maketx addpkg -deposit "1ugnot" -gas-fee "1ugnot" -gas-wanted "5000000" -remote "localhost:26657" -broadcast -chainid "dev" -pkgdir "/home/tad/sage/gno/build" -pkgpath "gno.land/r/demo/hello" test1

Now getting different error:

RPC error -32600 - Invalid Request: http: request body too large
grepsuzette commented 1 year ago

Based on the command you typed, you're trying to push all your gno binaries in /home/tad/sage/gno/build to the chain. You likely want another dir after -pkgdir. Some example (with the old cli).

tadvi commented 1 year ago

ok. I have moved code into separate dir: /home/tad/sage/gno/build/hello.

./gnokey maketx addpkg -deposit "1ugnot" -gas-fee "1ugnot" -gas-wanted "5000000" -remote "localhost:26657" -broadcast -chainid "dev" -pkgdir "/home/tad/sage/gno/build/hello" -pkgpath "gno.land/r/demo/hello" test1

Getting internal error again.

grepsuzette commented 1 year ago

Tip: when you get internal error you can look in the console of your node. Somewhere you will find a long stack trace showing what the actual error was (usually some wrong import or a syntax error). If you fix that, eventually you will manage to add the package.

tadvi commented 1 year ago

solved. This time it was an issue in the smart contract code.