Skip to content

Commit

Permalink
Merge pull request #1 from mysteriumnetwork/exit_code
Browse files Browse the repository at this point in the history
reflect result in exit code
  • Loading branch information
Snawoot authored Feb 28, 2022
2 parents 43873ac + 4b88064 commit aa0b4e9
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 4 deletions.
5 changes: 4 additions & 1 deletion cmd/ethdiff/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,12 +55,15 @@ func run() int {
leftClient, rightClient := diff.NewRetryingClient(leftClientResult.Client, *retries),
diff.NewRetryingClient(rightClientResult.Client, *retries)

lastCommonBlock, err := diff.LastCommonBlock(ctx, leftClient, rightClient, *offset)
lastCommonBlock, observedHeight, err := diff.LastCommonBlock(ctx, leftClient, rightClient, *offset)
if err != nil {
log.Fatalf("LastCommonBlock(%v, %v) error: %v", flag.Arg(0), flag.Arg(1), err)
}

fmt.Printf("0x%x\n", lastCommonBlock)
if (lastCommonBlock != observedHeight) {
return 3
}

return 0
}
Expand Down
6 changes: 3 additions & 3 deletions diff/diff.go
Original file line number Diff line number Diff line change
Expand Up @@ -77,10 +77,10 @@ func getBlocks(ctx context.Context, left, right Client, blockNumber uint64) (*ty
return leftBlock, rightBlock, nil
}

func LastCommonBlock(ctx context.Context, left, right Client, offset uint64) (uint64, error) {
func LastCommonBlock(ctx context.Context, left, right Client, offset uint64) (uint64, uint64, error) {
leftLatestBlock, rightLatestBlock, err := getNumbers(ctx, left, right)
if err != nil {
return 0, err
return 0, 0, err
}
highestCommonBlock := max(leftLatestBlock, rightLatestBlock)
log.Printf("highestCommonBlock = 0x%x (%d)", highestCommonBlock, highestCommonBlock)
Expand All @@ -101,7 +101,7 @@ func LastCommonBlock(ctx context.Context, left, right Client, offset uint64) (ui
log.Printf("searchFunc(0x%x) = %v", blockNumber, result)
return result, nil
})
return res - 1, err
return res - 1, highestCommonBlock, err
}

func max(x, y uint64) uint64 {
Expand Down

0 comments on commit aa0b4e9

Please sign in to comment.