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

feat: Improve config generation #318

Closed
wants to merge 1 commit into from
Closed
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
28 changes: 20 additions & 8 deletions cmd/cartesi-rollups-node/handlers.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,31 +12,43 @@ 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.CartesiHttpAddress(),
getPort(nodeConfig.CartesiHttpPort(), portOffsetGraphQLServer),
)
if err != nil {
config.ErrorLogger.Fatal(err)
}
handler.Handle("/graphql", graphqlProxy)

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

inspectProxy, err := newReverseProxy(getPort(portOffsetInspectServer))
inspectProxy, err := newReverseProxy(
nodeConfig.CartesiHttpAddress(),
getPort(nodeConfig.CartesiHttpPort(), 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.CartesiHttpAddress(),
getPort(nodeConfig.CartesiHttpPort(), portOffsetHostRunnerRollups),
)
if err != nil {
config.ErrorLogger.Fatal(err)
}
Expand All @@ -50,10 +62,10 @@ func healthcheckHandler(w http.ResponseWriter, r *http.Request) {
w.WriteHeader(http.StatusOK)
}

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

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

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

nodeConfig.Validate()

config.InitLog(nodeConfig)

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
Loading