-
Notifications
You must be signed in to change notification settings - Fork 87
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
2414: Wrap Byron and Shelley in the HFC r=mrBliss a=mrBliss Closes #2407. Co-authored-by: Thomas Winant <thomas@well-typed.com>
- Loading branch information
Showing
9 changed files
with
200 additions
and
51 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
79 changes: 79 additions & 0 deletions
79
ouroboros-consensus-cardano/src/Ouroboros/Consensus/Cardano/ByronHFC.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 |
---|---|---|
@@ -0,0 +1,79 @@ | ||
{-# LANGUAGE DataKinds #-} | ||
{-# LANGUAGE FlexibleInstances #-} | ||
{-# LANGUAGE TypeApplications #-} | ||
{-# OPTIONS_GHC -Wno-orphans #-} | ||
module Ouroboros.Consensus.Cardano.ByronHFC ( | ||
ByronBlockHFC | ||
) where | ||
|
||
import qualified Data.Map.Strict as Map | ||
import Data.SOP.Strict | ||
|
||
import Ouroboros.Consensus.Block | ||
import Ouroboros.Consensus.Config | ||
import Ouroboros.Consensus.Node.NetworkProtocolVersion | ||
import Ouroboros.Consensus.Storage.ChainDB.Serialisation | ||
|
||
import Ouroboros.Consensus.HardFork.Combinator | ||
import Ouroboros.Consensus.HardFork.Combinator.Degenerate | ||
import Ouroboros.Consensus.HardFork.Combinator.Serialisation.Common | ||
|
||
import Ouroboros.Consensus.Byron.Ledger | ||
import Ouroboros.Consensus.Byron.Node () | ||
|
||
import Ouroboros.Consensus.Cardano.CanHardFork | ||
import Ouroboros.Consensus.Cardano.Node () | ||
|
||
{------------------------------------------------------------------------------- | ||
Synonym for convenience | ||
-------------------------------------------------------------------------------} | ||
|
||
-- | Byron as the single era in the hard fork combinator | ||
type ByronBlockHFC = HardForkBlock '[ByronBlock] | ||
|
||
{------------------------------------------------------------------------------- | ||
NoHardForks instance | ||
-------------------------------------------------------------------------------} | ||
|
||
instance NoHardForks ByronBlock where | ||
getEraParams cfg = | ||
byronEraParamsNeverHardForks (byronGenesisConfig (configBlock cfg)) | ||
toPartialConsensusConfig _ = id | ||
toPartialLedgerConfig _ cfg = ByronPartialLedgerConfig { | ||
byronLedgerConfig = cfg | ||
, triggerHardFork = TriggerHardForkNever | ||
} | ||
|
||
{------------------------------------------------------------------------------- | ||
SupportedNetworkProtocolVersion instance | ||
-------------------------------------------------------------------------------} | ||
|
||
-- | Forward to the ByronBlock instance. Only supports | ||
-- 'HardForkNodeToNodeDisabled', which is compatible with nodes running with | ||
-- 'ByronBlock'. | ||
instance SupportedNetworkProtocolVersion ByronBlockHFC where | ||
supportedNodeToNodeVersions _ = | ||
Map.map HardForkNodeToNodeDisabled $ | ||
supportedNodeToNodeVersions (Proxy @ByronBlock) | ||
|
||
supportedNodeToClientVersions _ = | ||
Map.map HardForkNodeToClientDisabled $ | ||
supportedNodeToClientVersions (Proxy @ByronBlock) | ||
|
||
{------------------------------------------------------------------------------- | ||
SerialiseHFC instance | ||
-------------------------------------------------------------------------------} | ||
|
||
-- | Forward to the ByronBlock instance, this means we don't add an era | ||
-- wrapper around blocks on disk. This makes sure we're compatible with the | ||
-- existing Byron blocks. | ||
instance SerialiseHFC '[ByronBlock] where | ||
encodeDiskHfcBlock (DegenCodecConfig ccfg) (DegenBlock b) = | ||
encodeDisk ccfg b | ||
decodeDiskHfcBlock (DegenCodecConfig ccfg) = | ||
fmap DegenBlock <$> decodeDisk ccfg | ||
reconstructHfcPrefixLen _ = | ||
reconstructPrefixLen (Proxy @(Header ByronBlock)) | ||
reconstructHfcNestedCtxt _ prefix blockSize = | ||
mapSomeNestedCtxt NCZ $ | ||
reconstructNestedCtxt (Proxy @(Header ByronBlock)) prefix blockSize |
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
65 changes: 65 additions & 0 deletions
65
ouroboros-consensus-cardano/src/Ouroboros/Consensus/Cardano/ShelleyHFC.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 |
---|---|---|
@@ -0,0 +1,65 @@ | ||
{-# LANGUAGE DataKinds #-} | ||
{-# LANGUAGE FlexibleInstances #-} | ||
{-# LANGUAGE ScopedTypeVariables #-} | ||
{-# LANGUAGE TypeApplications #-} | ||
{-# OPTIONS_GHC -Wno-orphans #-} | ||
module Ouroboros.Consensus.Cardano.ShelleyHFC ( | ||
ShelleyBlockHFC | ||
) where | ||
|
||
import qualified Data.Map.Strict as Map | ||
import Data.SOP.Strict | ||
|
||
import Ouroboros.Consensus.Config | ||
import Ouroboros.Consensus.Node.NetworkProtocolVersion | ||
|
||
import Ouroboros.Consensus.HardFork.Combinator | ||
import Ouroboros.Consensus.HardFork.Combinator.Serialisation.Common | ||
|
||
import Ouroboros.Consensus.Shelley.Ledger | ||
import Ouroboros.Consensus.Shelley.Node () | ||
import Ouroboros.Consensus.Shelley.Protocol | ||
|
||
import Ouroboros.Consensus.Cardano.CanHardFork | ||
import Ouroboros.Consensus.Cardano.Node () | ||
|
||
{------------------------------------------------------------------------------- | ||
Synonym for convenience | ||
-------------------------------------------------------------------------------} | ||
|
||
-- | Shelley as the single era in the hard fork combinator | ||
type ShelleyBlockHFC c = HardForkBlock '[ShelleyBlock c] | ||
|
||
{------------------------------------------------------------------------------- | ||
NoHardForks instance | ||
-------------------------------------------------------------------------------} | ||
|
||
instance TPraosCrypto c => NoHardForks (ShelleyBlock c) where | ||
getEraParams cfg = shelleyLedgerEraParams (configLedger cfg) | ||
toPartialConsensusConfig _ = tpraosParams | ||
toPartialLedgerConfig _ = ShelleyPartialLedgerConfig | ||
|
||
{------------------------------------------------------------------------------- | ||
SupportedNetworkProtocolVersion instance | ||
-------------------------------------------------------------------------------} | ||
|
||
-- | Forward to the ShelleyBlock instance. Only supports | ||
-- 'HardForkNodeToNodeDisabled', which is compatible with nodes running with | ||
-- 'ShelleyBlock'. | ||
instance TPraosCrypto c => SupportedNetworkProtocolVersion (ShelleyBlockHFC c) where | ||
supportedNodeToNodeVersions _ = | ||
Map.map HardForkNodeToNodeDisabled $ | ||
supportedNodeToNodeVersions (Proxy @(ShelleyBlock c)) | ||
|
||
supportedNodeToClientVersions _ = | ||
Map.map HardForkNodeToClientDisabled $ | ||
supportedNodeToClientVersions (Proxy @(ShelleyBlock c)) | ||
|
||
{------------------------------------------------------------------------------- | ||
SerialiseHFC instance | ||
-------------------------------------------------------------------------------} | ||
|
||
-- | Use the default implementations. This means the serialisation of blocks | ||
-- includes an era wrapper. Each block should do this from the start to be | ||
-- prepared for future hard forks without having to do any bit twiddling. | ||
instance TPraosCrypto c => SerialiseHFC '[ShelleyBlock c] where |
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 +1 @@ | ||
��D&؏o� | ||
��D&؏o |
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 +1 @@ | ||
�D&؏o� | ||
�D&؏o |
Oops, something went wrong.