Skip to content

Commit 2971325

Browse files
authored
fix(dot): no error logged for init check (#2502)
- Rename `NodeInitialized` to `IsNodeInitialised` - Rename `nodeInitialised` to `isNodeInitialised` - Do not log `IsNodeInitialised` error
1 parent 51c5983 commit 2971325

File tree

6 files changed

+31
-34
lines changed

6 files changed

+31
-34
lines changed

cmd/gossamer/config.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -519,7 +519,7 @@ func setDotGlobalConfigFromFlags(ctx *cli.Context, cfg *dot.GlobalConfig) error
519519

520520
func setDotGlobalConfigName(ctx *cli.Context, tomlCfg *ctoml.Config, cfg *dot.GlobalConfig) error {
521521
globalBasePath := utils.ExpandDir(cfg.BasePath)
522-
initialised := dot.NodeInitialized(globalBasePath)
522+
initialised := dot.IsNodeInitialised(globalBasePath)
523523

524524
// consider the --name flag as higher priority
525525
if ctx.GlobalString(NameFlag.Name) != "" {

cmd/gossamer/main.go

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -226,7 +226,7 @@ func gossamerAction(ctx *cli.Context) error {
226226
// from createDotConfig because dot config should not include expanded path)
227227
cfg.Global.BasePath = utils.ExpandDir(cfg.Global.BasePath)
228228

229-
if !dot.NodeInitialized(cfg.Global.BasePath) {
229+
if !dot.IsNodeInitialised(cfg.Global.BasePath) {
230230
// initialise node (initialise state database and load genesis data)
231231
err = dot.InitNode(cfg)
232232
if err != nil {
@@ -320,8 +320,7 @@ func initAction(ctx *cli.Context) error {
320320
// from createDotConfig because dot config should not include expanded path)
321321
cfg.Global.BasePath = utils.ExpandDir(cfg.Global.BasePath)
322322
// check if node has been initialised (expected false - no warning log)
323-
if dot.NodeInitialized(cfg.Global.BasePath) {
324-
323+
if dot.IsNodeInitialised(cfg.Global.BasePath) {
325324
// use --force value to force initialise the node
326325
force := ctx.Bool(ForceFlag.Name)
327326

dot/mock_node_builder_test.go

Lines changed: 14 additions & 14 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dot/node.go

Lines changed: 10 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ type Node struct {
5050
//go:generate mockgen -source=node.go -destination=mock_node_builder_test.go -package=$GOPACKAGE
5151

5252
type nodeBuilderIface interface {
53-
nodeInitialised(string) error
53+
isNodeInitialised(basepath string) error
5454
initNode(config *Config) error
5555
createStateService(config *Config) (*state.Service, error)
5656
createNetworkService(cfg *Config, stateSrvc *state.Service, telemetryMailer telemetry.Client) (*network.Service,
@@ -76,19 +76,17 @@ var _ nodeBuilderIface = (*nodeBuilder)(nil)
7676

7777
type nodeBuilder struct{}
7878

79-
// NodeInitialized returns true if, within the configured data directory for the
80-
// node, the state database has been created and the genesis data has been loaded
81-
func NodeInitialized(basepath string) bool {
79+
// IsNodeInitialised returns true if, within the configured data directory for the
80+
// node, the state database has been created and the genesis data can been loaded
81+
func IsNodeInitialised(basepath string) bool {
8282
nodeInstance := nodeBuilder{}
83-
err := nodeInstance.nodeInitialised(basepath)
84-
if err != nil {
85-
logger.Errorf("failed to initialise node from base path %s: %s", basepath, err)
86-
return false
87-
}
88-
return true
83+
err := nodeInstance.isNodeInitialised(basepath)
84+
return err == nil
8985
}
9086

91-
func (*nodeBuilder) nodeInitialised(basepath string) error {
87+
// isNodeInitialised returns nil if the node is successfully initialised
88+
// and an error otherwise.
89+
func (*nodeBuilder) isNodeInitialised(basepath string) error {
9290
// check if key registry exists
9391
registry := filepath.Join(basepath, utils.DefaultDatabaseDir, "KEYREGISTRY")
9492

@@ -235,7 +233,7 @@ func newNode(cfg *Config,
235233
debug.SetGCPercent(prev)
236234
}
237235

238-
if builder.nodeInitialised(cfg.Global.BasePath) != nil {
236+
if builder.isNodeInitialised(cfg.Global.BasePath) != nil {
239237
err := builder.initNode(cfg)
240238
if err != nil {
241239
return nil, fmt.Errorf("cannot initialise node: %w", err)

dot/node_integration_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -68,13 +68,13 @@ func TestNodeInitializedIntegration(t *testing.T) {
6868

6969
cfg.Init.Genesis = genFile
7070

71-
result := NodeInitialized(cfg.Global.BasePath)
71+
result := IsNodeInitialised(cfg.Global.BasePath)
7272
require.False(t, result)
7373

7474
err := InitNode(cfg)
7575
require.NoError(t, err)
7676

77-
result = NodeInitialized(cfg.Global.BasePath)
77+
result = IsNodeInitialised(cfg.Global.BasePath)
7878
require.True(t, result)
7979
}
8080

dot/node_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -154,7 +154,7 @@ func TestNewNode(t *testing.T) {
154154
mockServiceRegistry.EXPECT().RegisterService(gomock.Any()).Times(8)
155155

156156
m := NewMocknodeBuilderIface(ctrl)
157-
m.EXPECT().nodeInitialised(dotConfig.Global.BasePath).Return(nil)
157+
m.EXPECT().isNodeInitialised(dotConfig.Global.BasePath).Return(nil)
158158
m.EXPECT().createStateService(dotConfig).DoAndReturn(func(cfg *Config) (*state.Service, error) {
159159
stateSrvc := state.NewService(config)
160160
// create genesis from configuration file
@@ -285,7 +285,7 @@ func TestNodeInitialized(t *testing.T) {
285285
}
286286
for _, tt := range tests {
287287
t.Run(tt.name, func(t *testing.T) {
288-
got := NodeInitialized(tt.basepath)
288+
got := IsNodeInitialised(tt.basepath)
289289
assert.Equal(t, tt.want, got)
290290
})
291291
}

0 commit comments

Comments
 (0)