From cd24244308a0e2afc9511c3f2a767e21c1d05140 Mon Sep 17 00:00:00 2001 From: Adrian Brink Date: Sun, 13 May 2018 18:19:42 -0400 Subject: [PATCH 1/3] Sort all genesis transaction by node id This ensures that users can rename the genesis transactions and they will still be in the same order. --- cmd/gaia/app/genesis.go | 5 +++-- server/init.go | 19 +++++++++++++++---- 2 files changed, 18 insertions(+), 6 deletions(-) diff --git a/cmd/gaia/app/genesis.go b/cmd/gaia/app/genesis.go index 9d88953cf..7cb7564dd 100644 --- a/cmd/gaia/app/genesis.go +++ b/cmd/gaia/app/genesis.go @@ -66,8 +66,9 @@ func GaiaAppInit() server.AppInit { fsAppGenTx := pflag.NewFlagSet("", pflag.ContinueOnError) fsAppGenTx.String(flagName, "", "validator moniker, if left blank, do not add validator") - fsAppGenTx.String(flagClientHome, DefaultCLIHome, "home directory for the client, used for key generation") - fsAppGenTx.Bool(flagOWK, false, "overwrite the for the accounts created") + fsAppGenTx.String(flagClientHome, DefaultCLIHome, + "home directory for the client, used for key generation") + fsAppGenTx.Bool(flagOWK, false, "overwrite the accounts created") return server.AppInit{ FlagsAppGenState: fsAppGenState, diff --git a/server/init.go b/server/init.go index 2d8be85f8..ffb84f27c 100644 --- a/server/init.go +++ b/server/init.go @@ -7,6 +7,7 @@ import ( "os" "path" "path/filepath" + "sort" "github.com/pkg/errors" "github.com/spf13/cobra" @@ -210,12 +211,14 @@ func InitCmd(ctx *Context, cdc *wire.Codec, appInit AppInit) *cobra.Command { func processGenTxs(genTxsDir string, cdc *wire.Codec, appInit AppInit) ( validators []tmtypes.GenesisValidator, appGenTxs []json.RawMessage, persistentPeers string, err error) { - // XXX sort the files by contents just incase people renamed their files var fos []os.FileInfo fos, err = ioutil.ReadDir(genTxsDir) if err != nil { return } + + genTxs := make(map[string]GenesisTx) + var nodeIDs []string for _, fo := range fos { filename := path.Join(genTxsDir, fo.Name()) if !fo.IsDir() && (path.Ext(filename) != ".json") { @@ -234,16 +237,24 @@ func processGenTxs(genTxsDir string, cdc *wire.Codec, appInit AppInit) ( return } + genTxs[genTx.NodeID] = genTx + nodeIDs = append(nodeIDs, genTx.NodeID) + } + + sort.Strings(nodeIDs) + + for _, nodeID := range nodeIDs { // combine some stuff - validators = append(validators, genTx.Validator) - appGenTxs = append(appGenTxs, genTx.AppGenTx) + validators = append(validators, genTxs[nodeID].Validator) + appGenTxs = append(appGenTxs, genTxs[nodeID].AppGenTx) // Add a persistent peer comma := "," if len(persistentPeers) == 0 { comma = "" } - persistentPeers += fmt.Sprintf("%s%s@%s:46656", comma, genTx.NodeID, genTx.IP) + persistentPeers += fmt.Sprintf("%s%s@%s:46656", comma, genTxs[nodeID].NodeID, + genTxs[nodeID].IP) } return From 878a53bf0def7c4aa1d76145383dfda204514b5b Mon Sep 17 00:00:00 2001 From: Adrian Brink Date: Sun, 13 May 2018 18:24:48 -0400 Subject: [PATCH 2/3] Prevent --gen-txs from failing silently Instead of just failing silently if there is a non .json file or folder in the gentx/ directory it now just skips that file or directory. ref #940 --- server/init.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/server/init.go b/server/init.go index ffb84f27c..8912d2a6f 100644 --- a/server/init.go +++ b/server/init.go @@ -222,7 +222,7 @@ func processGenTxs(genTxsDir string, cdc *wire.Codec, appInit AppInit) ( for _, fo := range fos { filename := path.Join(genTxsDir, fo.Name()) if !fo.IsDir() && (path.Ext(filename) != ".json") { - return + continue } // get the genTx From d2163017ceed3a6b8b5ef5e0c907f9f9957991df Mon Sep 17 00:00:00 2001 From: rigelrozanski Date: Mon, 14 May 2018 09:39:29 -0400 Subject: [PATCH 3/3] small efficiency increase --- server/init.go | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/server/init.go b/server/init.go index 8912d2a6f..68a1709bc 100644 --- a/server/init.go +++ b/server/init.go @@ -244,17 +244,18 @@ func processGenTxs(genTxsDir string, cdc *wire.Codec, appInit AppInit) ( sort.Strings(nodeIDs) for _, nodeID := range nodeIDs { + genTx := genTxs[nodeID] + // combine some stuff - validators = append(validators, genTxs[nodeID].Validator) - appGenTxs = append(appGenTxs, genTxs[nodeID].AppGenTx) + validators = append(validators, genTx.Validator) + appGenTxs = append(appGenTxs, genTx.AppGenTx) // Add a persistent peer comma := "," if len(persistentPeers) == 0 { comma = "" } - persistentPeers += fmt.Sprintf("%s%s@%s:46656", comma, genTxs[nodeID].NodeID, - genTxs[nodeID].IP) + persistentPeers += fmt.Sprintf("%s%s@%s:46656", comma, genTx.NodeID, genTx.IP) } return