Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -5,16 +5,18 @@
-- TODO where to put this?
module Ouroboros.Consensus.Shelley.Ledger.TPraos () where

import Cardano.Crypto.VRF.Class (certifiedNatural)

import Ouroboros.Consensus.Block
import Ouroboros.Consensus.Protocol.Signed

import qualified Shelley.Spec.Ledger.BlockChain as SL
import qualified Shelley.Spec.Ledger.OCert as SL

import Ouroboros.Consensus.Shelley.Ledger.Block
import Ouroboros.Consensus.Shelley.Ledger.Config ()
import Ouroboros.Consensus.Shelley.Protocol

import qualified Shelley.Spec.Ledger.BlockChain as SL
import qualified Shelley.Spec.Ledger.Keys as SL
import qualified Shelley.Spec.Ledger.OCert as SL

{-------------------------------------------------------------------------------
Support for Transitional Praos consensus algorithm
-------------------------------------------------------------------------------}
Expand All @@ -24,11 +26,18 @@ type instance BlockProtocol (ShelleyBlock c) = TPraos c
instance TPraosCrypto c => BlockSupportsProtocol (ShelleyBlock c) where
validateView _cfg (ShelleyHeader hdr _) = hdr

selectView _ (ShelleyHeader hdr _) = ChainSelectView
{ csvChainLength = SL.bheaderBlockNo . SL.bhbody $ hdr
, csvIssuer = SL.bheaderVk . SL.bhbody $ hdr
, csvIssueNo = SL.ocertN . SL.bheaderOCert . SL.bhbody $ hdr
}
selectView _ (ShelleyHeader hdr _) =
ChainSelectView
{ csvChainLength = SL.bheaderBlockNo . SL.bhbody $ hdr
, csvLeaderVRF =
SL.fromNatural
. certifiedNatural
. SL.bheaderL
. SL.bhbody
$ hdr
, csvIssuer = SL.bheaderVk . SL.bhbody $ hdr
, csvIssueNo = SL.ocertN . SL.bheaderOCert . SL.bhbody $ hdr
}

-- TODO correct place for these two?
type instance Signed (Header (ShelleyBlock c)) = SL.BHBody c
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -221,18 +221,22 @@ instance TPraosCrypto c => NoUnexpectedThunks (ConsensusConfig (TPraos c))
--
-- We order between chains as follows:
-- - By chain length, with longer chains always preferred; _else_
-- - By the leader value of the chain tip, with lower values preferred; _else_
-- - If the tip of each chain was issued by the same agent, then we prefer the
-- chain whose tip has the highest ocert issue number, if one exists; _else_
-- - All chains are considered equally preferable
data TPraosChainSelectView c = ChainSelectView {
csvChainLength :: BlockNo
, csvLeaderVRF :: SL.UnitInterval
, csvIssuer :: SL.VKey 'SL.BlockIssuer c
, csvIssueNo :: Natural
} deriving (Show, Eq)

instance Crypto c => Ord (TPraosChainSelectView c) where
compare (ChainSelectView l1 i1 in1) (ChainSelectView l2 i2 in2) =
compare l1 l2 <> if i1 == i2 then compare in1 in2 else EQ
compare (ChainSelectView l1 v1 i1 in1) (ChainSelectView l2 v2 i2 in2) =
compare l1 l2
<> compare v2 v1 -- note inverted, since we prefer lower values!
<> if i1 == i2 then compare in1 in2 else EQ

instance TPraosCrypto c => ChainSelection (TPraos c) where

Expand Down