|
18 | 18 | ../../waku/common/logging,
|
19 | 19 | ../../waku/factory/external_config,
|
20 | 20 | ../../waku/factory/networks_config,
|
21 |
| - ../../waku/factory/app |
| 21 | + ../../waku/factory/app, |
| 22 | + ../../waku/node/health_monitor |
22 | 23 |
|
23 | 24 | logScope:
|
24 | 25 | topics = "wakunode main"
|
@@ -88,54 +89,74 @@ when isMainModule:
|
88 | 89 | doInspectRlnDb(conf)
|
89 | 90 | of noCommand:
|
90 | 91 | case conf.clusterId
|
91 |
| - # cluster-id=0 |
92 |
| - of 0: |
93 |
| - let clusterZeroConf = ClusterConf.ClusterZeroConf() |
94 |
| - conf.pubsubTopics = clusterZeroConf.pubsubTopics |
95 |
| - # TODO: Write some template to "merge" the configs |
96 |
| - # cluster-id=1 (aka The Waku Network) |
97 |
| - of 1: |
98 |
| - let twnClusterConf = ClusterConf.TheWakuNetworkConf() |
99 |
| - if len(conf.shards) != 0: |
100 |
| - conf.pubsubTopics = conf.shards.mapIt(twnClusterConf.pubsubTopics[it.uint16]) |
101 |
| - else: |
102 |
| - conf.pubsubTopics = twnClusterConf.pubsubTopics |
103 |
| - |
104 |
| - # Override configuration |
105 |
| - conf.maxMessageSize = twnClusterConf.maxMessageSize |
106 |
| - conf.clusterId = twnClusterConf.clusterId |
107 |
| - conf.rlnRelay = twnClusterConf.rlnRelay |
108 |
| - conf.rlnRelayEthContractAddress = twnClusterConf.rlnRelayEthContractAddress |
109 |
| - conf.rlnRelayDynamic = twnClusterConf.rlnRelayDynamic |
110 |
| - conf.rlnRelayBandwidthThreshold = twnClusterConf.rlnRelayBandwidthThreshold |
111 |
| - conf.discv5Discovery = twnClusterConf.discv5Discovery |
112 |
| - conf.discv5BootstrapNodes = |
113 |
| - conf.discv5BootstrapNodes & twnClusterConf.discv5BootstrapNodes |
114 |
| - conf.rlnEpochSizeSec = twnClusterConf.rlnEpochSizeSec |
115 |
| - conf.rlnRelayUserMessageLimit = twnClusterConf.rlnRelayUserMessageLimit |
| 92 | + # cluster-id=0 |
| 93 | + of 0: |
| 94 | + let clusterZeroConf = ClusterConf.ClusterZeroConf() |
| 95 | + conf.pubsubTopics = clusterZeroConf.pubsubTopics |
| 96 | + # TODO: Write some template to "merge" the configs |
| 97 | + # cluster-id=1 (aka The Waku Network) |
| 98 | + of 1: |
| 99 | + let twnClusterConf = ClusterConf.TheWakuNetworkConf() |
| 100 | + if len(conf.shards) != 0: |
| 101 | + conf.pubsubTopics = conf.shards.mapIt(twnClusterConf.pubsubTopics[it.uint16]) |
116 | 102 | else:
|
117 |
| - discard |
| 103 | + conf.pubsubTopics = twnClusterConf.pubsubTopics |
| 104 | + |
| 105 | + # Override configuration |
| 106 | + conf.maxMessageSize = twnClusterConf.maxMessageSize |
| 107 | + conf.clusterId = twnClusterConf.clusterId |
| 108 | + conf.rlnRelay = twnClusterConf.rlnRelay |
| 109 | + conf.rlnRelayEthContractAddress = twnClusterConf.rlnRelayEthContractAddress |
| 110 | + conf.rlnRelayDynamic = twnClusterConf.rlnRelayDynamic |
| 111 | + conf.rlnRelayBandwidthThreshold = twnClusterConf.rlnRelayBandwidthThreshold |
| 112 | + conf.discv5Discovery = twnClusterConf.discv5Discovery |
| 113 | + conf.discv5BootstrapNodes = |
| 114 | + conf.discv5BootstrapNodes & twnClusterConf.discv5BootstrapNodes |
| 115 | + conf.rlnEpochSizeSec = twnClusterConf.rlnEpochSizeSec |
| 116 | + conf.rlnRelayUserMessageLimit = twnClusterConf.rlnRelayUserMessageLimit |
| 117 | + else: |
| 118 | + discard |
118 | 119 |
|
119 | 120 | info "Running nwaku node", version = app.git_version
|
120 | 121 | logConfig(conf)
|
121 | 122 |
|
| 123 | + # NOTE: {.threadvar.} is used to make the global variable GC safe for the closure uses it |
| 124 | + # It will always be called from main thread anyway. |
| 125 | + # Ref: https://nim-lang.org/docs/manual.html#threads-gc-safety |
| 126 | + var nodeHealthMonitor {.threadvar.}: WakuNodeHealthMonitor |
| 127 | + nodeHealthMonitor = WakuNodeHealthMonitor() |
| 128 | + nodeHealthMonitor.setOverallHealth(HealthStatus.INITIALIZING) |
| 129 | + |
| 130 | + let restServerRes = startRestServerEsentials(nodeHealthMonitor, conf) |
| 131 | + if restServerRes.isErr(): |
| 132 | + error "Starting REST server failed.", error = $restServerRes.error() |
| 133 | + quit(QuitFailure) |
| 134 | + |
122 | 135 | var wakunode2 = App.init(conf).valueOr:
|
123 | 136 | error "App initialization failed", error = error
|
124 | 137 | quit(QuitFailure)
|
125 | 138 |
|
| 139 | + nodeHealthMonitor.setNode(wakunode2.node) |
| 140 | + |
126 | 141 | wakunode2.startApp().isOkOr:
|
127 | 142 | error "Starting app failed", error = error
|
128 | 143 | quit(QuitFailure)
|
129 | 144 |
|
| 145 | + if conf.rest and not restServerRes.isErr(): |
| 146 | + wakunode2.restServer = restServerRes.value |
| 147 | + |
130 | 148 | wakunode2.setupMonitoringAndExternalInterfaces().isOkOr:
|
131 | 149 | error "Starting monitoring and external interfaces failed", error = error
|
132 | 150 | quit(QuitFailure)
|
133 | 151 |
|
| 152 | + nodeHealthMonitor.setOverallHealth(HealthStatus.READY) |
| 153 | + |
134 | 154 | debug "Setting up shutdown hooks"
|
135 | 155 | ## Setup shutdown hooks for this process.
|
136 | 156 | ## Stop node gracefully on shutdown.
|
137 | 157 |
|
138 | 158 | proc asyncStopper(node: App) {.async: (raises: [Exception]).} =
|
| 159 | + nodeHealthMonitor.setOverallHealth(HealthStatus.SHUTTING_DOWN) |
139 | 160 | await node.stop()
|
140 | 161 | quit(QuitSuccess)
|
141 | 162 |
|
|
0 commit comments