From db9bd54276a90741c7f48f4487be644a0e2134a4 Mon Sep 17 00:00:00 2001 From: Agustin Mista Date: Wed, 29 Oct 2025 10:14:29 +0100 Subject: [PATCH] Store previous epoch nonce in PraosState --- .../golden/cardano/disk/ChainDepState_Babbage | Bin 372 -> 374 bytes .../golden/cardano/disk/ChainDepState_Conway | Bin 403 -> 405 bytes .../cardano/disk/ChainDepState_Dijkstra | Bin 434 -> 436 bytes .../cardano/disk/ExtLedgerState_Babbage | Bin 1062 -> 1064 bytes .../golden/cardano/disk/ExtLedgerState_Conway | Bin 1699 -> 1701 bytes .../cardano/disk/ExtLedgerState_Dijkstra | Bin 1825 -> 1827 bytes .../Ouroboros/Consensus/Protocol/Praos.hs | 26 +++++++++++++----- .../Protocol/Serialisation/Generators.hs | 1 + 8 files changed, 20 insertions(+), 7 deletions(-) diff --git a/ouroboros-consensus-cardano/golden/cardano/disk/ChainDepState_Babbage b/ouroboros-consensus-cardano/golden/cardano/disk/ChainDepState_Babbage index 3bc6eaac885800f5f1b8eb0fabab59681f170b0c..2e06ac93cf4aa1346a99ec7b1c931741423f2e73 100644 GIT binary patch delta 22 bcmeyu^o?o4e8!H63woFu872oXs(>&6Ywrj5 delta 15 Xcmeyy^o41{e8%>P3wkE&F?s+1IZFm@ diff --git a/ouroboros-consensus-cardano/golden/cardano/disk/ChainDepState_Conway b/ouroboros-consensus-cardano/golden/cardano/disk/ChainDepState_Conway index 5043da9e145a6a9d9676cf5834dd47f9ac7d3a87..760307285a4749f2f4ed0f2c6283a5b02b163783 100644 GIT binary patch delta 18 acmbQtJe7IEKE{rT`+Jxg874C_dH?`H@CHHv delta 15 XcmbQrJehgIKF0Qm`+FucGI{_2Ffs+c diff --git a/ouroboros-consensus-cardano/golden/cardano/disk/ChainDepState_Dijkstra b/ouroboros-consensus-cardano/golden/cardano/disk/ChainDepState_Dijkstra index 8745a735ad11111d74404736a355100d5dff5a9b..64bfb1dc43fd531d6019573e103b75cb054715c3 100644 GIT binary patch delta 18 acmdnQyoGtfUB-@y_j;Hb873<*dH?`P6$ae^ delta 15 XcmdnOyoq_jUB>o__j)EPFnRz0HRA?Z diff --git a/ouroboros-consensus-cardano/golden/cardano/disk/ExtLedgerState_Babbage b/ouroboros-consensus-cardano/golden/cardano/disk/ExtLedgerState_Babbage index 622ee470ffed81a6ab3e1e364f2899cb2ec655b0..e1cb075b826f387453cd45895ec48a903d70cbd8 100644 GIT binary patch delta 24 gcmZ3+v4UemATw)66C>lIiLc})moR5dzQgPV0Balw-v9sr delta 24 gcmZ3%v5aFwATw)w6C>lIiLc})moR5de!%Pj0Bafu-~a#s diff --git a/ouroboros-consensus-cardano/golden/cardano/disk/ExtLedgerState_Conway b/ouroboros-consensus-cardano/golden/cardano/disk/ExtLedgerState_Conway index 1d2b0c3c12cd92022d0827ede068bd448dd3fcd5..74fe8bc5754d646432047d745a1b988197a3e6f2 100644 GIT binary patch delta 20 ccmZ3?yOejsIabDw$>&*nm>L--3$l3t08rir*8l(j delta 17 ZcmZ3=yO?*wIabE@$>&*nCJVB8002Fo22%h4 diff --git a/ouroboros-consensus-cardano/golden/cardano/disk/ExtLedgerState_Dijkstra b/ouroboros-consensus-cardano/golden/cardano/disk/ExtLedgerState_Dijkstra index 563a4897c6cea24d29792667e8db97561abad6e2..a57ec35d1a051ec9bfb5207deb824e6b6ff974fb 100644 GIT binary patch delta 20 bcmZ3;x0r8(4;y30WM8%(rbdRz{cIipMU@6o delta 17 YcmZ3?w~%jx4;y3qWM8(P$^C2|05xI-%>V!Z diff --git a/ouroboros-consensus-protocol/src/ouroboros-consensus-protocol/Ouroboros/Consensus/Protocol/Praos.hs b/ouroboros-consensus-protocol/src/ouroboros-consensus-protocol/Ouroboros/Consensus/Protocol/Praos.hs index 772f3c2550..547e9e54aa 100644 --- a/ouroboros-consensus-protocol/src/ouroboros-consensus-protocol/Ouroboros/Consensus/Protocol/Praos.hs +++ b/ouroboros-consensus-protocol/src/ouroboros-consensus-protocol/Ouroboros/Consensus/Protocol/Praos.hs @@ -279,6 +279,8 @@ data PraosState = PraosState -- ^ Candidate nonce , praosStateEpochNonce :: !Nonce -- ^ Epoch nonce + , praosStatePreviousEpochNonce :: !Nonce + -- ^ Previous epoch nonce , praosStateLabNonce :: !Nonce -- ^ Nonce constructed from the hash of the previous block , praosStateLastEpochBlockNonce :: !Nonce @@ -303,17 +305,19 @@ instance Serialise PraosState where , praosStateEvolvingNonce , praosStateCandidateNonce , praosStateEpochNonce + , praosStatePreviousEpochNonce , praosStateLabNonce , praosStateLastEpochBlockNonce } = encodeVersion 0 $ mconcat - [ CBOR.encodeListLen 7 + [ CBOR.encodeListLen 8 , toCBOR praosStateLastSlot , toCBOR praosStateOCertCounters , toCBOR praosStateEvolvingNonce , toCBOR praosStateCandidateNonce , toCBOR praosStateEpochNonce + , toCBOR praosStatePreviousEpochNonce , toCBOR praosStateLabNonce , toCBOR praosStateLastEpochBlockNonce ] @@ -323,7 +327,7 @@ instance Serialise PraosState where [(0, Decode decodePraosState)] where decodePraosState = do - enforceSize "PraosState" 7 + enforceSize "PraosState" 8 PraosState <$> fromCBOR <*> fromCBOR @@ -332,6 +336,7 @@ instance Serialise PraosState where <*> fromCBOR <*> fromCBOR <*> fromCBOR + <*> fromCBOR data instance Ticked PraosState = TickedPraosState { tickedPraosStateChainDepState :: PraosState @@ -423,11 +428,13 @@ instance PraosCrypto c => ConsensusProtocol (Praos c) where -- Updating the chain dependent state for Praos. -- -- If we are not in a new epoch, then nothing happens. If we are in a new - -- epoch, we do two things: + -- epoch, we do three things: -- - Update the epoch nonce to the combination of the candidate nonce and the -- nonce derived from the last block of the previous epoch. - -- - Update the "last block of previous epoch" nonce to the nonce derived from - -- the last applied block. + -- - Store the current epoch nonce as the "previous epoch" nonce. This is + -- needed by Peras to be able to validate slightly old certificates. + -- - Update the "last block of previous epoch" nonce to the nonce derived + -- from the last applied block. tickChainDepState PraosConfig{praosEpochInfo} lv @@ -450,7 +457,10 @@ instance PraosCrypto c => ConsensusProtocol (Praos c) where { praosStateEpochNonce = praosStateCandidateNonce st ⭒ praosStateLastEpochBlockNonce st - , praosStateLastEpochBlockNonce = praosStateLabNonce st + , praosStatePreviousEpochNonce = + praosStateEpochNonce st + , praosStateLastEpochBlockNonce = + praosStateLabNonce st } else st @@ -758,7 +768,8 @@ instance TranslateProto (TPraos c) (Praos c) where , praosStateOCertCounters = Map.mapKeysMonotonic coerce certCounters , praosStateEvolvingNonce = evolvingNonce , praosStateCandidateNonce = candidateNonce - , praosStateEpochNonce = SL.ticknStateEpochNonce csTickn + , praosStateEpochNonce = epochNonce + , praosStatePreviousEpochNonce = epochNonce -- same as current epoch nonce , praosStateLabNonce = csLabNonce , praosStateLastEpochBlockNonce = SL.ticknStatePrevHashNonce csTickn } @@ -767,6 +778,7 @@ instance TranslateProto (TPraos c) (Praos c) where tpraosStateChainDepState tpState SL.PrtclState certCounters evolvingNonce candidateNonce = csProtocol + epochNonce = SL.ticknStateEpochNonce csTickn {------------------------------------------------------------------------------- Util diff --git a/ouroboros-consensus-protocol/src/unstable-protocol-testlib/Test/Consensus/Protocol/Serialisation/Generators.hs b/ouroboros-consensus-protocol/src/unstable-protocol-testlib/Test/Consensus/Protocol/Serialisation/Generators.hs index a88e986783..3b3cf99494 100644 --- a/ouroboros-consensus-protocol/src/unstable-protocol-testlib/Test/Consensus/Protocol/Serialisation/Generators.hs +++ b/ouroboros-consensus-protocol/src/unstable-protocol-testlib/Test/Consensus/Protocol/Serialisation/Generators.hs @@ -81,3 +81,4 @@ instance Arbitrary PraosState where <*> arbitrary <*> arbitrary <*> arbitrary + <*> arbitrary