Skip to content

Commit

Permalink
renamings
Browse files Browse the repository at this point in the history
  • Loading branch information
vgonkivs committed May 7, 2024
1 parent f9586b5 commit d4115b9
Show file tree
Hide file tree
Showing 7 changed files with 20 additions and 17 deletions.
4 changes: 2 additions & 2 deletions nodebuilder/config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
Expand All @@ -65,7 +65,7 @@ var outdatedConfig = `
GRPCPort = "0"
[State]
KeyringAccName = "thisshouldnthavechanged"
KeyringKeyName = ["thisshouldnthavechanged"]
KeyringBackend = "test"
[P2P]
Expand Down
4 changes: 2 additions & 2 deletions nodebuilder/state/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -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{},
}
Expand Down
12 changes: 7 additions & 5 deletions nodebuilder/state/flags.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import (
)

var (
keyringAccNameFlag = "keyring.accnames"
keyringKeyNameFlag = "keyring.keyname"
keyringBackendFlag = "keyring.backend"

granterAddressFlag = "granter.address"
Expand All @@ -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))

Expand All @@ -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()

Expand Down
7 changes: 4 additions & 3 deletions nodebuilder/state/keyring.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
4 changes: 3 additions & 1 deletion nodebuilder/testing.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 (
Expand Down Expand Up @@ -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())),
Expand Down
2 changes: 0 additions & 2 deletions nodebuilder/tests/blob_test.go
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
//go:build blob || integration

package tests

import (
Expand Down
4 changes: 2 additions & 2 deletions state/state.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}

0 comments on commit d4115b9

Please sign in to comment.