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

feat: add 'gnokey maketx run' #1001

Merged
merged 25 commits into from
Nov 23, 2023
Merged

feat: add 'gnokey maketx run' #1001

merged 25 commits into from
Nov 23, 2023

Conversation

moul
Copy link
Member

@moul moul commented Jul 29, 2023

With the gnokey maketx run command, you can execute any code directly on the chain from your user realm. It's convenient because it doesn't require uploading a whole new package - it simply creates a temporary memfile.

After merging this pull request, our next goal is to develop a client that enables a chain-backed REPL, providing a shell experience similar to Unix. This client will utilize q_eval for reading and run for writing, enabling seamless interaction with the chain directly from a Go shell. However, for now, let's focus on the current plan.

  • Update CLI
  • Implement RPC handler
  • Perform unit and integration tests
  • Restrict to package main
  • Fix: tests.GetPrevRealm(struct{("g1vp3uusf5txt06lx76x7qq70nldh5n2hcjqcs88" std.Address),("gno.land/r/g123456/run", string)} std.Realm) -> finally won't fix it; we want it to be seen as "gno.land/r/{caller.Addr()}/run"
  • Use main instead of Main
  • Blacklist addpkg -pkgpath gno.land/r/main (reserved)

Bonuses and notes for later -> #1283

@moul moul self-assigned this Jul 29, 2023
@github-actions github-actions bot added 📦 🌐 tendermint v2 Issues or PRs tm2 related 📦 ⛰️ gno.land Issues or PRs gno.land package related labels Jul 29, 2023
@moul moul added this to the 🌟 main.gno.land (wanted) milestone Sep 8, 2023
Signed-off-by: Manfred Touron <94029+moul@users.noreply.github.com>
Signed-off-by: moul <94029+moul@users.noreply.github.com>
@codecov
Copy link

codecov bot commented Oct 18, 2023

Codecov Report

Attention: 159 lines in your changes are missing coverage. Please review.

Comparison is base (1126d9f) 55.98% compared to head (3d677db) 56.31%.

Files Patch % Lines
tm2/pkg/crypto/keys/client/run.go 0.00% 105 Missing ⚠️
gno.land/pkg/sdk/vm/handler.go 0.00% 18 Missing ⚠️
gno.land/pkg/sdk/vm/msgs.go 41.93% 17 Missing and 1 partial ⚠️
gno.land/pkg/sdk/vm/keeper.go 75.36% 12 Missing and 5 partials ⚠️
tm2/pkg/crypto/keys/client/maketx.go 0.00% 1 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##           master    #1001      +/-   ##
==========================================
+ Coverage   55.98%   56.31%   +0.32%     
==========================================
  Files         420      422       +2     
  Lines       65443    68166    +2723     
==========================================
+ Hits        36640    38389    +1749     
- Misses      25940    26816     +876     
- Partials     2863     2961      +98     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

Signed-off-by: moul <94029+moul@users.noreply.github.com>
Signed-off-by: moul <94029+moul@users.noreply.github.com>
@moul moul changed the title feat: add 'gnokey maketx exec' feat: add 'gnokey maketx run' Oct 19, 2023
Signed-off-by: moul <94029+moul@users.noreply.github.com>
Signed-off-by: moul <94029+moul@users.noreply.github.com>
@moul
Copy link
Member Author

moul commented Oct 19, 2023

$ cat /tmp/script.gno
package main

import (
    "std"

    "gno.land/r/demo/tests"
    "gno.land/r/demo/users"
)

func Main() {
    println("HELLO WORLD3x!")
    println("render", users.Render(""))
    println("tests.CurrentRealmPath", tests.CurrentRealmPath())
    println("tests.IsOriginCall", tests.IsOriginCall())
    println("tests.GetPrevRealm", tests.GetPrevRealm())
    println("std.GetOrigCaller", std.GetOrigCaller())
    println("std.PrevRealm", std.PrevRealm())
}
$ go run ./gno.land/cmd/gnokey maketx run moul -gas-wanted 10000000 -gas-fee 10000000ugnot -broadcast /tmp/script.gno
Enter password.
HELLO WORLD3x!
render  * [administrator](/r/demo/users:administrator)
 * [anarcher](/r/demo/users:anarcher)
 * [ideamour](/r/demo/users:ideamour)
 * [manfred](/r/demo/users:manfred)
 * [piupiu](/r/demo/users:piupiu)
 * [zo_oma](/r/demo/users:zo_oma)

tests.CurrentRealmPath gno.land/r/demo/tests
tests.IsOriginCall false
tests.GetPrevRealm (struct{("g1vp3uusf5txt06lx76x7qq70nldh5n2hcjqcs88" std.Address),("gno.land/r/main" string)} std.Realm)
std.GetOrigCaller g1u7y667z64x2h7vc6fmpcprgey4ck233jaww9zq
std.PrevRealm (struct{("g1u7y667z64x2h7vc6fmpcprgey4ck233jaww9zq" std.Address),("" string)} std.Realm)

OK!
GAS WANTED: 10000000
GAS USED:   401843

Signed-off-by: moul <94029+moul@users.noreply.github.com>
Signed-off-by: moul <94029+moul@users.noreply.github.com>
Signed-off-by: moul <94029+moul@users.noreply.github.com>
Signed-off-by: moul <94029+moul@users.noreply.github.com>
@moul moul marked this pull request as ready for review October 19, 2023 02:39
@moul moul requested review from a team and jaekwon as code owners October 19, 2023 02:39
Signed-off-by: moul <94029+moul@users.noreply.github.com>
Signed-off-by: moul <94029+moul@users.noreply.github.com>
@moul
Copy link
Member Author

moul commented Oct 19, 2023

@moul moul mentioned this pull request Oct 19, 2023
Signed-off-by: moul <94029+moul@users.noreply.github.com>
Signed-off-by: moul <94029+moul@users.noreply.github.com>
Signed-off-by: moul <94029+moul@users.noreply.github.com>
Copy link
Contributor

@jaekwon jaekwon left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i didn't review every line but generally looks great!

Signed-off-by: moul <94029+moul@users.noreply.github.com>
Signed-off-by: moul <94029+moul@users.noreply.github.com>
@moul moul mentioned this pull request Oct 23, 2023
5 tasks
Copy link
Member

@thehowl thehowl left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So, I started reviewing individual files and added a few comments but didn't finish.

Essentially, my take on this is that we should have only one of run or call.

Call could be an alias for run, so that what is implicitly sent to the chain is package main; func main() { FunctionCall(args...) }.

Wdyt?

tm2/pkg/crypto/keys/client/run.go Show resolved Hide resolved
tm2/pkg/crypto/keys/client/run.go Outdated Show resolved Hide resolved
@moul
Copy link
Member Author

moul commented Nov 6, 2023

Essentially, my take on this is that we should have only one of run or call.

Call could be an alias for run, so that what is implicitly sent to the chain is package main; func main() { FunctionCall(args...) }.

I had the same feeling. However, the 1st call function is efficient and should be retained due to its minimal parsing overhead. I'm considering adding a —dry-run (or readonly) mode without transactions on run, possibly as an optional feature for local full node testing, not for public use: disabled on public RPCs.

Another thing that’s different is that run is meant to be used in a specific context: r/user/run, but call works directly in the context it’s meant for, which lets you use unexported helper functions and variables directly.

moul added a commit that referenced this pull request Nov 8, 2023
This PR adds a `contribs/gnomd` binary.
Please review PR #1001 for the `maketx run`. 

Additionally, this PR introduces the `contribs/` folder. It allows the
creation of `contribs/gno*` Go packages, Python/Rust/Shell/… scripts.
This approach keeps the main `gno`, `gnokey`, and `gnoland` simple while
adhering to the Unix philosophy and incorporating several specific gno
commands.

![CleanShot 2023-10-19 at 09 17
40@2x](https://github.com/gnolang/gno/assets/94029/9b92bf18-f923-4f70-aea7-a88f185f2342)

---------

Signed-off-by: moul <94029+moul@users.noreply.github.com>
Co-authored-by: Morgan <morgan@morganbaz.com>
moul added a commit to moul/gno that referenced this pull request Nov 14, 2023
This PR adds a `contribs/gnomd` binary.
Please review PR gnolang#1001 for the `maketx run`. 

Additionally, this PR introduces the `contribs/` folder. It allows the
creation of `contribs/gno*` Go packages, Python/Rust/Shell/… scripts.
This approach keeps the main `gno`, `gnokey`, and `gnoland` simple while
adhering to the Unix philosophy and incorporating several specific gno
commands.

![CleanShot 2023-10-19 at 09 17
40@2x](https://github.com/gnolang/gno/assets/94029/9b92bf18-f923-4f70-aea7-a88f185f2342)

---------

Signed-off-by: moul <94029+moul@users.noreply.github.com>
Co-authored-by: Morgan <morgan@morganbaz.com>
Signed-off-by: moul <94029+moul@users.noreply.github.com>
Signed-off-by: moul <94029+moul@users.noreply.github.com>
@gfanton gfanton merged commit c72a31e into master Nov 23, 2023
179 checks passed
@gfanton gfanton deleted the dev/moul/exec branch November 23, 2023 17:27
@thehowl
Copy link
Member

thehowl commented Nov 23, 2023

The summary of how I think we should be going:

  • qeval and msg_call should have the same basic input: an expression which may return a value which is evaluated. With qeval, this is just a query and cannot modify state, while msg_call creates a tx.
  • msg_call can, additionally, be enriched with some extra code, which is parsed as a normal Gno file.
    • This code is executed in the "realm" of the user; any contract calls from that code will have PrevRealm == OrigCaller.
    • msg_call's main parameter may call the functions defined in this realm. Ie. --address my_address --expr 'main()' will be essentially the way that maketx run is working now.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
📦 🌐 tendermint v2 Issues or PRs tm2 related 📦 ⛰️ gno.land Issues or PRs gno.land package related
Projects
Status: Done
Status: 🌟 Wanted for Launch
Archived in project
Development

Successfully merging this pull request may close these issues.

None yet

5 participants