-
Notifications
You must be signed in to change notification settings - Fork 386
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
[mini-RFC] GNO Commands #460
Comments
Good stuff, @moul @zivkovicmilos. Thank you for sharing! The GNO commands provide essential functions for GNO IDE as a product. Therefore, I break it down into functionalities. What we have implemented and are yet to implement fit here nicely. The feature list could be a starting point to map the features and commands.
|
Thank you. As discussed during today's call. The next step is to validate that our current favorite choice is compatible with our requirements. Here is a basic breakdown:
If it can help, I made one package that extended |
Just looked into your As I can see in the README and code, the differences between the packages are minimal. I wanted to mention that the I'm fine with using either, as the functionality |
I've tried playing around with I've created a small example gist that illustrates both of these functionalities: In the example, you can set the |
Looks great; you can start the PoC with real command creating the Please make sure to:
|
I've opened up a small draft PR that introduces a wrapper for
Let me know what you think, so I can continue applying this logic to other commands as well. I think it vastly cuts down on the code needed to instrument a command |
@moul I've also stumbled upon a caveat of ffcli while working on this, and it relates to the fact that you cannot mix places for flags and arguments (flags always go first, remaining arguments go last) - this is the related issue on ffcli, and it's due to the way flags are being parsed after the command has been invoked. I've updated all of our docs / workflows / tests to reflect this change |
Hi @zivkovicmilos, I recommend closing your initial RFC and continuing the discussion on #731 since it's related to this issue. The new proposal refers back to this one. |
Closing now - let's continue the chat on the new issue, as this one is outdated as is |
As suggested by @moul, I am making this internal mini RFC visible on the GitHub repo for the general public, so we can get as much input as possible.
The original Notion document is available here, and it contains valuable comments not visible in this markdown.
cc @piux2 @anarcher @giansalex et al.
GNO Commands
Created: January 4, 2023 4:04 PM
Tags: Gno, Tech
This document aims to outline the current command structure in the gno repository, and give suggestions on how it can be improved, which areas are lacking clarity user-wise and how some redundancies can be streamlined.
Available Commands
The current command structure can be essentially divided into two groups:
User commands are the following:
gnokey
- used primarily for key manipulation, but also for general interaction with gnolandgnoland
- runs the blockchain nodegnotxport
- used for importing and exporting transactions from the local blockchain node storagewebsite
- serves the gno website, along with user-defined contentlogos
- intended to be used as a browserDeveloper commands are the following:
gnoscan
- dumps imports from the specified file’s ASTgenproto
- helper for generating .proto implementationsgnofaucet
- serves a faucet for native network currencygnodev
- handy tool for developing gno packages / contractsGeneral Suggestions
Before diving deep into each command and their respective subcommands, it is worth noting some suggestions that apply to the majority (or all) commands mentioned.
Improve the CLI code workflow
The current command code structure is custom-made, without relying on third-party tools such as Cobra for management. This respects one of the central points of the gno project philosophy – no excessive dependencies, but also increases code complexity, somewhat compromises readability and makes it harder to add or tweak commands down the line.
Cobra usually gets a bad rep because it used to come bundled with the whole command orchestration circus (CLI generation tooling, docs generation tooling, viper etc.). That hasn’t been the case for a long time, it has a much smaller footprint now. Additionally, the gno project seemingly used Cobra in the past, but eventually deprecated the usage.
Nevertheless, for the use-case of the gno project, a much stabler package needs to be sought, one that is not updated as often and that contains the bare minimum features for the command structure to be easy to manage.
Such a package is ff/cli, that has a similar core feature set to Cobra, but without the unnecessary baggage.
What problems would using such a tool specifically solve?
Command line tools in general solve one central problem – standardization. The gno project has its fair share of non-standard command behavior, such as:
genproto
,gnoscan
)gnoland
inside thebuild
directory)BaseOptions
are not used for most commands that don’t require direct user input and node interaction)Utilizing tools like
💡 Note Manfredff/cli
can help standardize usage with minimal changes to the current command functionality, while improving UX.Another advantage of switching to ff/cli → better consistency across our tools and other tools; better consistency in terms of code style
I suggest we go with ff/cli, but wrap it from
pkgs/commands
Separate repos for complementary functionality
There are several tools bundled in the official gno repo that should be extracted out into separate repositories on the gnolang GitHub organization, as their functionality is only complementary and not essential to modules contained within gno.
The modules that should be moved to their separate respective repositories are:
gnoland/website
- the static site serving does not need to be bundled with the rest of the codebase, and can benefit from being moved to a separate repositorymisc/logos
- seems to be self-contained, and thus can be moved outcmd/gnotxport
- this standalone command tool interacts with the node using web socket connections, and thus does not require core functionality from the rest of the repo to function. Alternatively, it can be incorporated into a separate command as a subcommand (ex.gnoland
)I’m maybe biased but I love monorepos.
Some reasons:
git clone, go mod download
, and tada, you’re ready to work offline.I suggest we make the same virtual split, not with repos, but with folders and better documentation for now.
Probably it will make more sense to split the day we consider that Gnolang and Gnoland are mature enough and should be split.
Support configuration files
Currently, no command in the gno repository takes in configuration files.
For now, the only command that would benefit from such parameter simplification is the
gnoland
command, and these improvements are explored in a later section.Configuration files are usually used to for containing mutable / immutable runtime parameters. The GNO project should consider adding support for configuration file formats (for now, only in the
gnoland
command) such as:if we go this way, we need to take care of silenced unexpected behaviors.
I think we can define some things like:
--home
is available at$GNOKEY_HOME
CLI args
>config files
>env vars
>defaults
.Completely drop unused helpers
Commands that are exclusively used as helper code snippets should be moved to script files, and not offered as special runtime binaries. An example of this type of command is goscan, that should be removed from binary generation (and the repository as a command package), as it is a simple helper script.
Additionally, this command does not utilize anything from the rest of the repository and is self-sufficient.
💡 Note Manfred:Agree, I like having a
misc/
or things likex/
for experimentsSpecific Command Suggestions
gnotxport
Apart from the initial general suggestion of moving out this functionality into a separate repository, this command can benefit from a performance boost.
Currently, the
gnotxport
command simply iterates over transactions for importing and exporting, which can be suboptimal. A better approach to this would be to utilize batching of transactions, and compression of these batches (usinggzip
, for example). Transactions, instead of being exported out one by one to disk, would be batched together, and those batches could be compressed to further save disk space. The import process would be the inverse – decompression and just batch imports.This way, the functionality of
gnotxport
is clear – it is used for backing up a local node’s transactions.This command can also be renamed to
💡 Note Manfred:gnobackup
as it better reflects the functionality it offers.I also had concerns with this tool, for me the highest priority is not about gzip or transactions, but making an automated way to resume, i.e., by using sqlite as backend or automatic file discovery.
Then, we could also add a
--watch
flag or something allowing us to keep the process in the foreground with polling or another method.gnobackup
sounds better for me, maybegnosync
is even more accurate?gnoland
It was previously mentioned that the functionality of reading configuration files is not present in the current command structure. The command that could benefit from this the most is the
gnoland
command.Specifically, the
gnoland
command has flags that are used only on initial start, but are not relevant during runtime, that can be extracted out into agenesis.json
:chainid
- the ID of the chaingenesis
-balances-file - the initial balance sheet for accountsgenesis-txs-file
- the initial transactions to be executedThe proposed
genesis.json
can contain startup logic for the node, that doesn’t need to be specified each time during runtime.The
gnoland
command also has 2 flags that should be phased out:skip-failing-genesis-txs
- skips transactions that fail from thegenesis-txs-file
. This functionality should be phased out, as transactions contained in thegenesis-txs-file
should never fail in the first placeskip-start
- stops node execution before it has a chance to ramp up (creates directories and sets the stage for the node, but doesn’t allow it to start). Any sort of generation logic can be moved to other commands entirely, and existing commands shouldn’t be modified to have a kill switch for execution, as it complicates the command flowI think
genesis-txs.txt
file should only contain transaction, because you may want to compose a chain with multiple genesis files and use custom chainid.But if we go with better config file support, we can imagine shipping
genesis.json
+params.json
together instead of giving a list of params.About the params that are only useful during init time; let’s prefix them with
init-
.gnokey
The
gnokey
command is discussed last, as it contains the majority of suggestions.The original concept of the
gnokey
command was to facilitate private key management for the user, and have helper functionality for interacting with the underlying key-base, like manually signing and verifying transactions.However, the
gnokey
command has since grown to be bulky and should be split up into multiple commands / subcommands based on the functionality it provides.The full list of
gnokey
subcommands is:add
- adds a new private key to the key-basedelete
- removes a key from the key-basegenerate
- generates a new key, and adds it to the key-baseexport
- exports a private key’s encrypted armorimport
- imports a private key’s encrypted armor. Pending PR reviewlist
- outputs a list of all keys present in the key-basesign
- signs a transaction (in a file)verify
- verifies a signature of a transaction (from a file)broadcast
- broadcasts a signed documentquery
- makes an ABCI querymaketx
- composes a transaction document to be signedaddpkg
- uploads a new packagecall
- calls a public functionsend
- sends native currency to an addressThere are several subcommands that stand out here, as mainly just requiring private key access to work, but don’t specifically add / remove anything from the key-base, which should be the main functionality of the
gnokey
command.Namely, these subcommands are:
sign
andverify
- signing and verifying transactions (files) can be extracted out into a separate command likegnosign
, that offers these two subcommands, and takes in a reference to the key-basebroadcast
andquery
- these subcommands feel like they belong in the applicative section of gno, possibly with thegnoland
commandmaketx
- themaketx
command and its subcommands should be moved out to a separate command, much likesign
andverify
, for example to a command likegnotx
General suggestions for
gnokey
dry-run
flag, as it doesn’t seem to be used as much, and it clutters the code flowlist
subcommand should have a better, stylized (formatted) output for present keys. A good package for this sort of output would be columnize, as it has a small and stable footprintbroadcast
subcommand takes in a file as a parameter, but it isn’t mentioned anywhere (even in the help usage output), this should be explained betterquery
offers two flags that are still unsupported:height
andprove
. These flags should be removed for now as they have no functionmaketx send
command has a flag namedsend
, that is really the amount to be sent, so this flag should be renamed (for ex.amount
) to reflect that (and the help description updated)maketx send
command can also be used to broadcast the transaction, instead of simply creating it. This functionality breaks the principle ofmaketx
being used solely for transaction creations, not broadcastsThis is more like a general note;
I think we should maintain the abstraction between the commands and features inside these commands, meaning that commands should have no/less business logic related to the underlying feature but only have logic related to command itself like command args,flags,description or listing data, moving, combining data between different business logics. All the business logic related to a feature could be a separate, reusable Go package.
This abstraction makes things easier when we start building more clients other than the CLI commands e.g. while building the Gno IDE, we could benefit from some of these reusable packages/features.
The text was updated successfully, but these errors were encountered: