Skip to content

Commit

Permalink
HACK for translating ChainDepStates: set tip slot to bound slot
Browse files Browse the repository at this point in the history
This prevents nonce mixing happening twice at era boundaries.

This should also be done for PBft I think, but it doesn't seem to be strictly necessary.
  • Loading branch information
amesgen committed Sep 12, 2023
1 parent 20d850e commit bf6c179
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -291,11 +291,11 @@ translateChainDepStateAcrossShelley ::
(ShelleyBlock protoTo eraTo)
translateChainDepStateAcrossShelley =
ignoringBoth $
Translate $ \_bound (Comp (WrapTickedChainDepState chainDepState)) ->
Translate $ \bound (Comp (WrapTickedChainDepState chainDepState)) ->
-- Same protocol, same 'ChainDepState'. Note that we don't have to apply
-- any changes related to an epoch transition, this is already done when
-- ticking the state.
WrapChainDepState $ Proto.translateChainDepState @protoFrom @protoTo chainDepState
WrapChainDepState $ Proto.translateChainDepState @protoFrom @protoTo (boundSlot bound) chainDepState

crossEraForecastAcrossShelley ::
forall eraFrom eraTo protoFrom protoTo.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -231,6 +231,7 @@ fromShelleyLedgerExamplesPraos ShelleyLedgerExamples {
, shelleyLedgerTransition = ShelleyTransitionInfo {shelleyAfterVoting = 0}
}
chainDepState = translateChainDepState @(TPraos (EraCrypto era)) @(Praos (EraCrypto era))
1
TPraos.TickedChainDepState {
TPraos.tickedTPraosStateChainDepState = \_lvExtraEntropy -> sleChainDepState
, TPraos.untickedTPraosStateLastSlot = NotOrigin 1
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ import qualified Cardano.Protocol.TPraos.Rules.Prtcl as SL
import qualified Cardano.Protocol.TPraos.Rules.Tickn as SL
import Data.Coerce (coerce)
import qualified Data.Map.Strict as Map
import Ouroboros.Consensus.Block
import Ouroboros.Consensus.Protocol.Praos (ConsensusConfig (..),
Praos, PraosParams (..), PraosState (..),
Ticked (TickedPraosLedgerView),
Expand All @@ -37,16 +38,17 @@ import Ouroboros.Consensus.Protocol.Translate (TranslateProto (..))
instance (c1 ~ c2) => TranslateProto (TPraos c1) (TPraos c2) where
translateConsensusConfig = id
translateTickedLedgerView = id
translateChainDepState x = TPraos.TPraosState {
TPraos.tpraosStateLastSlot = TPraos.untickedTPraosStateLastSlot x
translateChainDepState transSlot x = TPraos.TPraosState {
TPraos.tpraosStateLastSlot = NotOrigin transSlot
, TPraos.tpraosStateChainDepState =
TPraos.tickedTPraosStateChainDepState x SL.NeutralNonce -- TODO comment justifying NeutralNonce
}

instance (c1 ~ c2) => TranslateProto (Praos c1) (Praos c2) where
translateConsensusConfig = id
translateTickedLedgerView = id
translateChainDepState = tickedPraosStateChainDepState
translateChainDepState transSlot x =
(tickedPraosStateChainDepState x) { praosStateLastSlot = NotOrigin transSlot }

-- | We can translate between TPraos and Praos, provided:
--
Expand Down Expand Up @@ -100,9 +102,9 @@ instance
coerceIndividualPoolStake (SL.IndividualPoolStake stake vrf) =
SL.IndividualPoolStake stake $ coerce vrf

translateChainDepState tpState =
translateChainDepState transSlot tpState =
PraosState
{ praosStateLastSlot = TPraos.untickedTPraosStateLastSlot tpState,
{ praosStateLastSlot = NotOrigin transSlot,
praosStateOCertCounters = Map.mapKeysMonotonic coerce certCounters,
praosStateEvolvingNonce = evolvingNonce,
praosStateCandidateNonce = candidateNonce,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

module Ouroboros.Consensus.Protocol.Translate (TranslateProto (..)) where

import Ouroboros.Consensus.Block
import Ouroboros.Consensus.Protocol.Abstract
import Ouroboros.Consensus.Ticked (Ticked)

Expand All @@ -16,4 +17,4 @@ class TranslateProto protoFrom protoTo
translateTickedLedgerView ::
Ticked (LedgerView protoFrom) -> Ticked (LedgerView protoTo)
translateChainDepState ::
Ticked (ChainDepState protoFrom) -> ChainDepState protoTo
SlotNo -> Ticked (ChainDepState protoFrom) -> ChainDepState protoTo

0 comments on commit bf6c179

Please sign in to comment.