Skip to content

Commit

Permalink
Upgrade tendermint to 0.28.0-dev0 (cosmos#3279)
Browse files Browse the repository at this point in the history
  • Loading branch information
alessio authored and jackzampolin committed Jan 11, 2019
1 parent 05d5389 commit df56761
Show file tree
Hide file tree
Showing 13 changed files with 65 additions and 42 deletions.
5 changes: 3 additions & 2 deletions Gopkg.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion Gopkg.toml
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@

[[override]]
name = "github.com/tendermint/tendermint"
revision = "v0.27.4"
revision = "v0.28.0-dev0"

[[constraint]]
name = "github.com/zondax/ledger-cosmos-go"
Expand Down
2 changes: 1 addition & 1 deletion PENDING.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ BREAKING CHANGES
meter utilization during aborted ante handler executions.

* Tendermint
* [\#3278](https://github.com/cosmos/cosmos-sdk/pull/3278) Upgrade to 0.27.4 release
* \#3279 Upgrade to Tendermint 0.28.0-dev0

FEATURES

Expand Down
6 changes: 3 additions & 3 deletions client/lcd/test_helpers.go
Original file line number Diff line number Diff line change
Expand Up @@ -227,8 +227,8 @@ func InitializeTestLCD(
logger := log.NewTMLogger(log.NewSyncWriter(os.Stdout))
logger = log.NewFilter(logger, log.AllowError())

privValidatorFile := config.PrivValidatorFile()
privVal := pvm.LoadOrGenFilePV(privValidatorFile)
privVal := pvm.LoadOrGenFilePV(config.PrivValidatorKeyFile(),
config.PrivValidatorStateFile())
privVal.Reset()

db := dbm.NewMemDB()
Expand All @@ -247,7 +247,7 @@ func InitializeTestLCD(
for i := 0; i < nValidators; i++ {
operPrivKey := secp256k1.GenPrivKey()
operAddr := operPrivKey.PubKey().Address()
pubKey := privVal.PubKey
pubKey := privVal.GetPubKey()
delegation := 100
if i > 0 {
pubKey = ed25519.GenPrivKey().PubKey()
Expand Down
30 changes: 15 additions & 15 deletions cmd/gaia/init/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"encoding/json"
"fmt"
"io/ioutil"
"path/filepath"
"time"

amino "github.com/tendermint/go-amino"
Expand All @@ -16,6 +17,7 @@ import (

"github.com/cosmos/cosmos-sdk/cmd/gaia/app"
"github.com/cosmos/cosmos-sdk/codec"
"github.com/cosmos/cosmos-sdk/server"
)

// ExportGenesisFile creates and writes the genesis configuration to disk. An
Expand Down Expand Up @@ -58,20 +60,6 @@ func ExportGenesisFileWithTime(
return genDoc.SaveAs(genFile)
}

// read of create the private key file for this config
func ReadOrCreatePrivValidator(privValFile string) crypto.PubKey {
var privValidator *privval.FilePV

if common.FileExists(privValFile) {
privValidator = privval.LoadFilePV(privValFile)
} else {
privValidator = privval.GenFilePV(privValFile)
privValidator.Save()
}

return privValidator.GetPubKey()
}

// InitializeNodeValidatorFiles creates private validator and p2p configuration files.
func InitializeNodeValidatorFiles(
config *cfg.Config) (nodeID string, valPubKey crypto.PubKey, err error,
Expand All @@ -83,7 +71,19 @@ func InitializeNodeValidatorFiles(
}

nodeID = string(nodeKey.ID())
valPubKey = ReadOrCreatePrivValidator(config.PrivValidatorFile())
server.UpgradeOldPrivValFile(config)

pvKeyFile := config.PrivValidatorKeyFile()
if err := common.EnsureDir(filepath.Dir(pvKeyFile), 0777); err != nil {
return nodeID, valPubKey, nil
}

pvStateFile := config.PrivValidatorStateFile()
if err := common.EnsureDir(filepath.Dir(pvStateFile), 0777); err != nil {
return nodeID, valPubKey, nil
}

valPubKey = privval.LoadOrGenFilePV(pvKeyFile, pvStateFile).GetPubKey()

return nodeID, valPubKey, nil
}
Expand Down
7 changes: 5 additions & 2 deletions docs/examples/basecoin/cmd/basecoind/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,13 @@ package main
import (
"encoding/json"
"fmt"
"github.com/cosmos/cosmos-sdk/store"
"io"
"os"

"github.com/cosmos/cosmos-sdk/store"

"github.com/tendermint/tendermint/p2p"
"github.com/tendermint/tendermint/privval"

"github.com/cosmos/cosmos-sdk/baseapp"
gaiaInit "github.com/cosmos/cosmos-sdk/cmd/gaia/init"
Expand Down Expand Up @@ -78,7 +80,8 @@ func InitCmd(ctx *server.Context, cdc *codec.Codec) *cobra.Command {
}
nodeID := string(nodeKey.ID())

pk := gaiaInit.ReadOrCreatePrivValidator(config.PrivValidatorFile())
pk := privval.LoadOrGenFilePV(config.PrivValidatorKeyFile(),
config.PrivValidatorStateFile()).GetPubKey()
genTx, appMessage, validator, err := server.SimpleAppGenTx(cdc, pk)
if err != nil {
return err
Expand Down
4 changes: 3 additions & 1 deletion docs/examples/democoin/cmd/democoind/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import (
"github.com/spf13/viper"
"github.com/tendermint/tendermint/libs/common"
"github.com/tendermint/tendermint/p2p"
"github.com/tendermint/tendermint/privval"

"github.com/cosmos/cosmos-sdk/client"

Expand Down Expand Up @@ -81,7 +82,8 @@ func InitCmd(ctx *server.Context, cdc *codec.Codec) *cobra.Command {
}
nodeID := string(nodeKey.ID())

pk := gaiaInit.ReadOrCreatePrivValidator(config.PrivValidatorFile())
pk := privval.LoadOrGenFilePV(config.PrivValidatorKeyFile(),
config.PrivValidatorStateFile()).GetPubKey()
genTx, appMessage, validator, err := server.SimpleAppGenTx(cdc, pk)
if err != nil {
return err
Expand Down
2 changes: 1 addition & 1 deletion server/export.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ func ExportCmd(ctx *Context, cdc *codec.Codec, appExporter AppExporter) *cobra.C
return err
}

if emptyState {
if emptyState || appExporter == nil {
fmt.Println("WARNING: State is not initialized. Returning genesis file.")
genesisFile := path.Join(home, "config", "genesis.json")
genesis, err := ioutil.ReadFile(genesisFile)
Expand Down
3 changes: 2 additions & 1 deletion server/start.go
Original file line number Diff line number Diff line change
Expand Up @@ -114,10 +114,11 @@ func startInProcess(ctx *Context, appCreator AppCreator) (*node.Node, error) {
return nil, err
}

UpgradeOldPrivValFile(cfg)
// create & start tendermint node
tmNode, err := node.NewNode(
cfg,
pvm.LoadOrGenFilePV(cfg.PrivValidatorFile()),
pvm.LoadOrGenFilePV(cfg.PrivValidatorKeyFile(), cfg.PrivValidatorStateFile()),
nodeKey,
proxy.NewLocalClientCreator(app),
node.DefaultGenesisDocProviderFunc(cfg),
Expand Down
15 changes: 10 additions & 5 deletions server/tm_cmds.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,10 @@ func ShowValidatorCmd(ctx *Context) *cobra.Command {
RunE: func(cmd *cobra.Command, args []string) error {

cfg := ctx.Config
privValidator := pvm.LoadOrGenFilePV(cfg.PrivValidatorFile())
valPubKey := privValidator.PubKey
UpgradeOldPrivValFile(cfg)
privValidator := pvm.LoadOrGenFilePV(
cfg.PrivValidatorKeyFile(), cfg.PrivValidatorStateFile())
valPubKey := privValidator.GetPubKey()

if viper.GetBool(client.FlagJson) {
return printlnJSON(valPubKey)
Expand All @@ -67,9 +69,12 @@ func ShowAddressCmd(ctx *Context) *cobra.Command {
Use: "show-address",
Short: "Shows this node's tendermint validator consensus address",
RunE: func(cmd *cobra.Command, args []string) error {

cfg := ctx.Config
privValidator := pvm.LoadOrGenFilePV(cfg.PrivValidatorFile())
valConsAddr := (sdk.ConsAddress)(privValidator.Address)
UpgradeOldPrivValFile(cfg)
privValidator := pvm.LoadOrGenFilePV(
cfg.PrivValidatorKeyFile(), cfg.PrivValidatorStateFile())
valConsAddr := (sdk.ConsAddress)(privValidator.GetAddress())

if viper.GetBool(client.FlagJson) {
return printlnJSON(valConsAddr)
Expand Down Expand Up @@ -102,7 +107,7 @@ func UnsafeResetAllCmd(ctx *Context) *cobra.Command {
Short: "Resets the blockchain database, removes address book files, and resets priv_validator.json to the genesis state",
RunE: func(cmd *cobra.Command, args []string) error {
cfg := ctx.Config
tcmd.ResetAll(cfg.DBDir(), cfg.P2P.AddrBookFile(), cfg.PrivValidatorFile(), ctx.Logger)
tcmd.ResetAll(cfg.DBDir(), cfg.P2P.AddrBookFile(), cfg.PrivValidatorKeyFile(), cfg.PrivValidatorStateFile(), ctx.Logger)
return nil
},
}
Expand Down
11 changes: 11 additions & 0 deletions server/util.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import (
"github.com/tendermint/tendermint/libs/cli"
tmflags "github.com/tendermint/tendermint/libs/cli/flags"
"github.com/tendermint/tendermint/libs/log"
pvm "github.com/tendermint/tendermint/privval"

"github.com/cosmos/cosmos-sdk/client"
"github.com/cosmos/cosmos-sdk/codec"
Expand Down Expand Up @@ -221,6 +222,16 @@ func TrapSignal(cleanupFunc func()) {
}()
}

// UpgradeOldPrivValFile converts old priv_validator.json file (prior to Tendermint 0.28)
// to the new priv_validator_key.json and priv_validator_state.json files.
func UpgradeOldPrivValFile(config *cfg.Config) {
if _, err := os.Stat(config.OldPrivValidatorFile()); !os.IsNotExist(err) {
if oldFilePV, err := pvm.LoadOldFilePV(config.OldPrivValidatorFile()); err == nil {
oldFilePV.Upgrade(config.PrivValidatorKeyFile(), config.PrivValidatorStateFile())
}
}
}

func skipInterface(iface net.Interface) bool {
if iface.Flags&net.FlagUp == 0 {
return true // interface down
Expand Down
18 changes: 9 additions & 9 deletions x/auth/ante_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -620,23 +620,23 @@ func TestCountSubkeys(t *testing.T) {
}
return ret
}
genMultiKey := func(n, k int, keysGen func(n int) []crypto.PubKey) crypto.PubKey {
return multisig.NewPubKeyMultisigThreshold(k, keysGen(n))
}
singleKey := secp256k1.GenPrivKey().PubKey()
singleLevelMultiKey := multisig.NewPubKeyMultisigThreshold(4, genPubKeys(5))
multiLevelSubKey1 := multisig.NewPubKeyMultisigThreshold(4, genPubKeys(5))
multiLevelSubKey2 := multisig.NewPubKeyMultisigThreshold(4, genPubKeys(5))
multiLevelMultiKey := multisig.NewPubKeyMultisigThreshold(2, []crypto.PubKey{
multiLevelSubKey1, multiLevelSubKey2, secp256k1.GenPrivKey().PubKey()})
type args struct {
pub crypto.PubKey
}
mkey := genMultiKey(5, 4, genPubKeys)
mkeyType := mkey.(*multisig.PubKeyMultisigThreshold)
mkeyType.PubKeys = append(mkeyType.PubKeys, genMultiKey(6, 5, genPubKeys))
tests := []struct {
name string
args args
want int
}{
{"single key", args{secp256k1.GenPrivKey().PubKey()}, 1},
{"multi sig key", args{genMultiKey(5, 4, genPubKeys)}, 5},
{"multi multi sig", args{mkey}, 11},
{"single key", args{singleKey}, 1},
{"single level multikey", args{singleLevelMultiKey}, 5},
{"multi level multikey", args{multiLevelMultiKey}, 11},
}
for _, tt := range tests {
t.Run(tt.name, func(T *testing.T) {
Expand Down
2 changes: 1 addition & 1 deletion x/auth/stdtx.go
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ func (tx StdTx) ValidateBasic() sdk.Error {

// countSubKeys counts the total number of keys for a multi-sig public key.
func countSubKeys(pub crypto.PubKey) int {
v, ok := pub.(*multisig.PubKeyMultisigThreshold)
v, ok := pub.(multisig.PubKeyMultisigThreshold)
if !ok {
return 1
}
Expand Down

0 comments on commit df56761

Please sign in to comment.