Skip to content

Commit aba5ef9

Browse files
amesgennfrisby
andcommitted
HFC: generalize cross era ticking
Co-authored-by: Nicolas Frisby <[email protected]>
1 parent 82c5ebf commit aba5ef9

File tree

15 files changed

+520
-616
lines changed

15 files changed

+520
-616
lines changed

ouroboros-consensus-cardano/src/byron/Ouroboros/Consensus/Byron/Ledger/Ledger.hs

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,8 @@ import Ouroboros.Consensus.Byron.Ledger.Serialisation
7474
import Ouroboros.Consensus.Config
7575
import Ouroboros.Consensus.Forecast
7676
import Ouroboros.Consensus.HardFork.Abstract
77+
import Ouroboros.Consensus.HardFork.Combinator.Embed.Nary
78+
(Untick (..))
7779
import qualified Ouroboros.Consensus.HardFork.History as HardFork
7880
import Ouroboros.Consensus.HeaderValidation
7981
import Ouroboros.Consensus.Ledger.Abstract
@@ -83,6 +85,7 @@ import Ouroboros.Consensus.Ledger.Query
8385
import Ouroboros.Consensus.Ledger.SupportsPeerSelection
8486
import Ouroboros.Consensus.Ledger.SupportsProtocol
8587
import Ouroboros.Consensus.Protocol.PBFT
88+
import Ouroboros.Consensus.TypeFamilyWrappers
8689
import Ouroboros.Consensus.Util (ShowProxy (..), (..:))
8790

8891
{-------------------------------------------------------------------------------
@@ -164,6 +167,7 @@ getByronTip state =
164167
-- | The ticked Byron ledger state
165168
data instance Ticked (LedgerState ByronBlock) = TickedByronLedgerState {
166169
tickedByronLedgerState :: !CC.ChainValidationState
170+
, untickedByronLedgerTipBlockNo :: !(WithOrigin BlockNo)
167171
, untickedByronLedgerTransition :: !ByronTransition
168172
}
169173
deriving (Generic, NoThunks)
@@ -178,6 +182,8 @@ instance IsLedger (LedgerState ByronBlock) where
178182
TickedByronLedgerState {
179183
tickedByronLedgerState =
180184
CC.applyChainTick cfg (toByronSlotNo slotNo) byronLedgerState
185+
, untickedByronLedgerTipBlockNo =
186+
byronLedgerTipBlockNo
181187
, untickedByronLedgerTransition =
182188
byronLedgerTransition
183189
}
@@ -503,3 +509,27 @@ decodeByronResult :: BlockQuery ByronBlock result
503509
-> forall s. Decoder s result
504510
decodeByronResult query = case query of
505511
GetUpdateInterfaceState -> fromByronCBOR
512+
513+
{-------------------------------------------------------------------------------
514+
Unticking
515+
-------------------------------------------------------------------------------}
516+
517+
instance Untick (WrapChainDepState ByronBlock) where
518+
untick =
519+
pure
520+
. WrapChainDepState
521+
. getTickedPBftState
522+
. unwrapTickedChainDepState
523+
524+
instance Untick (LedgerState ByronBlock) where
525+
untick st = pure ByronLedgerState {
526+
byronLedgerTipBlockNo = untickedByronLedgerTipBlockNo
527+
, byronLedgerState = tickedByronLedgerState
528+
, byronLedgerTransition = untickedByronLedgerTransition
529+
}
530+
where
531+
TickedByronLedgerState {
532+
tickedByronLedgerState
533+
, untickedByronLedgerTipBlockNo
534+
, untickedByronLedgerTransition
535+
} = st

0 commit comments

Comments
 (0)