Skip to content

Commit

Permalink
Rename SupportsHeaderValidation to BlocksSupportsHeader
Browse files Browse the repository at this point in the history
  • Loading branch information
dnadales committed Nov 27, 2024
1 parent e52c1ff commit 1b5a867
Show file tree
Hide file tree
Showing 39 changed files with 106 additions and 106 deletions.
4 changes: 2 additions & 2 deletions docs/website/contents/for-developers/AbstractProtocol.md
Original file line number Diff line number Diff line change
Expand Up @@ -169,12 +169,12 @@ Classes connected to headers and blocks:
class (StandardHash blk, Typeable blk) => HasHeader blk where -- abstract over block headers
getHeaderFields :: blk HeaderFields blk -- i.e., return three fields: slot, blockno, hash

class HasHeader (Header blk) => SupportsHeaderValidation blk where
class HasHeader (Header blk) => BlocksSupportsHeader blk where
getHeader :: blk Header blk -- extract header from the block
blockMatchesHeader :: Header blk blk Bool -- check if the header is the header of the block
headerIsEBB :: Header blk Maybe EpochNo -- when the header of an Epoch Boundary Block (EBB), ...

class (HasHeader blk, SupportsHeaderValidation blk) => GetPrevHash blk where
class (HasHeader blk, BlocksSupportsHeader blk) => GetPrevHash blk where
headerPrevHash :: Header blk ChainHash blk -- get the hash of predecessor

-- construct the two views on block 'b' required by protocol 'p'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,7 @@ instance GetHeader ByronBlock ByronBlock where
-- Which is 7 bytes, enough for up to 4294967295 bytes.
overhead = 7 {- CBOR-in-CBOR -} + 2 {- EBB tag -}

instance SupportsHeaderValidation ByronBlock where
instance BlocksSupportsHeader ByronBlock where
-- Check if a block matches its header
--
-- Note that we cannot check this for an EBB, as the EBB header doesn't
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,14 +15,14 @@
{-# LANGUAGE UndecidableSuperClasses #-}

module Ouroboros.Consensus.Shelley.Ledger.Block (
Header (..)
BlocksSupportsHeader (..)
, Header (..)
, IsShelleyBlock
, NestedCtxt_ (..)
, ShelleyBasedEra
, ShelleyBlock (..)
, ShelleyBlockLedgerEra
, ShelleyHash (..)
, SupportsHeaderValidation (..)
-- * Shelley Compatibility
, ShelleyCompatible
, mkShelleyBlock
Expand Down Expand Up @@ -173,7 +173,7 @@ instance ShelleyCompatible proto era
, shelleyHeaderHash = hdrHash
}

instance ShelleyCompatible proto era => SupportsHeaderValidation (ShelleyBlock proto era) where
instance ShelleyCompatible proto era => BlocksSupportsHeader (ShelleyBlock proto era) where
blockMatchesHeader hdr blk =
-- Compute the hash the body of the block (the transactions) and compare
-- that against the hash of the body stored in the header.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ data ByronSpecBlock = ByronSpecBlock {
deriving (Show, Eq, Generic, Serialise)

{-------------------------------------------------------------------------------
SupportsHeaderValidation
BlocksSupportsHeader
-------------------------------------------------------------------------------}

data instance Header ByronSpecBlock = ByronSpecHeader {
Expand All @@ -59,7 +59,7 @@ instance GetHeader ByronSpecBlock ByronSpecBlock where
, byronSpecHeaderHash = byronSpecBlockHash
}

instance SupportsHeaderValidation ByronSpecBlock where
instance BlocksSupportsHeader ByronSpecBlock where
-- We don't care about integrity checks, so we don't bother checking whether
-- the hashes of the body are correct
blockMatchesHeader hdr blk = blockHash hdr == blockHash blk
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ data WithLedgerState blk = WithLedgerState
, wlsStateAfter :: LedgerState blk
}

class (HasAnnTip blk, GetPrevHash blk, SupportsHeaderValidation blk, Condense (HeaderHash blk)) => HasAnalysis blk where
class (HasAnnTip blk, GetPrevHash blk, BlocksSupportsHeader blk, Condense (HeaderHash blk)) => HasAnalysis blk where

countTxOutputs :: blk -> Int
blockTxSizes :: blk -> [SizeInBytes]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -203,7 +203,7 @@ blockContextFromPrevHeader hdr =
-- current slot, ChainDB chain fragment, and ChainDB tip block number
mkCurrentBlockContext ::
forall blk.
( SupportsHeaderValidation blk
( BlocksSupportsHeader blk
, BasicEnvelopeValidation blk )
=> SlotNo
-> AnchoredFragment (Header blk)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ serve sockAddr application = withIOManager \iocp -> do
run ::
forall blk.
( GetPrevHash blk
, SupportsHeaderValidation blk
, BlocksSupportsHeader blk
, ShowProxy blk
, SupportedNetworkProtocolVersion blk
, SerialiseNodeToNodeConstraints blk
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ data GenesisNodeKernelArgs m blk = GenesisNodeKernelArgs {
-- 'ChainDB.GetLoEFragment' that will be replaced via 'setGetLoEFragment') and a
-- function to update the 'ChainDbArgs' accordingly.
mkGenesisNodeKernelArgs ::
forall m blk. (IOLike m, SupportsHeaderValidation blk, Typeable blk)
forall m blk. (IOLike m, BlocksSupportsHeader blk, Typeable blk)
=> GenesisConfig
-> m ( GenesisNodeKernelArgs m blk
, Complete ChainDbArgs m blk -> Complete ChainDbArgs m blk
Expand All @@ -115,7 +115,7 @@ mkGenesisNodeKernelArgs gcfg = do
-- | Set 'gnkaGetLoEFragment' to the actual logic for determining the current
-- LoE fragment.
setGetLoEFragment ::
forall m blk. (IOLike m, SupportsHeaderValidation blk, Typeable blk)
forall m blk. (IOLike m, BlocksSupportsHeader blk, Typeable blk)
=> STM m GSM.GsmState
-> STM m (AnchoredFragment (HeaderWithTime blk))
-- ^ The LoE fragment.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,7 @@ data instance Header BlockA = HdrA {
instance GetHeader BlockA BlockA where
getHeader = blkA_header

instance SupportsHeaderValidation BlockA where
instance BlocksSupportsHeader BlockA where
blockMatchesHeader = \_ _ -> True -- We are not interested in integrity here
headerIsEBB = const Nothing

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@ data instance Header BlockB = HdrB {
instance GetHeader BlockB BlockB where
getHeader = blkB_header

instance SupportsHeaderValidation BlockB where
instance BlocksSupportsHeader BlockB where
blockMatchesHeader = \_ _ -> True -- We are not interested in integrity here
headerIsEBB = const Nothing

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -190,7 +190,7 @@ lifecycleStart start liResources liResult = do
-- | Shut down the node by killing all its threads after extracting the
-- persistent state used to restart the node later.
lifecycleStop ::
(IOLike m, SupportsHeaderValidation blk, Typeable blk) =>
(IOLike m, BlocksSupportsHeader blk, Typeable blk) =>
LiveResources blk m ->
LiveNode blk m ->
m (LiveIntervalResult blk)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,9 @@ module Ouroboros.Consensus.Block.Abstract (
, GetPrevHash (..)
, blockPrevHash
-- * Working with headers
, BlocksSupportsHeader (..)
, GetHeader (..)
, Header
, SupportsHeaderValidation (..)
, blockIsEBB
, blockToIsEBB
, getBlockHeaderFields
Expand Down Expand Up @@ -131,7 +131,7 @@ data family Header blk :: Type
class HasHeader (Header blk) => GetHeader a blk | a -> blk where
getHeader :: a -> Header blk

class (HasHeader (Header blk), GetHeader blk blk) => SupportsHeaderValidation blk where
class (HasHeader (Header blk), GetHeader blk blk) => BlocksSupportsHeader blk where
-- | Check whether the header is the header of the block.
--
-- For example, by checking whether the hash of the body stored in the
Expand All @@ -142,13 +142,13 @@ class (HasHeader (Header blk), GetHeader blk blk) => SupportsHeaderValidation bl
-- its epoch number.
headerIsEBB :: Header blk -> Maybe EpochNo

headerToIsEBB :: SupportsHeaderValidation blk => Header blk -> IsEBB
headerToIsEBB :: BlocksSupportsHeader blk => Header blk -> IsEBB
headerToIsEBB = toIsEBB . isJust . headerIsEBB

blockIsEBB :: SupportsHeaderValidation blk => blk -> Maybe EpochNo
blockIsEBB :: BlocksSupportsHeader blk => blk -> Maybe EpochNo
blockIsEBB = headerIsEBB . getHeader

blockToIsEBB :: SupportsHeaderValidation blk => blk -> IsEBB
blockToIsEBB :: BlocksSupportsHeader blk => blk -> IsEBB
blockToIsEBB = headerToIsEBB . getHeader

type instance BlockProtocol (Header blk) = BlockProtocol blk
Expand Down Expand Up @@ -178,7 +178,7 @@ instance HasHeader blk => StandardHash (Header blk)
-- > ..
--
-- but we can't do that when we do things this way around.
getBlockHeaderFields :: SupportsHeaderValidation blk => blk -> HeaderFields blk
getBlockHeaderFields :: BlocksSupportsHeader blk => blk -> HeaderFields blk
getBlockHeaderFields = castHeaderFields . getHeaderFields . getHeader

{-------------------------------------------------------------------------------
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import Ouroboros.Consensus.Protocol.Abstract
-------------------------------------------------------------------------------}

-- | Evidence that a block supports its protocol
class ( SupportsHeaderValidation blk
class ( BlocksSupportsHeader blk
, GetPrevHash blk
, ConsensusProtocol (BlockProtocol blk)
, NoThunks (Header blk)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -237,7 +237,7 @@ evaluateGDD cfg tracer stateView = do
-- The function also yields the suffixes of the intersection of @loeFrag@ with
-- every candidate fragment.
sharedCandidatePrefix ::
(Typeable blk, SupportsHeaderValidation blk) =>
(Typeable blk, BlocksSupportsHeader blk) =>
AnchoredFragment (Header blk) ->
[(peer, AnchoredFragment (HeaderWithTime blk))] ->
(AnchoredFragment (HeaderWithTime blk), [(peer, AnchoredFragment (HeaderWithTime blk))])
Expand Down Expand Up @@ -271,7 +271,7 @@ data DensityBounds blk =
idling :: Bool
}

deriving stock instance (Show (Header blk), SupportsHeaderValidation blk) => Show (DensityBounds blk)
deriving stock instance (Show (Header blk), BlocksSupportsHeader blk) => Show (DensityBounds blk)

-- | @densityDisconnect genWin k states candidateSuffixes loeFrag@
-- yields the list of peers which are known to lose the density comparison with
Expand Down Expand Up @@ -446,7 +446,7 @@ data GDDDebugInfo peer blk =
}

deriving stock instance
( SupportsHeaderValidation blk, Show (Header blk), Show peer
( BlocksSupportsHeader blk, Show (Header blk), Show peer
) => Show (GDDDebugInfo peer blk)

data TraceGDDEvent peer blk =
Expand All @@ -456,5 +456,5 @@ data TraceGDDEvent peer blk =
TraceGDDDebug (GDDDebugInfo peer blk)

deriving stock instance
( SupportsHeaderValidation blk, Show (Header blk), Show peer
( BlocksSupportsHeader blk, Show (Header blk), Show peer
) => Show (TraceGDDEvent peer blk)
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ import Ouroboros.Consensus.TypeFamilyWrappers
import Ouroboros.Consensus.Util (ShowProxy, (.:))

{-------------------------------------------------------------------------------
SupportsHeaderValidation
BlocksSupportsHeader
-------------------------------------------------------------------------------}

newtype instance Header (HardForkBlock xs) = HardForkHeader {
Expand All @@ -57,7 +57,7 @@ instance Typeable xs => ShowProxy (Header (HardForkBlock xs)) where
instance CanHardFork xs => GetHeader (HardForkBlock xs) (HardForkBlock xs) where
getHeader = HardForkHeader . oneEraBlockHeader . getHardForkBlock

instance CanHardFork xs => SupportsHeaderValidation (HardForkBlock xs) where
instance CanHardFork xs => BlocksSupportsHeader (HardForkBlock xs) where
blockMatchesHeader = \hdr blk ->
case Match.matchNS
(getOneEraHeader (getHardForkHeader hdr))
Expand All @@ -66,7 +66,7 @@ instance CanHardFork xs => SupportsHeaderValidation (HardForkBlock xs) where
Right hdrAndBlk ->
hcollapse $ hcliftA proxySingle matchesSingle hdrAndBlk
where
matchesSingle :: SupportsHeaderValidation blk => Product Header I blk -> K Bool blk
matchesSingle :: BlocksSupportsHeader blk => Product Header I blk -> K Bool blk
matchesSingle (Pair hdr (I blk)) = K (blockMatchesHeader hdr blk)

headerIsEBB =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,7 @@ newtype instance Header (DualBlock m a) = DualHeader { dualHeaderMain :: Header
instance Bridge m a => GetHeader (DualBlock m a) (DualBlock m a) where
getHeader = DualHeader . getHeader . dualBlockMain

instance Bridge m a => SupportsHeaderValidation (DualBlock m a) where
instance Bridge m a => BlocksSupportsHeader (DualBlock m a) where
blockMatchesHeader hdr =
blockMatchesHeader (dualHeaderMain hdr) . dualBlockMain

Expand Down Expand Up @@ -221,15 +221,15 @@ instance ( NoThunks (StorageConfig m)
-- | Bridge the two ledgers
class (
-- Requirements on the main block
HasHeader m
, SupportsHeaderValidation m
, HasHeader (Header m)
, LedgerSupportsProtocol m
, HasHardForkHistory m
, LedgerSupportsMempool m
, CommonProtocolParams m
, HasTxId (GenTx m)
, Show (ApplyTxErr m)
HasHeader m
, BlocksSupportsHeader m
, HasHeader (Header m)
, LedgerSupportsProtocol m
, HasHardForkHistory m
, LedgerSupportsMempool m
, CommonProtocolParams m
, HasTxId (GenTx m)
, Show (ApplyTxErr m)

-- Requirements on the auxiliary block
-- No 'LedgerSupportsProtocol' for @a@!
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,7 @@ data PBftSelectView = PBftSelectView {
deriving anyclass (NoThunks)
deriving (ChainOrder) via SimpleChainOrder PBftSelectView

mkPBftSelectView :: SupportsHeaderValidation blk => Header blk -> PBftSelectView
mkPBftSelectView :: BlocksSupportsHeader blk => Header blk -> PBftSelectView
mkPBftSelectView hdr = PBftSelectView {
pbftSelectViewBlockNo = blockNo hdr
, pbftSelectViewIsEBB = headerToIsEBB hdr
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ copyToImmutableDB ::
( IOLike m
, ConsensusProtocol (BlockProtocol blk)
, HasHeader blk
, SupportsHeaderValidation blk
, BlocksSupportsHeader blk
, HasCallStack
)
=> ChainDbEnv m blk
Expand Down Expand Up @@ -219,7 +219,7 @@ copyAndSnapshotRunner ::
( IOLike m
, ConsensusProtocol (BlockProtocol blk)
, HasHeader blk
, SupportsHeaderValidation blk
, BlocksSupportsHeader blk
, IsLedger (LedgerState blk)
, LgrDbSerialiseConstraints blk
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ newFollower ::
forall m blk b.
( IOLike m
, HasHeader blk
, SupportsHeaderValidation blk
, BlocksSupportsHeader blk
, HasNestedContent Header blk
, EncodeDiskDep (NestedCtxt Header) blk
)
Expand Down Expand Up @@ -122,7 +122,7 @@ makeNewFollower ::
forall m blk b.
( IOLike m
, HasHeader blk
, SupportsHeaderValidation blk
, BlocksSupportsHeader blk
, HasNestedContent Header blk
, EncodeDiskDep (NestedCtxt Header) blk
)
Expand Down Expand Up @@ -200,7 +200,7 @@ instructionHelper ::
forall m blk b f.
( IOLike m
, HasHeader blk
, SupportsHeaderValidation blk
, BlocksSupportsHeader blk
, HasNestedContent Header blk
, EncodeDiskDep (NestedCtxt Header) blk
, Traversable f, Applicative f
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -378,7 +378,7 @@ computeReversePath lookupBlockInfo endHash =
-- When the suffix of the 'ChainDiff' is non-empty, @P@ will be the last point
-- in the suffix.
isReachable
:: forall blk. (HasHeader blk, SupportsHeaderValidation blk)
:: forall blk. (HasHeader blk, BlocksSupportsHeader blk)
=> LookupBlockInfo blk
-> AnchoredFragment (Header blk) -- ^ Chain fragment to connect the point to
-> RealPoint blk
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -278,15 +278,15 @@ tipToAnchor = \case
NotOrigin (Tip { tipSlotNo, tipHash, tipBlockNo }) ->
AF.Anchor tipSlotNo tipHash tipBlockNo

headerToTip :: SupportsHeaderValidation blk => Header blk -> Tip blk
headerToTip :: BlocksSupportsHeader blk => Header blk -> Tip blk
headerToTip hdr = Tip {
tipSlotNo = blockSlot hdr
, tipIsEBB = headerToIsEBB hdr
, tipBlockNo = blockNo hdr
, tipHash = blockHash hdr
}

blockToTip :: SupportsHeaderValidation blk => blk -> Tip blk
blockToTip :: BlocksSupportsHeader blk => blk -> Tip blk
blockToTip = headerToTip . getHeader

-- | newtype with an 'Ord' instance that only uses 'tipSlotNo' and 'tipIsEBB'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -227,7 +227,7 @@ openDB ::
forall m blk ans.
( IOLike m
, GetPrevHash blk
, SupportsHeaderValidation blk
, BlocksSupportsHeader blk
, ConvertRawHash blk
, ImmutableDbSerialiseConstraints blk
, HasCallStack
Expand All @@ -247,7 +247,7 @@ openDBInternal ::
forall m blk ans.
( IOLike m
, GetPrevHash blk
, SupportsHeaderValidation blk
, BlocksSupportsHeader blk
, ConvertRawHash blk
, ImmutableDbSerialiseConstraints blk
, HasCallStack
Expand Down Expand Up @@ -487,7 +487,7 @@ getBlockComponentImpl dbEnv blockComponent pt =
appendBlockImpl ::
forall m blk.
( HasHeader blk
, SupportsHeaderValidation blk
, BlocksSupportsHeader blk
, EncodeDisk blk blk
, HasBinaryBlockInfo blk
, IOLike m
Expand Down
Loading

0 comments on commit 1b5a867

Please sign in to comment.