Skip to content

Commit

Permalink
Merge PR: check watchdb version when start node (#2502)
Browse files Browse the repository at this point in the history
  • Loading branch information
ilovers authored Sep 5, 2022
1 parent 9ad6773 commit 9455c04
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 0 deletions.
22 changes: 22 additions & 0 deletions x/evm/watcher/db.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
package watcher

import (
"io/ioutil"
"log"
"os"
"path/filepath"
"sync"

Expand Down Expand Up @@ -47,9 +49,29 @@ func initDb() dbm.DB {
backend = string(dbm.GoLevelDBBackend)
}

versionPath := filepath.Join(dbPath, WatchDBName+".db", "VERSION")
if !checkVersion(versionPath) {
os.RemoveAll(filepath.Join(dbPath, WatchDBName+".db"))
}
db := dbm.NewDB(WatchDBName, dbm.BackendType(backend), dbPath)
writeVersion(versionPath)
return db

return dbm.NewDB(WatchDBName, dbm.BackendType(backend), dbPath)
}

func checkVersion(versionPath string) bool {
content, err := ioutil.ReadFile(versionPath)
if err != nil || string(content) != version {
return false
}
return true
}

func writeVersion(versionPath string) {
ioutil.WriteFile(versionPath, []byte(version), 0666)
}

func (w WatchStore) Set(key []byte, value []byte) {
err := w.db.Set(key, value)
if err != nil {
Expand Down
2 changes: 2 additions & 0 deletions x/evm/watcher/watcher.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@ import (
"github.com/spf13/viper"
)

const version = "v1"

var itjs = jsoniter.ConfigCompatibleWithStandardLibrary

type Watcher struct {
Expand Down

0 comments on commit 9455c04

Please sign in to comment.