@@ -19,7 +19,7 @@ module Ouroboros.Consensus.Storage.ChainDB.Impl.ChainSel
19
19
, triggerChainSelectionAsync
20
20
21
21
-- * Exported for testing purposes
22
- , olderThanK
22
+ , olderThanImmTip
23
23
) where
24
24
25
25
import Cardano.Ledger.BaseTypes (unNonZero )
@@ -404,8 +404,8 @@ chainSelSync cdb@CDB{..} (ChainSelAddBlock BlockToAdd{blockToAdd = b, ..}) = do
404
404
-- We follow the steps from section "## Adding a block" in ChainDB.md
405
405
406
406
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)
409
409
lift $ deliverWrittenToDisk False
410
410
| isMember (blockHash b) -> do
411
411
lift $ traceWith addBlockTracer $ IgnoreBlockAlreadyInVolatileDB (blockRealPoint b)
@@ -459,31 +459,28 @@ chainSelSync cdb@CDB{..} (ChainSelAddBlock BlockToAdd{blockToAdd = b, ..}) = do
459
459
460
460
-- | Return 'True' when the given header should be ignored when adding it
461
461
-- 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 .
464
464
--
465
465
-- 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.
469
469
--
470
470
-- This special case can occur, for example, when the VolatileDB is empty
471
471
-- (because of corruption). The \"immutable\" block is then also the tip of
472
472
-- the chain. If we then try to add the EBB after it, it will have the same
473
473
-- block number, so we must allow it.
474
- olderThanK ::
475
- HasHeader ( Header blk ) =>
474
+ olderThanImmTip ::
475
+ GetHeader blk =>
476
476
-- | Header of the block to add
477
477
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.
482
479
WithOrigin BlockNo ->
483
480
Bool
484
- olderThanK hdr isEBB immBlockNo
481
+ olderThanImmTip hdr immBlockNo
485
482
| NotOrigin bNo == immBlockNo
486
- , isEBB == IsEBB =
483
+ , headerToIsEBB hdr == IsEBB =
487
484
False
488
485
| otherwise =
489
486
NotOrigin bNo <= immBlockNo
@@ -594,9 +591,9 @@ chainSelectionForBlock cdb@CDB{..} blockCache hdr punish = electric $ withRegist
594
591
595
592
if
596
593
-- 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
600
597
601
598
-- The block is invalid
602
599
| Just (InvalidBlockInfo reason _) <- Map. lookup (headerHash hdr) invalid -> do
@@ -636,9 +633,6 @@ chainSelectionForBlock cdb@CDB{..} blockCache hdr punish = electric $ withRegist
636
633
p :: RealPoint blk
637
634
p = headerRealPoint hdr
638
635
639
- isEBB :: IsEBB
640
- isEBB = headerToIsEBB hdr
641
-
642
636
addBlockTracer :: Tracer m (TraceAddBlockEvent blk )
643
637
addBlockTracer = TraceAddBlockEvent >$< cdbTracer
644
638
0 commit comments