Skip to content

Commit

Permalink
Remove support for composite (BLS) key type (#817)
Browse files Browse the repository at this point in the history
* remove support for composite (BLS) type from priv_key_type option of init CLI command

Note that this removal is limited to the LBM layer and composite keys in Ostracon can still be used.

* fixed to be error when unsupported key types are specified.
* fixed duplicated default values in help messages.
* added test case: ed25519 → success, composite → failure, lamport → failure

* add test case

* add changelog
* add uncovered test case
* correct import sequence

* remove unused field
  • Loading branch information
torao committed Dec 12, 2022
1 parent 00a66cf commit 22edb12
Show file tree
Hide file tree
Showing 6 changed files with 79 additions and 6 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ Ref: https://keepachangelog.com/en/1.0.0/
* (cosmovisor) [\#792](https://github.com/line/lbm-sdk/pull/792) Use upstream's cosmovisor

### Bug Fixes
* (client) [\#817](https://github.com/line/lbm-sdk/pull/817) remove support for composite (BLS) type

### Breaking Changes
* (rest) [\#807](https://github.com/line/lbm-sdk/pull/807) remove legacy REST API
Expand Down
4 changes: 2 additions & 2 deletions client/flags/flags.go
Original file line number Diff line number Diff line change
Expand Up @@ -117,8 +117,8 @@ func AddTxFlagsToCmd(cmd *cobra.Command) {
cmd.Flags().String(FlagKeyringBackend, DefaultKeyringBackend, "Select keyring's backend (os|file|kwallet|pass|test|memory)")
cmd.Flags().String(FlagSignMode, "", "Choose sign mode (direct|amino-json), this is an advanced feature")
cmd.Flags().Uint64(FlagTimeoutHeight, 0, "Set a block timeout height to prevent the tx from being committed past a certain height")
cmd.Flags().String(FlagPrivKeyType, DefaultPrivKeyType, "specify validator's private key type (ed25519|composite). \n"+
"set this to priv_key.type in priv_validator_key.json; default `ed25519`")
cmd.Flags().String(FlagPrivKeyType, DefaultPrivKeyType, "specify validator's private key type (currently only ed25519 is supported).\n"+
"This option affects the priv_key.type setting in priv_validator_key.json")
cmd.Flags().String(FlagFeeAccount, "", "Fee account pays fees for the transaction instead of deducting from the signer")

// --gas can accept integers and "auto"
Expand Down
12 changes: 12 additions & 0 deletions client/flags/flags_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package flags_test
import (
"testing"

"github.com/spf13/cobra"
"github.com/stretchr/testify/require"

"github.com/line/lbm-sdk/client/flags"
Expand Down Expand Up @@ -36,3 +37,14 @@ func TestParseGasSetting(t *testing.T) {
})
}
}

func TestAddFlagsToCmd(t *testing.T) {
cmd := cobra.Command{}
flags.AddQueryFlagsToCmd(&cmd)

cmd = cobra.Command{}
flags.AddTxFlagsToCmd(&cmd)

cmd = cobra.Command{}
flags.AddPaginationFlagsToCmd(&cmd, "")
}
4 changes: 2 additions & 2 deletions x/genutil/client/cli/collect.go
Original file line number Diff line number Diff line change
Expand Up @@ -65,8 +65,8 @@ func CollectGenTxsCmd(genBalIterator types.GenesisBalancesIterator, defaultNodeH

cmd.Flags().String(flags.FlagHome, defaultNodeHome, "The application home directory")
cmd.Flags().String(flagGenTxDir, "", "override default \"gentx\" directory from which collect and execute genesis transactions; default [--home]/config/gentx/")
cmd.Flags().String(flags.FlagPrivKeyType, flags.DefaultPrivKeyType, "specify validator's private key type (ed25519|composite). \n"+
"set this to priv_key.type in priv_validator_key.json; default `ed25519`")
cmd.Flags().String(flags.FlagPrivKeyType, flags.DefaultPrivKeyType, "specify validator's private key type (currently only ed25519 is supported).\n"+
"This option affects the priv_key.type setting in priv_validator_key.json")

return cmd
}
10 changes: 8 additions & 2 deletions x/genutil/client/cli/init.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,14 @@ import (
"fmt"
"os"
"path/filepath"
"strings"

"github.com/cosmos/go-bip39"
cfg "github.com/line/ostracon/config"
"github.com/line/ostracon/libs/cli"
ostos "github.com/line/ostracon/libs/os"
ostrand "github.com/line/ostracon/libs/rand"
"github.com/line/ostracon/privval"
"github.com/line/ostracon/types"
"github.com/pkg/errors"
"github.com/spf13/cobra"
Expand Down Expand Up @@ -99,6 +101,10 @@ func InitCmd(mbm module.BasicManager, defaultNodeHome string) *cobra.Command {
}
}

if strings.ToLower(config.PrivKeyType) != privval.PrivKeyTypeEd25519 {
return fmt.Errorf("unsupported %s: \"%s\"", flags.FlagPrivKeyType, config.PrivKeyType)
}

nodeID, _, err := genutil.InitializeNodeValidatorFilesFromMnemonic(config, mnemonic)
if err != nil {
return err
Expand Down Expand Up @@ -149,8 +155,8 @@ func InitCmd(mbm module.BasicManager, defaultNodeHome string) *cobra.Command {
cmd.Flags().BoolP(FlagOverwrite, "o", false, "overwrite the genesis.json file")
cmd.Flags().Bool(FlagRecover, false, "provide seed phrase to recover existing key instead of creating")
cmd.Flags().String(flags.FlagChainID, "", "genesis file chain-id, if left blank will be randomly created")
cmd.Flags().String(flags.FlagPrivKeyType, flags.DefaultPrivKeyType, "specify validator's private key type (ed25519|composite). \n"+
"set this to priv_key.type in priv_validator_key.json; default `ed25519`")
cmd.Flags().String(flags.FlagPrivKeyType, flags.DefaultPrivKeyType, "specify validator's private key type (currently only ed25519 is supported).\n"+
"This option affects the priv_key.type setting in priv_validator_key.json")

return cmd
}
54 changes: 54 additions & 0 deletions x/genutil/client/cli/init_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,60 @@ func TestInitCmd(t *testing.T) {
}
}

func TestPrivKeyTypeSupports(t *testing.T) {
tests := []struct {
privKeyType string
shouldErr bool
}{
{
privKeyType: "Ed25519",
shouldErr: false,
},
{
privKeyType: "Composite",
shouldErr: true,
},
{
privKeyType: "Lamport",
shouldErr: true,
},
}

for _, tt := range tests {
tt := tt
t.Run(tt.privKeyType, func(t *testing.T) {
home := t.TempDir()
logger := log.NewNopLogger()
cfg, err := genutiltest.CreateDefaultTendermintConfig(home)
require.NoError(t, err)
cfg.PrivKeyType = tt.privKeyType

serverCtx := server.NewContext(viper.New(), cfg, logger)
interfaceRegistry := types.NewInterfaceRegistry()
marshaler := codec.NewProtoCodec(interfaceRegistry)
clientCtx := client.Context{}.
WithCodec(marshaler).
WithLegacyAmino(makeCodec()).
WithHomeDir(home)

ctx := context.Background()
ctx = context.WithValue(ctx, client.ClientContextKey, &clientCtx)
ctx = context.WithValue(ctx, server.ServerContextKey, serverCtx)

cmd := genutilcli.InitCmd(testMbm, home)
cmd.SetArgs([]string{"alice"})

if tt.shouldErr {
err := cmd.ExecuteContext(ctx)
require.EqualError(t, err, fmt.Sprintf("unsupported priv_key_type: \"%s\"", tt.privKeyType))
} else {
require.NoError(t, cmd.ExecuteContext(ctx))
}
})
}

}

func TestInitRecover(t *testing.T) {
home := t.TempDir()
logger := log.NewNopLogger()
Expand Down

0 comments on commit 22edb12

Please sign in to comment.