Skip to content

Commit 39e7aa4

Browse files
committed
Clairify LedgerPeersConsensusInterface.
- Rename getBlockHash to getImmutableBlockPoint. - The callback in getImmutableBlockPoint now has a dedicated GetImmutableBlockPointError error type.
1 parent 0e84bce commit 39e7aa4

6 files changed

Lines changed: 50 additions & 8 deletions

File tree

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
<!--
2+
A new scriv changelog fragment.
3+
4+
Uncomment the section that is right (remove the HTML comment wrapper).
5+
For top level release notes, leave all the headers commented out.
6+
-->
7+
8+
9+
### Breaking
10+
11+
- Rename `getBlockHash` to `getImmutableBlockPoint` to better reflect that it queries the immutable DB and returns a `Point`.
12+
- Change the return type of `getBlockHash` (renamed to `getImmutableBlockPoint`) from `Maybe (Point RawBlockHash)` to `Either GetImmutableBlockPointError (Point RawBlockHash)`, replacing an opaque `Nothing` with structured error information.
13+
14+
<!--
15+
### Non-Breaking
16+
17+
- A bullet item for the Non-Breaking category.
18+
19+
-->
20+
<!--
21+
### Patch
22+
23+
- A bullet item for the Patch category.
24+
25+
-->

cardano-diffusion/lib/Cardano/Network/LedgerPeerConsensusInterface.hs

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
module Cardano.Network.LedgerPeerConsensusInterface
44
( LedgerPeersConsensusInterface (..)
5+
, GetImmutableBlockPointError (..)
56
-- * Re-exports
67
, FetchMode (..)
78
, LedgerStateJudgement (..)
@@ -18,6 +19,20 @@ import Ouroboros.Network.BlockFetch.ConsensusInterface (FetchMode (..))
1819
import Ouroboros.Network.PeerSelection.LedgerPeers.Type (RawBlockHash)
1920

2021

22+
-- | Error returned by 'getImmutableBlockPoint'.
23+
--
24+
data GetImmutableBlockPointError
25+
= -- | Genesis point was provided as the target, which has no slot or hash
26+
-- to look up.
27+
ImmutableBlockPointGenesisPoint
28+
| -- | The block was not found in ImmutableDB because the target slot
29+
-- is not yet immutable.
30+
ImmutableBlockPointNotYetImmutable
31+
| -- | ImmutableDB is empty (tip is at origin).
32+
ImmutableBlockPointTipIsOrigin
33+
deriving (Show, Eq)
34+
35+
2136
-- | Cardano Node specific consensus interface actions.
2237
--
2338
data LedgerPeersConsensusInterface m =
@@ -39,6 +54,8 @@ data LedgerPeersConsensusInterface m =
3954
-- | Ask the Consensus layer's immutable DB for a point. The callback will yield either:
4055
-- - the block at the target slot if there is a block in the immutable DB at that slot;
4156
-- - or the block from the next occupied slot.
42-
, getBlockHash
43-
:: forall r. Point RawBlockHash -> (m (Maybe (Point RawBlockHash)) -> m r) -> m r
57+
, getImmutableBlockPoint
58+
:: forall r. Point RawBlockHash
59+
-> (m (Either GetImmutableBlockPointError (Point RawBlockHash)) -> m r)
60+
-> m r
4461
}

cardano-diffusion/lib/Cardano/Network/PeerSelection/Governor/Monitor.hs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -691,7 +691,7 @@ jobVerifyPeerSnapshot :: MonadSTM m
691691
-> Cardano.LedgerPeersConsensusInterface m
692692
-> Job () m (Completion m extraState extraDebugState extraFlags extraPeers peeraddr peerconn)
693693
jobVerifyPeerSnapshot (slotNo, fileHash)
694-
Cardano.LedgerPeersConsensusInterface { getBlockHash }
694+
Cardano.LedgerPeersConsensusInterface { getImmutableBlockPoint }
695695
= Job job (const (completion False)) () "jobVerifyPeerSnapshot"
696696
where
697697
completion result = return . Completion $ \st _now ->
@@ -700,9 +700,9 @@ jobVerifyPeerSnapshot (slotNo, fileHash)
700700
decisionState = st,
701701
decisionJobs = [] }
702702

703-
job = getBlockHash (BlockPoint slotNo fileHash) $ \promise -> do
703+
job = getImmutableBlockPoint (BlockPoint slotNo fileHash) $ \promise -> do
704704
waited <- promise
705705
case waited of
706-
Just (BlockPoint { withHash }) -> do
706+
Right (BlockPoint { withHash }) -> do
707707
completion $ fileHash == withHash
708708
_otherwise -> completion False

cardano-diffusion/tests/lib/Test/Cardano/Network/Diffusion/Testnet/Simulation.hs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1273,7 +1273,7 @@ diffusionSimulationM
12731273
Cardano.LedgerPeersConsensusInterface {
12741274
Cardano.readFetchMode = pure (PraosFetchMode FetchModeDeadline)
12751275
, Cardano.getLedgerStateJudgement = pure TooOld
1276-
, Cardano.getBlockHash = error "getBlockHash not implemented"
1276+
, Cardano.getImmutableBlockPoint = error "getImmutableBlockPoint not implemented"
12771277
, Cardano.updateOutboundConnectionsState =
12781278
\a -> do
12791279
a' <- readTVar onlyOutboundConnectionsStateVar

cardano-diffusion/tests/lib/Test/Cardano/Network/PeerSelection.hs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4324,7 +4324,7 @@ _governorFindingPublicRoots targetNumberOfRootPeers readDomains readUseBootstrap
43244324
lpExtraAPI = Cardano.LedgerPeersConsensusInterface {
43254325
readFetchMode = pure (PraosFetchMode FetchModeDeadline),
43264326
getLedgerStateJudgement = readLedgerStateJudgement,
4327-
getBlockHash = error "getBlockHash not implemented",
4327+
getImmutableBlockPoint = error "getImmutableBlockPoint not implemented",
43284328
updateOutboundConnectionsState = \a -> do
43294329
a' <- readTVar olocVar
43304330
when (a /= a') $

cardano-diffusion/tests/lib/Test/Cardano/Network/PeerSelection/MockEnvironment.hs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -486,7 +486,7 @@ mockPeerSelectionActions' tracer
486486
lpExtraAPI = Cardano.LedgerPeersConsensusInterface {
487487
readFetchMode = pure (PraosFetchMode FetchModeDeadline),
488488
getLedgerStateJudgement = readLedgerStateJudgement,
489-
getBlockHash = error "getBlockHash not implemented",
489+
getImmutableBlockPoint = error "getImmutableBlockPoint not implemented",
490490
updateOutboundConnectionsState = \a -> do
491491
a' <- readTVar outboundConnectionsStateVar
492492
when (a /= a') $

0 commit comments

Comments
 (0)