Skip to content

Commit

Permalink
Try #6183:
Browse files Browse the repository at this point in the history
  • Loading branch information
spacemesh-bors[bot] authored Jul 28, 2024
2 parents 9eae780 + e98838b commit cdfd622
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 49 deletions.
76 changes: 37 additions & 39 deletions cmd/merge-nodes/main.go
Original file line number Diff line number Diff line change
@@ -1,57 +1,55 @@
package main

import (
"fmt"
"log"
"os"

"github.com/urfave/cli/v2"
"github.com/spf13/cobra"
"go.uber.org/zap"

"github.com/spacemeshos/go-spacemesh/cmd/merge-nodes/internal"
)

var version string

func init() {
rootCmd.Flags().StringP("from", "f", "",
"The `data` folder to read identities from and merge into `to`")
rootCmd.MarkFlagRequired("from")
rootCmd.Flags().StringP("to", "t", "",
"The `data` folder to write the merged node to. Can be an existing remote node or empty.")
rootCmd.MarkFlagRequired("to")
}

func main() {
cfg := zap.NewProductionConfig()
cfg.Encoding = "console"
dbLog, err := cfg.Build()
err := rootCmd.Execute()
if err != nil {
fmt.Println("create logger:", err)
os.Exit(1)
}
defer dbLog.Sync()

app := &cli.App{
Name: "Spacemesh Node Merger",
Usage: "Merge identities of two Spacemesh nodes into one.\n" +
"The `from` node will be merged into the `to` node, leaving the `from` node untouched.\n" +
"The `to` node can be an existing node or an empty folder.\n" +
"Be sure to backup the `to` node before running this command.\n" +
"NOTE: both `from` and `to` nodes must be upgraded to the latest version before running this command.\n" +
"NOTE: after upgrading and starting the nodes at least once, convert them to remote nodes before merging.",
Version: version,
Flags: []cli.Flag{
&cli.StringFlag{
Name: "from",
Aliases: []string{"f"},
Usage: "The `data` folder to read identities from and merge into `to`",
Required: true,
},
&cli.StringFlag{
Name: "to",
Aliases: []string{"t"},
Usage: "The `data` folder to write the merged node to. Can be an existing remote node or empty.",
Required: true,
},
},
Action: func(ctx *cli.Context) error {
return internal.MergeDBs(ctx.Context, dbLog, ctx.String("from"), ctx.String("to"))
},
}
}

if err := app.Run(os.Args); err != nil {
dbLog.Sugar().Warnln("app run:", err)
os.Exit(1)
}
var rootCmd = &cobra.Command{
Use: "merge-nodes -f <dir> -t <dir>",
Short: "Spacemesh Node Merger",
Long: `Merge identities of two Spacemesh nodes into one.
The 'from' node will be merged into the 'to' node, leaving the 'from' node untouched.
The 'to' node can be an existing node or an empty folder.
Be sure to backup the 'to' node before running this command.
NOTE: both 'from' and 'to' nodes must be upgraded to the latest version before running this command.
NOTE: after upgrading and starting the nodes at least once, convert them to remote nodes before merging.`,
Version: version,
RunE: func(cmd *cobra.Command, _ []string) error {
cfg := zap.NewProductionConfig()
cfg.Encoding = "console"
dbLog, err := cfg.Build()
if err != nil {
log.Fatalf("create logger: %v", err)
}
defer dbLog.Sync()

f := cmd.Flag("from").Value.String()
t := cmd.Flag("to").Value.String()

return internal.MergeDBs(cmd.Context(), dbLog, f, t)
},
}
4 changes: 0 additions & 4 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,6 @@ require (
github.com/spf13/viper v1.19.0
github.com/stretchr/testify v1.9.0
github.com/syndtr/goleveldb v1.0.1-0.20210819022825-2ae1ddf74ef7
github.com/urfave/cli/v2 v2.27.3
github.com/zeebo/blake3 v0.2.3
go.uber.org/mock v0.4.0
go.uber.org/zap v1.27.0
Expand Down Expand Up @@ -85,7 +84,6 @@ require (
github.com/cespare/xxhash/v2 v2.3.0 // indirect
github.com/containerd/cgroups v1.1.0 // indirect
github.com/coreos/go-systemd/v22 v22.5.0 // indirect
github.com/cpuguy83/go-md2man/v2 v2.0.4 // indirect
github.com/davecgh/go-spew v1.1.2-0.20180830191138-d8f796af33cc // indirect
github.com/davidlazar/go-crypto v0.0.0-20200604182044-b73af7476f6c // indirect
github.com/decred/dcrd/dcrec/secp256k1/v4 v4.3.0 // indirect
Expand Down Expand Up @@ -202,7 +200,6 @@ require (
github.com/quic-go/webtransport-go v0.8.0 // indirect
github.com/raulk/go-watchdog v1.3.0 // indirect
github.com/robfig/cron/v3 v3.0.1 // indirect
github.com/russross/blackfriday/v2 v2.1.0 // indirect
github.com/sagikazarmark/locafero v0.4.0 // indirect
github.com/sagikazarmark/slog-shim v0.1.0 // indirect
github.com/sourcegraph/conc v0.3.0 // indirect
Expand All @@ -211,7 +208,6 @@ require (
github.com/spf13/cast v1.6.0 // indirect
github.com/subosito/gotenv v1.6.0 // indirect
github.com/whyrusleeping/go-keyspace v0.0.0-20160322163242-5b898ac5add1 // indirect
github.com/xrash/smetrics v0.0.0-20240521201337-686a1a2994c1 // indirect
go.opencensus.io v0.24.0 // indirect
go.opentelemetry.io/contrib/instrumentation/google.golang.org/grpc/otelgrpc v0.49.0 // indirect
go.opentelemetry.io/contrib/instrumentation/net/http/otelhttp v0.49.0 // indirect
Expand Down
6 changes: 0 additions & 6 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,6 @@ github.com/cosmos/btcutil v1.0.5 h1:t+ZFcX77LpKtDBhjucvnOH8C2l2ioGsBNEQ3jef8xFk=
github.com/cosmos/btcutil v1.0.5/go.mod h1:IyB7iuqZMJlthe2tkIFL33xPyzbFYP0XVdS8P5lUPis=
github.com/cpuguy83/go-md2man/v2 v2.0.0-20190314233015-f79a8a8ca69d/go.mod h1:maD7wRr/U5Z6m/iR4s+kqSMx2CaBsrgA7czyZG/E6dU=
github.com/cpuguy83/go-md2man/v2 v2.0.0/go.mod h1:maD7wRr/U5Z6m/iR4s+kqSMx2CaBsrgA7czyZG/E6dU=
github.com/cpuguy83/go-md2man/v2 v2.0.4 h1:wfIWP927BUkWJb2NmU/kNDYIBTh/ziUX91+lVfRxZq4=
github.com/cpuguy83/go-md2man/v2 v2.0.4/go.mod h1:tgQtvFlXSQOSOSIRvRPT7W67SCa46tRHOmNcaadrF8o=
github.com/creack/pty v1.1.9/go.mod h1:oKZEueFk5CKHvIhNR5MUki03XCEU+Q6VDXinZuGJ33E=
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
Expand Down Expand Up @@ -555,7 +554,6 @@ github.com/rs/cors v1.11.0 h1:0B9GE/r9Bc2UxRMMtymBkHTenPkHDv0CW4Y98GBY+po=
github.com/rs/cors v1.11.0/go.mod h1:XyqrcTp5zjWr1wsJ8PIRZssZ8b/WMcMf71DJnit4EMU=
github.com/russross/blackfriday v1.5.2/go.mod h1:JO/DiYxRf+HjHt06OyowR9PTA263kcR/rfWxYHBV53g=
github.com/russross/blackfriday/v2 v2.0.1/go.mod h1:+Rmxgy9KzJVeS9/2gXHxylqXiyQDYRxCVz55jmeOWTM=
github.com/russross/blackfriday/v2 v2.1.0 h1:JIOH55/0cWyOuilr9/qlrm0BSXldqnqwMsf35Ld67mk=
github.com/russross/blackfriday/v2 v2.1.0/go.mod h1:+Rmxgy9KzJVeS9/2gXHxylqXiyQDYRxCVz55jmeOWTM=
github.com/ryszard/goskiplist v0.0.0-20150312221310-2dfbae5fcf46/go.mod h1:uAQ5PCi+MFsC7HjREoAz1BU+Mq60+05gifQSsHSDG/8=
github.com/sagikazarmark/locafero v0.4.0 h1:HApY1R9zGo4DBgr7dqsTH/JJxLTTsOt7u6keLGt6kNQ=
Expand Down Expand Up @@ -660,17 +658,13 @@ github.com/tarm/serial v0.0.0-20180830185346-98f6abe2eb07/go.mod h1:kDXzergiv9cb
github.com/tinylib/msgp v1.0.2/go.mod h1:+d+yLhGm8mzTaHzB+wgMYrodPfmZrzkirds8fDWklFE=
github.com/urfave/cli v1.22.2/go.mod h1:Gos4lmkARVdJ6EkW0WaNv/tZAAMe9V7XWyB60NtXRu0=
github.com/urfave/cli v1.22.10/go.mod h1:Gos4lmkARVdJ6EkW0WaNv/tZAAMe9V7XWyB60NtXRu0=
github.com/urfave/cli/v2 v2.27.3 h1:/POWahRmdh7uztQ3CYnaDddk0Rm90PyOgIxgW2rr41M=
github.com/urfave/cli/v2 v2.27.3/go.mod h1:m4QzxcD2qpra4z7WhzEGn74WZLViBnMpb1ToCAKdGRQ=
github.com/viant/assertly v0.4.8/go.mod h1:aGifi++jvCrUaklKEKT0BU95igDNaqkvz+49uaYMPRU=
github.com/viant/toolbox v0.24.0/go.mod h1:OxMCG57V0PXuIP2HNQrtJf2CjqdmbrOx5EkMILuUhzM=
github.com/warpfork/go-wish v0.0.0-20220906213052-39a1cc7a02d0 h1:GDDkbFiaK8jsSDJfjId/PEGEShv6ugrt4kYsC5UIDaQ=
github.com/warpfork/go-wish v0.0.0-20220906213052-39a1cc7a02d0/go.mod h1:x6AKhvSSexNrVSrViXSHUEbICjmGXhtgABaHIySUSGw=
github.com/whyrusleeping/go-keyspace v0.0.0-20160322163242-5b898ac5add1 h1:EKhdznlJHPMoKr0XTrX+IlJs1LH3lyx2nfr1dOlZ79k=
github.com/whyrusleeping/go-keyspace v0.0.0-20160322163242-5b898ac5add1/go.mod h1:8UvriyWtv5Q5EOgjHaSseUEdkQfvwFv1I/In/O2M9gc=
github.com/willf/bitset v1.1.9/go.mod h1:RjeCKbqT1RxIR/KWY6phxZiaY1IyutSBfGjNPySAYV4=
github.com/xrash/smetrics v0.0.0-20240521201337-686a1a2994c1 h1:gEOO8jv9F4OT7lGCjxCBTO/36wtF6j2nSip77qHd4x4=
github.com/xrash/smetrics v0.0.0-20240521201337-686a1a2994c1/go.mod h1:Ohn+xnUBiLI6FVj/9LpzZWtj1/D6lUovWYBkxHVV3aM=
github.com/yuin/goldmark v1.1.27/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9decYSb74=
github.com/yuin/goldmark v1.2.1/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9decYSb74=
github.com/yuin/goldmark v1.3.5/go.mod h1:mwnBkeHKe2W/ZEtQ+71ViKU8L12m81fl3OWwC1Zlc8k=
Expand Down

0 comments on commit cdfd622

Please sign in to comment.