Skip to content

Commit

Permalink
Use forecastFutureEpochStartUsingTip for the network tip
Browse files Browse the repository at this point in the history
  • Loading branch information
Anviking committed Jul 24, 2020
1 parent 4d6a02d commit f928fd0
Showing 1 changed file with 10 additions and 8 deletions.
18 changes: 10 additions & 8 deletions lib/core/src/Cardano/Wallet/Api/Server.hs
Original file line number Diff line number Diff line change
Expand Up @@ -259,6 +259,7 @@ import Cardano.Wallet.Primitive.Slotting
, currentEpoch
, epochSucc
, firstSlotInEpoch
, forecastFutureEpochStartUsingTip
, ongoingSlotAt
, startTime
, toSlotId
Expand Down Expand Up @@ -1540,16 +1541,17 @@ getNetworkInformation (_block0, _, st) nl = do
nodeTip <- liftHandler (NW.currentNodeTip nl)
apiNodeTip <- liftIO $ unsafeRunExceptT $ mkApiBlockReference ti nodeTip

ntrkTipSlot <- liftIO (runExceptT $ ti $ ongoingSlotAt now) >>= \case
Right (Just x) -> pure x
Left _ -> pure minBound
Right Nothing -> pure minBound
ntrkTip <- liftIO $ unsafeRunExceptT $ ti $ toSlotId ntrkTipSlot
-- A dummy tip. We should concider changing the api to allow
-- returning null.
let noTip = W.SlotId 0 0

let qry = ongoingSlotAt now >>= \x -> maybe (pure noTip) toSlotId x
ntrkTip <- liftIO (runExceptT $ ti qry) >>= \case
Right x -> pure x
Left _ -> pure noTip
let nextEpochNo = unsafeEpochSucc (ntrkTip ^. #epochNumber)
-- TODO: Re-write firstSlotInEpoch to look at the last time of the previous
-- epoch. firstSlotInEpoch may fail.
nextEpochStart <- liftIO $ unsafeRunExceptT $ ti
(firstSlotInEpoch nextEpochNo >>= startTime)
(forecastFutureEpochStartUsingTip (nodeTip ^. #slotNo) nextEpochNo)
progress <- liftIO $ syncProgress st (unsafeRunExceptT . ti) nodeTip now
pure $ Api.ApiNetworkInformation
{ Api.syncProgress = ApiT progress
Expand Down

0 comments on commit f928fd0

Please sign in to comment.