@@ -279,6 +279,8 @@ data PraosState = PraosState
279279 -- ^ Candidate nonce
280280 , praosStateEpochNonce :: ! Nonce
281281 -- ^ Epoch nonce
282+ , praosStatePreviousEpochNonce :: ! Nonce
283+ -- ^ Previous epoch nonce
282284 , praosStateLabNonce :: ! Nonce
283285 -- ^ Nonce constructed from the hash of the previous block
284286 , praosStateLastEpochBlockNonce :: ! Nonce
@@ -303,17 +305,19 @@ instance Serialise PraosState where
303305 , praosStateEvolvingNonce
304306 , praosStateCandidateNonce
305307 , praosStateEpochNonce
308+ , praosStatePreviousEpochNonce
306309 , praosStateLabNonce
307310 , praosStateLastEpochBlockNonce
308311 } =
309312 encodeVersion 0 $
310313 mconcat
311- [ CBOR. encodeListLen 7
314+ [ CBOR. encodeListLen 8
312315 , toCBOR praosStateLastSlot
313316 , toCBOR praosStateOCertCounters
314317 , toCBOR praosStateEvolvingNonce
315318 , toCBOR praosStateCandidateNonce
316319 , toCBOR praosStateEpochNonce
320+ , toCBOR praosStatePreviousEpochNonce
317321 , toCBOR praosStateLabNonce
318322 , toCBOR praosStateLastEpochBlockNonce
319323 ]
@@ -323,7 +327,7 @@ instance Serialise PraosState where
323327 [(0 , Decode decodePraosState)]
324328 where
325329 decodePraosState = do
326- enforceSize " PraosState" 7
330+ enforceSize " PraosState" 8
327331 PraosState
328332 <$> fromCBOR
329333 <*> fromCBOR
@@ -332,6 +336,7 @@ instance Serialise PraosState where
332336 <*> fromCBOR
333337 <*> fromCBOR
334338 <*> fromCBOR
339+ <*> fromCBOR
335340
336341data instance Ticked PraosState = TickedPraosState
337342 { tickedPraosStateChainDepState :: PraosState
@@ -423,11 +428,13 @@ instance PraosCrypto c => ConsensusProtocol (Praos c) where
423428 -- Updating the chain dependent state for Praos.
424429 --
425430 -- If we are not in a new epoch, then nothing happens. If we are in a new
426- -- epoch, we do two things:
431+ -- epoch, we do three things:
427432 -- - Update the epoch nonce to the combination of the candidate nonce and the
428433 -- nonce derived from the last block of the previous epoch.
429- -- - Update the "last block of previous epoch" nonce to the nonce derived from
430- -- the last applied block.
434+ -- - Store the current epoch nonce as the "previous epoch" nonce. This is
435+ -- needed by Peras to be able to validate slightly old certificates.
436+ -- - Update the "last block of previous epoch" nonce to the nonce derived
437+ -- from the last applied block.
431438 tickChainDepState
432439 PraosConfig {praosEpochInfo}
433440 lv
@@ -450,7 +457,10 @@ instance PraosCrypto c => ConsensusProtocol (Praos c) where
450457 { praosStateEpochNonce =
451458 praosStateCandidateNonce st
452459 ⭒ praosStateLastEpochBlockNonce st
453- , praosStateLastEpochBlockNonce = praosStateLabNonce st
460+ , praosStatePreviousEpochNonce =
461+ praosStateEpochNonce st
462+ , praosStateLastEpochBlockNonce =
463+ praosStateLabNonce st
454464 }
455465 else st
456466
@@ -758,7 +768,8 @@ instance TranslateProto (TPraos c) (Praos c) where
758768 , praosStateOCertCounters = Map. mapKeysMonotonic coerce certCounters
759769 , praosStateEvolvingNonce = evolvingNonce
760770 , praosStateCandidateNonce = candidateNonce
761- , praosStateEpochNonce = SL. ticknStateEpochNonce csTickn
771+ , praosStateEpochNonce = epochNonce
772+ , praosStatePreviousEpochNonce = epochNonce -- same as current epoch nonce
762773 , praosStateLabNonce = csLabNonce
763774 , praosStateLastEpochBlockNonce = SL. ticknStatePrevHashNonce csTickn
764775 }
@@ -767,6 +778,7 @@ instance TranslateProto (TPraos c) (Praos c) where
767778 tpraosStateChainDepState tpState
768779 SL. PrtclState certCounters evolvingNonce candidateNonce =
769780 csProtocol
781+ epochNonce = SL. ticknStateEpochNonce csTickn
770782
771783{- ------------------------------------------------------------------------------
772784 Util
0 commit comments