/
main.go
69 lines (56 loc) · 1.75 KB
/
main.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
// (c) Cartesi and individual authors (see AUTHORS)
// SPDX-License-Identifier: Apache-2.0 (see LICENSE)
package main
import (
"context"
"os/signal"
"syscall"
"time"
"github.com/cartesi/rollups-node/internal/config"
"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()
sunodoValidatorEnabled := config.GetCartesiExperimentalSunodoValidatorEnabled()
if !sunodoValidatorEnabled {
// add Redis first
s = append(s, newRedis())
}
// add services without dependencies
s = append(s, newGraphQLServer())
s = append(s, newIndexer())
s = append(s, newStateServer())
// start either the server manager or host runner
if config.GetCartesiFeatureHostMode() {
s = append(s, newHostRunner())
} else {
s = append(s, newServerManager())
}
// enable claimer if reader mode and sunodo validator mode are disabled
if !config.GetCartesiFeatureDisableClaimer() && !sunodoValidatorEnabled {
s = append(s, newAuthorityClaimer())
}
// 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, newHttpService())
ready := make(chan struct{}, 1)
// logs startup time
go func() {
select {
case <-ready:
duration := time.Since(startTime)
config.InfoLogger.Printf("rollups-node: ready after %s", duration)
case <-ctx.Done():
}
}()
// start supervisor
supervisor := newSupervisorService(s)
if err := supervisor.Start(ctx, ready); err != nil {
config.ErrorLogger.Print(err)
}
}