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(gnodev): lazy loading & staging support #3237

Open
wants to merge 29 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 25 commits
Commits
Show all changes
29 commits
Select commit Hold shift + click to select a range
16ee7d9
wip: lazy loading & custom resolver support
gfanton Jul 6, 2024
fd13a5a
chore: fixup
gfanton Nov 28, 2024
135f854
feat: add remote resolver & fixup
gfanton Nov 30, 2024
d258fd5
wip: lazy loader
gfanton Dec 2, 2024
3f92248
wip: test
gfanton Dec 3, 2024
3e9c300
wip: staging
gfanton Dec 12, 2024
07c714a
Merge remote-tracking branch 'origin/master' into feat/dev/lazy-loader
gfanton Dec 13, 2024
0e5e5f0
wip: glob
gfanton Dec 13, 2024
54c8193
feat: staging
gfanton Dec 15, 2024
ec51f78
feat: gnodev app
gfanton Dec 15, 2024
d48ffd9
chore: lint
gfanton Dec 15, 2024
b193081
fix: web redirect
gfanton Dec 15, 2024
6ef3685
fix: minor fix
gfanton Dec 16, 2024
08e9465
Merge branch 'master' into feat/dev/lazy-loader
leohhhn Dec 16, 2024
0a1695c
feat: add lazy proxy
gfanton Jan 5, 2025
e592fa9
Merge remote-tracking branch 'origin/master' into feat/dev/lazy-loader
gfanton Jan 5, 2025
2158026
fix: add missing files
gfanton Jan 5, 2025
d6315a1
fix: typo
gfanton Jan 6, 2025
8e931e2
fix: remote package load
gfanton Jan 6, 2025
a7a9a53
fix: make custom resolvers override default resolver
gfanton Jan 7, 2025
9f80c6f
chore: cleanup errors
gfanton Jan 7, 2025
cc48898
Merge branch 'master' into feat/dev/lazy-loader
gfanton Jan 9, 2025
5fb70a9
fix: globl package
gfanton Jan 9, 2025
09ea7cc
chore: lint
gfanton Jan 9, 2025
8b7a457
fix: tests
gfanton Jan 9, 2025
3621f7f
chore: fix back typo
gfanton Jan 9, 2025
268096f
Merge branch 'master' into feat/dev/lazy-loader
gfanton Jan 9, 2025
99d5099
fix: proxy
gfanton Jan 9, 2025
e818b65
chore: lint
gfanton Jan 9, 2025
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
488 changes: 488 additions & 0 deletions contribs/gnodev/cmd/gnodev/app.go

Large diffs are not rendered by default.

62 changes: 62 additions & 0 deletions contribs/gnodev/cmd/gnodev/command_staging.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
package main

import (
"context"
"flag"
"path/filepath"

"github.com/gnolang/gno/gnovm/pkg/gnoenv"
"github.com/gnolang/gno/tm2/pkg/commands"
)

type stagingCfg struct {
dev devCfg
}

var defaultStagingOptions = devCfg{
chainId: "staging",
chainDomain: DefaultDomain,
logFormat: "json",
maxGas: 10_000_000_000,
webHome: ":none:",
webListenerAddr: "127.0.0.1:8888",
nodeRPCListenerAddr: "127.0.0.1:26657",
deployKey: DefaultDeployerAddress.String(),
home: gnoenv.HomeDir(),
root: gnoenv.RootDir(),
interactive: false,
unsafeAPI: false,
lazyLoader: false,
paths: filepath.Join(DefaultDomain, "/**"), // Load every package under the main domain},

// As we have no reason to configure this yet, set this to random port
// to avoid potential conflict with other app
nodeP2PListenerAddr: "tcp://127.0.0.1:0",
nodeProxyAppListenerAddr: "tcp://127.0.0.1:0",
}

func NewStagingCmd(io commands.IO) *commands.Command {
var cfg stagingCfg

return commands.NewCommand(
commands.Metadata{
Name: "staging",
ShortUsage: "gnodev staging [flags] [package_dir...]",
ShortHelp: "Start gnodev in staging mode",
LongHelp: "STAGING: Staging mode configure the node for server usage",
NoParentFlags: true,
},
&cfg,
func(_ context.Context, args []string) error {
return execStagingCmd(&cfg, args, io)
},
)
}

func (c *stagingCfg) RegisterFlags(fs *flag.FlagSet) {
c.dev.registerFlagsWithDefault(defaultStagingOptions, fs)
}

func execStagingCmd(cfg *stagingCfg, args []string, io commands.IO) error {
return runApp(&cfg.dev, io, args...)
}
54 changes: 39 additions & 15 deletions contribs/gnodev/cmd/gnodev/logger.go
Original file line number Diff line number Diff line change
@@ -1,35 +1,59 @@
package main

import (
"fmt"
"io"
"log/slog"

"github.com/charmbracelet/lipgloss"
"github.com/gnolang/gno/contribs/gnodev/pkg/logger"
gnolog "github.com/gnolang/gno/gno.land/pkg/log"
"github.com/gnolang/gno/gno.land/pkg/log"
"github.com/muesli/termenv"
"go.uber.org/zap/zapcore"
)

func setuplogger(cfg *devCfg, out io.Writer) *slog.Logger {
func setuplogger(cfg *devCfg, out io.Writer) (*slog.Logger, error) {
level := slog.LevelInfo
if cfg.verbose {
level = slog.LevelDebug
}

if cfg.serverMode {
zaplogger := logger.NewZapLogger(out, level)
return gnolog.ZapLoggerToSlog(zaplogger)
}
// Set up the logger
switch cfg.logFormat {
case "json":
return newJSONLogger(out, level), nil
case "console", "":
// Detect term color profile
colorProfile := termenv.DefaultOutput().Profile

clogger := logger.NewColumnLogger(out, level, colorProfile)

// Register well known group color with system colors
clogger.RegisterGroupColor(NodeLogName, lipgloss.Color("3"))
clogger.RegisterGroupColor(WebLogName, lipgloss.Color("4"))
clogger.RegisterGroupColor(KeyPressLogName, lipgloss.Color("5"))
clogger.RegisterGroupColor(EventServerLogName, lipgloss.Color("6"))

// Detect term color profile
colorProfile := termenv.DefaultOutput().Profile
clogger := logger.NewColumnLogger(out, level, colorProfile)
return slog.New(clogger), nil
default:
return nil, fmt.Errorf("invalid log format %q", cfg.logFormat)
}
}

// Register well known group color with system colors
clogger.RegisterGroupColor(NodeLogName, lipgloss.Color("3"))
clogger.RegisterGroupColor(WebLogName, lipgloss.Color("4"))
clogger.RegisterGroupColor(KeyPressLogName, lipgloss.Color("5"))
clogger.RegisterGroupColor(EventServerLogName, lipgloss.Color("6"))
func newJSONLogger(w io.Writer, level slog.Level) *slog.Logger {
var zaplevel zapcore.Level
switch level {
case slog.LevelDebug:
zaplevel = zapcore.DebugLevel
case slog.LevelInfo:
zaplevel = zapcore.InfoLevel
case slog.LevelWarn:
zaplevel = zapcore.WarnLevel
case slog.LevelError:
zaplevel = zapcore.ErrorLevel
default:
panic("unknown slog level: " + level.String())
}

return slog.New(clogger)
return log.ZapLoggerToSlog(log.NewZapJSONLogger(w, zaplevel))
}
Loading
Loading