Skip to content

Commit

Permalink
chore(dot/node): remove IsNodeInitialized method from nodeBuilder (
Browse files Browse the repository at this point in the history
  • Loading branch information
EclesioMeloJunior authored Apr 2, 2024
1 parent a4e1f12 commit c040366
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 37 deletions.
15 changes: 0 additions & 15 deletions dot/mock_node_builder_test.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

36 changes: 15 additions & 21 deletions dot/node.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,6 @@ type Node struct {
}

type nodeBuilderIface interface {
isNodeInitialised(basepath string) (bool, error)
initNode(config *cfg.Config) error
createStateService(config *cfg.Config) (*state.Service, error)
createNetworkService(config *cfg.Config, stateSrvc *state.Service, telemetryMailer Telemetry) (*network.Service,
Expand Down Expand Up @@ -79,13 +78,6 @@ type nodeBuilder struct{}
// IsNodeInitialised returns true if, within the configured data directory for the
// node, the state database has been created and the genesis data can been loaded
func IsNodeInitialised(basepath string) (bool, error) {
nodeInstance := nodeBuilder{}
return nodeInstance.isNodeInitialised(basepath)
}

// isNodeInitialised returns nil if the node is successfully initialised
// and an error otherwise.
func (nodeBuilder) isNodeInitialised(basepath string) (bool, error) {
// check if key registry exists
nodeDatabaseDir := filepath.Join(basepath, database.DefaultDatabaseDir)

Expand Down Expand Up @@ -239,7 +231,21 @@ func LoadGlobalNodeName(basepath string) (nodename string, err error) {
// NewNode creates a node based on the given Config and key store.
func NewNode(config *cfg.Config, ks *keystore.GlobalKeystore) (*Node, error) {
serviceRegistryLogger := logger.New(log.AddContext("pkg", "services"))
return newNode(config, ks, &nodeBuilder{}, services.NewServiceRegistry(serviceRegistryLogger))

isInitialised, err := IsNodeInitialised(config.BasePath)
if err != nil {
return nil, fmt.Errorf("checking if node is initialised: %w", err)
}

builder := &nodeBuilder{}
if !isInitialised {
err := builder.initNode(config)
if err != nil {
return nil, fmt.Errorf("cannot initialise node: %w", err)
}
}

return newNode(config, ks, builder, services.NewServiceRegistry(serviceRegistryLogger))
}

func newNode(config *cfg.Config,
Expand All @@ -253,18 +259,6 @@ func newNode(config *cfg.Config,
debug.SetGCPercent(prev)
}

isInitialised, err := builder.isNodeInitialised(config.BasePath)
if err != nil {
return nil, fmt.Errorf("checking if node is initialised: %w", err)
}

if !isInitialised {
err := builder.initNode(config)
if err != nil {
return nil, fmt.Errorf("cannot initialise node: %w", err)
}
}

globalLogLevel, err := log.ParseLevel(config.LogLevel)
if err != nil {
return nil, fmt.Errorf("cannot parse global log level: %w", err)
Expand Down
1 change: 0 additions & 1 deletion dot/node_integration_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,6 @@ func TestNewNode(t *testing.T) {
mockServiceRegistry.EXPECT().RegisterService(gomock.Any()).Times(8)

m := NewMocknodeBuilderIface(ctrl)
m.EXPECT().isNodeInitialised(initConfig.BasePath).Return(true, nil)
m.EXPECT().createStateService(initConfig).DoAndReturn(func(config *cfg.Config) (*state.Service, error) {
stateSrvc := state.NewService(stateConfig)
// create genesis from configuration file
Expand Down

0 comments on commit c040366

Please sign in to comment.