Skip to content

Commit 21e5fac

Browse files
committed
ChainSel: olderThanK -> olderThanImmTip
1 parent d791dfb commit 21e5fac

File tree

4 files changed

+22
-29
lines changed
  • ouroboros-consensus-diffusion/test/consensus-test/Test/Consensus/PeerSimulator
  • ouroboros-consensus
    • src/ouroboros-consensus/Ouroboros/Consensus/Storage/ChainDB/Impl
    • test/storage-test/Test/Ouroboros/Storage/ChainDB

4 files changed

+22
-29
lines changed

ouroboros-consensus-diffusion/test/consensus-test/Test/Consensus/PeerSimulator/Trace.hs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -418,8 +418,8 @@ traceChainDBEventTestBlockWith tracer = \case
418418
trace $ "Switched to a fork; now: " ++ terseHFragment newFragment
419419
StoreButDontChange point ->
420420
trace $ "Did not select block due to LoE: " ++ terseRealPoint point
421-
IgnoreBlockOlderThanK point ->
422-
trace $ "Ignored block older than k: " ++ terseRealPoint point
421+
IgnoreBlockOlderThanImmTip point ->
422+
trace $ "Ignored block older than imm tip: " ++ terseRealPoint point
423423
ChainSelectionLoEDebug curChain (LoEEnabled loeFrag0) -> do
424424
trace $ "Current chain: " ++ terseHFragment curChain
425425
trace $ "LoE fragment: " ++ terseHFragment loeFrag0

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

Lines changed: 16 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ module Ouroboros.Consensus.Storage.ChainDB.Impl.ChainSel
1919
, triggerChainSelectionAsync
2020

2121
-- * Exported for testing purposes
22-
, olderThanK
22+
, olderThanImmTip
2323
) where
2424

2525
import Cardano.Ledger.BaseTypes (unNonZero)
@@ -404,8 +404,8 @@ chainSelSync cdb@CDB{..} (ChainSelAddBlock BlockToAdd{blockToAdd = b, ..}) = do
404404
-- We follow the steps from section "## Adding a block" in ChainDB.md
405405

406406
if
407-
| olderThanK hdr isEBB immBlockNo -> do
408-
lift $ traceWith addBlockTracer $ IgnoreBlockOlderThanK (blockRealPoint b)
407+
| olderThanImmTip hdr immBlockNo -> do
408+
lift $ traceWith addBlockTracer $ IgnoreBlockOlderThanImmTip (blockRealPoint b)
409409
lift $ deliverWrittenToDisk False
410410
| isMember (blockHash b) -> do
411411
lift $ traceWith addBlockTracer $ IgnoreBlockAlreadyInVolatileDB (blockRealPoint b)
@@ -459,31 +459,28 @@ chainSelSync cdb@CDB{..} (ChainSelAddBlock BlockToAdd{blockToAdd = b, ..}) = do
459459

460460
-- | Return 'True' when the given header should be ignored when adding it
461461
-- because it is too old, i.e., we wouldn't be able to switch to a chain
462-
-- containing the corresponding block because its block number is more than
463-
-- @k@ blocks or exactly @k@ blocks back.
462+
-- containing the corresponding block because its block number is older than
463+
-- that of the immutable tip.
464464
--
465465
-- Special case: the header corresponds to an EBB which has the same block
466-
-- number as the block @k@ blocks back (the most recent \"immutable\" block).
467-
-- As EBBs share their block number with the block before them, the EBB is not
468-
-- too old in that case and can be adopted as part of our chain.
466+
-- number as the most recent \"immutable\" block. As EBBs share their block
467+
-- number with the block before them, the EBB is not too old in that case and
468+
-- can be adopted as part of our chain.
469469
--
470470
-- This special case can occur, for example, when the VolatileDB is empty
471471
-- (because of corruption). The \"immutable\" block is then also the tip of
472472
-- the chain. If we then try to add the EBB after it, it will have the same
473473
-- block number, so we must allow it.
474-
olderThanK ::
475-
HasHeader (Header blk) =>
474+
olderThanImmTip ::
475+
GetHeader blk =>
476476
-- | Header of the block to add
477477
Header blk ->
478-
-- | Whether the block is an EBB or not
479-
IsEBB ->
480-
-- | The block number of the most recent \"immutable\" block, i.e., the
481-
-- block @k@ blocks back.
478+
-- | The block number of the most recent immutable block.
482479
WithOrigin BlockNo ->
483480
Bool
484-
olderThanK hdr isEBB immBlockNo
481+
olderThanImmTip hdr immBlockNo
485482
| NotOrigin bNo == immBlockNo
486-
, isEBB == IsEBB =
483+
, headerToIsEBB hdr == IsEBB =
487484
False
488485
| otherwise =
489486
NotOrigin bNo <= immBlockNo
@@ -594,9 +591,9 @@ chainSelectionForBlock cdb@CDB{..} blockCache hdr punish = electric $ withRegist
594591

595592
if
596593
-- The chain might have grown since we added the block such that the
597-
-- block is older than @k@.
598-
| olderThanK hdr isEBB immBlockNo -> do
599-
traceWith addBlockTracer $ IgnoreBlockOlderThanK p
594+
-- block is older than the immutable tip.
595+
| olderThanImmTip hdr immBlockNo -> do
596+
traceWith addBlockTracer $ IgnoreBlockOlderThanImmTip p
600597

601598
-- The block is invalid
602599
| Just (InvalidBlockInfo reason _) <- Map.lookup (headerHash hdr) invalid -> do
@@ -636,9 +633,6 @@ chainSelectionForBlock cdb@CDB{..} blockCache hdr punish = electric $ withRegist
636633
p :: RealPoint blk
637634
p = headerRealPoint hdr
638635

639-
isEBB :: IsEBB
640-
isEBB = headerToIsEBB hdr
641-
642636
addBlockTracer :: Tracer m (TraceAddBlockEvent blk)
643637
addBlockTracer = TraceAddBlockEvent >$< cdbTracer
644638

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

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -811,9 +811,8 @@ deriving stock instance
811811

812812
-- | Trace type for the various events that occur when adding a block.
813813
data TraceAddBlockEvent blk
814-
= -- | A block with a 'BlockNo' more than @k@ back than the current tip was
815-
-- ignored.
816-
IgnoreBlockOlderThanK (RealPoint blk)
814+
= -- | A block with a 'BlockNo' not newer than the immutable tip was ignored.
815+
IgnoreBlockOlderThanImmTip (RealPoint blk)
817816
| -- | A block that is already in the Volatile DB was ignored.
818817
IgnoreBlockAlreadyInVolatileDB (RealPoint blk)
819818
| -- | A block that is know to be invalid was ignored.

ouroboros-consensus/test/storage-test/Test/Ouroboros/Storage/ChainDB/Model.hs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -122,7 +122,7 @@ import Ouroboros.Consensus.Storage.ChainDB.API
122122
, UnknownRange (..)
123123
, validBounds
124124
)
125-
import Ouroboros.Consensus.Storage.ChainDB.Impl.ChainSel (olderThanK)
125+
import Ouroboros.Consensus.Storage.ChainDB.Impl.ChainSel (olderThanImmTip)
126126
import Ouroboros.Consensus.Storage.Common ()
127127
import Ouroboros.Consensus.Util (repeatedly)
128128
import qualified Ouroboros.Consensus.Util.AnchoredFragment as Fragment
@@ -415,7 +415,7 @@ addBlock cfg blk m
415415
ignoreBlock =
416416
-- If the block is as old as the tip of the ImmutableDB, i.e. older
417417
-- than @k@, we ignore it, as we can never switch to it.
418-
olderThanK hdr (headerToIsEBB hdr) immBlockNo
418+
olderThanImmTip hdr immBlockNo
419419
||
420420
-- If it's an invalid block we've seen before, ignore it.
421421
Map.member (blockHash blk) (invalid m)

0 commit comments

Comments
 (0)