@@ -25,7 +25,9 @@ import Ntp.Client (NtpConfiguration, NtpStatus (..),
25
25
import Ntp.Packet (NtpOffset )
26
26
import Pos.Chain.Block (LastKnownHeader , LastKnownHeaderTag )
27
27
import Pos.Chain.Ssc (SscContext )
28
- import Pos.Chain.Update (UpdateConfiguration , curSoftwareVersion )
28
+ import Pos.Chain.Update (ConfirmedProposalState (.. ), SoftwareVersion ,
29
+ UpdateConfiguration , UpdateProposal (.. ),
30
+ curSoftwareVersion )
29
31
import Pos.Client.CLI.NodeOptions (NodeApiArgs (.. ))
30
32
import Pos.Context (HasPrimaryKey (.. ), HasSscContext (.. ),
31
33
NodeContext (.. ))
@@ -38,6 +40,7 @@ import Pos.DB.GState.Lock (Priority (..), StateLock,
38
40
withStateLockNoMetrics )
39
41
import qualified Pos.DB.Rocks as DB
40
42
import Pos.DB.Txp.MemState (GenericTxpLocalData , TxpHolderTag )
43
+ import Pos.DB.Update (UpdateContext (.. ))
41
44
import Pos.Infra.Diffusion.Subscription.Status (ssMap )
42
45
import Pos.Infra.Diffusion.Types (Diffusion (.. ))
43
46
import Pos.Infra.InjectFail (FInject (.. ), testLogFInject )
@@ -64,6 +67,10 @@ type NodeV1Api
64
67
nodeV1Api :: Proxy NodeV1Api
65
68
nodeV1Api = Proxy
66
69
70
+ --------------------------------------------------------------------------------
71
+ -- Legacy Handlers
72
+ --------------------------------------------------------------------------------
73
+
67
74
data LegacyCtx = LegacyCtx
68
75
{ legacyCtxTxpLocalData
69
76
:: !(GenericTxpLocalData ())
@@ -101,13 +108,22 @@ instance {-# OVERLAPPING #-} DB.MonadDBRead (ReaderT LegacyCtx IO) where
101
108
dbGetSerUndo = DB. dbGetSerUndoRealDefault
102
109
dbGetSerBlund = DB. dbGetSerBlundRealDefault
103
110
111
+ -- | Prepare a 'Server' for the 'Legacy.NodeApi'. We expose a 'Server' so that
112
+ -- it can be embedded in other APIs, instead of an 'Application', which can only
113
+ -- be run on a given port.
104
114
legacyNodeApi :: LegacyCtx -> Server Legacy. NodeApi
105
115
legacyNodeApi r =
106
116
hoistServer
107
117
(Proxy :: Proxy Legacy. NodeApi )
108
118
(Handler . ExceptT . try . flip runReaderT r)
109
119
Legacy. nodeServantHandlers
110
120
121
+ --------------------------------------------------------------------------------
122
+ -- Entry point
123
+ --------------------------------------------------------------------------------
124
+
125
+ -- | This function launches a node API server, which serves the new V1 API, the
126
+ -- legacy node API, and the documentation server for both.
111
127
launchNodeServer
112
128
:: NodeApiArgs
113
129
-> NtpConfiguration
@@ -149,6 +165,7 @@ launchNodeServer
149
165
updateConfiguration
150
166
compileTimeInfo
151
167
shutdownCtx
168
+ (ncUpdateContext nodeCtx)
152
169
:<|> legacyApi
153
170
154
171
concurrently_
@@ -187,6 +204,7 @@ launchNodeServer
187
204
(ipAddress, portNumber) = nodeBackendAddress params
188
205
(docAddress, docPort) = nodeBackendDocAddress params
189
206
207
+ -- | Assembles the handlers for the new node API.
190
208
handlers
191
209
:: Diffusion IO
192
210
-> TVar NtpStatus
@@ -198,12 +216,17 @@ handlers
198
216
-> UpdateConfiguration
199
217
-> CompileTimeInfo
200
218
-> ShutdownContext
219
+ -> UpdateContext
201
220
-> ServerT Node. API Handler
202
- handlers d t s n l ts sv uc ci sc =
221
+ handlers d t s n l ts sv uc ci sc uCtx =
203
222
getNodeSettings ci uc ts sv
204
223
:<|> getNodeInfo d t s n l
205
- :<|> applyUpdate sc
206
- :<|> postponeUpdate
224
+ :<|> getNextUpdate uCtx
225
+ :<|> restartNode sc
226
+
227
+ --------------------------------------------------------------------------------
228
+ -- Node Settings
229
+ --------------------------------------------------------------------------------
207
230
208
231
getNodeSettings
209
232
:: CompileTimeInfo
@@ -239,20 +262,31 @@ instance Core.HasSlottingVar SettingsCtx where
239
262
slottingVar =
240
263
lens settingsCtxSlottingVar (\ s t -> s { settingsCtxSlottingVar = t })
241
264
242
- applyUpdate :: ShutdownContext -> Handler NoContent
243
- applyUpdate shutdownCtx = liftIO $ do
265
+ --------------------------------------------------------------------------------
266
+ -- Updates
267
+ --------------------------------------------------------------------------------
268
+
269
+ -- | Handler
270
+ restartNode :: ShutdownContext -> Handler NoContent
271
+ restartNode shutdownCtx = liftIO $ do
244
272
doFail <- testLogFInject (_shdnFInjects shutdownCtx) FInjApplyUpdateNoExit
245
273
unless doFail (runReaderT triggerShutdown shutdownCtx)
246
274
pure NoContent
247
275
248
- -- | In the old implementation, we would delete the new update from the
249
- -- acid-stae database. We no longer persist this information, so postponing an
250
- -- update is simply a noop.
251
- --
252
- -- TODO: verify this is a real thought and not, in fact, bad
253
- postponeUpdate :: Handler NoContent
254
- postponeUpdate = do
255
- pure NoContent
276
+ -- | This endpoint does a 404 unless there is an update available. If an update
277
+ -- is available, it returns the 'SoftwareVersion' for that update.
278
+ getNextUpdate :: UpdateContext -> Handler (APIResponse (V1 SoftwareVersion ))
279
+ getNextUpdate uc = do
280
+ mproposalState <- tryReadMVar (ucDownloadedUpdate uc)
281
+ single <$> case mproposalState of
282
+ Just proposalState ->
283
+ pure (V1 (upSoftwareVersion (cpsUpdateProposal proposalState)))
284
+ Nothing ->
285
+ throwError err404
286
+
287
+ --------------------------------------------------------------------------------
288
+ -- Node Info
289
+ --------------------------------------------------------------------------------
256
290
257
291
getNodeInfo
258
292
:: Diffusion IO
@@ -319,7 +353,6 @@ instance DB.MonadDBRead (ReaderT InfoCtx IO) where
319
353
dbGetSerUndo = DB. dbGetSerUndoRealDefault
320
354
dbGetSerBlund = DB. dbGetSerBlundRealDefault
321
355
322
-
323
356
getNodeSyncProgress
324
357
::
325
358
( MonadIO m
0 commit comments