Skip to content

Commit

Permalink
Merge branch 'master' into merge-v1.12.0
Browse files Browse the repository at this point in the history
  • Loading branch information
Tristan-Wilson authored Aug 11, 2023
2 parents 0685207 + b1fff89 commit 66163ca
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 5 deletions.
13 changes: 9 additions & 4 deletions node/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand All @@ -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))
}
Expand Down
2 changes: 1 addition & 1 deletion node/config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down

0 comments on commit 66163ca

Please sign in to comment.