From d4115b9fabe9d1ec7dfdbeb8cc935c1e348a642c Mon Sep 17 00:00:00 2001 From: Viacheslav Gonkivskyi Date: Tue, 7 May 2024 13:43:42 +0300 Subject: [PATCH] renamings --- nodebuilder/config_test.go | 4 ++-- nodebuilder/state/config.go | 4 ++-- nodebuilder/state/flags.go | 12 +++++++----- nodebuilder/state/keyring.go | 7 ++++--- nodebuilder/testing.go | 4 +++- nodebuilder/tests/blob_test.go | 2 -- state/state.go | 4 ++-- 7 files changed, 20 insertions(+), 17 deletions(-) diff --git a/nodebuilder/config_test.go b/nodebuilder/config_test.go index e7b64b0aed..8af6fc88ea 100644 --- a/nodebuilder/config_test.go +++ b/nodebuilder/config_test.go @@ -52,7 +52,7 @@ func TestUpdateConfig(t *testing.T) { // ensure this config field is now set after updating the config require.Equal(t, newCfg.Share.PeerManagerParams, cfg.Share.PeerManagerParams) // ensure old custom values were not changed - require.Equal(t, "thisshouldnthavechanged", cfg.State.KeyringAccName) + require.Equal(t, "thisshouldnthavechanged", cfg.State.KeyringKeyName) require.Equal(t, "7979", cfg.RPC.Port) require.True(t, cfg.Gateway.Enabled) } @@ -65,7 +65,7 @@ var outdatedConfig = ` GRPCPort = "0" [State] - KeyringAccName = "thisshouldnthavechanged" + KeyringKeyName = ["thisshouldnthavechanged"] KeyringBackend = "test" [P2P] diff --git a/nodebuilder/state/config.go b/nodebuilder/state/config.go index 6ff5592aa1..862ac9007f 100644 --- a/nodebuilder/state/config.go +++ b/nodebuilder/state/config.go @@ -11,14 +11,14 @@ var defaultKeyringBackend = keyring.BackendTest // Config contains configuration parameters for constructing // the node's keyring signer. type Config struct { - KeyringAccName []string + KeyringKeyName []string KeyringBackend string GranterAddress state.AccAddress } func DefaultConfig() Config { return Config{ - KeyringAccName: []string{}, + KeyringKeyName: []string{}, KeyringBackend: defaultKeyringBackend, GranterAddress: state.AccAddress{}, } diff --git a/nodebuilder/state/flags.go b/nodebuilder/state/flags.go index aca3984407..a0ed1d1820 100644 --- a/nodebuilder/state/flags.go +++ b/nodebuilder/state/flags.go @@ -9,7 +9,7 @@ import ( ) var ( - keyringAccNameFlag = "keyring.accnames" + keyringKeyNameFlag = "keyring.keyname" keyringBackendFlag = "keyring.backend" granterAddressFlag = "granter.address" @@ -19,8 +19,10 @@ var ( func Flags() *flag.FlagSet { flags := &flag.FlagSet{} - flags.StringSlice(keyringAccNameFlag, []string{}, "Directs node's keyring signer to use the key prefixed with the "+ - "given string.") + flags.StringSlice(keyringKeyNameFlag, []string{}, "Directs node's keyring signer to use the key prefixed with the "+ + "given string. The first key in the list will be the default key that will be used to sign the transactions. "+ + "All other keynames allows user signing transactions with these keys but the correct key"+ + "have to be specified in a transaction.") flags.String(keyringBackendFlag, defaultKeyringBackend, fmt.Sprintf("Directs node's keyring signer to use the given "+ "backend. Default is %s.", defaultKeyringBackend)) @@ -30,11 +32,11 @@ func Flags() *flag.FlagSet { // ParseFlags parses State flags from the given cmd and saves them to the passed config. func ParseFlags(cmd *cobra.Command, cfg *Config) error { - keyringAccName, err := cmd.Flags().GetStringSlice(keyringAccNameFlag) + keyringKeyName, err := cmd.Flags().GetStringSlice(keyringKeyNameFlag) if err != nil { return err } - cfg.KeyringAccName = keyringAccName + cfg.KeyringKeyName = keyringKeyName cfg.KeyringBackend = cmd.Flag(keyringBackendFlag).Value.String() diff --git a/nodebuilder/state/keyring.go b/nodebuilder/state/keyring.go index 48619e702e..8fe5001fb7 100644 --- a/nodebuilder/state/keyring.go +++ b/nodebuilder/state/keyring.go @@ -17,17 +17,18 @@ func Keyring(cfg Config, ks keystore.Keystore) (kr.Keyring, AccountName, error) ring := ks.Keyring() var info *kr.Record - for _, accName := range cfg.KeyringAccName { + // go through all keys in the config and check their availability in the KeyStore. + for _, accName := range cfg.KeyringKeyName { keyInfo, err := ring.Key(accName) if err != nil { - log.Errorw("failed to find key by given name", "keyring.accname", cfg.KeyringAccName) + log.Errorw("keyname does not exist", "keyring.keyname", cfg.KeyringKeyName) return nil, "", err } if info == nil { info = keyInfo } } - + // set the default key in case config does not provide any keys. if info == nil { // use default key keyInfo, err := ring.Key(DefaultAccountName) diff --git a/nodebuilder/testing.go b/nodebuilder/testing.go index dac6cb82ee..3ed83851fb 100644 --- a/nodebuilder/testing.go +++ b/nodebuilder/testing.go @@ -16,6 +16,7 @@ import ( "github.com/celestiaorg/celestia-node/libs/fxutil" "github.com/celestiaorg/celestia-node/nodebuilder/node" "github.com/celestiaorg/celestia-node/nodebuilder/p2p" + "github.com/celestiaorg/celestia-node/nodebuilder/state" ) const ( @@ -58,8 +59,9 @@ func TestNodeWithConfig(t *testing.T, tp node.Type, cfg *Config, opts ...fx.Opti require.NoError(t, err) _, _, err = kr.NewMnemonic(TestKeyringName1, keyring.English, "", "", hd.Secp256k1) require.NoError(t, err) + cfg.State.KeyringKeyName = []string{TestKeyringName, TestKeyringName1} + _, _, _ = state.Keyring(cfg.State, ks) - cfg.State.KeyringAccName = []string{TestKeyringName, TestKeyringName1} opts = append(opts, // temp dir for the eds store FIXME: Should be in mem fx.Replace(node.StorePath(t.TempDir())), diff --git a/nodebuilder/tests/blob_test.go b/nodebuilder/tests/blob_test.go index 60af146f67..f186e41f77 100644 --- a/nodebuilder/tests/blob_test.go +++ b/nodebuilder/tests/blob_test.go @@ -1,5 +1,3 @@ -//go:build blob || integration - package tests import ( diff --git a/state/state.go b/state/state.go index c934448889..67337626b9 100644 --- a/state/state.go +++ b/state/state.go @@ -60,6 +60,6 @@ func (a Address) MarshalJSON() ([]byte, error) { // PayForBlobOptions contains additional options that will be applied to the `MsgPayForBlob`. type PayForBlobOptions struct { // Specifies the key that should be used to sign transactions. - // NOTE: This `AccName` should be available in the `Keystore`. - AccName string + // NOTE: This `KeyName` should be available in the `Keystore`. + KeyName string }