Skip to content
This repository has been archived by the owner on Feb 9, 2021. It is now read-only.

Commit

Permalink
[#526] Remove MonadError constraint from registerEpoch and epochTrans…
Browse files Browse the repository at this point in the history
…ition
  • Loading branch information
intricate committed Jun 18, 2019
1 parent 4d315c4 commit 3265e42
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 23 deletions.
13 changes: 5 additions & 8 deletions cardano-ledger/src/Cardano/Chain/Block/Validation.hs
Original file line number Diff line number Diff line change
Expand Up @@ -497,7 +497,7 @@ updateHeader bvmode env st h = do
`orThrowError` ChainValidationHeaderTooLarge maxHeaderSize (headerLength h)

-- Perform epoch transition
epochTransition epochEnv st (headerSlot h)
pure $! epochTransition epochEnv st (headerSlot h)
where
maxHeaderSize = Update.ppMaxHeaderSize $ UPI.adoptedProtocolParameters st

Expand Down Expand Up @@ -530,16 +530,13 @@ data EpochEnvironment = EpochEnvironment
-- confirmed proposals and cleans up the state. This corresponds to the EPOCH
-- rules from the Byron chain specification.
epochTransition
:: MonadError ChainValidationError m
=> EpochEnvironment
:: EpochEnvironment
-> UPI.State
-> SlotNumber
-> m UPI.State
-> UPI.State
epochTransition env st slot = if nextEpoch > currentEpoch
then
UPI.registerEpoch updateEnv st nextEpoch
`wrapError` ChainValidationUpdateError
else pure st
then UPI.registerEpoch updateEnv st nextEpoch
else st
where
EpochEnvironment { protocolMagic, k, numGenKeys, delegationMap, currentEpoch }
= env
Expand Down
28 changes: 13 additions & 15 deletions cardano-ledger/src/Cardano/Chain/Update/Validation/Interface.hs
Original file line number Diff line number Diff line change
Expand Up @@ -368,12 +368,11 @@ registerEndorsement env st endorsement = do
--
-- This corresponds to the @UPIEC@ rules in the Byron ledger specification.
registerEpoch
:: MonadError Error m
=> Environment
:: Environment
-> State
-> EpochNumber
-- ^ Epoch seen on the block.
-> m State
-> State
registerEpoch env st lastSeenEpoch = do
let PVBump.State
currentEpoch'
Expand All @@ -387,22 +386,21 @@ registerEpoch env st lastSeenEpoch = do
-- therefore the protocol parameters cannot change) or there are no
-- update proposals that can be adopted (either because there are no
-- candidates or they do not fulfill the requirements for adoption).
pure $! st
st
else
-- We have a new protocol version, so we update the current protocol
-- version and parameters, and we perform a cleanup of the state
-- variables.
pure $!
st { currentEpoch = currentEpoch'
, adoptedProtocolVersion = adoptedProtocolVersion'
, adoptedProtocolParameters = nextProtocolParameters'
, candidateProtocolUpdates = []
, registeredProtocolUpdateProposals = M.empty
, confirmedProposals = M.empty
, proposalVotes = M.empty
, registeredEndorsements = S.empty
, proposalRegistrationSlot = M.empty
}
st { currentEpoch = currentEpoch'
, adoptedProtocolVersion = adoptedProtocolVersion'
, adoptedProtocolParameters = nextProtocolParameters'
, candidateProtocolUpdates = []
, registeredProtocolUpdateProposals = M.empty
, confirmedProposals = M.empty
, proposalVotes = M.empty
, registeredEndorsements = S.empty
, proposalRegistrationSlot = M.empty
}
where
subEnv = PVBump.Environment k currentSlot candidateProtocolUpdates

Expand Down

0 comments on commit 3265e42

Please sign in to comment.