Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

go-kosu: add reset and show_node_info cmds #239

Merged
merged 5 commits into from Aug 28, 2019
Merged
Changes from 1 commit
Commits
File filter...
Filter file types
Jump to…
Jump to file or symbol
Failed to load files and symbols.

Always

Just for now

go-kosu: mimic unsafe_reset_all

  • Loading branch information
gchaincl committed Aug 28, 2019
commit 2a44b253211d6e7cdfdcfeea52845b447707ab15
@@ -2,11 +2,11 @@ package abci

import (
"encoding/hex"
"fmt"
"io"
"io/ioutil"
"os"

"github.com/tendermint/tendermint/cmd/tendermint/commands"
"github.com/tendermint/tendermint/config"
tmflags "github.com/tendermint/tendermint/libs/cli/flags"
log "github.com/tendermint/tendermint/libs/log"
@@ -89,37 +89,12 @@ func ShowNodeInfo(cfg *config.Config) (*NodeInfo, error) {
// ResetAll wipes the kosu home represented by cfg, keeping only the config and the genesis files
// ResetAll is idempotent, which means that running reset twice, should have no effect
// All the output will be written to w
func ResetAll(cfg *config.Config, w io.Writer) error {
func ResetAll(cfg *config.Config, w io.Writer) {
if w == nil {
w = ioutil.Discard
}

files := []string{
cfg.P2P.AddrBookFile(),
cfg.PrivValidatorKeyFile(),
cfg.PrivValidatorStateFile(),
}

if err := removeFiles(w, files...); err != nil {
return err
}

fmt.Fprintf(w, "Deleting directory %s", cfg.DBDir())
if err := os.RemoveAll(cfg.DBDir()); err != nil {
return err
}

return nil
}

func removeFiles(w io.Writer, files ...string) error {
for _, file := range files {
fmt.Fprintf(w, "Deleting %s\n", file)
if err := os.Remove(file); err != nil {
if !os.IsNotExist(err) {
return err
}
}
}
return nil
logger := log.NewTMLogger(w)
commands.ResetAll(cfg.DBDir(), cfg.P2P.AddrBookFile(), cfg.PrivValidatorKeyFile(),
cfg.PrivValidatorStateFile(), logger)
}
@@ -19,6 +19,10 @@ import (
"go-kosu/witness"
)

const (
dbName = "kosu"
)

// Config holds the program execution arguments
type Config struct {
Home string
@@ -28,7 +32,7 @@ type Config struct {
}

func newDB(dir string, debug bool) (db.DB, error) {
gdb, err := db.NewGoLevelDB("kosu", dir)
gdb, err := db.NewGoLevelDB(dbName, dir)
if err != nil {
return nil, err
}
@@ -157,11 +161,10 @@ func main() {
return err
}

if err := abci.ResetAll(kosuCfg, os.Stdout); err != nil {
return err
}
abci.ResetAll(kosuCfg, os.Stdout)

return abci.InitTendermint(cfg.Home)
dbdir := path.Join(kosuCfg.RootDir, dbName+".db")
return os.RemoveAll(dbdir)
},
}

@@ -223,6 +223,7 @@ github.com/tendermint/tendermint v0.31.2-0.20190822092307-7b2d018f847e/go.mod h1
github.com/tendermint/tendermint v0.31.5 h1:vTet8tCq3B9/J9Yo11dNZ8pOB7NtSy++bVSfkP4KzR4=
github.com/tendermint/tendermint v0.31.5/go.mod h1:ymcPyWblXCplCPQjbOYbrF1fWnpslATMVqiGgWbZrlc=
github.com/tendermint/tendermint v0.32.1 h1:J8ddXMbCmG6GZjdCl/N1wgdXDU9uO91J2Y5CA9xYfGo=
github.com/tendermint/tendermint v0.32.3 h1:GEnWpGQ795h5oTFNbfBLsY0LW/CW2j6p6HtiYNfxsgg=
github.com/tendermint/tm-db v0.1.1/go.mod h1:0cPKWu2Mou3IlxecH+MEUSYc1Ch537alLe6CpFrKzgw=
github.com/tidwall/gjson v1.3.0 h1:kfpsw1W3trbg4Xm6doUtqSl9+LhLB6qJ9PkltVAQZYs=
github.com/tidwall/gjson v1.3.0/go.mod h1:P256ACg0Mn+j1RXIDXoss50DeIABTYK1PULOJHhxOls=
ProTip! Use n and p to navigate between commits in a pull request.
You can’t perform that action at this time.