diff --git a/cmd/cartesi-rollups-node/main.go b/cmd/cartesi-rollups-node/main.go index a18f5f254..70a9be9cc 100644 --- a/cmd/cartesi-rollups-node/main.go +++ b/cmd/cartesi-rollups-node/main.go @@ -10,12 +10,12 @@ import ( "time" "github.com/cartesi/rollups-node/internal/config" + "github.com/cartesi/rollups-node/internal/node" "github.com/cartesi/rollups-node/internal/services" ) func main() { startTime := time.Now() - var s []services.Service ctx, stop := signal.NotifyContext(context.Background(), syscall.SIGINT, syscall.SIGTERM) defer stop() @@ -23,38 +23,8 @@ func main() { nodeConfig := config.NewNodeConfigFromEnv() nodeConfig.Validate() - config.InitLog(nodeConfig) - - sunodoValidatorEnabled := nodeConfig.CartesiExperimentalSunodoValidatorEnabled() - if !sunodoValidatorEnabled { - // add Redis first - s = append(s, newRedis(nodeConfig)) - } - - // add services without dependencies - s = append(s, newGraphQLServer(nodeConfig)) - s = append(s, newIndexer(nodeConfig)) - s = append(s, newStateServer(nodeConfig)) - - // start either the server manager or host runner - if nodeConfig.CartesiFeatureHostMode() { - s = append(s, newHostRunner(nodeConfig)) - } else { - s = append(s, newServerManager(nodeConfig)) - } - - // enable claimer if reader mode and sunodo validator mode are disabled - if !nodeConfig.CartesiFeatureDisableClaimer() && !sunodoValidatorEnabled { - s = append(s, newAuthorityClaimer(nodeConfig)) - } - - // add services with dependencies - s = append(s, newAdvanceRunner(nodeConfig)) // Depends on the server-manager/host-runner - s = append(s, newDispatcher(nodeConfig)) // Depends on the state server - s = append(s, newInspectServer(nodeConfig)) // Depends on the server-manager/host-runner - - s = append(s, newHttpService(nodeConfig)) + s := node.NewNodeServices(nodeConfig) ready := make(chan struct{}, 1) // logs startup time @@ -68,7 +38,11 @@ func main() { }() // start supervisor - supervisor := newSupervisorService(s) + supervisor := services.SupervisorService{ + Name: "rollups-node", + Services: s, + } + if err := supervisor.Start(ctx, ready); err != nil { config.ErrorLogger.Print(err) } diff --git a/cmd/cartesi-rollups-node/handlers.go b/internal/node/handlers.go similarity index 99% rename from cmd/cartesi-rollups-node/handlers.go rename to internal/node/handlers.go index 94957a71d..b6ced8d62 100644 --- a/cmd/cartesi-rollups-node/handlers.go +++ b/internal/node/handlers.go @@ -1,7 +1,7 @@ // (c) Cartesi and individual authors (see AUTHORS) // SPDX-License-Identifier: Apache-2.0 (see LICENSE) -package main +package node import ( "fmt" diff --git a/cmd/cartesi-rollups-node/services.go b/internal/node/node_services.go similarity index 92% rename from cmd/cartesi-rollups-node/services.go rename to internal/node/node_services.go index 3626c7763..90bfc61fc 100644 --- a/cmd/cartesi-rollups-node/services.go +++ b/internal/node/node_services.go @@ -1,7 +1,7 @@ // (c) Cartesi and individual authors (see AUTHORS) // SPDX-License-Identifier: Apache-2.0 (see LICENSE) -package main +package node import ( "fmt" @@ -387,13 +387,6 @@ func newStateServer(nodeConfig config.NodeConfig) services.CommandService { return s } -func newSupervisorService(s []services.Service) services.SupervisorService { - return services.SupervisorService{ - Name: "rollups-node", - Services: s, - } -} - func newHttpService(nodeConfig config.NodeConfig) services.HttpService { addr := fmt.Sprintf( "%v:%v", @@ -407,3 +400,38 @@ func newHttpService(nodeConfig config.NodeConfig) services.HttpService { Handler: handler, } } + +func NewNodeServices(nodeConfig config.NodeConfig) []services.Service { + var s []services.Service + sunodoValidatorEnabled := nodeConfig.CartesiExperimentalSunodoValidatorEnabled() + if !sunodoValidatorEnabled { + // add Redis first + s = append(s, newRedis(nodeConfig)) + } + + // add services without dependencies + s = append(s, newGraphQLServer(nodeConfig)) + s = append(s, newIndexer(nodeConfig)) + s = append(s, newStateServer(nodeConfig)) + + // start either the server manager or host runner + if nodeConfig.CartesiFeatureHostMode() { + s = append(s, newHostRunner(nodeConfig)) + } else { + s = append(s, newServerManager(nodeConfig)) + } + + // enable claimer if reader mode and sunodo validator mode are disabled + if !nodeConfig.CartesiFeatureDisableClaimer() && !sunodoValidatorEnabled { + s = append(s, newAuthorityClaimer(nodeConfig)) + } + + // add services with dependencies + s = append(s, newAdvanceRunner(nodeConfig)) // Depends on the server-manager/host-runner + s = append(s, newDispatcher(nodeConfig)) // Depends on the state server + s = append(s, newInspectServer(nodeConfig)) // Depends on the server-manager/host-runner + + s = append(s, newHttpService(nodeConfig)) + + return s +}