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

fix(gnovm): don't print to stdout by default #3076

Merged
merged 3 commits into from
Nov 7, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions contribs/gnodev/pkg/dev/node.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"context"
"fmt"
"log/slog"
"os"
"path/filepath"
"strings"
"sync"
Expand Down Expand Up @@ -576,5 +577,6 @@ func newNodeConfig(tmc *tmcfg.Config, chainid string, appstate gnoland.GnoGenesi
PrivValidator: pv,
TMConfig: tmc,
Genesis: genesis,
VMOutput: os.Stdout,
}
}
5 changes: 4 additions & 1 deletion gno.land/pkg/gnoland/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package gnoland

import (
"fmt"
"io"
"log/slog"
"path/filepath"
"strconv"
Expand Down Expand Up @@ -36,10 +37,11 @@ type AppOptions struct {
DB dbm.DB // required
Logger *slog.Logger // required
EventSwitch events.EventSwitch // required
VMOutput io.Writer // optional
InitChainerConfig // options related to InitChainer
}

// DefaultAppOptions provides a "ready" default [AppOptions] for use with
// TestAppOptions provides a "ready" default [AppOptions] for use with
// [NewAppWithOptions], using the provided db.
func TestAppOptions(db dbm.DB) *AppOptions {
return &AppOptions{
Expand Down Expand Up @@ -91,6 +93,7 @@ func NewAppWithOptions(cfg *AppOptions) (abci.Application, error) {
bankKpr := bank.NewBankKeeper(acctKpr)
paramsKpr := params.NewParamsKeeper(mainKey, "vm")
vmk := vm.NewVMKeeper(baseKey, mainKey, acctKpr, bankKpr, paramsKpr)
vmk.Output = cfg.VMOutput

// Set InitChainer
icc := cfg.InitChainerConfig
Expand Down
3 changes: 3 additions & 0 deletions gno.land/pkg/gnoland/node_inmemory.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import (
"fmt"
"io"
"log/slog"
"path/filepath"
"time"
Expand All @@ -23,6 +24,7 @@
Genesis *bft.GenesisDoc
TMConfig *tmcfg.Config
DB *memdb.MemDB // will be initialized if nil
VMOutput io.Writer // optional

// If StdlibDir not set, then it's filepath.Join(TMConfig.RootDir, "gnovm", "stdlibs")
InitChainerConfig
Expand Down Expand Up @@ -107,6 +109,7 @@
DB: cfg.DB,
EventSwitch: evsw,
InitChainerConfig: cfg.InitChainerConfig,
VMOutput: cfg.VMOutput,

Check warning on line 112 in gno.land/pkg/gnoland/node_inmemory.go

View check run for this annotation

Codecov / codecov/patch

gno.land/pkg/gnoland/node_inmemory.go#L112

Added line #L112 was not covered by tests
})
if err != nil {
return nil, fmt.Errorf("error initializing new app: %w", err)
Expand Down
28 changes: 17 additions & 11 deletions gno.land/pkg/sdk/vm/keeper.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@
"bytes"
"context"
"fmt"
"io"
"log/slog"
"os"
"path/filepath"
"regexp"
"strings"
Expand Down Expand Up @@ -57,6 +57,9 @@

// VMKeeper holds all package code and store state.
type VMKeeper struct {
// Needs to be explicitly set, like in the case of gnodev.
Output io.Writer

baseKey store.StoreKey
iavlKey store.StoreKey
acck auth.AccountKeeper
Expand Down Expand Up @@ -108,7 +111,7 @@
m2 := gno.NewMachineWithOptions(
gno.MachineOptions{
PkgPath: "",
Output: os.Stdout, // XXX
Output: vm.Output,
Store: vm.gnoStore,
})
defer m2.Release()
Expand Down Expand Up @@ -191,8 +194,7 @@
m := gno.NewMachineWithOptions(gno.MachineOptions{
PkgPath: "gno.land/r/stdlibs/" + pkgPath,
// PkgPath: pkgPath, XXX why?
Output: os.Stdout,
Store: store,
Store: store,
})
defer m.Release()
m.RunMemPackage(memPkg, true)
Expand Down Expand Up @@ -275,7 +277,7 @@
m := gno.NewMachineWithOptions(
gno.MachineOptions{
PkgPath: "",
Output: os.Stdout, // XXX
Output: vm.Output,

Check warning on line 280 in gno.land/pkg/sdk/vm/keeper.go

View check run for this annotation

Codecov / codecov/patch

gno.land/pkg/sdk/vm/keeper.go#L280

Added line #L280 was not covered by tests
Store: store,
Context: msgCtx,
Alloc: store.GetAllocator(),
Expand Down Expand Up @@ -376,7 +378,7 @@
m2 := gno.NewMachineWithOptions(
gno.MachineOptions{
PkgPath: "",
Output: os.Stdout, // XXX
Output: vm.Output,
Store: gnostore,
Alloc: gnostore.GetAllocator(),
Context: msgCtx,
Expand Down Expand Up @@ -477,7 +479,7 @@
m := gno.NewMachineWithOptions(
gno.MachineOptions{
PkgPath: "",
Output: os.Stdout, // XXX
Output: vm.Output,
Store: gnostore,
Context: msgCtx,
Alloc: gnostore.GetAllocator(),
Expand Down Expand Up @@ -574,10 +576,14 @@
}
// Parse and run the files, construct *PV.
buf := new(bytes.Buffer)
output := io.Writer(buf)
if vm.Output != nil {
output = io.MultiWriter(buf, vm.Output)
}

Check warning on line 582 in gno.land/pkg/sdk/vm/keeper.go

View check run for this annotation

Codecov / codecov/patch

gno.land/pkg/sdk/vm/keeper.go#L581-L582

Added lines #L581 - L582 were not covered by tests
m := gno.NewMachineWithOptions(
gno.MachineOptions{
PkgPath: "",
Output: buf,
Output: output,
Store: gnostore,
Alloc: gnostore.GetAllocator(),
Context: msgCtx,
Expand All @@ -603,7 +609,7 @@
m2 := gno.NewMachineWithOptions(
gno.MachineOptions{
PkgPath: "",
Output: buf,
Output: output,
Store: gnostore,
Alloc: gnostore.GetAllocator(),
Context: msgCtx,
Expand Down Expand Up @@ -735,7 +741,7 @@
m := gno.NewMachineWithOptions(
gno.MachineOptions{
PkgPath: pkgPath,
Output: os.Stdout, // XXX
Output: vm.Output,
Store: gnostore,
Context: msgCtx,
Alloc: alloc,
Expand Down Expand Up @@ -802,7 +808,7 @@
m := gno.NewMachineWithOptions(
gno.MachineOptions{
PkgPath: pkgPath,
Output: os.Stdout, // XXX
Output: vm.Output,

Check warning on line 811 in gno.land/pkg/sdk/vm/keeper.go

View check run for this annotation

Codecov / codecov/patch

gno.land/pkg/sdk/vm/keeper.go#L811

Added line #L811 was not covered by tests
Store: gnostore,
Context: msgCtx,
Alloc: alloc,
Expand Down
3 changes: 1 addition & 2 deletions gnovm/pkg/gnolang/machine.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ import (
"encoding/json"
"fmt"
"io"
"os"
"reflect"
"slices"
"strconv"
Expand Down Expand Up @@ -144,7 +143,7 @@ func NewMachineWithOptions(opts MachineOptions) *Machine {

output := opts.Output
if output == nil {
output = os.Stdout
output = io.Discard
}
alloc := opts.Alloc
if alloc == nil {
Expand Down
Loading