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

Added smart contract does not run #581

Closed
tadvi opened this issue Mar 9, 2023 · 23 comments
Closed

Added smart contract does not run #581

tadvi opened this issue Mar 9, 2023 · 23 comments
Labels
investigating This behavior is still being tested out

Comments

@tadvi
Copy link

tadvi commented Mar 9, 2023

Description

Commit# 469b97a

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
Copy link
Contributor

grepsuzette commented Mar 9, 2023

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
Copy link
Author

tadvi commented Mar 9, 2023

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
Copy link
Contributor

grepsuzette commented Mar 9, 2023

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
Copy link
Author

tadvi commented Mar 9, 2023

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
Copy link
Author

tadvi commented Mar 9, 2023

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

@grepsuzette
Copy link
Contributor

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
Copy link
Member

@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:
#460 (comment)

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
Copy link
Author

tadvi commented Mar 9, 2023

Hello function has no arguments.

@tadvi
Copy link
Author

tadvi commented Mar 11, 2023

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
Copy link
Contributor

grepsuzette commented Mar 12, 2023

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
Copy link
Contributor

grepsuzette commented Mar 12, 2023

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
Copy link
Author

tadvi commented Mar 12, 2023

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
Copy link
Contributor

grepsuzette commented Mar 12, 2023

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
Copy link
Author

tadvi commented Mar 12, 2023

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

@grepsuzette
Copy link
Contributor

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

@tadvi
Copy link
Author

tadvi commented Mar 12, 2023

./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
Copy link
Contributor

grepsuzette commented Mar 13, 2023

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
Copy link
Contributor

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.

@zivkovicmilos zivkovicmilos added the investigating This behavior is still being tested out label Mar 13, 2023
@tadvi
Copy link
Author

tadvi commented Mar 13, 2023

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
Copy link
Contributor

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
Copy link
Author

tadvi commented Mar 13, 2023

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
Copy link
Contributor

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
Copy link
Author

tadvi commented Mar 13, 2023

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
investigating This behavior is still being tested out
Projects
Development

No branches or pull requests

3 participants