diff --git a/.github/workflows/gnoland.yml b/.github/workflows/gnoland.yml index 3832a8e7b3c..edb8def9773 100644 --- a/.github/workflows/gnoland.yml +++ b/.github/workflows/gnoland.yml @@ -79,3 +79,5 @@ jobs: # TODO: setup docker caching - run: make test.docker - run: docker logs int_gnoland || true + + # TODO: docker-less integration test? diff --git a/.gitpod.yml b/.gitpod.yml index aeb4943ea04..cd9f1f0bdc6 100644 --- a/.gitpod.yml +++ b/.gitpod.yml @@ -18,7 +18,7 @@ tasks: - name: Gnoland Node init: go install ./gno.land/cmd/gnoland - command: gnoland + command: gnoland start ports: - port: 8888 diff --git a/examples/gno.land/r/demo/boards/README.md b/examples/gno.land/r/demo/boards/README.md index ba526a8b075..67c218d4951 100644 --- a/examples/gno.land/r/demo/boards/README.md +++ b/examples/gno.land/r/demo/boards/README.md @@ -118,7 +118,7 @@ Use this mneonic: ### Start `gnoland` node. ```bash -./build/gnoland +./build/gnoland start ``` NOTE: This can be reset with `make reset` diff --git a/gno.land/cmd/gnofaucet/README.md b/gno.land/cmd/gnofaucet/README.md index 162707ee6b7..a9ce0abaecf 100644 --- a/gno.land/cmd/gnofaucet/README.md +++ b/gno.land/cmd/gnofaucet/README.md @@ -16,7 +16,7 @@ Copy and paste the following mnemonic. Make sure you have started gnoland - ./build/gnoland + ./build/gnoland start ## Step3: diff --git a/gno.land/cmd/gnoland/README.md b/gno.land/cmd/gnoland/README.md index fdf99bb5c72..5132cd7f52b 100644 --- a/gno.land/cmd/gnoland/README.md +++ b/gno.land/cmd/gnoland/README.md @@ -6,4 +6,8 @@ $> cd ./gno/gno.land $> make install.gnoland +## Run `gnoland` full node + + $> gnoland start + Afterward, you can interact with [`gnokey`](../gnokey) or launch a [`gnoweb`](../gnoweb) interface. diff --git a/gno.land/cmd/gnoland/root.go b/gno.land/cmd/gnoland/root.go new file mode 100644 index 00000000000..cf2a6252478 --- /dev/null +++ b/gno.land/cmd/gnoland/root.go @@ -0,0 +1,42 @@ +package main + +import ( + "context" + "fmt" + "os" + + "github.com/gnolang/gno/tm2/pkg/commands" + "github.com/peterbourgon/ff/v3" + "github.com/peterbourgon/ff/v3/fftoml" +) + +func main() { + io := commands.NewDefaultIO() + cmd := newRootCmd(io) + + if err := cmd.ParseAndRun(context.Background(), os.Args[1:]); err != nil { + _, _ = fmt.Fprintf(os.Stderr, "%+v\n", err) + os.Exit(1) + } +} + +func newRootCmd(io *commands.IO) *commands.Command { + cmd := commands.NewCommand( + commands.Metadata{ + ShortUsage: " [flags] [...]", + ShortHelp: "Starts the gnoland blockchain node", + Options: []ff.Option{ + ff.WithConfigFileFlag("config"), + ff.WithConfigFileParser(fftoml.Parser), + }, + }, + commands.NewEmptyConfig(), + commands.HelpExec, + ) + + cmd.AddSubCommands( + newStartCmd(io), + ) + + return cmd +} diff --git a/gno.land/cmd/gnoland/main.go b/gno.land/cmd/gnoland/start.go similarity index 89% rename from gno.land/cmd/gnoland/main.go rename to gno.land/cmd/gnoland/start.go index a7119225d6c..c2a03c7b046 100644 --- a/gno.land/cmd/gnoland/main.go +++ b/gno.land/cmd/gnoland/start.go @@ -4,14 +4,10 @@ import ( "context" "flag" "fmt" - "os" "path/filepath" "strings" "time" - "github.com/peterbourgon/ff/v3" - "github.com/peterbourgon/ff/v3/fftoml" - "github.com/gnolang/gno/gno.land/pkg/gnoland" gno "github.com/gnolang/gno/gnovm/pkg/gnolang" "github.com/gnolang/gno/gnovm/pkg/gnomod" @@ -29,7 +25,7 @@ import ( "github.com/gnolang/gno/tm2/pkg/std" ) -type gnolandCfg struct { +type startCfg struct { skipFailingGenesisTxs bool skipStart bool genesisBalancesFile string @@ -41,32 +37,23 @@ type gnolandCfg struct { config string } -func main() { - cfg := &gnolandCfg{} +func newStartCmd(io *commands.IO) *commands.Command { + cfg := &startCfg{} - cmd := commands.NewCommand( + return commands.NewCommand( commands.Metadata{ - ShortUsage: "[flags] [...]", - LongHelp: "Starts the gnoland blockchain node", - Options: []ff.Option{ - ff.WithConfigFileFlag("config"), - ff.WithConfigFileParser(fftoml.Parser), - }, + Name: "start", + ShortUsage: "start [flags]", + ShortHelp: "Run the full node", }, cfg, - func(_ context.Context, _ []string) error { - return exec(cfg) + func(_ context.Context, args []string) error { + return execStart(cfg, args, io) }, ) - - if err := cmd.ParseAndRun(context.Background(), os.Args[1:]); err != nil { - _, _ = fmt.Fprintf(os.Stderr, "%+v\n", err) - - os.Exit(1) - } } -func (c *gnolandCfg) RegisterFlags(fs *flag.FlagSet) { +func (c *startCfg) RegisterFlags(fs *flag.FlagSet) { fs.BoolVar( &c.skipFailingGenesisTxs, "skip-failing-genesis-txs", @@ -131,8 +118,8 @@ func (c *gnolandCfg) RegisterFlags(fs *flag.FlagSet) { ) } -func exec(c *gnolandCfg) error { - logger := log.NewTMLogger(log.NewSyncWriter(os.Stdout)) +func execStart(c *startCfg, args []string, io *commands.IO) error { + logger := log.NewTMLogger(log.NewSyncWriter(io.Out)) rootDir := c.rootDir cfg := config.LoadOrMakeConfigWithOptions(rootDir, func(cfg *config.Config) { @@ -171,10 +158,10 @@ func exec(c *gnolandCfg) error { return fmt.Errorf("error in creating node: %w", err) } - fmt.Fprintln(os.Stderr, "Node created.") + fmt.Fprintln(io.Err, "Node created.") if c.skipStart { - fmt.Fprintln(os.Stderr, "'--skip-start' is set. Exiting.") + fmt.Fprintln(io.Err, "'--skip-start' is set. Exiting.") return nil } diff --git a/gno.land/cmd/gnoland/main_test.go b/gno.land/cmd/gnoland/start_test.go similarity index 50% rename from gno.land/cmd/gnoland/main_test.go rename to gno.land/cmd/gnoland/start_test.go index fa53dd3602e..27ef2f572ea 100644 --- a/gno.land/cmd/gnoland/main_test.go +++ b/gno.land/cmd/gnoland/start_test.go @@ -1,6 +1,7 @@ package main import ( + "bytes" "context" "os" "path/filepath" @@ -8,15 +9,14 @@ import ( "testing" "github.com/gnolang/gno/tm2/pkg/commands" - "github.com/gnolang/gno/tm2/pkg/testutils" "github.com/stretchr/testify/require" ) -func TestInitialize(t *testing.T) { +func TestStartInitialize(t *testing.T) { cases := []struct { args []string }{ - {[]string{"--skip-start", "--skip-failing-genesis-txs"}}, + {[]string{"start", "--skip-start", "--skip-failing-genesis-txs"}}, // {[]string{"--skip-start"}}, // FIXME: test seems flappy as soon as we have multiple cases. } @@ -25,28 +25,23 @@ func TestInitialize(t *testing.T) { for _, tc := range cases { name := strings.Join(tc.args, " ") t.Run(name, func(t *testing.T) { - closer := testutils.CaptureStdoutAndStderr() - - cfg := &gnolandCfg{} - cmd := commands.NewCommand( - commands.Metadata{}, - cfg, - func(_ context.Context, _ []string) error { - return exec(cfg) - }, - ) + mockOut := bytes.NewBufferString("") + mockErr := bytes.NewBufferString("") + io := commands.NewTestIO() + io.SetOut(commands.WriteNopCloser(mockOut)) + io.SetErr(commands.WriteNopCloser(mockErr)) + cmd := newRootCmd(io) t.Logf(`Running "gnoland %s"`, strings.Join(tc.args, " ")) err := cmd.ParseAndRun(context.Background(), tc.args) require.NoError(t, err) - stdouterr, bufErr := closer() - require.NoError(t, bufErr) - require.NoError(t, err) + stdout := mockOut.String() + stderr := mockErr.String() - require.Contains(t, stdouterr, "Node created.", "failed to create node") - require.Contains(t, stdouterr, "'--skip-start' is set. Exiting.", "not exited with skip-start") - require.NotContains(t, stdouterr, "panic:") + require.Contains(t, stderr, "Node created.", "failed to create node") + require.Contains(t, stderr, "'--skip-start' is set. Exiting.", "not exited with skip-start") + require.NotContains(t, stdout, "panic:") }) } } diff --git a/go.mod b/go.mod index 92da6c08240..24329c7ca14 100644 --- a/go.mod +++ b/go.mod @@ -41,6 +41,7 @@ require ( ) require ( + github.com/awalterschulze/gographviz v2.0.3+incompatible // indirect github.com/cespare/xxhash v1.1.0 // indirect github.com/cespare/xxhash/v2 v2.1.1 // indirect github.com/dgraph-io/ristretto v0.1.1 // indirect @@ -48,6 +49,7 @@ require ( github.com/facebookgo/ensure v0.0.0-20200202191622-63f1cf65ac4c // indirect github.com/facebookgo/stack v0.0.0-20160209184415-751773369052 // indirect github.com/facebookgo/subset v0.0.0-20200203212716-c811ad88dec4 // indirect + github.com/fatih/color v1.15.0 // indirect github.com/gdamore/encoding v1.0.0 // indirect github.com/gogo/protobuf v1.3.2 // indirect github.com/golang/glog v0.0.0-20160126235308-23def4e6c14b // indirect @@ -56,12 +58,16 @@ require ( github.com/google/flatbuffers v1.12.1 // indirect github.com/gorilla/securecookie v1.1.1 // indirect github.com/gorilla/sessions v1.2.1 // indirect + github.com/jessevdk/go-flags v1.4.0 // indirect github.com/klauspost/compress v1.12.3 // indirect github.com/kr/text v0.2.0 // indirect github.com/lib/pq v1.10.7 // indirect github.com/lucasb-eyer/go-colorful v1.0.3 // indirect + github.com/mattn/go-colorable v0.1.13 // indirect + github.com/mattn/go-isatty v0.0.17 // indirect github.com/pkg/errors v0.9.1 // indirect github.com/rivo/uniseg v0.2.0 // indirect + github.com/uber/go-torch v0.0.0-20181107071353-86f327cc820e // indirect go.opencensus.io v0.22.5 // indirect go.uber.org/atomic v1.7.0 // indirect golang.org/x/sys v0.9.0 // indirect diff --git a/go.sum b/go.sum index ad4fe1edb35..1294fcf0769 100644 --- a/go.sum +++ b/go.sum @@ -4,6 +4,8 @@ github.com/OneOfOne/xxhash v1.2.2 h1:KMrpdQIwFcEqXDklaen+P1axHaj9BSKzvpUUfnHldSE github.com/OneOfOne/xxhash v1.2.2/go.mod h1:HSdplMjZKSmBqAxg5vPj2TmRDmfkzw+cTzAElWljhcU= github.com/aead/siphash v1.0.1/go.mod h1:Nywa3cDsYNNK3gaciGTWPwHt0wlpNV15vwmswBAUSII= github.com/armon/consul-api v0.0.0-20180202201655-eb2c6b5be1b6/go.mod h1:grANhF5doyWs3UAsr3K4I6qtAmlQcZDesFNEHPZAzj8= +github.com/awalterschulze/gographviz v2.0.3+incompatible h1:9sVEXJBJLwGX7EQVhLm2elIKCm7P2YHFC8v6096G09E= +github.com/awalterschulze/gographviz v2.0.3+incompatible/go.mod h1:GEV5wmg4YquNw7v1kkyoX9etIk8yVmXj+AkDHuuETHs= github.com/btcsuite/btcd v0.20.1-beta/go.mod h1:wVuoA8VJLEcwgqHBwHmzLRazpKxTv13Px/pDuV7OomQ= github.com/btcsuite/btcd v0.22.0-beta.0.20220111032746-97732e52810c h1:lnAMg3ra/Gw4AkRMxrxYs8nrprWsHowg8H9zaYsJOo4= github.com/btcsuite/btcd v0.22.0-beta.0.20220111032746-97732e52810c/go.mod h1:tjmYdS6MLJ5/s0Fj4DbLgSbDHbEqLJrtnHecBFkdz5M= @@ -56,6 +58,8 @@ github.com/facebookgo/stack v0.0.0-20160209184415-751773369052 h1:JWuenKqqX8nojt github.com/facebookgo/stack v0.0.0-20160209184415-751773369052/go.mod h1:UbMTZqLaRiH3MsBH8va0n7s1pQYcu3uTb8G4tygF4Zg= github.com/facebookgo/subset v0.0.0-20200203212716-c811ad88dec4 h1:7HZCaLC5+BZpmbhCOZJ293Lz68O7PYrF2EzeiFMwCLk= github.com/facebookgo/subset v0.0.0-20200203212716-c811ad88dec4/go.mod h1:5tD+neXqOorC30/tWg0LCSkrqj/AR6gu8yY8/fpw1q0= +github.com/fatih/color v1.15.0 h1:kOqh6YHBtK8aywxGerMG2Eq3H6Qgoqeo13Bk2Mv/nBs= +github.com/fatih/color v1.15.0/go.mod h1:0h5ZqXfHYED7Bhv2ZJamyIOUej9KtShiJESRwBDUSsw= github.com/fortytw2/leaktest v1.3.0 h1:u8491cBMTQ8ft8aeV+adlcytMZylmA5nnwwkRZjI8vw= github.com/fortytw2/leaktest v1.3.0/go.mod h1:jDsjWgpAGjm2CA7WthBh/CdZYEPF31XHquHwclZch5g= github.com/fsnotify/fsnotify v1.4.7/go.mod h1:jwhsz4b93w/PPRr/qN1Yymfu8t87LnFCMoQvtojpjFo= @@ -117,6 +121,7 @@ github.com/inconshreveable/mousetrap v1.0.0/go.mod h1:PxqpIevigyE2G7u3NXJIT2ANyt github.com/jaekwon/testify v1.6.1 h1:4AtAJcR9GzXN5W4DdY7ie74iCPiJV1JJUJL90t2ZUyw= github.com/jaekwon/testify v1.6.1/go.mod h1:Oun0RXIHI7osufabQ60i4Lqkj0GXLbqI1I7kgzBNm1U= github.com/jessevdk/go-flags v0.0.0-20141203071132-1679536dcc89/go.mod h1:4FA24M0QyGHXBuZZK/XkWh8h0e1EYbRYJSGM75WSRxI= +github.com/jessevdk/go-flags v1.4.0 h1:4IU2WS7AumrZ/40jfhf4QVDMsQwqA7VEHozFRrGARJA= github.com/jessevdk/go-flags v1.4.0/go.mod h1:4FA24M0QyGHXBuZZK/XkWh8h0e1EYbRYJSGM75WSRxI= github.com/jmhodges/levigo v1.0.0 h1:q5EC36kV79HWeTBWsod3mG11EgStG3qArTKcvlksN1U= github.com/jmhodges/levigo v1.0.0/go.mod h1:Q6Qx+uH3RAqyK4rFQroq9RL7mdkABMcfhEI+nNuzMJQ= @@ -142,6 +147,11 @@ github.com/linxGnu/grocksdb v1.7.15/go.mod h1:pY55D0o+r8yUYLq70QmhdudxYvoDb9F+9p github.com/lucasb-eyer/go-colorful v1.0.3 h1:QIbQXiugsb+q10B+MI+7DI1oQLdmnep86tWFlaaUAac= github.com/lucasb-eyer/go-colorful v1.0.3/go.mod h1:R4dSotOR9KMtayYi1e77YzuveK+i7ruzyGqttikkLy0= github.com/magiconair/properties v1.8.0/go.mod h1:PppfXfuXeibc/6YijjN8zIbojt8czPbwD3XqdrwzmxQ= +github.com/mattn/go-colorable v0.1.13 h1:fFA4WZxdEF4tXPZVKMLwD8oUnCTTo08duU7wxecdEvA= +github.com/mattn/go-colorable v0.1.13/go.mod h1:7S9/ev0klgBDR4GtXTXX8a3vIGJpMovkB8vQcUbaXHg= +github.com/mattn/go-isatty v0.0.16/go.mod h1:kYGgaQfpe5nmfYZH+SKPsOc2e4SrIfOl2e/yFXSvRLM= +github.com/mattn/go-isatty v0.0.17 h1:BTarxUcIeDqL27Mc+vyvdWYSL28zpIhv3RoTdsLMPng= +github.com/mattn/go-isatty v0.0.17/go.mod h1:kYGgaQfpe5nmfYZH+SKPsOc2e4SrIfOl2e/yFXSvRLM= github.com/mattn/go-runewidth v0.0.7/go.mod h1:H031xJmbD/WCDINGzjvQ9THkh0rPKHF+m2gUSrubnMI= github.com/mattn/go-runewidth v0.0.14 h1:+xnbZSEeDbOIg5/mE6JF0w6n9duR1l3/WmbinWVwUuU= github.com/mattn/go-runewidth v0.0.14/go.mod h1:Jdepj2loyihRzMpdS35Xk/zdY8IAYHsh153qUoGf23w= @@ -195,6 +205,8 @@ github.com/syndtr/goleveldb v1.0.0 h1:fBdIW9lB4Iz0n9khmH8w27SJ3QEJ7+IgjPEwGSZiFd github.com/syndtr/goleveldb v1.0.0/go.mod h1:ZVVdQEZoIme9iO1Ch2Jdy24qqXrMMOU6lpPAyBWyWuQ= github.com/tecbot/gorocksdb v0.0.0-20191217155057-f0fad39f321c h1:g+WoO5jjkqGAzHWCjJB1zZfXPIAaDpzXIEJ0eS6B5Ok= github.com/tecbot/gorocksdb v0.0.0-20191217155057-f0fad39f321c/go.mod h1:ahpPrc7HpcfEWDQRZEmnXMzHY03mLDYMCxeDzy46i+8= +github.com/uber/go-torch v0.0.0-20181107071353-86f327cc820e h1:jV0Y58RWaOMT3i5foW2YoEKlaN6biewBtngFwAfEwQ0= +github.com/uber/go-torch v0.0.0-20181107071353-86f327cc820e/go.mod h1:uuMPbyv6WJykZcarrIuJiTjfSGC997/jnfHyyeeG2Jo= github.com/ugorji/go/codec v0.0.0-20181204163529-d75b2dcb6bc8/go.mod h1:VFNgLljTbGfSG7qAOspJ7OScBnGdDN/yBr0sguwnwf0= github.com/xordataexchange/crypt v0.0.3-0.20170626215501-b2862e3d0a77/go.mod h1:aYKd//L2LvnjZzWKhF00oedf4jCCReLcmhLdhm1A27Q= github.com/yuin/goldmark v1.1.27/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9decYSb74= @@ -258,6 +270,7 @@ golang.org/x/sys v0.0.0-20200323222414-85ca7c5b95cd/go.mod h1:h1NjWce9XRLGQEsW7w golang.org/x/sys v0.0.0-20200519105757-fe76b779f299/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20200814200057-3d37ad5750ed/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20200930185726-fdedc70b468f/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= +golang.org/x/sys v0.0.0-20220811171246-fbc7d0a398ab/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.0.0-20221010170243-090e33056c14/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.9.0 h1:KS/R3tvhPqvJvwcKfnBHJwwthS11LRhmM5D59eEXa0s= golang.org/x/sys v0.9.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= diff --git a/misc/deployments/staging.gno.land/docker-compose.yml b/misc/deployments/staging.gno.land/docker-compose.yml index c8701c1e1fb..268002902ab 100644 --- a/misc/deployments/staging.gno.land/docker-compose.yml +++ b/misc/deployments/staging.gno.land/docker-compose.yml @@ -9,6 +9,7 @@ services: working_dir: /opt/gno/src/gno.land command: - gnoland + - start - --skip-failing-genesis-txs - --chainid=staging - --genesis-remote=staging.gno.land:36657 diff --git a/misc/deployments/test2.gno.land/docker-compose.yml b/misc/deployments/test2.gno.land/docker-compose.yml index 138398dc8e4..c836c0cc65f 100644 --- a/misc/deployments/test2.gno.land/docker-compose.yml +++ b/misc/deployments/test2.gno.land/docker-compose.yml @@ -11,6 +11,7 @@ services: - LETSENCRYPT_HOST=rpc.test2.gno.land command: - gnoland + - start - --skip-failing-genesis-txs - --chainid - test2 diff --git a/misc/deployments/test3.gno.land/docker-compose.yml b/misc/deployments/test3.gno.land/docker-compose.yml index 8cf72bfb3ff..00f836fc6f9 100644 --- a/misc/deployments/test3.gno.land/docker-compose.yml +++ b/misc/deployments/test3.gno.land/docker-compose.yml @@ -11,6 +11,7 @@ services: - LETSENCRYPT_HOST=rpc.test3.gno.land command: - gnoland + - start - --skip-failing-genesis-txs - --chainid - test3 diff --git a/misc/docker-compose/docker-compose.yml b/misc/docker-compose/docker-compose.yml index 373cba5f513..26ef50913ff 100644 --- a/misc/docker-compose/docker-compose.yml +++ b/misc/docker-compose/docker-compose.yml @@ -7,7 +7,7 @@ services: dockerfile: ../..Dockerfile environment: - LOG_LEVEL=4 - command: [ "gnoland" ] + command: [ "gnoland", "start" ] volumes: - "gnonode:/opt/gno/src/testdir" networks: diff --git a/misc/docker-integration/integration_test.go b/misc/docker-integration/integration_test.go index cd156d29b2c..ebd4c0851a8 100644 --- a/misc/docker-integration/integration_test.go +++ b/misc/docker-integration/integration_test.go @@ -152,6 +152,7 @@ func startGnoland(t *testing.T) { "-w", "/opt/gno/src/gno.land", "gno:integration", "gnoland", + "start", }) output, err := cmd.CombinedOutput() require.NoError(t, err)