From 33a15352dc1a1e9fd29fd61dc6d5e644d4c64c04 Mon Sep 17 00:00:00 2001 From: ganeshvanahalli Date: Wed, 12 Jul 2023 11:00:23 -0400 Subject: [PATCH 1/2] change default path of nodekey --- node/config.go | 10 ++++++++-- node/config_test.go | 2 +- 2 files changed, 9 insertions(+), 3 deletions(-) diff --git a/node/config.go b/node/config.go index 37a7d5837f..683079b45c 100644 --- a/node/config.go +++ b/node/config.go @@ -375,7 +375,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 } @@ -384,7 +390,7 @@ 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()) + instanceDir := c.DataDir if err := os.MkdirAll(instanceDir, 0700); err != nil { log.Error(fmt.Sprintf("Failed to persist node key: %v", err)) return key diff --git a/node/config_test.go b/node/config_test.go index e8af8ddcd8..a9bb44f221 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() From 3f2543d2600b3609946823a3bd7b02c9766b6561 Mon Sep 17 00:00:00 2001 From: ganeshvanahalli Date: Thu, 10 Aug 2023 14:49:23 -0500 Subject: [PATCH 2/2] remove instanceDir --- node/config.go | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/node/config.go b/node/config.go index b79d92b75e..8bb844594d 100644 --- a/node/config.go +++ b/node/config.go @@ -400,12 +400,11 @@ func (c *Config) NodeKey() *ecdsa.PrivateKey { if err != nil { log.Crit(fmt.Sprintf("Failed to generate node key: %v", err)) } - instanceDir := c.DataDir - 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)) }