Skip to content

Commit

Permalink
scripts/compare-fscontent: use flag dependency instead of urfave
Browse files Browse the repository at this point in the history
Signed-off-by: Andrey Butusov <andrey@nspcc.io>
  • Loading branch information
End-rey committed Sep 2, 2024
1 parent 72baaa1 commit 290e13c
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 45 deletions.
57 changes: 27 additions & 30 deletions scripts/compare-fscontent/compare-fscontent.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"bytes"
"context"
"errors"
"flag"
"fmt"
"os"

Expand All @@ -14,7 +15,6 @@ import (
"github.com/nspcc-dev/neofs-contract/rpc/netmap"
"github.com/nspcc-dev/neofs-contract/rpc/nns"
"github.com/pmezard/go-difflib/difflib"
"github.com/urfave/cli"
)

func initClient(addr string, name string) (*rpcclient.Client, uint32, error) {
Expand Down Expand Up @@ -63,20 +63,29 @@ func getFSContent(c *rpcclient.Client) ([][]byte, []*netmap.NetmapNode, error) {
return containers, netmap, nil
}

func cliMain(c *cli.Context) error {
a := c.Args().Get(0)
b := c.Args().Get(1)
if a == "" {
return errors.New("no arguments given")
}
if b == "" {
return errors.New("missing second argument")
var (
compareFsContentFirstNodeAddress string
compareFsContentSecondNodeAddress string
compareFsContentIgnoreHeightFlag bool
)

func init() {
flag.StringVar(&compareFsContentFirstNodeAddress, "first", "", "First RPC node")
flag.StringVar(&compareFsContentSecondNodeAddress, "second", "", "Second RPC node")
flag.BoolVar(&compareFsContentIgnoreHeightFlag, "ignore-height", false, "Ignore height difference")
}

func cliMain() error {
flag.Parse()

if compareFsContentFirstNodeAddress == "" || compareFsContentSecondNodeAddress == "" {
return errors.New("2 RPC nodes need to be specified")
}
ca, ha, err := initClient(a, "A")
ca, ha, err := initClient(compareFsContentFirstNodeAddress, "A")
if err != nil {
return err
}
cb, hb, err := initClient(b, "B")
cb, hb, err := initClient(compareFsContentSecondNodeAddress, "B")
if err != nil {
return err
}
Expand All @@ -85,19 +94,19 @@ func cliMain(c *cli.Context) error {
if ha > hb {
diff = ha - hb
}
if diff > 10 && !c.Bool("ignore-height") { // Allow some height drift.
if diff > 10 && !compareFsContentIgnoreHeightFlag { // Allow some height drift.
return fmt.Errorf("chains have different heights: %d vs %d", ha, hb)
}
}
fmt.Printf("RPC %s height: %d\nRPC %s height: %d\n", a, ha, b, hb)
fmt.Printf("RPC %s height: %d\nRPC %s height: %d\n", compareFsContentFirstNodeAddress, ha, compareFsContentSecondNodeAddress, hb)

containersA, netmapA, err := getFSContent(ca)
if err != nil {
return fmt.Errorf("RPC %s: %w", a, err)
return fmt.Errorf("RPC %s: %w", compareFsContentFirstNodeAddress, err)
}
containersB, netmapB, err := getFSContent(cb)
if err != nil {
return fmt.Errorf("RPC %s: %w", b, err)
return fmt.Errorf("RPC %s: %w", compareFsContentSecondNodeAddress, err)
}

var (
Expand All @@ -111,7 +120,7 @@ func cliMain(c *cli.Context) error {
for i := range containersA {
if !bytes.Equal(containersA[i], containersB[i]) {
containersDiff++
dumpContentDiff("container", i, a, b, containersA[i], containersB[i])
dumpContentDiff("container", i, compareFsContentFirstNodeAddress, compareFsContentSecondNodeAddress, containersA[i], containersB[i])
}
}
}
Expand All @@ -132,7 +141,7 @@ func cliMain(c *cli.Context) error {
for i := range netmapA {
if netmapA[i].State.Cmp(netmapB[i].State) != 0 || !bytes.Equal(netmapA[i].BLOB, netmapB[i].BLOB) {
netmapDiff++
dumpContentDiff("netmap entry", i, a, b, netmapA[i], netmapB[i])
dumpContentDiff("netmap entry", i, compareFsContentFirstNodeAddress, compareFsContentSecondNodeAddress, netmapA[i], netmapB[i])
}
}
}
Expand Down Expand Up @@ -164,19 +173,7 @@ func dumpContentDiff(itemName string, i int, a string, b string, itemA any, item
}

func main() {
ctl := cli.NewApp()
ctl.Name = "compare-fscontent"
ctl.Version = "1.0"
ctl.Usage = "compare-fscontent RPC_A RPC_B"
ctl.Action = cliMain
ctl.Flags = []cli.Flag{
cli.BoolFlag{
Name: "ignore-height, g",
Usage: "ignore height difference",
},
}

if err := ctl.Run(os.Args); err != nil {
if err := cliMain(); err != nil {
fmt.Fprintln(os.Stderr, err)
os.Exit(1)
}
Expand Down
3 changes: 0 additions & 3 deletions scripts/compare-fscontent/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,11 @@ require (
github.com/nspcc-dev/neo-go v0.106.3
github.com/nspcc-dev/neofs-contract v0.20.0
github.com/pmezard/go-difflib v1.0.0
github.com/urfave/cli v1.22.15
)

require (
github.com/beorn7/perks v1.0.1 // indirect
github.com/cespare/xxhash/v2 v2.2.0 // indirect
github.com/cpuguy83/go-md2man/v2 v2.0.4 // indirect
github.com/decred/dcrd/dcrec/secp256k1/v4 v4.2.0 // indirect
github.com/golang/snappy v0.0.1 // indirect
github.com/google/uuid v1.6.0 // indirect
Expand All @@ -28,7 +26,6 @@ require (
github.com/prometheus/client_model v0.5.0 // indirect
github.com/prometheus/common v0.48.0 // indirect
github.com/prometheus/procfs v0.12.0 // indirect
github.com/russross/blackfriday/v2 v2.1.0 // indirect
github.com/syndtr/goleveldb v1.0.1-0.20210305035536-64b5b1c73954 // indirect
github.com/twmb/murmur3 v1.1.8 // indirect
go.etcd.io/bbolt v1.3.9 // indirect
Expand Down
12 changes: 0 additions & 12 deletions scripts/compare-fscontent/go.sum
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
github.com/BurntSushi/toml v1.3.2/go.mod h1:CxXYINrC8qIiEnFrOxCa7Jy5BFHlXnUU2pbicEuybxQ=
github.com/beorn7/perks v1.0.1 h1:VlbKKnNfV8bJzeqoa4cOKqO6bYr3WgKZxO8Z16+hsOM=
github.com/beorn7/perks v1.0.1/go.mod h1:G2ZrVWU2WbWT9wwq4/hrbKbnv/1ERSJQ0ibhJ6rlkpw=
github.com/bits-and-blooms/bitset v1.8.0 h1:FD+XqgOZDUxxZ8hzoBFuV9+cGWY9CslN6d5MS5JVb4c=
Expand All @@ -11,7 +10,6 @@ github.com/consensys/gnark-crypto v0.12.2-0.20231013160410-1f65e75b6dfb h1:f0BMg
github.com/consensys/gnark-crypto v0.12.2-0.20231013160410-1f65e75b6dfb/go.mod h1:v2Gy7L/4ZRosZ7Ivs+9SfUDr0f5UlG+EM5t7MPHiLuY=
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/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/decred/dcrd/dcrec/secp256k1/v4 v4.2.0 h1:8UrgZ3GkP4i/CLijOJx79Yu+etlyjdBU4sfcs2WYQMs=
Expand Down Expand Up @@ -87,21 +85,12 @@ github.com/rogpeppe/go-internal v1.11.0 h1:cWPaGQEPrBb5/AsnsZesgZZ9yb1OQ+GOISoDN
github.com/rogpeppe/go-internal v1.11.0/go.mod h1:ddIwULY96R17DhadqLgMfk9H9tvdUzkipdSkR5nkCZA=
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/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
github.com/stretchr/objx v0.4.0/go.mod h1:YvHI0jy2hoMjB+UWwv71VJQ9isScKT/TqJzVSSt89Yw=
github.com/stretchr/objx v0.5.0/go.mod h1:Yh+to48EsGEfYuaHDzXPcE3xhTkx73EhmCGUpEOglKo=
github.com/stretchr/objx v0.5.2/go.mod h1:FRsXN1f5AsAjCGJKqEizvkpNtU+EGNCLh3NxZ/8L+MA=
github.com/stretchr/testify v1.7.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
github.com/stretchr/testify v1.8.0/go.mod h1:yNjHg4UonilssWZ8iaSj1OCr/vHnekPRkoO+kdMU+MU=
github.com/stretchr/testify v1.8.4/go.mod h1:sz/lmYIOXD/1dqDmKjjqLyZ2RngseejIcXlSw2iwfAo=
github.com/stretchr/testify v1.9.0 h1:HtqpIVDClZ4nwg75+f6Lvsy/wHu+3BoSGCbBAcpTsTg=
github.com/stretchr/testify v1.9.0/go.mod h1:r2ic/lqez/lEtzL7wO/rwa5dbSLXVDPFyf8C91i36aY=
github.com/syndtr/goleveldb v1.0.1-0.20210305035536-64b5b1c73954 h1:xQdMZ1WLrgkkvOZ/LDQxjVxMLdby7osSh4ZEVa5sIjs=
github.com/syndtr/goleveldb v1.0.1-0.20210305035536-64b5b1c73954/go.mod h1:u2MKkTVTVJWe5D1rCvame8WqhBd88EuIwODJZ1VHCPM=
github.com/twmb/murmur3 v1.1.8 h1:8Yt9taO/WN3l08xErzjeschgZU2QSrwm1kclYq+0aRg=
github.com/twmb/murmur3 v1.1.8/go.mod h1:Qq/R7NUyOfr65zD+6Q5IHKsJLwP7exErjN6lyyq3OSQ=
github.com/urfave/cli v1.22.15 h1:nuqt+pdC/KqswQKhETJjo7pvn/k4xMUxgW6liI7XpnM=
github.com/urfave/cli v1.22.15/go.mod h1:wSan1hmo5zeyLGBjRJbzRTNk8gwoYa2B9n4q9dmRIc0=
github.com/urfave/cli/v2 v2.27.2 h1:6e0H+AkS+zDckwPCUrZkKX38mRaau4nL2uipkJpbkcI=
github.com/urfave/cli/v2 v2.27.2/go.mod h1:g0+79LmHHATl7DAcHO99smiR/T7uGLw84w8Y42x+4eM=
github.com/xrash/smetrics v0.0.0-20240312152122-5f08fbb34913 h1:+qGGcbkzsfDQNPPe9UDgpxAWQrhbbBXOYJFQDq/dtJw=
Expand Down Expand Up @@ -171,7 +160,6 @@ gopkg.in/yaml.v2 v2.2.4/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=
gopkg.in/yaml.v2 v2.3.0/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=
gopkg.in/yaml.v2 v2.4.0 h1:D8xgwECY7CYvx+Y2n4sBz93Jn9JRvxdiyyo8CTfuKaY=
gopkg.in/yaml.v2 v2.4.0/go.mod h1:RDklbk79AGWmwhnvt/jBztapEOGDOx6ZbXqjP6csGnQ=
gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA=
gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
rsc.io/tmplfunc v0.0.3 h1:53XFQh69AfOa8Tw0Jm7t+GV7KZhOi6jzsCzTtKbMvzU=
Expand Down

0 comments on commit 290e13c

Please sign in to comment.