Skip to content

Commit

Permalink
Merge pull request #205 from vegaprotocol/difftool
Browse files Browse the repository at this point in the history
feat: core snapshot vs db experimental
  • Loading branch information
ze97286 authored Nov 1, 2022
2 parents ddd37cd + 581dc44 commit 3889f78
Show file tree
Hide file tree
Showing 11 changed files with 1,692 additions and 8 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@
- [230](https://github.com/vegaprotocol/vegatools/issue/230) - Update datanode api use to v2
- [232](https://github.com/vegaprotocol/vegatools/issue/232) - Add batched orders to perftest
- [234](https://github.com/vegaprotocol/vegatools/issue/234) - Add pegged order support to perftest
- [236](https://github.com/vegaprotocol/vegatools/issues/236) - Diff tool introduced to compare core snapshot with data node `API`
- [237](https://github.com/vegaprotocol/vegatools/issue/237) - Rename of Oracles to Data Sources

### 🐛 Fixes
Expand Down
50 changes: 50 additions & 0 deletions cmd/difftool.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
package cmd

import (
"os"
"strings"

"code.vegaprotocol.io/vegatools/difftool/diff"
"code.vegaprotocol.io/vegatools/snapshotdb"
"github.com/spf13/cobra"
)

var (
diffToolOpts struct {
snapshotDatabasePath string
heightToOutput int64
datanode string
}

diffToolCmd = &cobra.Command{
Use: "difftool",
Short: "Compare the state of a core snapshot with datanode API",
RunE: runDiffToolCmd,
}
)

func init() {
rootCmd.AddCommand(diffToolCmd)
diffToolCmd.Flags().StringVarP(&diffToolOpts.snapshotDatabasePath, "snap-db-path", "s", "", "path to the goleveldb database folder")
diffToolCmd.Flags().Int64VarP(&diffToolOpts.heightToOutput, "block-height", "r", 0, "block-height of the snapshot to dump")
diffToolCmd.Flags().StringVarP(&diffToolOpts.datanode, "datanode", "d", "", "datanode url")
diffToolCmd.MarkFlagRequired("snap-db-path")
diffToolCmd.MarkFlagRequired("datanode")

}
func runDiffToolCmd(cmd *cobra.Command, args []string) error {
temp := os.TempDir()
if !strings.HasSuffix(temp, string(os.PathSeparator)) {
temp = temp + string(os.PathSeparator)
}
println(temp)
snapshotPath := temp + "snapshot.dat"

err := snapshotdb.Run(diffToolOpts.snapshotDatabasePath, false, snapshotPath, snapshotDBOpts.heightToOutput, "proto")
defer os.Remove(snapshotPath)
if err != nil {
return err
}

return diff.Run(snapshotPath, diffToolOpts.datanode)
}
6 changes: 4 additions & 2 deletions cmd/snapshotdb.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ var (
snapshotDBOpts struct {
databasePath string
outputPath string
outputFormat string
heightToOutput int64
versionCountOnly bool
}
Expand All @@ -23,12 +24,13 @@ var (
func init() {
rootCmd.AddCommand(snapshotDBCmd)
snapshotDBCmd.Flags().StringVarP(&snapshotDBOpts.databasePath, "db-path", "d", "", "path to the goleveldb database folder")
snapshotDBCmd.Flags().StringVarP(&snapshotDBOpts.outputPath, "out", "o", "", "file to write JSON to")
snapshotDBCmd.Flags().StringVarP(&snapshotDBOpts.outputPath, "out", "o", "", "file to write output to")
snapshotDBCmd.Flags().StringVarP(&snapshotDBOpts.outputFormat, "format", "f", "json", "output format")
snapshotDBCmd.Flags().Int64VarP(&snapshotDBOpts.heightToOutput, "block-height", "r", 0, "block-height of the snapshot to dump")
snapshotDBCmd.Flags().BoolVarP(&snapshotDBOpts.versionCountOnly, "versions", "v", false, "display the number of stored versions")
snapshotDBCmd.MarkFlagRequired("db-path")
}

func runSnapshotDBCmd(cmd *cobra.Command, args []string) error {
return snapshotdb.Run(snapshotDBOpts.databasePath, snapshotDBOpts.versionCountOnly, snapshotDBOpts.outputPath, snapshotDBOpts.heightToOutput)
return snapshotdb.Run(snapshotDBOpts.databasePath, snapshotDBOpts.versionCountOnly, snapshotDBOpts.outputPath, snapshotDBOpts.heightToOutput, snapshotDBOpts.outputFormat)
}
Loading

0 comments on commit 3889f78

Please sign in to comment.