Skip to content

Commit 13c868f

Browse files
committed
Refactor: SelectView = BlockNo × TiebreakerView
1 parent b4b1749 commit 13c868f

File tree

30 files changed

+314
-285
lines changed

30 files changed

+314
-285
lines changed
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
### Patch
2+
3+
- Adapted to changes related to `SelectView`.

ouroboros-consensus-cardano/src/byron/Ouroboros/Consensus/Byron/Ledger/PBFT.hs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ instance BlockSupportsProtocol ByronBlock where
7474
where
7575
epochSlots = byronEpochSlots cfg
7676

77-
selectView _ = mkPBftSelectView
77+
tiebreakerView _ = mkPBftTiebreakerView
7878

7979
toPBftLedgerView :: Delegation.Map -> PBftLedgerView PBftByronCrypto
8080
toPBftLedgerView = PBftLedgerView . Delegation.unMap

ouroboros-consensus-cardano/src/ouroboros-consensus-cardano/Ouroboros/Consensus/Cardano/CanHardFork.hs

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,7 @@ import Ouroboros.Consensus.Protocol.PBFT.State (PBftState)
8383
import qualified Ouroboros.Consensus.Protocol.PBFT.State as PBftState
8484
import Ouroboros.Consensus.Protocol.Praos (Praos)
8585
import qualified Ouroboros.Consensus.Protocol.Praos as Praos
86+
import Ouroboros.Consensus.Protocol.Praos.Common (PraosTiebreakerView)
8687
import Ouroboros.Consensus.Protocol.TPraos
8788
import qualified Ouroboros.Consensus.Protocol.TPraos as TPraos
8889
import Ouroboros.Consensus.Shelley.HFEras ()
@@ -171,10 +172,10 @@ instance CardanoHardForkConstraints c => CanHardFork (CardanoEras c) where
171172
}
172173
hardForkChainSel =
173174
-- Byron <-> Shelley, ...
174-
TCons (SOP.hpure CompareBlockNo)
175+
TCons (SOP.hpure NoTiebreakerAcrossEras)
175176
-- Inter-Shelley-based
176177
$
177-
Tails.hcpure (Proxy @(HasPraosSelectView c)) CompareSameSelectView
178+
Tails.hcpure (Proxy @(HasPraosTiebreakerView c)) SameTiebreakerAcrossEras
178179
hardForkInjectTxs =
179180
PCons (ignoringBoth $ Pair2 cannotInjectTx cannotInjectValidatedTx)
180181
$ PCons
@@ -249,8 +250,8 @@ instance CardanoHardForkConstraints c => CanHardFork (CardanoEras c) where
249250
fromConway x = fromDijkstra $ DijkstraMeasure x
250251
fromDijkstra x = x
251252

252-
class SelectView (BlockProtocol blk) ~ PraosChainSelectView c => HasPraosSelectView c blk
253-
instance SelectView (BlockProtocol blk) ~ PraosChainSelectView c => HasPraosSelectView c blk
253+
class TiebreakerView (BlockProtocol blk) ~ PraosTiebreakerView c => HasPraosTiebreakerView c blk
254+
instance TiebreakerView (BlockProtocol blk) ~ PraosTiebreakerView c => HasPraosTiebreakerView c blk
254255

255256
{-------------------------------------------------------------------------------
256257
Translation from Byron to Shelley

ouroboros-consensus-cardano/src/shelley/Ouroboros/Consensus/Shelley/Ledger/Block.hs

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -71,11 +71,8 @@ import Ouroboros.Consensus.HardFork.Combinator
7171
)
7272
import Ouroboros.Consensus.HeaderValidation
7373
import Ouroboros.Consensus.Protocol.Abstract
74-
( ChainDepState
75-
, SelectView
76-
)
7774
import Ouroboros.Consensus.Protocol.Praos.Common
78-
( PraosChainSelectView
75+
( PraosTiebreakerView
7976
)
8077
import Ouroboros.Consensus.Protocol.Signed (SignedHeader)
8178
import Ouroboros.Consensus.Shelley.Eras
@@ -119,7 +116,7 @@ class
119116
, Show (SL.TranslationContext era)
120117
, -- Currently the chain select view is identical
121118
-- Era and proto crypto must coincide
122-
SelectView proto ~ PraosChainSelectView (ProtoCrypto proto)
119+
TiebreakerView proto ~ PraosTiebreakerView (ProtoCrypto proto)
123120
, -- Need to be able to sign the protocol header
124121
SignedHeader (ShelleyProtocolHeader proto)
125122
, -- ChainDepState needs to be serialisable

ouroboros-consensus-cardano/src/shelley/Ouroboros/Consensus/Shelley/Ledger/Protocol.hs

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,8 @@ module Ouroboros.Consensus.Shelley.Ledger.Protocol () where
1111

1212
import qualified Cardano.Ledger.Shelley.API as SL
1313
import Ouroboros.Consensus.Block
14+
import Ouroboros.Consensus.Protocol.Praos.Common
1415
import Ouroboros.Consensus.Protocol.Signed
15-
import Ouroboros.Consensus.Protocol.TPraos
1616
import Ouroboros.Consensus.Shelley.Ledger.Block
1717
import Ouroboros.Consensus.Shelley.Ledger.Config (BlockConfig (..))
1818
import Ouroboros.Consensus.Shelley.Protocol.Abstract
@@ -30,13 +30,12 @@ import Ouroboros.Consensus.Shelley.Protocol.Abstract
3030
instance ShelleyCompatible proto era => BlockSupportsProtocol (ShelleyBlock proto era) where
3131
validateView _cfg = protocolHeaderView @proto . shelleyHeaderRaw
3232

33-
selectView _ hdr@(ShelleyHeader shdr _) =
34-
PraosChainSelectView
35-
{ csvChainLength = blockNo hdr
36-
, csvSlotNo = blockSlot hdr
37-
, csvIssuer = hdrIssuer
38-
, csvIssueNo = pHeaderIssueNo shdr
39-
, csvTieBreakVRF = pTieBreakVRFValue shdr
33+
tiebreakerView _ hdr@(ShelleyHeader shdr _) =
34+
PraosTiebreakerView
35+
{ ptvSlotNo = blockSlot hdr
36+
, ptvIssuer = hdrIssuer
37+
, ptvIssueNo = pHeaderIssueNo shdr
38+
, ptvTieBreakVRF = pTieBreakVRFValue shdr
4039
}
4140
where
4241
hdrIssuer :: SL.VKey 'SL.BlockIssuer

ouroboros-consensus-cardano/src/unstable-cardano-testlib/Test/ThreadNet/Infra/ShelleyBasedHardFork.hs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -271,7 +271,7 @@ instance
271271
, translateTxOutWith = SL.upgradeTxOut
272272
}
273273

274-
hardForkChainSel = Tails.mk2 CompareSameSelectView
274+
hardForkChainSel = Tails.mk2 SameTiebreakerAcrossEras
275275

276276
hardForkInjectTxs =
277277
InPairs.mk2 $

ouroboros-consensus-cardano/test/cardano-test/Test/Consensus/Cardano/DiffusionPipelining.hs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ import Ouroboros.Consensus.Byron.Ledger (ByronBlock)
2222
import Ouroboros.Consensus.Cardano (CardanoBlock)
2323
import Ouroboros.Consensus.HardFork.Combinator
2424
import Ouroboros.Consensus.HardFork.Combinator.AcrossEras
25+
import Ouroboros.Consensus.Protocol.Abstract
2526
import Ouroboros.Consensus.Protocol.PBFT
2627
import Ouroboros.Consensus.Shelley.Eras
2728
import Ouroboros.Consensus.Shelley.Ledger
@@ -79,7 +80,7 @@ instance GenTentativeHeaderViews ByronBlock where
7980
nubOrd . sort <$> listOf do
8081
bno <- arbitrary
8182
isEBB <- toIsEBB <$> arbitrary
82-
pure $ PBftSelectView bno isEBB
83+
pure $ SelectView bno (PBftTiebreakerView isEBB)
8384

8485
instance ShelleyCompatible proto era => GenTentativeHeaderViews (ShelleyBlock proto era) where
8586
genTentativeHeaderViews _ = do

ouroboros-consensus-diffusion/test/consensus-test/Test/Consensus/HardFork/Combinator.hs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -441,7 +441,7 @@ instance CanHardFork '[BlockA, BlockB] where
441441
, translateChainDepState = PCons chainDepState_AtoB PNil
442442
, crossEraForecast = PCons forecast_AtoB PNil
443443
}
444-
hardForkChainSel = Tails.mk2 CompareBlockNo
444+
hardForkChainSel = Tails.mk2 NoTiebreakerAcrossEras
445445
hardForkInjectTxs = InPairs.mk2 injectTx_AtoB
446446

447447
hardForkInjTxMeasure = \case
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
### Breaking
2+
3+
- Removed `PraosChainSelectView`, use `SelectView (TPraos c)`/`SelectView (Praos
4+
c)` instead.

ouroboros-consensus-protocol/src/ouroboros-consensus-protocol/Ouroboros/Consensus/Protocol/Praos.hs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -392,7 +392,7 @@ instance PraosCrypto c => ConsensusProtocol (Praos c) where
392392
type ChainDepState (Praos c) = PraosState
393393
type IsLeader (Praos c) = PraosIsLeader c
394394
type CanBeLeader (Praos c) = PraosCanBeLeader c
395-
type SelectView (Praos c) = PraosChainSelectView c
395+
type TiebreakerView (Praos c) = PraosTiebreakerView c
396396
type LedgerView (Praos c) = Views.LedgerView
397397
type ValidationErr (Praos c) = PraosValidationErr c
398398
type ValidateView (Praos c) = PraosValidateView c

0 commit comments

Comments
 (0)