@@ -25,8 +25,6 @@ import Data.Functor ((<&>))
25
25
import Data.Functor.Identity (Identity (.. ))
26
26
import qualified Data.Map.Strict as Map
27
27
import Data.Maybe.Strict (StrictMaybe (.. ))
28
- import Data.Set (Set )
29
- import qualified Data.Set as Set
30
28
import Ouroboros.Consensus.Block
31
29
import Ouroboros.Consensus.Config
32
30
import Ouroboros.Consensus.Storage.ChainDB.API
@@ -126,9 +124,8 @@ newFollower h registry chainType blockComponent = getEnv h $ \CDB{..} -> do
126
124
-- 'closeAllFollowers' will empty that map already.
127
125
followerState <- atomically $ readTVar varFollower
128
126
closeFollowerState followerState
129
- , fhSwitchFork = \ ipoint oldPoints ->
130
- modifyTVar varFollower $
131
- switchFork ipoint oldPoints
127
+ , fhSwitchFork = \ oldSuffix ->
128
+ modifyTVar varFollower $ switchFork oldSuffix
132
129
}
133
130
134
131
makeNewFollower ::
@@ -505,29 +502,27 @@ forward registry varFollower blockComponent CDB{..} =
505
502
writeTVar varFollower $
506
503
FollowerInImmutableDB (RollBackTo pt) immIt
507
504
return True
508
- _otherwise -> case pointToWithOriginRealPoint pt of
505
+ _otherwise -> case pt of
509
506
-- Genesis is always "in" the ImmutableDB
510
- Origin -> do
507
+ GenesisPoint -> do
511
508
join $ atomically $ updateState FollowerInit
512
509
return True
513
- NotOrigin pt' -> do
514
- inImmutableDB <- ImmutableDB. hasBlock cdbImmutableDB pt'
515
- if inImmutableDB
516
- then do
517
- immIt <-
518
- ImmutableDB. streamAfterKnownPoint
519
- cdbImmutableDB
520
- registry
521
- ((,) <$> getPoint <*> blockComponent)
522
- pt
523
- join $
524
- atomically $
525
- updateState $
526
- FollowerInImmutableDB (RollBackTo pt) immIt
527
- return True
528
- else
529
- -- The point is not in the current chain
530
- return False
510
+ BlockPoint {} ->
511
+ ImmutableDB. streamAfterPoint
512
+ cdbImmutableDB
513
+ registry
514
+ ((,) <$> getPoint <*> blockComponent)
515
+ pt
516
+ >>= \ case
517
+ Right immIt -> do
518
+ join $
519
+ atomically $
520
+ updateState $
521
+ FollowerInImmutableDB (RollBackTo pt) immIt
522
+ return True
523
+ Left _ ->
524
+ -- The point is not in the current chain
525
+ return False
531
526
532
527
-- \| Update the state of the follower to the given state. If the current
533
528
-- state is 'FollowerInImmutableDB', close the ImmutableDB iterator to avoid
@@ -547,25 +542,26 @@ forward registry varFollower blockComponent CDB{..} =
547
542
-- intersection point if it is.
548
543
switchFork ::
549
544
forall m blk b .
550
- HasHeader blk =>
551
- -- | Intersection point between the new and the old chain.
552
- Point blk ->
553
- -- | Set of points that are in the old chain and not in the
554
- -- new chain.
555
- Set (Point blk ) ->
545
+ GetHeader blk =>
546
+ -- | Suffix of the old chain anchored at the intersection with the new chain.
547
+ AnchoredFragment (Header blk ) ->
556
548
FollowerState m blk b ->
557
549
FollowerState m blk b
558
- switchFork ipoint oldPoints =
550
+ switchFork oldSuffix =
559
551
\ case
560
552
-- Roll back to the intersection point if and only if the position of the
561
553
-- follower is not in the new chain, but was part of the volatile DB. By the
562
554
-- invariant that the follower state is always in the current chain, it then
563
- -- should be in `oldPoints` .
555
+ -- should be on `oldSuffix` (ignoring the anchor) .
564
556
FollowerInMem (RollBackTo pt)
565
- | pt `Set.member` oldPoints -> FollowerInMem (RollBackTo ipoint)
557
+ | isOnOldSuffix pt -> FollowerInMem (RollBackTo ipoint)
566
558
FollowerInMem (RollForwardFrom pt)
567
- | pt `Set.member` oldPoints -> FollowerInMem (RollBackTo ipoint)
559
+ | isOnOldSuffix pt -> FollowerInMem (RollBackTo ipoint)
568
560
followerState -> followerState
561
+ where
562
+ ipoint = castPoint $ AF. anchorPoint oldSuffix
563
+
564
+ isOnOldSuffix pt = AF. pointOnFragment (castPoint pt) oldSuffix
569
565
570
566
-- | Close all open block and header 'Follower's.
571
567
closeAllFollowers ::
0 commit comments