Skip to content

Commit

Permalink
feat: Improve config generation
Browse files Browse the repository at this point in the history
  • Loading branch information
fmoura committed Feb 15, 2024
1 parent 4c74729 commit cbab2d2
Show file tree
Hide file tree
Showing 8 changed files with 522 additions and 292 deletions.
17 changes: 9 additions & 8 deletions cmd/cartesi-rollups-node/handlers.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,31 +12,32 @@ import (
"github.com/cartesi/rollups-node/internal/config"
)

func newHttpServiceHandler() http.Handler {
func newHttpServiceHandler(nodeConfig config.NodeConfig) http.Handler {
handler := http.NewServeMux()
handler.Handle("/healthz", http.HandlerFunc(healthcheckHandler))

graphqlProxy, err := newReverseProxy(getPort(portOffsetGraphQLServer))
graphqlProxy, err := newReverseProxy(nodeConfig, getPort(nodeConfig, portOffsetGraphQLServer))
if err != nil {
config.ErrorLogger.Fatal(err)
}
handler.Handle("/graphql", graphqlProxy)

dispatcherProxy, err := newReverseProxy(getPort(portOffsetDispatcher))
dispatcherProxy, err := newReverseProxy(nodeConfig, getPort(nodeConfig, portOffsetDispatcher))
if err != nil {
config.ErrorLogger.Fatal(err)
}
handler.Handle("/metrics", dispatcherProxy)

inspectProxy, err := newReverseProxy(getPort(portOffsetInspectServer))
inspectProxy, err := newReverseProxy(nodeConfig, getPort(nodeConfig, portOffsetInspectServer))
if err != nil {
config.ErrorLogger.Fatal(err)
}
handler.Handle("/inspect", inspectProxy)
handler.Handle("/inspect/", inspectProxy)

if config.GetCartesiFeatureHostMode() {
hostProxy, err := newReverseProxy(getPort(portOffsetHostRunnerRollups))
if nodeConfig.CartesiFeatureHostMode {
hostProxy, err := newReverseProxy(nodeConfig,
getPort(nodeConfig, portOffsetHostRunnerRollups))
if err != nil {
config.ErrorLogger.Fatal(err)
}
Expand All @@ -50,10 +51,10 @@ func healthcheckHandler(w http.ResponseWriter, r *http.Request) {
w.WriteHeader(http.StatusOK)
}

func newReverseProxy(port int) (*httputil.ReverseProxy, error) {
func newReverseProxy(nodeConfig config.NodeConfig, port int) (*httputil.ReverseProxy, error) {
urlStr := fmt.Sprintf(
"http://%v:%v/",
config.GetCartesiHttpAddress(),
nodeConfig.CartesiHttpAddress,
port,
)

Expand Down
30 changes: 16 additions & 14 deletions cmd/cartesi-rollups-node/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,35 +20,37 @@ func main() {
ctx, stop := signal.NotifyContext(context.Background(), syscall.SIGINT, syscall.SIGTERM)
defer stop()

sunodoValidatorEnabled := config.GetCartesiExperimentalSunodoValidatorEnabled()
nodeConfig := config.NewNodeConfigFromEnv()

sunodoValidatorEnabled := nodeConfig.CartesiExperimentalSunodoValidatorEnabled
if !sunodoValidatorEnabled {
// add Redis first
s = append(s, newRedis())
s = append(s, newRedis(nodeConfig))
}

// add services without dependencies
s = append(s, newGraphQLServer())
s = append(s, newIndexer())
s = append(s, newStateServer())
s = append(s, newGraphQLServer(nodeConfig))
s = append(s, newIndexer(nodeConfig))
s = append(s, newStateServer(nodeConfig))

// start either the server manager or host runner
if config.GetCartesiFeatureHostMode() {
s = append(s, newHostRunner())
if nodeConfig.CartesiFeatureHostMode {
s = append(s, newHostRunner(nodeConfig))
} else {
s = append(s, newServerManager())
s = append(s, newServerManager(nodeConfig))
}

// enable claimer if reader mode and sunodo validator mode are disabled
if !config.GetCartesiFeatureDisableClaimer() && !sunodoValidatorEnabled {
s = append(s, newAuthorityClaimer())
if !nodeConfig.CartesiFeatureDisableClaimer && !sunodoValidatorEnabled {
s = append(s, newAuthorityClaimer(nodeConfig))
}

// add services with dependencies
s = append(s, newAdvanceRunner()) // Depends on the server-manager/host-runner
s = append(s, newDispatcher()) // Depends on the state server
s = append(s, newInspectServer()) // Depends on the server-manager/host-runner
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())
s = append(s, newHttpService(nodeConfig))

ready := make(chan struct{}, 1)
// logs startup time
Expand Down
Loading

0 comments on commit cbab2d2

Please sign in to comment.