Skip to content

Commit

Permalink
Merge #3696
Browse files Browse the repository at this point in the history
3696: Propagate protocol epoch state decode error r=newhoggy a=newhoggy



Co-authored-by: John Ky <john.ky@iohk.io>
  • Loading branch information
iohk-bors[bot] and newhoggy authored Mar 9, 2022
2 parents bc36bd1 + 4c297c0 commit baa9b5e
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 9 deletions.
12 changes: 6 additions & 6 deletions cardano-api/src/Cardano/Api/LedgerState.hs
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ import Cardano.Api.NetworkId (NetworkId (..), NetworkMagic (NetworkMag
import Cardano.Api.ProtocolParameters
import Cardano.Api.Query (CurrentEpochState (..), ProtocolState,
SerialisedCurrentEpochState (..), decodeCurrentEpochState, decodeProtocolState)
import Cardano.Binary (FromCBOR)
import Cardano.Binary (DecoderError, FromCBOR)
import qualified Cardano.Chain.Genesis
import qualified Cardano.Chain.Update
import Cardano.Crypto (ProtocolMagicId (unProtocolMagicId), RequiresNetworkMagic (..))
Expand Down Expand Up @@ -1246,7 +1246,7 @@ unChainHash ch =

data LeadershipError = LeaderErrDecodeLedgerStateFailure
| LeaderErrDecodeProtocolStateFailure
| LeaderErrDecodeProtocolEpochStateFailure
| LeaderErrDecodeProtocolEpochStateFailure DecoderError
| LeaderErrGenesisSlot
| LeaderErrStakePoolHasNoStake PoolId
| LeaderErrStakeDistribUnstable
Expand All @@ -1271,8 +1271,8 @@ instance Error LeadershipError where
"Leadership schedule currently cannot be calculated from genesis"
displayError (LeaderErrStakePoolHasNoStake poolId) =
"The stake pool: " <> show poolId <> " has no stake"
displayError LeaderErrDecodeProtocolEpochStateFailure =
"Failed to successfully decode the current epoch state"
displayError (LeaderErrDecodeProtocolEpochStateFailure decoderError) =
"Failed to successfully decode the current epoch state: " <> show decoderError
displayError (LeaderErrStakeDistribUnstable curSlot stableAfterSlot stabWindow predictedLastSlot) =
"The current stake distribution is currently unstable and therefore we cannot predict " <>
"the following epoch's leadership schedule. Please wait until : " <> show stableAfterSlot <>
Expand Down Expand Up @@ -1349,7 +1349,7 @@ nextEpochEligibleLeadershipSlots sbe sGen serCurrEpochState ptclState

-- Then we get the "mark" snapshot. This snapshot will be used for the next
-- epoch's leadership schedule.
CurrentEpochState cEstate <- first (const LeaderErrDecodeProtocolEpochStateFailure)
CurrentEpochState cEstate <- first LeaderErrDecodeProtocolEpochStateFailure
$ obtainDecodeEpochStateConstraints sbe
$ decodeCurrentEpochState serCurrEpochState

Expand Down Expand Up @@ -1466,7 +1466,7 @@ currentEpochEligibleLeadershipSlots sbe sGen eInfo pParams ptclState
currentEpochRange <- first LeaderErrSlotRangeCalculationFailure
$ Slot.epochInfoRange eInfo currentEpoch

CurrentEpochState cEstate <- first (const LeaderErrDecodeProtocolEpochStateFailure)
CurrentEpochState cEstate <- first LeaderErrDecodeProtocolEpochStateFailure
$ obtainDecodeEpochStateConstraints sbe
$ decodeCurrentEpochState serCurrEpochState

Expand Down
5 changes: 2 additions & 3 deletions cardano-api/src/Cardano/Api/Query.hs
Original file line number Diff line number Diff line change
Expand Up @@ -350,9 +350,8 @@ decodeCurrentEpochState
=> FromCBOR (Core.Value (ShelleyLedgerEra era))
=> FromCBOR (Ledger.State (Core.EraRule "PPUP" (ShelleyLedgerEra era)))
=> SerialisedCurrentEpochState era
-> Either LBS.ByteString (CurrentEpochState era)
decodeCurrentEpochState (SerialisedCurrentEpochState (Serialised ls)) =
CurrentEpochState <$> first (const ls) (decodeFull ls)
-> Either DecoderError (CurrentEpochState era)
decodeCurrentEpochState (SerialisedCurrentEpochState (Serialised ls)) = CurrentEpochState <$> decodeFull ls

toShelleyAddrSet :: CardanoEra era
-> Set AddressAny
Expand Down

0 comments on commit baa9b5e

Please sign in to comment.