-
Notifications
You must be signed in to change notification settings - Fork 20
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
14 changed files
with
80 additions
and
93 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
4 changes: 4 additions & 0 deletions
4
ouroboros-consensus-protocol/changelog.d/delete-praos-translate.md
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
### Breaking | ||
|
||
- Deleted `Ouroboros.Consensus.Protocol.Praos.Translate`, moving the orphan | ||
instance to `Ouroboros.Consensus.Protocol.Translate`. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
79 changes: 0 additions & 79 deletions
79
...protocol/src/ouroboros-consensus-protocol/Ouroboros/Consensus/Protocol/Praos/Translate.hs
This file was deleted.
Oops, something went wrong.
79 changes: 76 additions & 3 deletions
79
...ensus-protocol/src/ouroboros-consensus-protocol/Ouroboros/Consensus/Protocol/Translate.hs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,22 +1,95 @@ | ||
{-# LANGUAGE AllowAmbiguousTypes #-} | ||
{-# LANGUAGE FlexibleInstances #-} | ||
{-# LANGUAGE GADTs #-} | ||
{-# LANGUAGE MultiParamTypeClasses #-} | ||
{-# LANGUAGE NamedFieldPuns #-} | ||
{-# LANGUAGE ScopedTypeVariables #-} | ||
{-# LANGUAGE TypeApplications #-} | ||
{-# LANGUAGE TypeOperators #-} | ||
|
||
module Ouroboros.Consensus.Protocol.Translate (TranslateProto (..)) where | ||
|
||
import Ouroboros.Consensus.Protocol.Abstract | ||
import Cardano.Crypto.DSIGN (VerKeyDSIGN) | ||
import Cardano.Crypto.VRF (VerKeyVRF) | ||
import qualified Cardano.Ledger.Chain as SL | ||
import Cardano.Ledger.Crypto (ADDRHASH, HASH) | ||
import qualified Cardano.Ledger.PoolDistr as SL | ||
import qualified Cardano.Protocol.TPraos.API as SL | ||
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 qualified Ouroboros.Consensus.Protocol.Abstract as Abstract | ||
import Ouroboros.Consensus.Protocol.Praos (Praos, PraosState (..)) | ||
import Ouroboros.Consensus.Protocol.Praos.Views | ||
(LedgerView (lvMaxBodySize, lvMaxHeaderSize, lvProtocolVersion)) | ||
import qualified Ouroboros.Consensus.Protocol.Praos.Views as Views | ||
import Ouroboros.Consensus.Protocol.TPraos (TPraos, | ||
TPraosState (tpraosStateChainDepState, tpraosStateLastSlot)) | ||
|
||
-- | Translate across protocols | ||
class TranslateProto protoFrom protoTo | ||
where | ||
-- | Translate the ledger view. | ||
translateLedgerView :: | ||
LedgerView protoFrom -> LedgerView protoTo | ||
Abstract.LedgerView protoFrom -> Abstract.LedgerView protoTo | ||
translateChainDepState :: | ||
ChainDepState protoFrom -> ChainDepState protoTo | ||
Abstract.ChainDepState protoFrom -> Abstract.ChainDepState protoTo | ||
|
||
-- | Degenerate instance - we may always translate from a protocol to itself. | ||
instance TranslateProto singleProto singleProto | ||
where | ||
translateLedgerView = id | ||
translateChainDepState = id | ||
|
||
{------------------------------------------------------------------------------- | ||
Translation from transitional Praos | ||
-------------------------------------------------------------------------------} | ||
|
||
-- | We can translate between TPraos and Praos, provided: | ||
-- | ||
-- - They share the same HASH algorithm | ||
-- - They share the same ADDRHASH algorithm | ||
-- - They share the same DSIGN verification keys | ||
-- - They share the same VRF verification keys | ||
instance | ||
( HASH c1 ~ HASH c2, | ||
ADDRHASH c1 ~ ADDRHASH c2, | ||
VerKeyDSIGN c1 ~ VerKeyDSIGN c2, | ||
VerKeyVRF c1 ~ VerKeyVRF c2 | ||
) => | ||
TranslateProto (TPraos c1) (Praos c2) | ||
where | ||
translateLedgerView SL.LedgerView {SL.lvPoolDistr, SL.lvChainChecks} = | ||
Views.LedgerView | ||
{ Views.lvPoolDistr = coercePoolDistr lvPoolDistr, | ||
lvMaxHeaderSize = SL.ccMaxBHSize lvChainChecks, | ||
lvMaxBodySize = SL.ccMaxBBSize lvChainChecks, | ||
lvProtocolVersion = SL.ccProtocolVersion lvChainChecks | ||
} | ||
where | ||
coercePoolDistr :: SL.PoolDistr c1 -> SL.PoolDistr c2 | ||
coercePoolDistr (SL.PoolDistr m) = | ||
SL.PoolDistr | ||
. Map.mapKeysMonotonic coerce | ||
. Map.map coerceIndividualPoolStake | ||
$ m | ||
coerceIndividualPoolStake :: SL.IndividualPoolStake c1 -> SL.IndividualPoolStake c2 | ||
coerceIndividualPoolStake (SL.IndividualPoolStake stake vrf) = | ||
SL.IndividualPoolStake stake $ coerce vrf | ||
|
||
translateChainDepState tpState = | ||
PraosState | ||
{ praosStateLastSlot = tpraosStateLastSlot tpState, | ||
praosStateOCertCounters = Map.mapKeysMonotonic coerce certCounters, | ||
praosStateEvolvingNonce = evolvingNonce, | ||
praosStateCandidateNonce = candidateNonce, | ||
praosStateEpochNonce = SL.ticknStateEpochNonce csTickn, | ||
praosStateLabNonce = csLabNonce, | ||
praosStateLastEpochBlockNonce = SL.ticknStatePrevHashNonce csTickn | ||
} | ||
where | ||
SL.ChainDepState {SL.csProtocol, SL.csTickn, SL.csLabNonce} = | ||
tpraosStateChainDepState tpState | ||
SL.PrtclState certCounters evolvingNonce candidateNonce = | ||
csProtocol |