From 1e50f0590136ad5ee1db45db020c62c4902fec4b Mon Sep 17 00:00:00 2001 From: Cerkoryn <30681834+Cerkoryn@users.noreply.github.com> Date: Tue, 3 Jun 2025 16:20:31 -0400 Subject: [PATCH 1/2] Praos: use leader VRF for tiebreaker --- .../Consensus/Shelley/Protocol/Praos.hs | 22 +++++++++++++------ 1 file changed, 15 insertions(+), 7 deletions(-) diff --git a/ouroboros-consensus-cardano/src/shelley/Ouroboros/Consensus/Shelley/Protocol/Praos.hs b/ouroboros-consensus-cardano/src/shelley/Ouroboros/Consensus/Shelley/Protocol/Praos.hs index 4d8744ed93..831b8672e2 100644 --- a/ouroboros-consensus-cardano/src/shelley/Ouroboros/Consensus/Shelley/Protocol/Praos.hs +++ b/ouroboros-consensus-cardano/src/shelley/Ouroboros/Consensus/Shelley/Protocol/Praos.hs @@ -7,7 +7,7 @@ module Ouroboros.Consensus.Shelley.Protocol.Praos (PraosEnvelopeError (..)) where import qualified Cardano.Crypto.KES as KES -import Cardano.Crypto.VRF (certifiedOutput) +import Cardano.Crypto.VRF (certifiedOutput, mkTestOutputVRF) import Cardano.Ledger.BHeaderView import Cardano.Ledger.BaseTypes (ProtVer (ProtVer), Version) import Cardano.Ledger.Keys (hashKey) @@ -26,6 +26,7 @@ import Ouroboros.Consensus.Protocol.Praos import Ouroboros.Consensus.Protocol.Praos.Common ( MaxMajorProtVer (MaxMajorProtVer) ) +import Ouroboros.Consensus.Protocol.Praos.VRF (vrfLeaderValue) import Ouroboros.Consensus.Protocol.Praos.Header ( Header (..) , HeaderBody (..) @@ -44,6 +45,8 @@ import Ouroboros.Consensus.Shelley.Protocol.Abstract , ShelleyProtocol , ShelleyProtocolHeader ) +import Cardano.Protocol.TPraos.BHeader (BoundedNatural (bvValue)) +import Data.Proxy (Proxy (..)) type instance ProtoCrypto (Praos c) = c @@ -184,12 +187,17 @@ instance PraosCrypto c => ProtocolHeaderSupportsProtocol (Praos c) where pHeaderIssuer = hbVk . headerBody pHeaderIssueNo = SL.ocertN . hbOCert . headerBody - -- This is the "unified" VRF value, prior to range extension which yields e.g. - -- the leader VRF value used for slot election. - -- - -- In the future, we might want to use a dedicated range-extended VRF value - -- here instead. - pTieBreakVRFValue = certifiedOutput . hbVrfRes . headerBody + -- Use the leader VRF value derived via range extension. + -- This mirrors the behaviour of 'TPraos', giving a slight + -- advantage to smaller pools in slot battles. + -- See https://github.com/IntersectMBO/ouroboros-network/issues/4051 + -- for the discussion around this tie breaker. + pTieBreakVRFValue = + mkTestOutputVRF + . bvValue + . vrfLeaderValue (Proxy @c) + . hbVrfRes + . headerBody instance PraosCrypto c => ProtocolHeaderSupportsLedger (Praos c) where mkHeaderView hdr@Header{headerBody} = From 3bdc3cb5311bc5ee0498e1e8218461378e08110e Mon Sep 17 00:00:00 2001 From: Cerkoryn <30681834+Cerkoryn@users.noreply.github.com> Date: Wed, 4 Jun 2025 07:04:54 -0400 Subject: [PATCH 2/2] Add LANGUAGE ScopedTypeVariables --- .../src/shelley/Ouroboros/Consensus/Shelley/Protocol/Praos.hs | 1 + 1 file changed, 1 insertion(+) diff --git a/ouroboros-consensus-cardano/src/shelley/Ouroboros/Consensus/Shelley/Protocol/Praos.hs b/ouroboros-consensus-cardano/src/shelley/Ouroboros/Consensus/Shelley/Protocol/Praos.hs index 831b8672e2..67d42db22f 100644 --- a/ouroboros-consensus-cardano/src/shelley/Ouroboros/Consensus/Shelley/Protocol/Praos.hs +++ b/ouroboros-consensus-cardano/src/shelley/Ouroboros/Consensus/Shelley/Protocol/Praos.hs @@ -1,3 +1,4 @@ +{-# LANGUAGE ScopedTypeVariables #-} {-# LANGUAGE DeriveGeneric #-} {-# LANGUAGE NamedFieldPuns #-} {-# LANGUAGE TypeApplications #-}