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

fix: fix redundant priv-validator-key generation when running with kms #1086

Merged
merged 5 commits into from
Aug 24, 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
3 changes: 2 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -47,10 +47,11 @@ Ref: https://keepachangelog.com/en/1.0.0/
* (third_party/proto) [\#1037](https://github.com/Finschia/finschia-sdk/pull/1037) change the proof.proto path to third_party/proto/confio
* (ostracon) [\#1057](https://github.com/Finschia/finschia-sdk/pull/1057) Bump up Ostracon from to v1.1.1
* (x/foundation) [\#1072](https://github.com/Finschia/finschia-sdk/pull/1072) Address generation of the empty coins in x/foundation (backport #952)
* (cli) [\#1086](https://github.com/Finschia/finschia-sdk/pull/1086) Fix for redundant key generation. With running kms, generating priv-key is unnecessary.
* (ostracon) [\#1089](https://github.com/Finschia/finschia-sdk/pull/1089) Bump up ostracon from v1.1.1 to v1.1.1-449aa3148b12

### Bug Fixes
* (ledger) [\#1040](https://github.com/Finschia/finschia-sdk/pull/1040) fix a bug(unable to connect nano S plus ledger on ubuntu)
* (ledger) [\#1040](https://github.com/Finschia/finschia-sdk/pull/1040) Fix a bug(unable to connect nano S plus ledger on ubuntu)
* (x/foundation) [\#1053](https://github.com/Finschia/finschia-sdk/pull/1053) Make x/foundation MsgExec propagate events
* (baseapp) [\#1091](https://github.com/cosmos/cosmos-sdk/pull/1091) Add `events.GetAttributes` and `event.GetAttribute` methods to simplify the retrieval of an attribute from event(s) (backport #1075)

Expand Down
11 changes: 10 additions & 1 deletion server/start.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,15 @@ import (
"net/http"
"os"
"runtime/pprof"
"strings"
"time"

"github.com/spf13/cobra"
"google.golang.org/grpc"

"github.com/Finschia/ostracon/abci/server"
ostcmd "github.com/Finschia/ostracon/cmd/ostracon/commands"
"github.com/Finschia/ostracon/config"
ostos "github.com/Finschia/ostracon/libs/os"
"github.com/Finschia/ostracon/node"
"github.com/Finschia/ostracon/p2p"
Expand Down Expand Up @@ -304,7 +306,7 @@ func startInProcess(ctx *Context, clientCtx client.Context, appCreator types.App
} else {
ctx.Logger.Info("starting node with ABCI Ostracon in-process")

pv := pvm.LoadOrGenFilePV(cfg.PrivValidatorKeyFile(), cfg.PrivValidatorStateFile())
pv := genPvFileOnlyWhenKmsAddressEmpty(cfg)

ocNode, err = node.NewNode(
cfg,
Expand Down Expand Up @@ -471,6 +473,13 @@ func startInProcess(ctx *Context, clientCtx client.Context, appCreator types.App
return WaitForQuitSignals()
}

func genPvFileOnlyWhenKmsAddressEmpty(cfg *config.Config) *pvm.FilePV {
if len(strings.TrimSpace(cfg.PrivValidatorListenAddr)) == 0 {
return pvm.LoadOrGenFilePV(cfg.PrivValidatorKeyFile(), cfg.PrivValidatorStateFile())
}
return nil
}

func startTelemetry(cfg serverconfig.Config) (*telemetry.Metrics, error) {
if !cfg.Telemetry.Enabled {
return nil, nil
Expand Down
32 changes: 32 additions & 0 deletions server/start_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
package server

import (
"github.com/Finschia/ostracon/config"
"github.com/stretchr/testify/assert"
"os"
"testing"
)

func TestGenPvFileOnlyWhenKmsAddressEmptyGenerateFiles(t *testing.T) {
cfg := config.DefaultConfig()
dir, err := os.MkdirTemp("", "start_test")
if err != nil {
t.Fatal(err.Error())
}
defer os.RemoveAll(dir)
cfg.PrivValidatorKey = dir + "/key.json"
cfg.PrivValidatorState = dir + "/state.json"

pv := genPvFileOnlyWhenKmsAddressEmpty(cfg)

assert.NotNil(t, pv)
}

func TestGenPvFileOnlyWhenKmsAddressEmptyShouldNotGenerateFiles(t *testing.T) {
cfg := config.DefaultConfig()
cfg.PrivValidatorListenAddr = "tcp://0.0.0.0:26659"

pv := genPvFileOnlyWhenKmsAddressEmpty(cfg)

assert.Nil(t, pv)
}