-
Notifications
You must be signed in to change notification settings - Fork 86
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Replace
anachronisticLedgerView
with Forecast
Closes #1933 Closes #998
- Loading branch information
Showing
18 changed files
with
230 additions
and
209 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
module Ouroboros.Consensus.Forecast ( | ||
Forecast(..) | ||
, trivialForecast | ||
, constantForecastOf | ||
, OutsideForecastRange(..) | ||
) where | ||
|
||
import Control.Exception (Exception) | ||
import Control.Monad.Except | ||
|
||
import Cardano.Slotting.Slot hiding (at) | ||
|
||
data Forecast a = Forecast { | ||
forecastAt :: WithOrigin SlotNo | ||
|
||
-- Precondition: @At s >= forecastAt@ | ||
, forecastFor :: SlotNo -> Except OutsideForecastRange a | ||
} | ||
|
||
-- | Trivial forecast of values of type @()@ | ||
-- | ||
-- Specialization of 'constantForecast'. | ||
trivialForecast :: WithOrigin SlotNo -> Forecast () | ||
trivialForecast = constantForecastOf () | ||
|
||
-- | Forecast where the values are never changing | ||
-- | ||
-- This is primarily useful for tests; the forecast range is infinite, but we | ||
-- do still check the precondition, to catch any bugs. | ||
constantForecastOf :: a -> WithOrigin SlotNo -> Forecast a | ||
constantForecastOf a at = Forecast { | ||
forecastAt = at | ||
, forecastFor = \for -> | ||
if At for >= at | ||
then return a | ||
else error "trivialForecast: precondition violated" | ||
} | ||
|
||
data OutsideForecastRange = | ||
OutsideForecastRange { | ||
-- | The slot for which the forecast was obtained | ||
outsideForecastAt :: !(WithOrigin SlotNo) | ||
|
||
-- | The slot for which we requested a value | ||
, outsideForecastFor :: !SlotNo | ||
} | ||
deriving (Show, Eq) | ||
|
||
instance Exception OutsideForecastRange |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.