compare-states: return 0 in case state matches

This commit is contained in:
Roman Khimov 2022-05-12 12:03:54 +03:00
parent dafd3639e8
commit 84c231757b

View file

@ -13,6 +13,8 @@ import (
"github.com/urfave/cli" "github.com/urfave/cli"
) )
var errStateMatches = errors.New("state matches")
func initClient(addr string, name string) (*client.Client, uint32, error) { func initClient(addr string, name string) (*client.Client, uint32, error) {
c, err := client.New(context.Background(), addr, client.Options{}) c, err := client.New(context.Background(), addr, client.Options{})
if err != nil { if err != nil {
@ -57,7 +59,7 @@ func bisectState(ca *client.Client, cb *client.Client, h uint32) (uint32, error)
} }
fmt.Printf("at %d: %s vs %s\n", h, ra.StringLE(), rb.StringLE()) fmt.Printf("at %d: %s vs %s\n", h, ra.StringLE(), rb.StringLE())
if ra.Equals(rb) { if ra.Equals(rb) {
return 0, fmt.Errorf("state matches at %d", h) return 0, fmt.Errorf("%w at %d", errStateMatches, h)
} }
bad := h bad := h
for bad-good > 1 { for bad-good > 1 {
@ -98,6 +100,9 @@ func cliMain(c *cli.Context) error {
} }
h, err := bisectState(ca, cb, ha-1) h, err := bisectState(ca, cb, ha-1)
if err != nil { if err != nil {
if errors.Is(err, errStateMatches) {
return nil
}
return err return err
} }
blk, err := ca.GetBlockByIndex(h) blk, err := ca.GetBlockByIndex(h)