@@ -64,7 +64,8 @@ import Ouroboros.Consensus.Util.STM (WithFingerprint (..))
64
64
import Ouroboros.Storage.ChainDB.API (InvalidBlockReason (.. ))
65
65
import Ouroboros.Storage.ChainDB.Impl.ImmDB (ImmDB )
66
66
import qualified Ouroboros.Storage.ChainDB.Impl.ImmDB as ImmDB
67
- import Ouroboros.Storage.ChainDB.Impl.LgrDB (LgrDB )
67
+ import Ouroboros.Storage.ChainDB.Impl.LgrDB (LgrDB ,
68
+ NewBlockInMemory (.. ))
68
69
import qualified Ouroboros.Storage.ChainDB.Impl.LgrDB as LgrDB
69
70
import qualified Ouroboros.Storage.ChainDB.Impl.Query as Query
70
71
import qualified Ouroboros.Storage.ChainDB.Impl.Reader as Reader
@@ -153,6 +154,7 @@ initialChainSelection immDB volDB lgrDB tracer cfg varInvalid curSlot = do
153
154
(contramap (TraceInitChainSelEvent . InitChainSelValidation ) tracer)
154
155
cfg
155
156
varInvalid
157
+ NoNewBlockInMemory
156
158
curChainAndLedger
157
159
(fmap (mkCandidateSuffix 0 ) candidates)
158
160
@@ -206,7 +208,7 @@ addBlock cdb@CDB{..} b = do
206
208
| otherwise -> do
207
209
VolDB. putBlock cdbVolDB b
208
210
trace $ AddedBlockToVolDB (blockPoint b) (blockNo b) (toIsEBB (cdbIsEBB b))
209
- chainSelectionForBlock cdb (getHeader b)
211
+ chainSelectionForBlock cdb (Right b)
210
212
where
211
213
trace :: TraceAddBlockEvent blk -> m ()
212
214
trace = traceWith (contramap TraceAddBlockEvent cdbTracer)
@@ -265,9 +267,11 @@ chainSelectionForBlock
265
267
, HasCallStack
266
268
)
267
269
=> ChainDbEnv m blk
268
- -> Header blk
270
+ -> Either (Header blk ) blk
271
+ -- ^ @'Header' blk@ in case the block is no longer in memory, @blk@ in
272
+ -- case it still is.
269
273
-> m ()
270
- chainSelectionForBlock cdb@ CDB {.. } hdr = do
274
+ chainSelectionForBlock cdb@ CDB {.. } hdrOrBlk = do
271
275
curSlot <- atomically $ getCurrentSlot cdbBlockchainTime
272
276
273
277
(invalid, isMember, succsOf, predecessor, curChain, tipPoint, ledgerDB, immBlockNo)
@@ -328,6 +332,9 @@ chainSelectionForBlock cdb@CDB{..} hdr = do
328
332
where
329
333
secParam@ (SecurityParam k) = protocolSecurityParam cdbNodeConfig
330
334
335
+ hdr :: Header blk
336
+ hdr = either id getHeader hdrOrBlk
337
+
331
338
p :: Point blk
332
339
p = headerPoint hdr
333
340
@@ -445,6 +452,7 @@ chainSelectionForBlock cdb@CDB{..} hdr = do
445
452
(contramap (TraceAddBlockEvent . AddBlockValidation ) cdbTracer)
446
453
cdbNodeConfig
447
454
cdbInvalid
455
+ (either (const NoNewBlockInMemory ) NewBlockInMemory hdrOrBlk)
448
456
449
457
-- | Try to swap the current (chain) fragment with the given candidate
450
458
-- fragment. The 'LgrDB.LedgerDB' is updated in the same transaction.
@@ -608,13 +616,14 @@ chainSelection
608
616
-> Tracer m (TraceValidationEvent blk )
609
617
-> NodeConfig (BlockProtocol blk )
610
618
-> StrictTVar m (WithFingerprint (InvalidBlocks blk ))
619
+ -> NewBlockInMemory blk
611
620
-> ChainAndLedger blk -- ^ The current chain and ledger
612
621
-> NonEmpty (CandidateSuffix blk ) -- ^ Candidates
613
622
-> m (Maybe (ChainAndLedger blk ))
614
623
-- ^ The (valid) chain and corresponding LedgerDB that was selected, or
615
624
-- 'Nothing' if there is no valid chain preferred over the current
616
625
-- chain.
617
- chainSelection lgrDB tracer cfg varInvalid
626
+ chainSelection lgrDB tracer cfg varInvalid newBlockInMemory
618
627
curChainAndLedger@ (ChainAndLedger curChain _) candidates =
619
628
assert (all (preferAnchoredCandidate cfg curChain . _suffix) candidates) $
620
629
assert (all (isJust . fitCandidateSuffixOn curChain) candidates) $
@@ -627,7 +636,7 @@ chainSelection lgrDB tracer cfg varInvalid
627
636
validate :: ChainAndLedger blk -- ^ Current chain and ledger
628
637
-> CandidateSuffix blk -- ^ Candidate fragment
629
638
-> m (Maybe (ChainAndLedger blk ))
630
- validate = validateCandidate lgrDB tracer cfg varInvalid
639
+ validate = validateCandidate lgrDB tracer cfg varInvalid newBlockInMemory
631
640
632
641
-- 1. Take the first candidate from the list of sorted candidates
633
642
-- 2. Validate it
@@ -719,12 +728,13 @@ validateCandidate
719
728
-> Tracer m (TraceValidationEvent blk )
720
729
-> NodeConfig (BlockProtocol blk )
721
730
-> StrictTVar m (WithFingerprint (InvalidBlocks blk ))
731
+ -> NewBlockInMemory blk
722
732
-> ChainAndLedger blk -- ^ Current chain and ledger
723
733
-> CandidateSuffix blk -- ^ Candidate fragment
724
734
-> m (Maybe (ChainAndLedger blk ))
725
- validateCandidate lgrDB tracer cfg varInvalid
735
+ validateCandidate lgrDB tracer cfg varInvalid newBlockInMemory
726
736
(ChainAndLedger curChain curLedger) candSuffix =
727
- LgrDB. validate lgrDB curLedger rollback newBlocks >>= \ case
737
+ LgrDB. validate lgrDB curLedger newBlockInMemory rollback newBlocks >>= \ case
728
738
LgrDB. MaximumRollbackExceeded supported _ -> do
729
739
trace $ CandidateExceedsRollback {
730
740
_supportedRollback = supported
0 commit comments