From 9a7f0916fbe016e478998ed48f97618560b5f917 Mon Sep 17 00:00:00 2001 From: gfanton <8671905+gfanton@users.noreply.github.com> Date: Mon, 18 Dec 2023 16:50:28 +0100 Subject: [PATCH 1/5] chore: cleanup devnode comments Signed-off-by: gfanton <8671905+gfanton@users.noreply.github.com> --- contribs/gnodev/main.go | 2 +- contribs/gnodev/pkg/dev/node.go | 43 ++++++++++++++++++--------------- 2 files changed, 25 insertions(+), 20 deletions(-) diff --git a/contribs/gnodev/main.go b/contribs/gnodev/main.go index 894d8b36738..d086780ca29 100644 --- a/contribs/gnodev/main.go +++ b/contribs/gnodev/main.go @@ -128,7 +128,7 @@ func execDev(cfg *devCfg, args []string, io commands.IO) error { // Setup Dev Node // XXX: find a good way to export or display node logs - devNode, err := setupDevNode(ctx, rt, pkgpaths, gnoroot) + devNode, err := setupDevNode(ctx, rt, pkgpaths) if err != nil { return err } diff --git a/contribs/gnodev/pkg/dev/node.go b/contribs/gnodev/pkg/dev/node.go index 6624edc13c1..f290ea7a42c 100644 --- a/contribs/gnodev/pkg/dev/node.go +++ b/contribs/gnodev/pkg/dev/node.go @@ -23,12 +23,6 @@ import ( const gnoDevChainID = "tendermint_test" // XXX: this is hardcoded and cannot be change bellow -// DevNode is a backup.Client -// var _ backup.Client = (*Node)(nil) - -// DevNode is a restore.Client -// var _ restore.Client = (*Node)(nil) - // Node is not thread safe type Node struct { *node.Node @@ -108,14 +102,16 @@ func (d *Node) GetRemoteAddress() string { return d.Node.Config().RPC.ListenAddress } +// UpdatePackages updates the package currently know packages. It will be take in consideration in the next reload of the node. func (d *Node) UpdatePackages(paths ...string) error { for _, path := range paths { - // list all packages from target path + // List all packages from target path pkgslist, err := gnomod.ListPkgs(path) if err != nil { return fmt.Errorf("failed to list gno packages for %q: %w", path, err) } + // Update or add package in the current known list. for _, pkg := range pkgslist { d.pkgs[pkg.Dir] = pkg } @@ -124,14 +120,17 @@ func (d *Node) UpdatePackages(paths ...string) error { return nil } +// Reset stops the node, if running, and reloads it with a new genesis state, +// effectively ignoring the current state. func (d *Node) Reset(ctx context.Context) error { + // Stop the node if it's currently running. if d.Node.IsRunning() { if err := d.Node.Stop(); err != nil { return fmt.Errorf("unable to stop the node: %w", err) } } - // generate genesis + // Generate a new genesis state based on the current packages txs, err := d.pkgs.Load(DefaultCreator, DefaultFee, nil) if err != nil { return fmt.Errorf("unable to load pkgs: %w", err) @@ -142,9 +141,11 @@ func (d *Node) Reset(ctx context.Context) error { Txs: txs, } + // Reset the node with the new genesis state. return d.reset(ctx, genesis) } +// ReloadAll updates all currently known packages and then reloads the node. func (d *Node) ReloadAll(ctx context.Context) error { pkgs := d.ListPkgs() paths := make([]string, len(pkgs)) @@ -159,22 +160,25 @@ func (d *Node) ReloadAll(ctx context.Context) error { return d.Reload(ctx) } +// Reload saves the current state, stops the node if running, starts a new node, +// and re-apply previously saved state along with packages updated by `UpdatePackages`. +// If any transaction, including 'addpkg', fails, it will be ignored. +// Use 'Reset' to completely reset the node's state in case of persistent errors. func (d *Node) Reload(ctx context.Context) error { - - // save current state + // Save the current state of the node. state, err := d.saveState(ctx) if err != nil { return fmt.Errorf("unable to save state: %s", err.Error()) } - // stop the node if not already stopped + // Stop the node if it's currently running. if d.Node.IsRunning() { if err := d.Node.Stop(); err != nil { return fmt.Errorf("unable to stop the node: %w", err) } } - // generate genesis + // Generate a new genesis state based on the current packages. txs, err := d.pkgs.Load(DefaultCreator, DefaultFee, nil) if err != nil { return fmt.Errorf("unable to load pkgs: %w", err) @@ -185,14 +189,14 @@ func (d *Node) Reload(ctx context.Context) error { Txs: txs, } - // try to reset the node + // Reset the node with the new genesis state. if err := d.reset(ctx, genesis); err != nil { return fmt.Errorf("unable to reset the node: %w", err) } + // Attempt to resend transactions from the saved state. for _, tx := range state { - // skip empty transaction - if len(tx.Msgs) == 0 { + if len(tx.Msgs) == 0 { // Skip empty transactions. continue } @@ -207,11 +211,12 @@ func (d *Node) Reload(ctx context.Context) error { func (d *Node) reset(ctx context.Context, genesis gnoland.GnoGenesisState) error { var err error + // recoverError handles panics and converts them to errors. recoverError := func() { if r := recover(); r != nil { panicErr, ok := r.(error) if !ok { - panic(r) + panic(r) // Re-panic if not an error. } err = panicErr @@ -235,15 +240,15 @@ func (d *Node) reset(ctx context.Context, genesis gnoland.GnoGenesisState) error d.Node = node } - // create the node + // Execute node creation and handle any errors. createNode() if err != nil { return err } - // wait for readiness + // Wait for the node to be ready select { - case <-d.GetNodeReadiness(): // ok + case <-d.GetNodeReadiness(): // Ok case <-ctx.Done(): return ctx.Err() } From 80de64e30a76f9a255c1920de28ec0e624354c09 Mon Sep 17 00:00:00 2001 From: gfanton <8671905+gfanton@users.noreply.github.com> Date: Mon, 18 Dec 2023 16:51:50 +0100 Subject: [PATCH 2/5] fix(gnodev): skip failing tx instead of raising an error Signed-off-by: gfanton <8671905+gfanton@users.noreply.github.com> --- contribs/gnodev/pkg/dev/node.go | 1 + 1 file changed, 1 insertion(+) diff --git a/contribs/gnodev/pkg/dev/node.go b/contribs/gnodev/pkg/dev/node.go index f290ea7a42c..8a552a47b16 100644 --- a/contribs/gnodev/pkg/dev/node.go +++ b/contribs/gnodev/pkg/dev/node.go @@ -406,6 +406,7 @@ func newNode(logger log.Logger, genesis gnoland.GnoGenesisState) (*node.Node, er rootdir := gnoenv.RootDir() nodeConfig := gnoland.NewDefaultInMemoryNodeConfig(rootdir) + nodeConfig.SkipFailingGenesisTxs = true nodeConfig.Genesis.AppState = genesis return gnoland.NewInMemoryNode(logger, nodeConfig) } From 7a6648b0b5de5eedbd8385f1d55b5a333a211c8a Mon Sep 17 00:00:00 2001 From: gfanton <8671905+gfanton@users.noreply.github.com> Date: Tue, 19 Dec 2023 10:57:18 +0100 Subject: [PATCH 3/5] fix(gnodev): method signature too many arguments Signed-off-by: gfanton <8671905+gfanton@users.noreply.github.com> --- contribs/gnodev/main.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/contribs/gnodev/main.go b/contribs/gnodev/main.go index d086780ca29..7b82e43ec7f 100644 --- a/contribs/gnodev/main.go +++ b/contribs/gnodev/main.go @@ -303,7 +303,7 @@ func setupRawTerm(io commands.IO) (rt *rawterm.RawTerm, restore func() error, er } // setupDevNode initializes and returns a new DevNode. -func setupDevNode(ctx context.Context, rt *rawterm.RawTerm, pkgspath []string, gnoroot string) (*gnodev.Node, error) { +func setupDevNode(ctx context.Context, rt *rawterm.RawTerm, pkgspath []string) (*gnodev.Node, error) { nodeOut := rt.NamespacedWriter("Node") logger := tmlog.NewTMLogger(nodeOut) From c023dd9d21daacc897b7ae33844a4da18db41c34 Mon Sep 17 00:00:00 2001 From: gfanton <8671905+gfanton@users.noreply.github.com> Date: Tue, 19 Dec 2023 11:47:53 +0100 Subject: [PATCH 4/5] fix: add gnodev install on the CI Signed-off-by: gfanton <8671905+gfanton@users.noreply.github.com> --- .github/workflows/contribs.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/.github/workflows/contribs.yml b/.github/workflows/contribs.yml index 939ac670710..e3bada1e195 100644 --- a/.github/workflows/contribs.yml +++ b/.github/workflows/contribs.yml @@ -24,6 +24,7 @@ jobs: - "1.21.x" program: - "gnomd" + - "gnodev" runs-on: ubuntu-latest timeout-minutes: 5 steps: From e4606c6f71648ea196561b0dfc19604fd2b418f7 Mon Sep 17 00:00:00 2001 From: Guilhem Fanton <8671905+gfanton@users.noreply.github.com> Date: Tue, 9 Jan 2024 11:19:58 +0100 Subject: [PATCH 5/5] Update contribs/gnodev/pkg/dev/node.go Co-authored-by: Hariom Verma --- contribs/gnodev/pkg/dev/node.go | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/contribs/gnodev/pkg/dev/node.go b/contribs/gnodev/pkg/dev/node.go index 8a552a47b16..6401f53e280 100644 --- a/contribs/gnodev/pkg/dev/node.go +++ b/contribs/gnodev/pkg/dev/node.go @@ -102,7 +102,8 @@ func (d *Node) GetRemoteAddress() string { return d.Node.Config().RPC.ListenAddress } -// UpdatePackages updates the package currently know packages. It will be take in consideration in the next reload of the node. +// UpdatePackages updates the currently known packages. It will be taken into +// consideration in the next reload of the node. func (d *Node) UpdatePackages(paths ...string) error { for _, path := range paths { // List all packages from target path