Skip to content

Commit

Permalink
fix: ask for a new libp2p password only once (#4489)
Browse files Browse the repository at this point in the history
  • Loading branch information
TobiaszCudnik authored Dec 12, 2023
1 parent 8ee0bc8 commit 5a867fe
Showing 1 changed file with 6 additions and 5 deletions.
11 changes: 6 additions & 5 deletions cmd/bee/cmd/start.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,8 @@ import (
)

const (
serviceName = "SwarmBeeSvc"
serviceName = "SwarmBeeSvc"
libp2pPKFilename = "libp2p_v2"
)

//go:embed bee-welcome-message.txt
Expand Down Expand Up @@ -236,7 +237,7 @@ func buildBeeNode(ctx context.Context, c *command, cmd *cobra.Command, logger lo
// if mainnet is true then we only accept networkID value 1, error otherwise
// if the user has not provided a network ID but mainnet is true - just overwrite with mainnet network ID (1)
// in all the other cases we default to test network ID (10)
var networkID = chaincfg.Testnet.NetworkID
networkID := chaincfg.Testnet.NetworkID

if userHasSetNetworkID {
networkID = c.config.GetUint64(optionNameNetworkID)
Expand Down Expand Up @@ -407,7 +408,7 @@ func (c *command) configureSigner(cmd *cobra.Command, logger log.Logger) (config
// if libp2p key exists we can assume all required keys exist
// so prompt for a password to unlock them
// otherwise prompt for new password with confirmation to create them
exists, err := keystore.Exists("libp2p")
exists, err := keystore.Exists(libp2pPKFilename)
if err != nil {
return nil, err
}
Expand Down Expand Up @@ -471,7 +472,7 @@ func (c *command) configureSigner(cmd *cobra.Command, logger log.Logger) (config

logger.Info("swarm public key", "public_key", hex.EncodeToString(crypto.EncodeSecp256k1PublicKey(publicKey)))

libp2pPrivateKey, created, err := keystore.Key("libp2p_v2", password, crypto.EDGSecp256_R1)
libp2pPrivateKey, created, err := keystore.Key(libp2pPKFilename, password, crypto.EDGSecp256_R1)
if err != nil {
return nil, fmt.Errorf("libp2p v2 key: %w", err)
}
Expand Down Expand Up @@ -515,7 +516,7 @@ type networkConfig struct {
}

func getConfigByNetworkID(networkID uint64, defaultBlockTimeInSeconds uint64) *networkConfig {
var config = networkConfig{
config := networkConfig{
blockTime: time.Duration(defaultBlockTimeInSeconds) * time.Second,
}
switch networkID {
Expand Down

0 comments on commit 5a867fe

Please sign in to comment.