diff --git a/node/config.go b/node/config.go index deac0a86a7a5..8bb844594deb 100644 --- a/node/config.go +++ b/node/config.go @@ -385,7 +385,13 @@ func (c *Config) NodeKey() *ecdsa.PrivateKey { return key } - keyfile := c.ResolvePath(datadirPrivateKey) + // Updating default path to nodekey to be $Chain/nodekey + var keyfile string + if filepath.IsAbs(datadirPrivateKey) { + keyfile = datadirPrivateKey + } else { + keyfile = filepath.Join(c.DataDir, datadirPrivateKey) + } if key, err := crypto.LoadECDSA(keyfile); err == nil { return key } @@ -394,12 +400,11 @@ func (c *Config) NodeKey() *ecdsa.PrivateKey { if err != nil { log.Crit(fmt.Sprintf("Failed to generate node key: %v", err)) } - instanceDir := filepath.Join(c.DataDir, c.name()) - if err := os.MkdirAll(instanceDir, 0700); err != nil { + if err := os.MkdirAll(c.DataDir, 0700); err != nil { log.Error(fmt.Sprintf("Failed to persist node key: %v", err)) return key } - keyfile = filepath.Join(instanceDir, datadirPrivateKey) + keyfile = filepath.Join(c.DataDir, datadirPrivateKey) if err := crypto.SaveECDSA(keyfile, key); err != nil { log.Error(fmt.Sprintf("Failed to persist node key: %v", err)) } diff --git a/node/config_test.go b/node/config_test.go index e8af8ddcd87b..a9bb44f221ac 100644 --- a/node/config_test.go +++ b/node/config_test.go @@ -106,7 +106,7 @@ func TestNodeKeyPersistency(t *testing.T) { // Create a temporary folder and make sure no key is present dir := t.TempDir() - keyfile := filepath.Join(dir, "unit-test", datadirPrivateKey) + keyfile := filepath.Join(dir, datadirPrivateKey) // Configure a node with a preset key and ensure it's not persisted key, err := crypto.GenerateKey()