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

Drop on-disk keybase in favor of keyring #164

Merged
merged 32 commits into from
Nov 18, 2019
Merged
Show file tree
Hide file tree
Changes from 21 commits
Commits
Show all changes
32 commits
Select commit Hold shift + click to select a range
3d6a06d
Port to new keyring
Oct 17, 2019
56202c4
modify add-genesis-account to use keyring
Oct 17, 2019
e9792ca
Adapt lcd tests to use keyring
Oct 17, 2019
c299dd9
Attempt to fix localnet ci job
Oct 17, 2019
6cba259
Revert "Attempt to fix localnet ci job"
Oct 17, 2019
0623331
Try pass env var to docker container
Oct 17, 2019
9ab3d70
localnet does need COSMOS_SDK_TEST_KEYRING to function properly
Oct 17, 2019
889daaf
Revert tiny change
Oct 17, 2019
3555048
Simplify tests
Oct 17, 2019
af22c1e
Refresh against sdk's respective branch latest commit
Oct 17, 2019
4f09117
Merge branch 'master' into alessio/switch-to-keyring
Oct 20, 2019
9fdbaad
Refresh against sdk branch's latest commit
Oct 20, 2019
ecdb113
Merge branch 'master' into alessio/switch-to-keyring
Oct 20, 2019
e67559d
Attempt to reduce diff size
Oct 20, 2019
8f372c5
Merge branch 'master' into alessio/switch-to-keyring
Oct 21, 2019
0ffb359
Merge branch 'master' into alessio/switch-to-keyring
Oct 21, 2019
a36c8bd
Refresh against latest commit
Oct 22, 2019
6c335d1
Merge branch 'master' into alessio/switch-to-keyring
Oct 24, 2019
c4ca05b
Merge branch 'master' into alessio/switch-to-keyring
Nov 4, 2019
878de8c
Update against latest commit
Nov 6, 2019
0b35127
Refresh against sdk's latest master
Nov 6, 2019
c3f6d77
Avoid create temporary keybase
Nov 7, 2019
ecdbafc
Revert "Avoid create temporary keybase"
Nov 7, 2019
d590f27
Update docs
Nov 7, 2019
cb0a675
Remove unnecessary arguments
Nov 8, 2019
dbffa35
Remove unnecessary arguments
Nov 8, 2019
e42aa4f
Code cleanup
Nov 8, 2019
0df6232
Refresh sdk module, add upgrade module
Nov 9, 2019
73f3742
Refresh deps
Nov 15, 2019
3a02f36
Merge branch 'master' into alessio/switch-to-keyring
Nov 15, 2019
2ccd6b9
Fix merge
Nov 17, 2019
1e26b07
Cleanup, AddrSeed does not need Password anymore
Nov 17, 2019
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ LEDGER_ENABLED ?= true
SDK_PACK := $(shell go list -m github.com/cosmos/cosmos-sdk | sed 's/ /\@/g')

export GO111MODULE = on
export COSMOS_SDK_TEST_KEYRING = y

# process build tags

Expand Down Expand Up @@ -157,7 +158,7 @@ build-docker-gaiadnode:

# Run a 4-node testnet locally
localnet-start: build-linux localnet-stop
@if ! [ -f build/node0/gaiad/config/genesis.json ]; then docker run --rm -v $(CURDIR)/build:/gaiad:Z tendermint/gaiadnode testnet --v 4 -o . --starting-ip-address 192.168.10.2 ; fi
@if ! [ -f build/node0/gaiad/config/genesis.json ]; then docker run -e COSMOS_SDK_TEST_KEYRING=y --rm -v $(CURDIR)/build:/gaiad:Z tendermint/gaiadnode testnet --v 4 -o . --starting-ip-address 192.168.10.2 ; fi
docker-compose up -d

# Stop testnet
Expand Down
3 changes: 1 addition & 2 deletions cli_test/cli_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -828,9 +828,8 @@ func TestGaiaCLIValidateSignatures(t *testing.T) {
defer os.Remove(unsignedTxFile.Name())

// validate we can successfully sign
success, stdout, stderr = f.TxSign(keyFoo, unsignedTxFile.Name())
success, stdout, _ = f.TxSign(keyFoo, unsignedTxFile.Name())
require.True(t, success)
require.Empty(t, stderr)
stdTx := unmarshalStdTx(t, stdout)
require.Equal(t, len(stdTx.Msgs), 1)
require.Equal(t, 1, len(stdTx.GetSignatures()))
Expand Down
10 changes: 5 additions & 5 deletions cli_test/test_helpers.go
Original file line number Diff line number Diff line change
Expand Up @@ -225,13 +225,13 @@ func (f *Fixtures) AddGenesisAccount(address sdk.AccAddress, coins sdk.Coins, fl
// GenTx is gaiad gentx
func (f *Fixtures) GenTx(name string, flags ...string) {
cmd := fmt.Sprintf("%s gentx --name=%s --home=%s --home-client=%s", f.GaiadBinary, name, f.GaiadHome, f.GaiacliHome)
executeWriteCheckErr(f.T, addFlags(cmd, flags), client.DefaultKeyPass)
executeWriteCheckErr(f.T, addFlags(cmd, flags))
}

// CollectGenTxs is gaiad collect-gentxs
func (f *Fixtures) CollectGenTxs(flags ...string) {
cmd := fmt.Sprintf("%s collect-gentxs --home=%s", f.GaiadBinary, f.GaiadHome)
executeWriteCheckErr(f.T, addFlags(cmd, flags), client.DefaultKeyPass)
executeWriteCheckErr(f.T, addFlags(cmd, flags))
}

// GDStart runs gaiad start with the appropriate flags and returns a process
Expand Down Expand Up @@ -270,19 +270,19 @@ func (f *Fixtures) KeysDelete(name string, flags ...string) {
// KeysAdd is gaiacli keys add
func (f *Fixtures) KeysAdd(name string, flags ...string) {
cmd := fmt.Sprintf("%s keys add --home=%s %s", f.GaiacliBinary, f.GaiacliHome, name)
executeWriteCheckErr(f.T, addFlags(cmd, flags), client.DefaultKeyPass)
executeWriteCheckErr(f.T, addFlags(cmd, flags))
}

// KeysAddRecover prepares gaiacli keys add --recover
func (f *Fixtures) KeysAddRecover(name, mnemonic string, flags ...string) (exitSuccess bool, stdout, stderr string) {
cmd := fmt.Sprintf("%s keys add --home=%s --recover %s", f.GaiacliBinary, f.GaiacliHome, name)
return executeWriteRetStdStreams(f.T, addFlags(cmd, flags), client.DefaultKeyPass, mnemonic)
return executeWriteRetStdStreams(f.T, addFlags(cmd, flags), mnemonic)
}

// KeysAddRecoverHDPath prepares gaiacli keys add --recover --account --index
func (f *Fixtures) KeysAddRecoverHDPath(name, mnemonic string, account uint32, index uint32, flags ...string) {
cmd := fmt.Sprintf("%s keys add --home=%s --recover %s --account %d --index %d", f.GaiacliBinary, f.GaiacliHome, name, account, index)
executeWriteCheckErr(f.T, addFlags(cmd, flags), client.DefaultKeyPass, mnemonic)
executeWriteCheckErr(f.T, addFlags(cmd, flags), mnemonic)
}

// KeysShow is gaiacli keys show
Expand Down
1 change: 1 addition & 0 deletions cmd/gaiacli/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ func main() {
config.SetBech32PrefixForAccount(sdk.Bech32PrefixAccAddr, sdk.Bech32PrefixAccPub)
config.SetBech32PrefixForValidator(sdk.Bech32PrefixValAddr, sdk.Bech32PrefixValPub)
config.SetBech32PrefixForConsensusNode(sdk.Bech32PrefixConsAddr, sdk.Bech32PrefixConsPub)
config.SetKeyringServiceName("gaia")
config.Seal()

// TODO: setup keybase, viper object, etc. to be passed into
Expand Down
6 changes: 4 additions & 2 deletions cmd/gaiad/genaccounts.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package main

import (
"bufio"
"errors"
"fmt"

Expand Down Expand Up @@ -40,14 +41,15 @@ the address will be looked up in the local Keybase. The list of initial tokens m
contain valid denominations. Accounts may optionally be supplied with vesting parameters.
`,
Args: cobra.ExactArgs(2),
RunE: func(_ *cobra.Command, args []string) error {
RunE: func(cmd *cobra.Command, args []string) error {
config := ctx.Config
config.SetRoot(viper.GetString(cli.HomeFlag))

addr, err := sdk.AccAddressFromBech32(args[0])
inBuf := bufio.NewReader(cmd.InOrStdin())
if err != nil {
// attempt to lookup address from Keybase if no address was provided
kb, err := keys.NewKeyBaseFromDir(viper.GetString(flagClientHome))
kb, err := keys.NewKeyringFromDir(viper.GetString(flagClientHome), inBuf)
if err != nil {
return err
}
Expand Down
1 change: 1 addition & 0 deletions cmd/gaiad/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ func main() {
config.SetBech32PrefixForAccount(sdk.Bech32PrefixAccAddr, sdk.Bech32PrefixAccPub)
config.SetBech32PrefixForValidator(sdk.Bech32PrefixValAddr, sdk.Bech32PrefixValPub)
config.SetBech32PrefixForConsensusNode(sdk.Bech32PrefixConsAddr, sdk.Bech32PrefixConsPub)
config.SetKeyringServiceName("gaia")
config.Seal()

ctx := server.NewDefaultContext()
Expand Down
27 changes: 6 additions & 21 deletions cmd/gaiad/testnet.go
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,7 @@ func InitTestnet(cmd *cobra.Command, config *tmconfig.Config, cdc *codec.Codec,
genFiles []string
)

inBuf := bufio.NewReader(cmd.InOrStdin())
// generate private keys, node IDs, and initial transactions
for i := 0; i < numValidators; i++ {
nodeDirName := fmt.Sprintf("%s%d", nodeDirPrefix, i)
Expand Down Expand Up @@ -156,24 +157,13 @@ func InitTestnet(cmd *cobra.Command, config *tmconfig.Config, cdc *codec.Codec,
memo := fmt.Sprintf("%s@%s:26656", nodeIDs[i], ip)
genFiles = append(genFiles, config.GenesisFile())

buf := bufio.NewReader(cmd.InOrStdin())
prompt := fmt.Sprintf(
"Password for account '%s' (default %s):", nodeDirName, client.DefaultKeyPass,
)

keyPass, err := client.GetPassword(prompt, buf)
alessio marked this conversation as resolved.
Show resolved Hide resolved
if err != nil && keyPass != "" {
// An error was returned that either failed to read the password from
// STDIN or the given password is not empty but failed to meet minimum
// length requirements.
kb, err := keys.NewKeyringFromDir(clientDir, inBuf)
if err != nil {
return err
}

if keyPass == "" {
keyPass = client.DefaultKeyPass
}

addr, secret, err := server.GenerateSaveCoinKey(clientDir, nodeDirName, keyPass, true)
keyPass := client.DefaultKeyPass
addr, secret, err := server.GenerateSaveCoinKey(kb, nodeDirName, keyPass, true)
if err != nil {
_ = os.RemoveAll(outputDir)
return err
Expand Down Expand Up @@ -209,13 +199,8 @@ func InitTestnet(cmd *cobra.Command, config *tmconfig.Config, cdc *codec.Codec,
sdk.OneInt(),
)

kb, err := keys.NewKeyBaseFromDir(clientDir)
if err != nil {
return err
}

tx := auth.NewStdTx([]sdk.Msg{msg}, auth.StdFee{}, []auth.StdSignature{}, memo)
txBldr := auth.NewTxBuilderFromCLI().WithChainID(chainID).WithMemo(memo).WithKeybase(kb)
txBldr := auth.NewTxBuilderFromCLI(inBuf).WithChainID(chainID).WithMemo(memo).WithKeybase(kb)

signedTx, err := txBldr.SignStdTx(nodeDirName, client.DefaultKeyPass, tx, false)
if err != nil {
Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ go 1.13

require (
github.com/btcsuite/btcd v0.0.0-20190807005414-4063feeff79a // indirect
github.com/cosmos/cosmos-sdk v0.34.4-0.20191031200835-02c6c9fafd58
github.com/cosmos/cosmos-sdk v0.34.4-0.20191106173136-8a0890147cde
github.com/cosmos/go-bip39 v0.0.0-20180819234021-555e2067c45d // indirect
github.com/golang/mock v1.3.1 // indirect
github.com/onsi/ginkgo v1.8.0 // indirect
Expand Down
6 changes: 4 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,8 @@ github.com/coreos/go-etcd v2.0.0+incompatible/go.mod h1:Jez6KQU2B/sWsbdaef3ED8Nz
github.com/coreos/go-semver v0.2.0/go.mod h1:nnelYz7RCh+5ahJtPPxZlU+153eP4D4r3EedlOD2RNk=
github.com/coreos/go-systemd v0.0.0-20190321100706-95778dfbb74e/go.mod h1:F5haX7vjVVG0kc13fIWeqUViNPyEJxv/OmvnBo0Yme4=
github.com/coreos/pkg v0.0.0-20180928190104-399ea9e2e55f/go.mod h1:E3G3o1h8I7cfcXa63jLwjI0eiQQMgzzUDFVpN/nH/eA=
github.com/cosmos/cosmos-sdk v0.34.4-0.20191031200835-02c6c9fafd58 h1:B3fXc6Y9ztj9glE2ANU0+NQJ0M1BXaG5LpnyKFwHW4M=
github.com/cosmos/cosmos-sdk v0.34.4-0.20191031200835-02c6c9fafd58/go.mod h1:PuN72vbZxlorpnHmoIl6RjzVMXEOMejmwORJlZ74K7Q=
github.com/cosmos/cosmos-sdk v0.34.4-0.20191106173136-8a0890147cde h1:Mbu3zK9dgkBQvqjqAAPq7bawxk9q7SMeRwTts/LJRcM=
github.com/cosmos/cosmos-sdk v0.34.4-0.20191106173136-8a0890147cde/go.mod h1:0sLtjU+qex1OfpGQHjWhJByx74IoH78R742PEAdoQJk=
github.com/cosmos/go-bip39 v0.0.0-20180618194314-52158e4697b8/go.mod h1:tSxLoYXyBmiFeKpvmq4dzayMdCjCnu8uqmCysIGBT2Y=
github.com/cosmos/go-bip39 v0.0.0-20180819234021-555e2067c45d h1:49RLWk1j44Xu4fjHb6JFYmeUnDORVwHNkDxaQ0ctCVU=
github.com/cosmos/go-bip39 v0.0.0-20180819234021-555e2067c45d/go.mod h1:tSxLoYXyBmiFeKpvmq4dzayMdCjCnu8uqmCysIGBT2Y=
Expand Down Expand Up @@ -375,5 +375,7 @@ gopkg.in/yaml.v2 v2.2.1/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=
gopkg.in/yaml.v2 v2.2.2/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=
gopkg.in/yaml.v2 v2.2.4 h1:/eiJrUcujPVeJ3xlSWaiNi3uSVmDGBK1pDHUHAnao1I=
gopkg.in/yaml.v2 v2.2.4/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=
gopkg.in/yaml.v2 v2.2.5 h1:ymVxjfMaHvXD8RqPRmzHHsB3VvucivSkIAvJFDI5O3c=
gopkg.in/yaml.v2 v2.2.5/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=
honnef.co/go/tools v0.0.0-20190102054323-c2f93a96b099/go.mod h1:rf3lG4BRIbNafJWhAfAdb/ePZxsR/4RtNHQocxwk9r4=
honnef.co/go/tools v0.0.0-20190523083050-ea95bdfd59fc/go.mod h1:rf3lG4BRIbNafJWhAfAdb/ePZxsR/4RtNHQocxwk9r4=
9 changes: 4 additions & 5 deletions lcd_test/helpers.go
Original file line number Diff line number Diff line change
Expand Up @@ -369,19 +369,19 @@ func init() {

// CreateAddr adds an address to the key store and returns an address and seed.
// It also requires that the key could be created.
func CreateAddr(name, password string, kb crkeys.Keybase) (sdk.AccAddress, string, error) {
func CreateAddr(name string, kb crkeys.Keybase) (sdk.AccAddress, string, error) {
var (
err error
info crkeys.Info
seed string
)
info, seed, err = kb.CreateMnemonic(name, crkeys.English, password, crkeys.Secp256k1)
info, seed, err = kb.CreateMnemonic(name, crkeys.English, client.DefaultKeyPass, crkeys.Secp256k1)
alessio marked this conversation as resolved.
Show resolved Hide resolved
return sdk.AccAddress(info.GetPubKey().Address()), seed, err
}

// CreateAddr adds multiple address to the key store and returns the addresses and associated seeds in lexographical order by address.
// It also requires that the keys could be created.
func CreateAddrs(kb crkeys.Keybase, numAddrs int) (addrs []sdk.AccAddress, seeds, names, passwords []string, errs []error) {
func CreateAddrs(kb crkeys.Keybase, numAddrs int) (addrs []sdk.AccAddress, seeds, names []string, errs []error) {
var (
err error
info crkeys.Info
Expand All @@ -393,7 +393,7 @@ func CreateAddrs(kb crkeys.Keybase, numAddrs int) (addrs []sdk.AccAddress, seeds
for i := 0; i < numAddrs; i++ {
name := fmt.Sprintf("test%d", i)
password := "1234567890"
info, seed, err = kb.CreateMnemonic(name, crkeys.English, password, crkeys.Secp256k1)
info, seed, err = kb.CreateMnemonic(name, crkeys.English, client.DefaultKeyPass, crkeys.Secp256k1)
if err != nil {
errs = append(errs, err)
}
Expand All @@ -409,7 +409,6 @@ func CreateAddrs(kb crkeys.Keybase, numAddrs int) (addrs []sdk.AccAddress, seeds
addrs = append(addrs, addrSeeds[i].Address)
seeds = append(seeds, addrSeeds[i].Seed)
names = append(names, addrSeeds[i].Name)
passwords = append(passwords, addrSeeds[i].Password)
}

return
Expand Down
Loading