Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Default path of nodekey is updated to be outside the nitro directory #241

Merged
merged 4 commits into from
Aug 11, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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) {
ganeshvanahalli marked this conversation as resolved.
Show resolved Hide resolved
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