Skip to content

Commit 1bc9135

Browse files
committed
consensus: add isDefinitelyNotInFuture to isPipelineable
1 parent aca7875 commit 1bc9135

File tree

2 files changed

+30
-3
lines changed

2 files changed

+30
-3
lines changed

ouroboros-consensus/src/Ouroboros/Consensus/Fragment/InFuture.hs

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,9 @@ data CheckInFuture m blk = CheckInFuture {
5252
-- > validatedFragment vf == af <=> null fut
5353
checkInFuture :: ValidatedFragment (Header blk) (LedgerState blk)
5454
-> m (AnchoredFragment (Header blk), [InFuture m blk])
55+
56+
, checkDefinitelyNotInFuture :: m (LedgerState blk -> SlotNo -> Bool)
57+
5558
}
5659
deriving NoThunks
5760
via OnlyCheckWhnfNamed "CheckInFuture" (CheckInFuture m blk)
@@ -124,6 +127,14 @@ reference cfg (ClockSkew clockSkew) SystemTime{..} = CheckInFuture {
124127
(hardForkSummary cfg (VF.validatedLedger validated))
125128
now
126129
(VF.validatedFragment validated)
130+
, checkDefinitelyNotInFuture = do
131+
now <- systemTimeCurrent
132+
133+
pure $ \ledgerState slot -> case HF.runQuery
134+
(HF.slotToWallclock slot)
135+
(hardForkSummary cfg ledgerState) of
136+
Left _err -> False
137+
Right (hdrTime, _) -> hdrTime < now
127138
}
128139
where
129140
checkFragment :: HF.Summary (HardForkIndices blk)
@@ -166,7 +177,8 @@ reference cfg (ClockSkew clockSkew) SystemTime{..} = CheckInFuture {
166177
-- This is useful for testing and tools such as the DB converter.
167178
dontCheck :: Monad m => CheckInFuture m blk
168179
dontCheck = CheckInFuture {
169-
checkInFuture = \validated -> return (VF.validatedFragment validated, [])
180+
checkInFuture = \validated -> return (VF.validatedFragment validated, [])
181+
, checkDefinitelyNotInFuture = return $ \_ledgerState _slot -> True
170182
}
171183

172184
-- | If by some miracle we have a function that can always tell us what the
@@ -182,6 +194,10 @@ miracle oracle clockSkew = CheckInFuture {
182194
checkInFuture = \validated -> do
183195
now <- atomically $ oracle
184196
return $ checkFragment now (VF.validatedFragment validated)
197+
, checkDefinitelyNotInFuture = do
198+
now <- atomically $ oracle
199+
200+
pure $ \_ledgerState slot -> slot <= now
185201
}
186202
where
187203
checkFragment :: SlotNo

ouroboros-consensus/src/Ouroboros/Consensus/Storage/ChainDB/Impl/ChainSel.hs

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -942,8 +942,17 @@ chainSelection chainSelEnv chainDiffs =
942942
-- the tentative followers.
943943
setTentativeHeader :: m (StrictMaybe (Header blk))
944944
setTentativeHeader = do
945+
gate <- do
946+
let ledger :: LedgerState blk
947+
ledger =
948+
ledgerState
949+
$ LgrDB.ledgerDbCurrent
950+
$ VF.validatedLedger
951+
$ curChainAndLedger
952+
f <- checkDefinitelyNotInFuture futureCheck
953+
pure $ f $ ledger
945954
mTentativeHeader <-
946-
(\ts -> isPipelineable bcfg ts candidate)
955+
(\ts -> isPipelineable bcfg ts gate candidate)
947956
<$> readTVarIO varTentativeState
948957
whenJust (strictMaybeToMaybe mTentativeHeader) $ \tentativeHeader -> do
949958
let setTentative = SetTentativeHeader tentativeHeader
@@ -1258,14 +1267,16 @@ isPipelineable ::
12581267
LedgerSupportsProtocol blk
12591268
=> BlockConfig blk
12601269
-> TentativeState blk
1270+
-> (SlotNo -> Bool)
12611271
-> ChainDiff (Header blk)
12621272
-> StrictMaybe (Header blk)
1263-
isPipelineable bcfg tentativeState ChainDiff {..}
1273+
isPipelineable bcfg tentativeState isDefinitelyNotInFuture ChainDiff {..}
12641274
| -- we apply exactly one header
12651275
AF.Empty _ :> hdr <- getSuffix
12661276
, preferToLastInvalidTentative bcfg tentativeState hdr
12671277
-- ensure that the diff is applied to the chain tip
12681278
, getRollback == 0
1279+
, isDefinitelyNotInFuture (blockSlot hdr)
12691280
= SJust hdr
12701281
| otherwise = SNothing
12711282

0 commit comments

Comments
 (0)