From 10caecc7b720fd2bcd3238867e15eca67a91c731 Mon Sep 17 00:00:00 2001 From: Milos Zivkovic Date: Thu, 1 Feb 2024 12:48:21 +0100 Subject: [PATCH 1/2] Remove legacy gnotxsync --- .github/workflows/gnoland.yml | 1 - Dockerfile | 5 - README.md | 1 - gno.land/Makefile | 6 +- gno.land/cmd/gnotxsync/README.md | 3 - gno.land/cmd/gnotxsync/export.go | 143 ---------------------------- gno.land/cmd/gnotxsync/import.go | 118 ----------------------- gno.land/cmd/gnotxsync/main.go | 47 --------- gno.land/cmd/gnotxsync/main_test.go | 1 - 9 files changed, 2 insertions(+), 323 deletions(-) delete mode 100644 gno.land/cmd/gnotxsync/README.md delete mode 100644 gno.land/cmd/gnotxsync/export.go delete mode 100644 gno.land/cmd/gnotxsync/import.go delete mode 100644 gno.land/cmd/gnotxsync/main.go delete mode 100644 gno.land/cmd/gnotxsync/main_test.go diff --git a/.github/workflows/gnoland.yml b/.github/workflows/gnoland.yml index 25b14c0db04..7c7d3747ee9 100644 --- a/.github/workflows/gnoland.yml +++ b/.github/workflows/gnoland.yml @@ -37,7 +37,6 @@ jobs: - gnokey - gnoweb - gnofaucet - - gnotxsync runs-on: ubuntu-latest timeout-minutes: 5 steps: diff --git a/Dockerfile b/Dockerfile index 9e7fc48dcb0..feff6d55ad2 100644 --- a/Dockerfile +++ b/Dockerfile @@ -10,7 +10,6 @@ RUN go build -o ./build/gnokey ./gno.land/cmd/gnokey RUN go build -o ./build/gnofaucet ./gno.land/cmd/gnofaucet RUN go build -o ./build/gnoweb ./gno.land/cmd/gnoweb RUN go build -o ./build/gno ./gnovm/cmd/gno -RUN go build -o ./build/gnotxsync ./gno.land/cmd/gnotxsync RUN ls -la ./build ADD . /opt/gno/src/ RUN rm -rf /opt/gno/src/.git @@ -43,10 +42,6 @@ COPY --from=build /opt/build/build/gnofaucet /opt/gno/bin/ ENTRYPOINT ["gnofaucet"] EXPOSE 5050 -FROM runtime-tls AS gnotxsync-slim -COPY --from=build /opt/build/build/gnotxsync /opt/gno/bin/ -ENTRYPOINT ["gnotxsync"] - FROM runtime-tls AS gnoweb-slim COPY --from=build /opt/build/build/gnoweb /opt/gno/bin/ COPY --from=build /opt/gno/src/gno.land/cmd/gnoweb /opt/gno/src/gnoweb diff --git a/README.md b/README.md index cc5931de8ef..987a24f5b66 100644 --- a/README.md +++ b/README.md @@ -83,7 +83,6 @@ repository offers more resources to dig into. We are eager to see your first PR! Developer commands: * [gno](./gnovm/cmd/gno) - handy tool for developing gno packages & realms - * [gnotxsync](./gno.land/cmd/gnotxsync) - importing/exporting transactions from local blockchain node storage * [goscan](./misc/goscan) - dumps imports from specified file’s AST * [genproto](./misc/genproto) - helper for generating .proto implementations * [gnofaucet](./gno.land/cmd/gnofaucet) - serves GNOT faucet diff --git a/gno.land/Makefile b/gno.land/Makefile index 8138dfcfe3e..f4f9dd1aae2 100644 --- a/gno.land/Makefile +++ b/gno.land/Makefile @@ -17,26 +17,24 @@ start.gnoland:; go run ./cmd/gnoland start start.gnoweb:; go run ./cmd/gnoweb .PHONY: build -build: build.gnoland build.gnokey build.gnoweb build.gnofaucet build.gnotxsync build.genesis +build: build.gnoland build.gnokey build.gnoweb build.gnofaucet build.genesis build.gnoland:; go build -o build/gnoland ./cmd/gnoland build.gnoweb:; go build -o build/gnoweb ./cmd/gnoweb build.gnofaucet:; go build -o build/gnofaucet ./cmd/gnofaucet build.gnokey:; go build -o build/gnokey ./cmd/gnokey -build.gnotxsync:; go build -o build/gnotxsync ./cmd/gnotxsync build.genesis:; go build -o build/genesis ./cmd/genesis run.gnoland:; go run ./cmd/gnoland start run.gnoweb:; go run ./cmd/gnoweb .PHONY: install -install: install.gnoland install.gnoweb install.gnofaucet install.gnokey install.gnotxsync install.genesis +install: install.gnoland install.gnoweb install.gnofaucet install.gnokey install.genesis install.gnoland:; go install ./cmd/gnoland install.gnoweb:; go install ./cmd/gnoweb install.gnofaucet:; go install ./cmd/gnofaucet install.gnokey:; go install ./cmd/gnokey -install.gnotxsync:; go install ./cmd/gnotxsync install.genesis:; go install ./cmd/genesis .PHONY: fclean diff --git a/gno.land/cmd/gnotxsync/README.md b/gno.land/cmd/gnotxsync/README.md deleted file mode 100644 index 3bd032a5f23..00000000000 --- a/gno.land/cmd/gnotxsync/README.md +++ /dev/null @@ -1,3 +0,0 @@ -This is a simple tool to fetch (valid) transactions using the HTTP rpc. -It is pretty slow, especially from a remote machine. -TODO: make it faster by running on local database instance. diff --git a/gno.land/cmd/gnotxsync/export.go b/gno.land/cmd/gnotxsync/export.go deleted file mode 100644 index f22a4cd22f4..00000000000 --- a/gno.land/cmd/gnotxsync/export.go +++ /dev/null @@ -1,143 +0,0 @@ -package main - -import ( - "context" - "flag" - "fmt" - "io" - "log" - "os" - "strings" - "time" - - "github.com/gnolang/gno/tm2/pkg/amino" - "github.com/gnolang/gno/tm2/pkg/bft/rpc/client" - "github.com/gnolang/gno/tm2/pkg/commands" - "github.com/gnolang/gno/tm2/pkg/std" - - _ "github.com/gnolang/gno/gno.land/pkg/sdk/vm" - _ "github.com/gnolang/gno/tm2/pkg/sdk/auth" // XXX better way? - _ "github.com/gnolang/gno/tm2/pkg/sdk/bank" -) - -type exportCfg struct { - rootCfg *config - - startHeight int64 - tailHeight int64 - endHeight int64 - outFile string - quiet bool - follow bool -} - -func newExportCommand(rootCfg *config) *commands.Command { - cfg := &exportCfg{ - rootCfg: rootCfg, - } - - return commands.NewCommand( - commands.Metadata{ - Name: "export", - ShortUsage: "export [flags] ", - ShortHelp: "Export transactions to file", - }, - cfg, - func(_ context.Context, _ []string) error { - return execExport(cfg) - }, - ) -} - -func (c *exportCfg) RegisterFlags(fs *flag.FlagSet) { - fs.Int64Var(&c.startHeight, "start", 1, "start height") - fs.Int64Var(&c.tailHeight, "tail", 0, "start at LAST - N") - fs.Int64Var(&c.endHeight, "end", 0, "end height (optional)") - fs.StringVar(&c.outFile, "out", defaultFilePath, "output file path") - fs.BoolVar(&c.quiet, "quiet", false, "omit console output during execution") - fs.BoolVar(&c.follow, "follow", false, "keep attached and follow new events") -} - -func execExport(c *exportCfg) error { - node := client.NewHTTP(c.rootCfg.remote, "/websocket") - - status, err := node.Status() - if err != nil { - return fmt.Errorf("unable to fetch node status, %w", err) - } - - var ( - start = c.startHeight - end = c.endHeight - tail = c.tailHeight - ) - - if end == 0 { // take last block height - end = status.SyncInfo.LatestBlockHeight - } - if tail > 0 { - start = end - tail - } - - var out io.Writer - switch c.outFile { - case "-", "STDOUT": - out = os.Stdout - default: - out, err = os.OpenFile(c.outFile, os.O_RDWR|os.O_CREATE, 0o755) - if err != nil { - return err - } - } - - for height := start; ; height++ { - if !c.follow && height >= end { - break - } - - getBlock: - block, err := node.Block(&height) - if err != nil { - if c.follow && strings.Contains(err.Error(), "") { - time.Sleep(time.Second) - - goto getBlock - } - - return fmt.Errorf("encountered error while fetching block, %w", err) - } - - txs := block.Block.Data.Txs - if len(txs) == 0 { - continue - } - - _, err = node.BlockResults(&height) - if err != nil { - if c.follow && strings.Contains(err.Error(), "") { - time.Sleep(time.Second) - - goto getBlock - } - - return fmt.Errorf("encountered error while fetching block results, %w", err) - } - - for i := 0; i < len(txs); i++ { - tx := txs[i] - stdtx := std.Tx{} - - amino.MustUnmarshal(tx, &stdtx) - - bz := amino.MustMarshalJSON(stdtx) - - _, _ = fmt.Fprintln(out, string(bz)) - } - - if !c.quiet { - log.Printf("h=%d/%d (txs=%d)", height, end, len(txs)) - } - } - - return nil -} diff --git a/gno.land/cmd/gnotxsync/import.go b/gno.land/cmd/gnotxsync/import.go deleted file mode 100644 index 3369b5378b5..00000000000 --- a/gno.land/cmd/gnotxsync/import.go +++ /dev/null @@ -1,118 +0,0 @@ -package main - -import ( - "bufio" - "context" - "flag" - "fmt" - "os" - "time" - - "github.com/gnolang/gno/tm2/pkg/amino" - "github.com/gnolang/gno/tm2/pkg/bft/rpc/client" - "github.com/gnolang/gno/tm2/pkg/commands" - "github.com/gnolang/gno/tm2/pkg/errors" - "github.com/gnolang/gno/tm2/pkg/std" - - _ "github.com/gnolang/gno/gno.land/pkg/sdk/vm" - _ "github.com/gnolang/gno/tm2/pkg/sdk/auth" // XXX better way? - _ "github.com/gnolang/gno/tm2/pkg/sdk/bank" -) - -type importCfg struct { - rootCfg *config - - inFile string -} - -func newImportCommand(rootCfg *config) *commands.Command { - cfg := &importCfg{ - rootCfg: rootCfg, - } - - return commands.NewCommand( - commands.Metadata{ - Name: "import", - ShortUsage: "import [flags] ", - ShortHelp: "Import transactions from file", - }, - cfg, - func(ctx context.Context, _ []string) error { - return execImport(ctx, cfg) - }, - ) -} - -func (c *importCfg) RegisterFlags(fs *flag.FlagSet) { - fs.StringVar(&c.inFile, "in", defaultFilePath, "input file path") -} - -func execImport(ctx context.Context, c *importCfg) error { - // Initial validation - if len(c.inFile) == 0 { - return errors.New("input file path not specified") - } - - // Read the input file - file, err := os.Open(c.inFile) - if err != nil { - return fmt.Errorf("unable to open input file, %w", err) - } - - defer file.Close() - - // Start the WS connection to the node - node := client.NewHTTP(c.rootCfg.remote, "/websocket") - - index := 0 - scanner := bufio.NewScanner(file) - for scanner.Scan() { - select { - case <-ctx.Done(): - // Stop signal received while parsing - // the import file - return nil - default: - print(".") - - line := scanner.Text() - if len(line) == 0 { - return fmt.Errorf("empty line encountered at %d", index) - } - - var tx std.Tx - amino.MustUnmarshalJSON([]byte(line), &tx) - txbz := amino.MustMarshal(tx) - - res, err := node.BroadcastTxSync(txbz) - - if err != nil || res.Error != nil { - print("!") - // wait for next block and try again. - // TODO: actually wait 1 block instead of fudging it. - time.Sleep(20 * time.Second) - - res, err := node.BroadcastTxSync(txbz) - if err != nil || res.Error != nil { - if err != nil { - fmt.Println("SECOND ERROR", err) - } else { - fmt.Println("SECOND ERROR!", res.Error) - } - - fmt.Println(line) - - return errors.Wrap(err, "broadcasting tx %d", index) - } - } - - index++ - } - } - - if err := scanner.Err(); err != nil { - return fmt.Errorf("error encountered while reading file, %w", err) - } - - return nil -} diff --git a/gno.land/cmd/gnotxsync/main.go b/gno.land/cmd/gnotxsync/main.go deleted file mode 100644 index 02a613d5dc8..00000000000 --- a/gno.land/cmd/gnotxsync/main.go +++ /dev/null @@ -1,47 +0,0 @@ -package main - -import ( - "context" - "flag" - "os" - - "github.com/gnolang/gno/tm2/pkg/commands" -) - -// config is the shared config for gnotxport, and its subcommands -type config struct { - remote string `default:"localhost:26657"` -} - -const ( - defaultFilePath = "txexport.log" -) - -func main() { - cfg := &config{} - - cmd := commands.NewCommand( - commands.Metadata{ - ShortUsage: " [flags] [...]", - LongHelp: "Exports or imports transactions from the node", - }, - cfg, - commands.HelpExec, - ) - - cmd.AddSubCommands( - newImportCommand(cfg), - newExportCommand(cfg), - ) - - cmd.Execute(context.Background(), os.Args[1:]) -} - -func (c *config) RegisterFlags(fs *flag.FlagSet) { - fs.StringVar( - &c.remote, - "remote", - "localhost:26657", - "remote RPC address ", - ) -} diff --git a/gno.land/cmd/gnotxsync/main_test.go b/gno.land/cmd/gnotxsync/main_test.go deleted file mode 100644 index 06ab7d0f9a3..00000000000 --- a/gno.land/cmd/gnotxsync/main_test.go +++ /dev/null @@ -1 +0,0 @@ -package main From 3a4f5d8603ca6316d3557440751f69912cc80ed6 Mon Sep 17 00:00:00 2001 From: Milos Zivkovic Date: Thu, 1 Feb 2024 12:50:33 +0100 Subject: [PATCH 2/2] Remove docs reference --- docs/gno-tooling/cli/tm2txsync.md | 45 ------------------------------- misc/docusaurus/sidebars.js | 1 - 2 files changed, 46 deletions(-) delete mode 100644 docs/gno-tooling/cli/tm2txsync.md diff --git a/docs/gno-tooling/cli/tm2txsync.md b/docs/gno-tooling/cli/tm2txsync.md deleted file mode 100644 index e9d616bcea5..00000000000 --- a/docs/gno-tooling/cli/tm2txsync.md +++ /dev/null @@ -1,45 +0,0 @@ ---- -id: gno-tooling-tm2txsync ---- - -# tm2txsync - -`tm2txsync` is used for backing up a local node's transactions. - -## Import Transaction Data To (or Export It From) a Node - -You may import or export transaction data with the following command. - -```bash -tm2txsync {SUB_COMMAND} -``` - -#### **Subcommands** - -| Name | Description | -| -------- | -------------------------- | -| `export` | Exports txs from the node. | -| `import` | Imports txs to the node. | - -### Import - -#### **Options** - -| Name | Type | Description | -| -------- | ------ | ----------------------------------------------------------------- | -| `remote` | String | The Remote RPC in `addr:port` format (default: `localhost:26657`) | -| `in` | String | The input file path (default: `txexport.log`) | - -### Export - -#### **Options** - -| Name | Type | Description | -| -------- | ------- | ----------------------------------------------------------------- | -| `remote` | String | The Remote RPC in `addr:port` format (default: `localhost:26657`) | -| `start` | Int64 | Starting height (default: `1`) | -| `tail` | Int64 | Start at LAST - N. | -| `end` | Int64 | End height (optional) | -| `out` | String | The output file path (default: `txexport.log`) | -| `quiet` | Boolean | Quiet mode. | -| `follow` | Boolean | Keep attached and follow new events. | diff --git a/misc/docusaurus/sidebars.js b/misc/docusaurus/sidebars.js index 021c58dd90b..a11468d9504 100644 --- a/misc/docusaurus/sidebars.js +++ b/misc/docusaurus/sidebars.js @@ -70,7 +70,6 @@ const sidebars = { 'gno-tooling/cli/gno-tooling-gnodev', 'gno-tooling/cli/gno-tooling-gnoland', 'gno-tooling/cli/gno-tooling-gnofaucet', - 'gno-tooling/cli/gno-tooling-tm2txsync', ] }, {