Skip to content
This repository was archived by the owner on Aug 18, 2020. It is now read-only.

Commit f5c1894

Browse files
committed
Implement
1 parent 8ee5e50 commit f5c1894

File tree

2 files changed

+24
-35
lines changed

2 files changed

+24
-35
lines changed

lib/src/Pos/Node/API.hs

+7-11
Original file line numberDiff line numberDiff line change
@@ -613,14 +613,10 @@ type API =
613613
:<|>
614614
InfoAPI
615615
:<|>
616-
"update"
617-
:> ( "apply"
618-
:> Summary "Apply the next available update"
619-
:> Post '[ValidJSON] NoContent
620-
:<|> "postpone"
621-
:> Summary "Discard and postpone the next available update"
622-
:> Post '[ValidJSON] NoContent
623-
:<|> "next"
624-
:> Summary "Version of the next update (404 if none)"
625-
:> Get '[ValidJSON] (APIResponse (V1 Core.SoftwareVersion))
626-
)
616+
Summary "Version of the next update (404 if none)"
617+
:> "next-update"
618+
:> Get '[ValidJSON] (APIResponse (V1 Core.SoftwareVersion))
619+
:<|>
620+
Summary "Restart the underlying node software."
621+
:> "restart-node"
622+
:> Post '[ValidJSON] NoContent

node/src/Cardano/Node/API.hs

+17-24
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,8 @@ import Ntp.Client (NtpConfiguration, NtpStatus (..),
2525
import Ntp.Packet (NtpOffset)
2626
import Pos.Chain.Block (LastKnownHeader, LastKnownHeaderTag)
2727
import Pos.Chain.Ssc (SscContext)
28-
import Pos.Chain.Update (SoftwareVersion, UpdateConfiguration,
28+
import Pos.Chain.Update (ConfirmedProposalState (..), SoftwareVersion,
29+
UpdateConfiguration, UpdateProposal (..),
2930
curSoftwareVersion)
3031
import Pos.Client.CLI.NodeOptions (NodeApiArgs (..))
3132
import Pos.Context (HasPrimaryKey (..), HasSscContext (..),
@@ -39,6 +40,7 @@ import Pos.DB.GState.Lock (Priority (..), StateLock,
3940
withStateLockNoMetrics)
4041
import qualified Pos.DB.Rocks as DB
4142
import Pos.DB.Txp.MemState (GenericTxpLocalData, TxpHolderTag)
43+
import Pos.DB.Update (UpdateContext (..))
4244
import Pos.Infra.Diffusion.Subscription.Status (ssMap)
4345
import Pos.Infra.Diffusion.Types (Diffusion (..))
4446
import Pos.Infra.InjectFail (FInject (..), testLogFInject)
@@ -163,6 +165,7 @@ launchNodeServer
163165
updateConfiguration
164166
compileTimeInfo
165167
shutdownCtx
168+
(ncUpdateContext nodeCtx)
166169
:<|> legacyApi
167170

168171
concurrently_
@@ -213,13 +216,13 @@ handlers
213216
-> UpdateConfiguration
214217
-> CompileTimeInfo
215218
-> ShutdownContext
219+
-> UpdateContext
216220
-> ServerT Node.API Handler
217-
handlers d t s n l ts sv uc ci sc =
221+
handlers d t s n l ts sv uc ci sc uCtx =
218222
getNodeSettings ci uc ts sv
219223
:<|> getNodeInfo d t s n l
220-
:<|> applyUpdate sc
221-
:<|> postponeUpdate
222-
:<|> getNextUpdate
224+
:<|> getNextUpdate uCtx
225+
:<|> restartNode sc
223226

224227
--------------------------------------------------------------------------------
225228
-- Node Settings
@@ -263,33 +266,23 @@ instance Core.HasSlottingVar SettingsCtx where
263266
-- Updates
264267
--------------------------------------------------------------------------------
265268

266-
applyUpdate :: ShutdownContext -> Handler NoContent
267-
applyUpdate shutdownCtx = liftIO $ do
269+
-- | Handler
270+
restartNode :: ShutdownContext -> Handler NoContent
271+
restartNode shutdownCtx = liftIO $ do
268272
doFail <- testLogFInject (_shdnFInjects shutdownCtx) FInjApplyUpdateNoExit
269273
unless doFail (runReaderT triggerShutdown shutdownCtx)
270274
pure NoContent
271275

272-
-- | In the old implementation, we would delete the new update from the
273-
-- acid-stae database. We no longer persist this information, so postponing an
274-
-- update is simply a noop.
275-
--
276-
-- TODO: verify this is a real thought and not, in fact, bad
277-
postponeUpdate :: Handler NoContent
278-
postponeUpdate = do
279-
pure NoContent
280-
281276
-- | This endpoint does a 404 unless there is an update available. If an update
282277
-- is available, it returns the 'SoftwareVersion' for that update.
283-
getNextUpdate :: Handler (APIResponse (V1 SoftwareVersion))
284-
getNextUpdate = do
285-
mupdate <- readUpdate
286-
single <$> case mupdate of
287-
Just update ->
288-
pure 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)))
289284
Nothing ->
290285
throwError err404
291-
where
292-
readUpdate = undefined
293286

294287
--------------------------------------------------------------------------------
295288
-- Node Info

0 commit comments

Comments
 (0)