-
Notifications
You must be signed in to change notification settings - Fork 86
/
Ledger.hs
587 lines (515 loc) · 22.5 KB
/
Ledger.hs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
{-# LANGUAGE DataKinds #-}
{-# LANGUAGE DeriveAnyClass #-}
{-# LANGUAGE DeriveGeneric #-}
{-# LANGUAGE DerivingStrategies #-}
{-# LANGUAGE DisambiguateRecordFields #-}
{-# LANGUAGE FlexibleContexts #-}
{-# LANGUAGE FlexibleInstances #-}
{-# LANGUAGE GADTs #-}
{-# LANGUAGE GeneralizedNewtypeDeriving #-}
{-# LANGUAGE MultiParamTypeClasses #-}
{-# LANGUAGE NamedFieldPuns #-}
{-# LANGUAGE OverloadedStrings #-}
{-# LANGUAGE ScopedTypeVariables #-}
{-# LANGUAGE StandaloneDeriving #-}
{-# LANGUAGE TypeApplications #-}
{-# LANGUAGE TypeFamilies #-}
{-# LANGUAGE UndecidableInstances #-}
{-# OPTIONS_GHC -Wno-orphans #-}
module Ouroboros.Consensus.Shelley.Ledger.Ledger (
LedgerState (..)
, ShelleyBasedEra
, ShelleyLedgerError (..)
, ShelleyTip (..)
, ShelleyTransition (..)
, Ticked (..)
, castShelleyTip
, shelleyLedgerTipPoint
, shelleyTipToPoint
-- * Ledger config
, ShelleyLedgerConfig (..)
, mkShelleyLedgerConfig
, shelleyEraParams
, shelleyEraParamsNeverHardForks
, shelleyLedgerGenesis
-- * Auxiliary
, ShelleyLedgerEvent (..)
, ShelleyReapplyException (..)
, getPParams
-- * Serialisation
, decodeShelleyAnnTip
, decodeShelleyLedgerState
, encodeShelleyAnnTip
, encodeShelleyHeaderState
, encodeShelleyLedgerState
) where
import Codec.CBOR.Decoding (Decoder)
import qualified Codec.CBOR.Decoding as CBOR
import Codec.CBOR.Encoding (Encoding)
import qualified Codec.CBOR.Encoding as CBOR
import Codec.Serialise (decode, encode)
import Control.Arrow (left)
import qualified Control.Exception as Exception
import Control.Monad.Except
import Data.Functor ((<&>))
import Data.Functor.Identity
import qualified Data.Text as Text
import Data.Word
import GHC.Generics (Generic)
import Lens.Micro.Extras (view)
import NoThunks.Class (NoThunks (..))
import Cardano.Ledger.Binary.Plain (FromCBOR (..), ToCBOR (..),
enforceSize)
import Cardano.Ledger.Core (Era, ppMaxBHSizeL, ppMaxTxSizeL)
import Cardano.Slotting.EpochInfo
import Ouroboros.Consensus.Block
import Ouroboros.Consensus.BlockchainTime.WallClock.Types
import Ouroboros.Consensus.Config
import Ouroboros.Consensus.HardFork.Abstract
import qualified Ouroboros.Consensus.HardFork.History as HardFork
import Ouroboros.Consensus.HardFork.History.Util
import Ouroboros.Consensus.HeaderValidation
import Ouroboros.Consensus.Ledger.Abstract
import Ouroboros.Consensus.Ledger.CommonProtocolParams
import Ouroboros.Consensus.Ledger.Extended
import Ouroboros.Consensus.Util ((..:))
import Ouroboros.Consensus.Util.CBOR (decodeWithOrigin,
encodeWithOrigin)
import Ouroboros.Consensus.Util.Versioned
import qualified Cardano.Ledger.BHeaderView as SL (BHeaderView)
import qualified Cardano.Ledger.BaseTypes as SL (epochInfoPure)
import qualified Cardano.Ledger.Core as Core
import qualified Cardano.Ledger.Shelley.API as SL
import qualified Control.State.Transition.Extended as STS
import Ouroboros.Consensus.Protocol.Ledger.Util (isNewEpoch)
import Ouroboros.Consensus.Protocol.TPraos (MaxMajorProtVer (..),
Ticked (TickedPraosLedgerView))
import Ouroboros.Consensus.Shelley.Eras (EraCrypto)
import Ouroboros.Consensus.Shelley.Ledger.Block
import Ouroboros.Consensus.Shelley.Ledger.Config
import Ouroboros.Consensus.Shelley.Ledger.Protocol ()
import Ouroboros.Consensus.Shelley.Protocol.Abstract
(EnvelopeCheckError, envelopeChecks, mkHeaderView)
{-------------------------------------------------------------------------------
Ledger errors
-------------------------------------------------------------------------------}
newtype ShelleyLedgerError era = BBodyError (SL.BlockTransitionError era)
deriving (Generic)
deriving instance ShelleyBasedEra era => Eq (ShelleyLedgerError era)
deriving instance ShelleyBasedEra era => Show (ShelleyLedgerError era)
instance ShelleyBasedEra era => NoThunks (ShelleyLedgerError era)
{-------------------------------------------------------------------------------
Config
-------------------------------------------------------------------------------}
data ShelleyLedgerConfig era = ShelleyLedgerConfig {
shelleyLedgerCompactGenesis :: !(CompactGenesis (EraCrypto era))
-- | Derived from 'shelleyLedgerGenesis' but we store a cached version
-- because it used very often.
, shelleyLedgerGlobals :: !SL.Globals
, shelleyLedgerTranslationContext :: !(Core.TranslationContext era)
}
deriving (Generic)
deriving instance (NoThunks (Core.TranslationContext era), Era era) =>
NoThunks (ShelleyLedgerConfig era)
shelleyLedgerGenesis :: ShelleyLedgerConfig era -> SL.ShelleyGenesis (EraCrypto era)
shelleyLedgerGenesis = getCompactGenesis . shelleyLedgerCompactGenesis
shelleyEraParams ::
SL.ShelleyGenesis c
-> HardFork.EraParams
shelleyEraParams genesis = HardFork.EraParams {
eraEpochSize = SL.sgEpochLength genesis
, eraSlotLength = mkSlotLength $ SL.fromNominalDiffTimeMicro $ SL.sgSlotLength genesis
, eraSafeZone = HardFork.StandardSafeZone stabilityWindow
}
where
stabilityWindow =
SL.computeStabilityWindow
(SL.sgSecurityParam genesis)
(SL.sgActiveSlotCoeff genesis)
-- | Separate variant of 'shelleyEraParams' to be used for a Shelley-only chain.
shelleyEraParamsNeverHardForks :: SL.ShelleyGenesis c -> HardFork.EraParams
shelleyEraParamsNeverHardForks genesis = HardFork.EraParams {
eraEpochSize = SL.sgEpochLength genesis
, eraSlotLength = mkSlotLength $ SL.fromNominalDiffTimeMicro $ SL.sgSlotLength genesis
, eraSafeZone = HardFork.UnsafeIndefiniteSafeZone
}
mkShelleyLedgerConfig
:: SL.ShelleyGenesis (EraCrypto era)
-> Core.TranslationContext era
-> EpochInfo (Except HardFork.PastHorizonException)
-> MaxMajorProtVer
-> ShelleyLedgerConfig era
mkShelleyLedgerConfig genesis transCtxt epochInfo mmpv =
ShelleyLedgerConfig {
shelleyLedgerCompactGenesis = compactGenesis genesis
, shelleyLedgerGlobals =
SL.mkShelleyGlobals
genesis
(hoistEpochInfo (left (Text.pack . show) . runExcept) epochInfo)
maxMajorPV
, shelleyLedgerTranslationContext = transCtxt
}
where
MaxMajorProtVer maxMajorPV = mmpv
type instance LedgerCfg (LedgerState (ShelleyBlock proto era)) = ShelleyLedgerConfig era
{-------------------------------------------------------------------------------
LedgerState
-------------------------------------------------------------------------------}
data ShelleyTip proto era = ShelleyTip {
shelleyTipSlotNo :: !SlotNo
, shelleyTipBlockNo :: !BlockNo
, shelleyTipHash :: !(HeaderHash (ShelleyBlock proto era))
}
deriving (Eq, Show, Generic, NoThunks)
shelleyTipToPoint :: WithOrigin (ShelleyTip proto era) -> Point (ShelleyBlock proto era)
shelleyTipToPoint Origin = GenesisPoint
shelleyTipToPoint (NotOrigin tip) = BlockPoint (shelleyTipSlotNo tip)
(shelleyTipHash tip)
castShelleyTip ::
HeaderHash (ShelleyBlock proto era) ~ HeaderHash (ShelleyBlock proto' era')
=> ShelleyTip proto era -> ShelleyTip proto' era'
castShelleyTip (ShelleyTip sn bn hh) = ShelleyTip {
shelleyTipSlotNo = sn
, shelleyTipBlockNo = bn
, shelleyTipHash = hh
}
data instance LedgerState (ShelleyBlock proto era) = ShelleyLedgerState {
shelleyLedgerTip :: !(WithOrigin (ShelleyTip proto era))
, shelleyLedgerState :: !(SL.NewEpochState era)
, shelleyLedgerTransition :: !ShelleyTransition
}
deriving (Generic)
deriving instance ShelleyBasedEra era => Show (LedgerState (ShelleyBlock proto era))
deriving instance ShelleyBasedEra era => Eq (LedgerState (ShelleyBlock proto era))
deriving instance ShelleyBasedEra era => NoThunks (LedgerState (ShelleyBlock proto era))
-- | Information required to determine the hard fork point from Shelley to the
-- next ledger
newtype ShelleyTransition = ShelleyTransitionInfo {
-- | The number of blocks in this epoch past the voting deadline
--
-- We record this to make sure that we can tell the HFC about hard forks
-- if and only if we are certain:
--
-- 1. Blocks that came in within an epoch after the 4k/f voting deadline
-- are not relevant (10k/f - 2 * 3k/f).
-- 2. Since there are slots between blocks, we are probably only sure that
-- there will be no more relevant block when we have seen the first
-- block after the deadline.
-- 3. If we count how many blocks we have seen post deadline, and we have
-- reached k of them, we know that that last pre-deadline block won't
-- be rolled back anymore.
-- 4. At this point we can look at the ledger state and see which
-- proposals we accepted in the voting period, if any, and notify the
-- HFC is one of them indicates a transition.
shelleyAfterVoting :: Word32
}
deriving stock (Eq, Show, Generic)
deriving newtype (NoThunks)
shelleyLedgerTipPoint :: LedgerState (ShelleyBlock proto era) -> Point (ShelleyBlock proto era)
shelleyLedgerTipPoint = shelleyTipToPoint . shelleyLedgerTip
instance ShelleyCompatible proto era => UpdateLedger (ShelleyBlock proto era)
{-------------------------------------------------------------------------------
GetTip
-------------------------------------------------------------------------------}
instance GetTip (LedgerState (ShelleyBlock proto era)) where
getTip = castPoint . shelleyLedgerTipPoint
instance GetTip (Ticked (LedgerState (ShelleyBlock proto era))) where
getTip = castPoint . untickedShelleyLedgerTipPoint
{-------------------------------------------------------------------------------
Ticking
-------------------------------------------------------------------------------}
-- | Ticking only affects the state itself
data instance Ticked (LedgerState (ShelleyBlock proto era)) = TickedShelleyLedgerState {
untickedShelleyLedgerTip :: !(WithOrigin (ShelleyTip proto era))
-- | We are counting blocks within an epoch, this means:
--
-- 1. We are only incrementing this when /applying/ a block, not when ticking.
-- 2. However, we count within an epoch, which is slot-based. So the count
-- must be reset when /ticking/, not when applying a block.
, tickedShelleyLedgerTransition :: !ShelleyTransition
, tickedShelleyLedgerState :: !(SL.NewEpochState era)
}
deriving (Generic)
deriving instance ShelleyBasedEra era
=> NoThunks (Ticked (LedgerState (ShelleyBlock proto era)))
untickedShelleyLedgerTipPoint ::
Ticked (LedgerState (ShelleyBlock proto era))
-> Point (ShelleyBlock proto era)
untickedShelleyLedgerTipPoint = shelleyTipToPoint . untickedShelleyLedgerTip
instance ShelleyBasedEra era => IsLedger (LedgerState (ShelleyBlock proto era)) where
type LedgerErr (LedgerState (ShelleyBlock proto era)) = ShelleyLedgerError era
type AuxLedgerEvent (LedgerState (ShelleyBlock proto era)) = ShelleyLedgerEvent era
applyChainTickLedgerResult cfg slotNo ShelleyLedgerState{
shelleyLedgerTip
, shelleyLedgerState
, shelleyLedgerTransition
} =
swizzle appTick <&> \l' ->
TickedShelleyLedgerState {
untickedShelleyLedgerTip =
shelleyLedgerTip
, tickedShelleyLedgerTransition =
-- The voting resets each epoch
if isNewEpoch ei (shelleyTipSlotNo <$> shelleyLedgerTip) slotNo then
ShelleyTransitionInfo { shelleyAfterVoting = 0 }
else
shelleyLedgerTransition
, tickedShelleyLedgerState = l'
}
where
globals = shelleyLedgerGlobals cfg
ei :: EpochInfo Identity
ei = SL.epochInfoPure globals
swizzle (l, events) =
LedgerResult {
lrEvents = map ShelleyLedgerEventTICK events
, lrResult = l
}
appTick =
SL.applyTickOpts
STS.ApplySTSOpts {
asoAssertions = STS.globalAssertionPolicy
, asoValidation = STS.ValidateAll
, asoEvents = STS.EPReturn
}
globals
shelleyLedgerState
slotNo
-- | All events emitted by the Shelley ledger API
data ShelleyLedgerEvent era =
-- | An event emitted when (re)applying a block
ShelleyLedgerEventBBODY (STS.Event (Core.EraRule "BBODY" era))
-- | An event emitted during the chain tick
| ShelleyLedgerEventTICK (STS.Event (Core.EraRule "TICK" era))
instance ShelleyCompatible proto era
=> ApplyBlock (LedgerState (ShelleyBlock proto era)) (ShelleyBlock proto era) where
-- Note: in the Shelley ledger, the @CHAIN@ rule is used to apply a whole
-- block. In consensus, we split up the application of a block to the ledger
-- into separate steps that are performed together by 'applyExtLedgerState':
--
-- + 'applyChainTickLedgerResult': executes the @TICK@ transition
-- + 'validateHeader':
-- - 'validateEnvelope': executes the @chainChecks@
-- - 'updateChainDepState': executes the @PRTCL@ transition
-- + 'applyBlockLedgerResult': executes the @BBODY@ transition
--
applyBlockLedgerResult =
applyHelper (swizzle ..: appBlk)
where
swizzle m =
withExcept BBodyError m <&> \(l, events) ->
LedgerResult {
lrEvents = map ShelleyLedgerEventBBODY events
, lrResult = l
}
-- Apply the BBODY transition using the ticked state
appBlk =
SL.applyBlockOpts
STS.ApplySTSOpts {
asoAssertions = STS.globalAssertionPolicy
, asoValidation = STS.ValidateAll
, asoEvents = STS.EPReturn
}
reapplyBlockLedgerResult =
runIdentity ..: applyHelper (swizzle ..: reappBlk)
where
swizzle m = case runExcept m of
Left err ->
Exception.throw $! ShelleyReapplyException @era err
Right (l, events) ->
pure LedgerResult {
lrEvents = map ShelleyLedgerEventBBODY events
, lrResult = l
}
-- Reapply the BBODY transition using the ticked state
reappBlk =
SL.applyBlockOpts
STS.ApplySTSOpts {
asoAssertions = STS.AssertionsOff
, asoValidation = STS.ValidateNone
, asoEvents = STS.EPReturn
}
data ShelleyReapplyException =
forall era. Show (SL.BlockTransitionError era)
=> ShelleyReapplyException (SL.BlockTransitionError era)
instance Show ShelleyReapplyException where
show (ShelleyReapplyException err) = "(ShelleyReapplyException " <> show err <> ")"
instance Exception.Exception ShelleyReapplyException where
applyHelper ::
(ShelleyCompatible proto era, Monad m)
=> ( SL.Globals
-> SL.NewEpochState era
-> SL.Block (SL.BHeaderView (EraCrypto era)) era
-> m (LedgerResult
(LedgerState (ShelleyBlock proto era))
(SL.NewEpochState era)
)
)
-> LedgerConfig (ShelleyBlock proto era)
-> ShelleyBlock proto era
-> Ticked (LedgerState (ShelleyBlock proto era))
-> m (LedgerResult
(LedgerState (ShelleyBlock proto era))
(LedgerState (ShelleyBlock proto era)))
applyHelper f cfg blk TickedShelleyLedgerState{
tickedShelleyLedgerTransition
, tickedShelleyLedgerState
} = do
ledgerResult <-
f
globals
tickedShelleyLedgerState
( let b = shelleyBlockRaw blk
h' = mkHeaderView (SL.bheader b)
-- Jared Corduan explains that the " Unsafe " here ultimately only
-- means the value must not be serialized. We're only passing it to
-- 'STS.applyBlockOpts', which does not serialize it. So this is a
-- safe use.
in SL.UnsafeUnserialisedBlock h' (SL.bbody b)
)
return $ ledgerResult <&> \newNewEpochState -> ShelleyLedgerState {
shelleyLedgerTip = NotOrigin ShelleyTip {
shelleyTipBlockNo = blockNo blk
, shelleyTipSlotNo = blockSlot blk
, shelleyTipHash = blockHash blk
}
, shelleyLedgerState =
newNewEpochState
, shelleyLedgerTransition = ShelleyTransitionInfo {
shelleyAfterVoting =
-- We count the number of blocks that have been applied after the
-- voting deadline has passed.
(if blockSlot blk >= votingDeadline then succ else id) $
shelleyAfterVoting tickedShelleyLedgerTransition
}
}
where
globals = shelleyLedgerGlobals cfg
swindow = SL.stabilityWindow globals
ei :: EpochInfo Identity
ei = SL.epochInfoPure globals
-- The start of the next epoch is within the safe zone, always.
startOfNextEpoch :: SlotNo
startOfNextEpoch = runIdentity $ do
blockEpoch <- epochInfoEpoch ei (blockSlot blk)
let nextEpoch = succ blockEpoch
epochInfoFirst ei nextEpoch
-- The block must come in strictly before the voting deadline
-- See Fig 13, "Protocol Parameter Update Inference Rules", of the
-- Shelley specification.
votingDeadline :: SlotNo
votingDeadline = subSlots (2 * swindow) startOfNextEpoch
instance HasHardForkHistory (ShelleyBlock proto era) where
type HardForkIndices (ShelleyBlock proto era) = '[ShelleyBlock proto era]
hardForkSummary = neverForksHardForkSummary $
shelleyEraParamsNeverHardForks . shelleyLedgerGenesis
instance ShelleyCompatible proto era
=> CommonProtocolParams (ShelleyBlock proto era) where
maxHeaderSize = fromIntegral . view ppMaxBHSizeL . getPParams . shelleyLedgerState
maxTxSize = fromIntegral . view ppMaxTxSizeL . getPParams . shelleyLedgerState
{-------------------------------------------------------------------------------
ValidateEnvelope
-------------------------------------------------------------------------------}
instance ShelleyCompatible proto era => BasicEnvelopeValidation (ShelleyBlock proto era) where
-- defaults all OK
instance ShelleyCompatible proto era => ValidateEnvelope (ShelleyBlock proto era) where
type OtherHeaderEnvelopeError (ShelleyBlock proto era) =
EnvelopeCheckError proto
additionalEnvelopeChecks cfg tlv hdr =
envelopeChecks (configConsensus cfg) tlv (shelleyHeaderRaw hdr)
{-------------------------------------------------------------------------------
Auxiliary
-------------------------------------------------------------------------------}
getPParams :: SL.NewEpochState era -> Core.PParams era
getPParams = SL.esPp . SL.nesEs
{-------------------------------------------------------------------------------
Serialisation
-------------------------------------------------------------------------------}
-- | Current version
--
-- o 'serialisationFormatVersion0' used to include the 'LedgerViewHistory', but
-- since we had to break binary backwards compatibility of the 'TPraosState',
-- we dropped backwards compatibility with 'serialisationFormatVersion0' too.
-- o 'serialisationFormatVersion1' did not include a 'BlockNo' at the tip of
-- the ledger, which was introduced in version 2. Again, since we broke
-- compat anyway, we dropped support for version 1.
serialisationFormatVersion2 :: VersionNumber
serialisationFormatVersion2 = 2
encodeShelleyAnnTip ::
ShelleyCompatible proto era
=> AnnTip (ShelleyBlock proto era) -> Encoding
encodeShelleyAnnTip = defaultEncodeAnnTip toCBOR
decodeShelleyAnnTip ::
ShelleyCompatible proto era
=> Decoder s (AnnTip (ShelleyBlock proto era))
decodeShelleyAnnTip = defaultDecodeAnnTip fromCBOR
encodeShelleyHeaderState ::
ShelleyCompatible proto era
=> HeaderState (ShelleyBlock proto era)
-> Encoding
encodeShelleyHeaderState = encodeHeaderState
encode
encodeShelleyAnnTip
encodeShelleyTip :: ShelleyCompatible proto era => ShelleyTip proto era -> Encoding
encodeShelleyTip ShelleyTip {
shelleyTipSlotNo
, shelleyTipBlockNo
, shelleyTipHash
} = mconcat [
CBOR.encodeListLen 3
, encode shelleyTipSlotNo
, encode shelleyTipBlockNo
, encode shelleyTipHash
]
decodeShelleyTip :: ShelleyCompatible proto era => Decoder s (ShelleyTip proto era)
decodeShelleyTip = do
enforceSize "ShelleyTip" 3
shelleyTipSlotNo <- decode
shelleyTipBlockNo <- decode
shelleyTipHash <- decode
return ShelleyTip {
shelleyTipSlotNo
, shelleyTipBlockNo
, shelleyTipHash
}
encodeShelleyTransition :: ShelleyTransition -> Encoding
encodeShelleyTransition ShelleyTransitionInfo{shelleyAfterVoting} = mconcat [
CBOR.encodeWord32 shelleyAfterVoting
]
decodeShelleyTransition :: Decoder s ShelleyTransition
decodeShelleyTransition = do
shelleyAfterVoting <- CBOR.decodeWord32
return ShelleyTransitionInfo{shelleyAfterVoting}
encodeShelleyLedgerState ::
ShelleyCompatible proto era
=> LedgerState (ShelleyBlock proto era)
-> Encoding
encodeShelleyLedgerState
ShelleyLedgerState { shelleyLedgerTip
, shelleyLedgerState
, shelleyLedgerTransition
} =
encodeVersion serialisationFormatVersion2 $ mconcat [
CBOR.encodeListLen 3
, encodeWithOrigin encodeShelleyTip shelleyLedgerTip
, toCBOR shelleyLedgerState
, encodeShelleyTransition shelleyLedgerTransition
]
decodeShelleyLedgerState ::
forall era proto s. ShelleyCompatible proto era
=> Decoder s (LedgerState (ShelleyBlock proto era))
decodeShelleyLedgerState = decodeVersion [
(serialisationFormatVersion2, Decode decodeShelleyLedgerState2)
]
where
decodeShelleyLedgerState2 :: Decoder s' (LedgerState (ShelleyBlock proto era))
decodeShelleyLedgerState2 = do
enforceSize "LedgerState ShelleyBlock" 3
shelleyLedgerTip <- decodeWithOrigin decodeShelleyTip
shelleyLedgerState <- fromCBOR
shelleyLedgerTransition <- decodeShelleyTransition
return ShelleyLedgerState {
shelleyLedgerTip
, shelleyLedgerState
, shelleyLedgerTransition
}